// validateNonZero implements the `nonzero` validation tag.
// If nonzero is set, the validator is only run if field is present in config.
// It checks for numbers and durations to be != 0, and for strings/arrays/slices
// not being empty.
764479
func validateNonZero(v interface{}, name string) error {
	if v == nil {
		return nil
	}

	if d, ok := v.(time.Duration); ok {
		if d == 0 {
			return ErrZeroValue
		}
		return nil
	}

	val := reflect.ValueOf(v)
	switch val.Kind() {
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		if val.Int() != 0 {
			return nil
		}
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
		if val.Uint() != 0 {
			return nil
		}
	case reflect.Float32, reflect.Float64:
		if val.Float() != 0 {
			return nil
		}
	default:
		return validateNonEmpty(v, name)
	}

	return ErrZeroValue
}
251778
func (t TimeRange) IsZero() bool {
	return t.Min.IsZero() && t.Max.IsZero()
}
1176983
func IsZero(obj interface{}) bool {
	if obj == nil || obj == "" || obj == false {
		return true
	}

	for _, v := range numericZeros {
		if obj == v {
			return true
		}
	}

	return reflect.DeepEqual(obj, ZeroOf(obj))
}
993062
func (c *EnumConstraint) Validate(v interface{}) (err error) {
	if pdebug.Enabled {
		g := pdebug.Marker("EnumConstraint.Validate (%s)", v).BindError(&err)
		defer g.End()
	}
	for _, e := range c.enums {
		if e == v {
			return nil
		}
	}
	return errors.New("value is not in enumeration")
}
674501
func (mv *Validator) Valid(val interface{}, tags string) error {
	if tags == "-" {
		return nil
	}
	v := reflect.ValueOf(val)
	if v.Kind() == reflect.Ptr && !v.IsNil() {
		return mv.Valid(v.Elem().Interface(), tags)
	}
	var err error
	switch v.Kind() {
	case reflect.Struct:
		return ErrUnsupported
	case reflect.Invalid:
		err = mv.validateVar(nil, tags)
	default:
		err = mv.validateVar(val, tags)
	}
	return err
}
159843
func ValidateNonnegativeField(value int64, fldPath *field.Path) field.ErrorList {
	allErrs := field.ErrorList{}
	if value < 0 {
		allErrs = append(allErrs, field.Invalid(fldPath, value, IsNegativeErrorMsg))
	}
	return allErrs
}
1166421
func (c Flags) Validate() error {
	var notFilled []string
	for _, v := range c {
		// if no value given (nil) for required flag then it is not valid
		isRequired := v.Default == nil
		val := reflect.ValueOf(v.Value).Elem().String()
		if isRequired && val == "" {
			notFilled = append(notFilled, v.Name)
		}
	}

	if len(notFilled) > 0 {
		if len(notFilled) == 1 {
			return errFlagMissing.Format(notFilled[0])
		}
		return errFlagMissing.Format(strings.Join(notFilled, ","))

	}
	return nil

}
1036349
func (jfo *JobFindOptions) IsValid() bool {
	s := structs.New(jfo)
	f := s.Fields()

	nonZeroValues := 0

	for _, field := range f {
		if !field.IsZero() {
			nonZeroValues += 1
		}
	}

	return nonZeroValues == 0 || nonZeroValues == 1
}
692895
func isZeros(a Address) bool {
	for i := 0; i < len(a); i++ {
		if a[i] != 0 {
			return false
		}
	}
	return true
}
504104
func isZero(rv reflect.Value) bool {
	zero := true
	switch rv.Kind() {
	case reflect.Bool:
		zero = !rv.Bool()
	case reflect.Float32, reflect.Float64:
		zero = rv.Float() == 0
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		zero = rv.Int() == 0
	case reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
		zero = rv.IsNil()
	case reflect.String:
		zero = rv.String() == ""
	case reflect.Uint, reflect.Uintptr, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
		zero = rv.Uint() == 0
	}

	return zero
}
498122
func onlyZeros(array []uint) bool {
	for _, num := range array {
		if num != 0 {
			return false
		}
	}
	return true
}
736408
func isNonZero(v *Version) bool {
	if v.Major() != 0 || v.Minor() != 0 || v.Patch() != 0 || v.Prerelease() != "" {
		return true
	}

	return false
}
746417
func (d *FieldData) GetDefaultOrZero(k string) interface{} {
	schema, ok := d.Schema[k]
	if !ok {
		panic(fmt.Sprintf("field %s not in the schema", k))
	}

	return schema.DefaultOrZero()
}
107041
func isZero(v reflect.Value) bool {
	zero := reflect.Zero(v.Type()).Interface()
	value := v.Interface()
	return reflect.DeepEqual(value, zero)
}
952529
func (a *Duration) IsZero() bool {
	for i := range a.Node.Values {
		if a.Node.Values[i].Magnitude != 0 {
			return false
		}
	}
	return true
}
19711
func (a *Amount) Validate(c *validation.Context) {
	if a.GetDefault() < 0 {
		c.Errorf("default amount must be non-negative")
	}
	// The algorithm works with any time 7 days greater than the zero time.
	now := time.Date(2018, 1, 1, 12, 0, 0, 0, time.UTC)
	schs := make([]indexedSchedule, len(a.GetChange()))
	for i, s := range a.GetChange() {
		c.Enter("change %d", i)
		s.Validate(c)
		c.Exit()
		t, err := s.mostRecentStart(now)
		if err != nil {
			// s.Validate(c) already emitted this error.
			return
		}
		schs[i] = indexedSchedule{
			Schedule: s,
			index:    i,
			sortKey:  t,
		}
	}
	sort.Slice(schs, func(i, j int) bool { return schs[i].sortKey.Before(schs[j].sortKey) })
	prevEnd := time.Time{}
	for i := 0; i < len(schs); i++ {
		c.Enter("change %d", schs[i].index)
		start := schs[i].sortKey
		if schs[i].sortKey.Before(prevEnd) {
			// Implies intervals are half-open: [start, end). prevEnd
			// is initialized to the zero time, therefore this can't
			// succeed when i is 0, meaning i-1 is never -1.
			c.Errorf("start time is before change %d", schs[i-1].index)
		}
		sec, err := schs[i].Schedule.Length.ToSeconds()
		if err != nil {
			c.Exit()
			return
		}
		prevEnd = start.Add(time.Second * time.Duration(sec))
		c.Exit()
	}
	if len(schs) > 0 {
		// Schedules are relative to the week.
		// Check for a conflict between the last and first.
		c.Enter("change %d", schs[0].index)
		// Treat the first schedule as starting in a week. This checks for a conflict
		// between the last configured schedule and the first configured schedule.
		start := schs[0].sortKey.Add(time.Hour * time.Duration(24*7))
		if start.Before(prevEnd) {
			c.Errorf("start time is before change %d", schs[len(schs)-1].index)
		}
	}
}
908701
func nonzero(v interface{}, param string) error {
	st := reflect.ValueOf(v)
	valid := true
	switch st.Kind() {
	case reflect.String:
		valid = len(st.String()) != 0
	case reflect.Ptr, reflect.Interface:
		valid = !st.IsNil()
	case reflect.Slice, reflect.Map, reflect.Array:
		valid = st.Len() != 0
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		valid = st.Int() != 0
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
		valid = st.Uint() != 0
	case reflect.Float32, reflect.Float64:
		valid = st.Float() != 0
	case reflect.Bool:
		valid = st.Bool()
	case reflect.Invalid:
		valid = false // always invalid
	case reflect.Struct:
		valid = true // always valid since only nil pointers are empty
	default:
		return ErrUnsupported
	}

	if !valid {
		return ErrZeroValue
	}
	return nil
}