// Normalize will normalize the Template message, returning an error if it is
// invalid.
8368
func (t *File_Template) Normalize() error {
	if t.Body == "" {
		return errors.New("body is empty")
	}

	defaultParams := make(map[string]*Value, len(t.Param))
	for k, param := range t.Param {
		if k == "" {
			return fmt.Errorf("param %q: invalid name", k)
		}
		if !ParamRegex.MatchString(k) {
			return fmt.Errorf("param %q: malformed name", k)
		}
		if !strings.Contains(t.Body, k) {
			return fmt.Errorf("param %q: not present in body", k)
		}
		if err := param.Normalize(); err != nil {
			return fmt.Errorf("param %q: %s", k, err)
		}
		if param.Default != nil {
			defaultParams[k] = param.Default
		} else {
			defaultParams[k] = param.Schema.Zero()
		}
	}

	maybeJSON, err := t.Render(defaultParams)
	if err != nil {
		return fmt.Errorf("rendering: %s", err)
	}

	err = json.Unmarshal([]byte(maybeJSON), &map[string]interface{}{})
	if err != nil {
		return fmt.Errorf("parsing rendered body: %s", err)
	}
	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)
	}
}
632278
func (s *Scheme) Normalize() (err error) {
	tfv := s.t.FreeTypeVar()

	if len(tfv) == 0 {
		return nil
	}

	defer ReturnTypeVarSet(tfv)
	ord := BorrowTypeVarSet(len(tfv))
	for i := range tfv {
		ord[i] = TypeVariable(letters[i])
	}

	s.t, err = s.t.Normalize(tfv, ord)
	s.tvs = ord.Set()
	return
}
468255
func (vs Values) Normalize() []Value {
	var output []Value
	var total float64

	for _, v := range vs {
		total += v.Value
	}

	for _, v := range vs {
		if v.Value > 0 {
			output = append(output, Value{
				Style: v.Style,
				Label: v.Label,
				Value: util.Math.RoundDown(v.Value/total, 0.0001),
			})
		}
	}
	return output
}
813411
func (t *File_Template) Normalize() error {
	if t.DistributorConfigName == "" {
		return fmt.Errorf("missing distributor_config_name")
	}
	if err := t.Parameters.Normalize(); err != nil {
		return err
	}
	if err := t.DistributorParameters.Normalize(); err != nil {
		return err
	}
	return nil
}
1271835
func (app *AppModel) Normalize() error {
	for _, env := range app.Environments {
		if err := env.Normalize(); err != nil {
			return err
		}
	}
	return nil
}
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
}
430644
func (r *EnsureGraphDataReq) Normalize() error {
	if r.ForExecution != nil {
		if err := r.ForExecution.Normalize(); err != nil {
			return err
		}
	}

	if err := r.RawAttempts.Normalize(); err != nil {
		return err
	}

	hasAttempts := false
	if r.RawAttempts != nil {
		for _, nums := range r.RawAttempts.To {
			if len(nums.Nums) == 0 {
				return errors.New("EnsureGraphDataReq.attempts must only include valid (non-0, non-empty) attempt numbers")
			}
			hasAttempts = true
		}
	}

	if len(r.Quest) != len(r.QuestAttempt) {
		return errors.New("mismatched quest_attempt v. quest lengths")
	}

	if len(r.TemplateQuest) != len(r.TemplateAttempt) {
		return errors.New("mismatched template_attempt v. template_quest lengths")
	}

	if err := checkAttemptNums("template_attempts", r.TemplateAttempt); err != nil {
		return err
	}

	for i, q := range r.TemplateQuest {
		if err := q.Normalize(); err != nil {
			return fmt.Errorf("template_quests[%d]: %s", i, err)
		}
	}

	if err := checkAttemptNums("quest_attempt", r.QuestAttempt); err != nil {
		return err
	}

	for i, desc := range r.Quest {
		if err := desc.Normalize(); err != nil {
			return fmt.Errorf("quest[%d]: %s", i, err)
		}
	}

	if len(r.Quest) == 0 && len(r.TemplateQuest) == 0 && !hasAttempts {
		return errors.New("EnsureGraphDataReq must have at least one of quests, template_quests and raw_attempts")
	}

	if r.Limit == nil {
		r.Limit = &EnsureGraphDataReq_Limit{}
	}
	if r.Limit.MaxDataSize == 0 {
		r.Limit.MaxDataSize = DefaultLimitMaxDataSize
	}
	if r.Limit.MaxDataSize > MaxLimitMaxDataSize {
		r.Limit.MaxDataSize = MaxLimitMaxDataSize
	}

	if r.Include == nil {
		r.Include = &EnsureGraphDataReq_Include{Attempt: &EnsureGraphDataReq_Include_Options{}}
	} else if r.Include.Attempt == nil {
		r.Include.Attempt = &EnsureGraphDataReq_Include_Options{}
	}
	return nil
}
81711
func (s *stateV4) normalize() {
	sort.Stable(sortResourcesV4(s.Resources))
	for _, rs := range s.Resources {
		sort.Stable(sortInstancesV4(rs.Instances))
	}
}
306007
func (d *DepsStage) Normalize() error {
	for _, d := range d.Deps {
		if err := d.Normalize(); err != nil {
			return err
		}
	}
	return nil
}
1133828
func (a *AttemptList_Nums) Normalize() error {
	if len(a.Nums) == 0 || (len(a.Nums) == 1 && a.Nums[0] == 0) {
		a.Nums = nil
		return nil
	}
	slc := revUint32Slice(a.Nums)
	sort.Sort(slc)
	if a.Nums[len(a.Nums)-1] == 0 {
		return errors.New("AttemptList.Nums contains 0 as well as other values.")
	}
	a.Nums = a.Nums[:set.Uniq(slc)]
	return nil
}
1093702
func (v Vector) Normalize() Vector {
	n2 := v.Norm2()
	if n2 == 0 {
		return Vector{0, 0, 0}
	}
	return v.Mul(1 / math.Sqrt(n2))
}
834500
func (s *Etcd) normalize(key string) string {
	key = store.Normalize(key)
	return strings.TrimPrefix(key, "/")
}
366549
func (a *Execution_Auth) Normalize() error {
	if a == nil {
		return errors.New("Execution_Auth is nil")
	}
	if a.Id == nil {
		return errors.New("Execution_Auth.Id is nil")
	}
	return nil
}
93927
func normalize(c context.Context, cfg *Config) error {
	for _, p := range cfg.Projects.GetProject() {
		p.Revision = cfg.revision
	}
	for _, v := range cfg.VMs.GetVms() {
		for _, ch := range v.Amount.GetChange() {
			if err := ch.Length.Normalize(); err != nil {
				return errors.Annotate(err, "failed to normalize %q", v.Prefix).Err()
			}
		}
		if err := v.Lifetime.Normalize(); err != nil {
			return errors.Annotate(err, "failed to normalize %q", v.Prefix).Err()
		}
		v.Revision = cfg.revision
		if err := v.Timeout.Normalize(); err != nil {
			return errors.Annotate(err, "failed to normalize %q", v.Prefix).Err()
		}
	}
	return nil
}
1132359
func (p Point) Normalize() Point {
	if p.X == 0 && p.Y == 0 {
		return p
	}
	return p.Mul(1 / p.Norm())
}
801791
func (arc *AddressResourceConfig) Normalize() {
	testProto := strings.Trim(strings.ToLower(arc.Protocol), " ")
	arc.Protocol = testProto
}