// Normalize returns an error iff this GraphQuery is not valid.
2456
func (g *GraphQuery) Normalize() error {
	if err := g.AttemptList.Normalize(); err != nil {
		return err
	}
	if len(g.AttemptRange) > 0 {
		lme := errors.NewLazyMultiError(len(g.AttemptRange))
		for i, rng := range g.AttemptRange {
			lme.Assign(i, rng.Normalize())
		}
		if err := lme.Get(); err != nil {
			return err
		}
	}
	if len(g.Search) > 0 {
		lme := errors.NewLazyMultiError(len(g.Search))
		for i, s := range g.Search {
			lme.Assign(i, s.Normalize())
		}
		if err := lme.Get(); err != nil {
			return err
		}
	}
	return nil
}
1220665
func (s *Specifier) Normalize() error {
	if s.TemplateName == "" {
		return errors.New("empty template_name")
	}
	for k, v := range s.Params {
		if k == "" {
			return errors.New("empty param key")
		}
		if err := v.Normalize(); err != nil {
			return fmt.Errorf("param %q: %s", k, err)
		}
	}
	return nil
}
1088722
func (h Host) Normalize() string {
	s := string(h)
	_, s = parse.Transport(s)

	// The error can be ignore here, because this function is called after the corefile has already been vetted.
	host, _, _, _ := SplitHostPort(s)
	return Name(host).Normalize()
}
814983
func (t *Quest_Desc_Meta_Timeouts) Normalize() error {
	if d := google.DurationFromProto(t.Start); d < 0 {
		return fmt.Errorf("desc.meta.timeouts.start < 0: %s", d)
	}
	if d := google.DurationFromProto(t.Run); d < 0 {
		return fmt.Errorf("desc.meta.timeouts.run < 0: %s", d)
	}
	if d := google.DurationFromProto(t.Stop); d < 0 {
		return fmt.Errorf("desc.meta.timeouts.stop < 0: %s", d)
	}
	return nil
}
1132359
func (p Point) Normalize() Point {
	if p.X == 0 && p.Y == 0 {
		return p
	}
	return p.Mul(1 / p.Norm())
}
965641
func (j *JsonResult) Normalize() error {
	if j == nil {
		return nil
	}
	if j.Object == "" {
		j.Size = 0
		return nil
	}
	if len(j.Object) > jsonNonNormalizedSize {
		return fmt.Errorf(
			"JSONObject.Object length exceeds max non-normalized length: %d > %d (max)",
			len(j.Object), jsonNonNormalizedSize)
	}
	normed, err := template.NormalizeJSON(j.Object, true)
	if err != nil {
		return err
	}
	if len(normed) > JSONObjectMaxLength {
		return fmt.Errorf(
			"JSONObject.Object length exceeds max: %d > %d (max)",
			len(normed), JSONObjectMaxLength)
	}
	j.Object = normed
	j.Size = uint32(len(j.Object))
	return nil
}
1109781
func (a *FinishAttemptReq) Normalize() error {
	if err := a.Auth.Normalize(); err != nil {
		return err
	}
	if err := a.Data.Normalize(); err != nil {
		return err
	}
	if a.Data == nil || len(a.Data.Object) == 0 {
		return errors.New("data field is required")
	}
	return nil
}
422902
func (e *Env) normalizeKey(k string) string {
	if e.CaseInsensitive {
		return strings.ToUpper(k)
	}
	return k
}
1130119
func (n *SimpleNameNormalizer) Normalize(name string) string {
	var retMe []byte
	nameBytes := []byte(name)
	for i, b := range nameBytes {
		if n.safeByte(b) {
			if retMe != nil {
				retMe[i] = b
			}
		} else {
			if retMe == nil {
				retMe = make([]byte, len(nameBytes))
				copy(retMe[0:i], nameBytes[0:i])
			}
			retMe[i] = n.Replacement
		}
	}
	if retMe == nil {
		return name
	}
	return string(retMe)
}
707561
func (a *AttemptList) Normalize() error {
	for q, vals := range a.GetTo() {
		if vals == nil {
			a.To[q] = &AttemptList_Nums{}
		} else {
			if err := vals.Normalize(); err != nil {
				return err
			}
		}
	}
	return nil
}
927225
func (lrs *LinearRegressionSeries) normalize(xvalue float64) float64 {
	return (xvalue - lrs.avgx) / lrs.stddevx
}
714596
func (w *WalkGraphReq) Normalize() error {
	if w.Auth != nil {
		if err := w.Auth.Normalize(); err != nil {
			return err
		}
	}

	if w.Query == nil {
		return errors.New("must specify a Query")
	}
	if err := w.Query.Normalize(); err != nil {
		return err
	}

	if w.Mode == nil {
		w.Mode = &WalkGraphReq_Mode{}
	}

	if w.Limit != nil {
		if w.Limit.MaxDepth < -1 {
			return errors.New("limit.max_depth must be >= -1")
		}
		if google.DurationFromProto(w.Limit.GetMaxTime()) < 0 {
			return errors.New("limit.max_time must be positive")
		}
	} else {
		w.Limit = &WalkGraphReq_Limit{}
	}
	if w.Limit.MaxDataSize == 0 {
		w.Limit.MaxDataSize = DefaultLimitMaxDataSize
	}
	if w.Limit.MaxDataSize > MaxLimitMaxDataSize {
		w.Limit.MaxDataSize = MaxLimitMaxDataSize
	}

	if w.Include == nil {
		w.Include = &WalkGraphReq_Include{
			Quest:     &WalkGraphReq_Include_Options{},
			Attempt:   &WalkGraphReq_Include_Options{},
			Execution: &WalkGraphReq_Include_Options{},
		}
	} else {
		if w.Include.Quest == nil {
			w.Include.Quest = &WalkGraphReq_Include_Options{}
		} else if w.Include.Quest.Result || w.Include.Quest.Abnormal || w.Include.Quest.Expired {
			return errors.New("include.quest does not support result, abnormal or expired")
		}

		if w.Include.Attempt == nil {
			w.Include.Attempt = &WalkGraphReq_Include_Options{}
		} else {
			if w.Include.Attempt.Result {
				w.Include.Attempt.Data = true
			}
		}

		if w.Include.Execution == nil {
			w.Include.Execution = &WalkGraphReq_Include_Options{}
		}
	}

	if w.Exclude == nil {
		w.Exclude = &WalkGraphReq_Exclude{}
	}
	return w.Exclude.Normalize()
}
1225876
func (env *EnvironmentItemModel) Normalize() error {
	opts, err := env.GetOptions()
	if err != nil {
		return err
	}
	(*env)[OptionsKey] = opts
	return nil
}
922693
func (step *StepModel) Normalize() error {
	for _, input := range step.Inputs {
		if err := input.Normalize(); err != nil {
			return err
		}
	}

	for _, output := range step.Outputs {
		if err := output.Normalize(); err != nil {
			return err
		}
	}

	normalizedMeta, err := JSONMarshallable(step.Meta)
	if err != nil {
		return err
	}
	step.Meta = normalizedMeta

	return nil
}
1333938
func normalize(i interface{}) (int, error) {
	switch v := i.(type) {
	case int:
		return v, nil
	case int32:
		return int(v), nil
	case int64:
		return int(v), nil
	case float32:
		return int(v + 0.5), nil
	case float64:
		// We need this check here because NaN can be a float. Casting NaN to
		// int results in a large negative number. Even after you add 0.5.
		if math.IsNaN(v) {
			return -1, fmt.Errorf("Could not normalize NaN %v", v)
		}
		return int(v + 0.5), nil
	case string:
		f, err := strconv.ParseFloat(v, 64)
		if err != nil {
			return -1, err
		}
		return normalize(f)
	default:
		return -1, fmt.Errorf("Could not normalize %q", v)
	}
}
1298700
func (p *Phrase) Normalize() error {
	if p != nil {
		if p.Name == "" {
			return fmt.Errorf("empty ID")
		}
		for _, s := range p.Stages {
			if err := s.Normalize(); err != nil {
				return err
			}
		}
		if p.ReturnStage == nil {
			p.ReturnStage = &ReturnStage{Retval: 1}
		}
	}
	return nil
}
404779
func (t *TimePeriod) Normalize() error {
	if t.GetDuration() == "" {
		return nil
	}
	n, err := t.Time.(*TimePeriod_Duration).ToSeconds()
	if err != nil {
		return errors.Annotate(err, "invalid duration").Err()
	}
	t.Time = &TimePeriod_Seconds{
		Seconds: n,
	}
	return nil
}