// AddValidator add validator to resource, it will invoked when creating, updating, and will rollback the change if validator return any error
199385
func (res *Resource) AddValidator(validator *Validator) {
	for idx, v := range res.Validators {
		if v.Name == validator.Name {
			res.Validators[idx] = validator
			return
		}
	}

	res.Validators = append(res.Validators, validator)
}
257327
func (e *manualEnviron) ConstraintsValidator(ctx context.ProviderCallContext) (constraints.Validator, error) {
	validator := constraints.NewValidator()
	validator.RegisterUnsupported(unsupportedConstraints)
	if isRunningController() {
		validator.UpdateVocabulary(constraints.Arch, []string{arch.HostArch()})
	} else {
		// We're running outside of the Juju controller, so we must
		// SSH to the machine and detect its architecture.
		hw, _, err := e.seriesAndHardwareCharacteristics()
		if err != nil {
			return nil, errors.Trace(err)
		}
		validator.UpdateVocabulary(constraints.Arch, []string{*hw.Arch})
	}
	return validator, nil
}
740907
func (e *environ) ConstraintsValidator(ctx context.ProviderCallContext) (constraints.Validator, error) {
	validator := constraints.NewValidator()
	validator.RegisterConflicts(
		[]string{constraints.InstanceType},
		[]string{constraints.Mem, constraints.Cores, constraints.CpuPower})
	validator.RegisterUnsupported(unsupportedConstraints)
	instanceTypes, err := e.supportedInstanceTypes(ctx)
	if err != nil {
		return nil, errors.Trace(err)
	}
	instTypeNames := make([]string, len(instanceTypes))
	for i, itype := range instanceTypes {
		instTypeNames[i] = itype.Name
	}
	validator.RegisterVocabulary(constraints.InstanceType, instTypeNames)
	return validator, nil
}
945776
func (r *RollingUpdateInstanceGroup) ValidateCluster(rollingUpdateData *RollingUpdateCluster, cluster *api.Cluster, instanceGroupList *api.InstanceGroupList) error {
	if _, err := validation.ValidateCluster(cluster, instanceGroupList, rollingUpdateData.K8sClient); err != nil {
		return fmt.Errorf("cluster %q did not pass validation: %v", cluster.Name, err)
	}

	return nil

}
1220351
func (env *environ) ConstraintsValidator(ctx context.ProviderCallContext) (constraints.Validator, error) {
	validator := constraints.NewValidator()
	validator.RegisterUnsupported(unsupportedConstraints)
	validator.RegisterVocabulary(constraints.Arch, []string{
		arch.AMD64, arch.I386,
	})
	return validator, nil
}
758560
func RecordValidator(ps peerstore.Peerstore) record.Validator {
	return record.NamespacedValidator{
		"pk":   record.PublicKeyValidator{},
		"ipns": ipns.Validator{KeyBook: ps},
	}
}
677629
func NewValidationAssertion() (Assertion, Failures) {
	vf := &validationFailer{
		offset:  2,
		details: []FailureDetail{},
		errs:    []error{},
	}
	return NewAssertion(vf), vf
}
706722
func AddLabelToSelector(selector *metav1.LabelSelector, labelKey, labelValue string) *metav1.LabelSelector {
	if labelKey == "" {
		// Don't need to add a label.
		return selector
	}
	if selector.MatchLabels == nil {
		selector.MatchLabels = make(map[string]string)
	}
	selector.MatchLabels[labelKey] = labelValue
	return selector
}
413915
func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain, engine consensus.Engine) *BlockValidator {
	validator := &BlockValidator{
		config: config,
		engine: engine,
		bc:     blockchain,
	}
	return validator
}
301393
func (form FormImpl) AddEventHandler(evt string, f HandlerFunc) Form {
	if form.trans == nil {
		form.trans = map[string]HandlerFunc{}
	}
	form.trans[evt] = f
	return form
}
632656
func GetValidator(name string, args interface{}) (FieldValidatorFunc, error) {
	switch name {
	case `one-of`:
		if typeutil.IsArray(args) {
			return ValidateIsOneOf(sliceutil.Sliceify(args)...), nil
		} else {
			return nil, fmt.Errorf("Must specify an array of values for validator 'one-of'")
		}

	case `not-zero`:
		return ValidateNonZero, nil

	case `not-empty`:
		return ValidateNotEmpty, nil

	case `positive-integer`:
		return ValidatePositiveInteger, nil

	case `positive-or-zero-integer`:
		return ValidatePositiveOrZeroInteger, nil

	case `url`:
		return ValidateIsURL, nil

	case `match`, `match-all`:
		if typeutil.IsArray(args) {
			return ValidateMatchAll(sliceutil.Stringify(args)...), nil
		} else {
			return nil, fmt.Errorf("Must specify an array of values for validator 'match'")
		}

	case `match-any`:
		if typeutil.IsArray(args) {
			return ValidateMatchAny(sliceutil.Stringify(args)...), nil
		} else {
			return nil, fmt.Errorf("Must specify an array of values for validator 'match-any'")
		}

	default:
		return nil, fmt.Errorf("Unknown validator %q", name)
	}
}
1313315
func (p *ProviderAggregator) AddProvider(provider provider.Provider) error {
	err := provider.Init()
	if err != nil {
		return err
	}

	if fileProvider, ok := provider.(*file.Provider); ok {
		p.fileProvider = fileProvider
	} else {
		p.providers = append(p.providers, provider)
	}
	return nil
}
351131
func (a customResourceStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
	return a.validator.ValidateUpdate(ctx, obj, old, a.scale)
}
1061063
func MinValidator(param string, v reflect.Value) (ValidationResult, error) {
	switch v.Kind() {
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		pInt, err := strconv.ParseInt(param, 0, 64)
		if err != nil {
			return 0, ErrInvalidConfigValue
		}
		if v.Int() < pInt {
			return ValidationNG, nil
		}
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
		pUint, err := strconv.ParseUint(param, 0, 64)
		if err != nil {
			return 0, ErrInvalidConfigValue
		}
		if v.Uint() < pUint {
			return ValidationNG, nil
		}
	case reflect.Float32, reflect.Float64:
		pFloat, err := strconv.ParseFloat(param, 64)
		if err != nil {
			return 0, ErrInvalidConfigValue
		}
		if v.Float() < pFloat {
			return ValidationNG, nil
		}
	default:
		return 0, ErrValidateUnsupportedType
	}

	return ValidationOK, nil
}
96085
func DefaultValidator(param string, v reflect.Value) (ValidationResult, error) {
	switch v.Kind() {
	case reflect.String:
		if !v.CanAddr() {
			return ValidationNG, nil
		}
		if v.String() == "" {
			v.SetString(param)
		}
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		if !v.CanAddr() {
			return ValidationNG, nil
		}
		pInt, err := strconv.ParseInt(param, 0, 64)
		if err != nil {
			return ValidationNG, nil
		}
		if v.Int() == 0 {
			v.SetInt(pInt)
		}
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
		if !v.CanAddr() {
			return ValidationNG, nil
		}
		pUint, err := strconv.ParseUint(param, 0, 64)
		if err != nil {
			return ValidationNG, nil
		}
		if v.Uint() == 0 {
			v.SetUint(pUint)
		}
	case reflect.Float32, reflect.Float64:
		if !v.CanAddr() {
			return ValidationNG, nil
		}
		pFloat, err := strconv.ParseFloat(param, 64)
		if err != nil {
			return ValidationNG, nil
		}
		if v.Float() == 0 {
			v.SetFloat(pFloat)
		}
	default:
		return 0, ErrValidateUnsupportedType
	}

	return ValidationOK, nil
}
1027105
func NewValidatorWithOpts(options Options) *Validator {
	if options.MinLength <= 0 {
		options.MinLength = 8
	}
	if options.MinDiff <= 0 {
		options.MinDiff = 5
	}
	if options.MinDist < 0 {
		options.MinDist = 3
	}

	return &Validator{
		options:     options,
		words:       make(map[string]struct{}),
		hashedWords: make(map[string]string),
	}
}
1072104
func (v *ValidationError) Add(err error) {
	if err != nil {
		v.Errors = append(v.Errors, err)
	}
}