// BuildShape will recursively build the referenced shape based on the json
// object provided.  isMap will dictate how the field name is specified. If
// isMap is true, we will expect the member name to be quotes like "Foo".
553477
func (b ShapeValueBuilder) BuildShape(ref *ShapeRef, shapes map[string]interface{}, isMap bool) string {
	order := make([]string, len(shapes))
	for k := range shapes {
		order = append(order, k)
	}
	sort.Strings(order)

	ret := ""
	for _, name := range order {
		if name == "" {
			continue
		}
		shape := shapes[name]

		// If the shape isn't a map, we want to export the value, since every field
		// defined in our shapes are exported.
		if len(name) > 0 && !isMap && strings.ToLower(name[0:1]) == name[0:1] {
			name = strings.Title(name)
		}

		memName := name
		passRef := ref.Shape.MemberRefs[name]

		if isMap {
			memName = fmt.Sprintf("%q", memName)
			passRef = &ref.Shape.ValueRef
		}

		switch v := shape.(type) {
		case map[string]interface{}:
			ret += b.BuildComplex(name, memName, passRef, v)
		case []interface{}:
			ret += b.BuildList(name, memName, passRef, v)
		default:
			ret += b.BuildScalar(name, memName, passRef, v, ref.Shape.Payload == name)
		}
	}
	return ret
}
247926
func BuildTriangle(sideLength, height float64) string {
	halfWidth := sideLength / 2

	return fmt.Sprintf("%v,0,%v,%v,0,%v,%v,0", halfWidth, sideLength, height, height, halfWidth)
}
742661
func (b *planBuilder) buildProjection(p LogicalPlan, fields []*ast.SelectField, mapper map[*ast.AggregateFuncExpr]int) (LogicalPlan, int) {
	proj := &Projection{
		Exprs:           make([]expression.Expression, 0, len(fields)),
		baseLogicalPlan: newBaseLogicalPlan(Proj, b.allocator),
	}
	proj.self = proj
	proj.initIDAndContext(b.ctx)
	schema := expression.NewSchema(make([]*expression.Column, 0, len(fields)))
	oldLen := 0
	for _, field := range fields {
		newExpr, np, err := b.rewrite(field.Expr, p, mapper, true)
		if err != nil {
			b.err = errors.Trace(err)
			return nil, oldLen
		}
		p = np
		proj.Exprs = append(proj.Exprs, newExpr)
		var tblName, colName model.CIStr
		if field.AsName.L != "" {
			colName = field.AsName
		} else if c, ok := newExpr.(*expression.Column); ok && !c.IsAggOrSubq {
			if astCol, ok := getInnerFromParentheses(field.Expr).(*ast.ColumnNameExpr); ok {
				colName = astCol.Name.Name
				tblName = astCol.Name.Table
			} else {
				colName = c.ColName
				tblName = c.TblName
			}
		} else {
			// When the query is select t.a from t group by a; The Column Name should be a but not t.a;
			if agg, ok := field.Expr.(*ast.AggregateFuncExpr); ok && agg.F == ast.AggFuncFirstRow {
				if col, ok := agg.Args[0].(*ast.ColumnNameExpr); ok {
					colName = col.Name.Name
				}
			} else {
				innerExpr := getInnerFromParentheses(field.Expr)
				if _, ok := innerExpr.(*ast.ValueExpr); ok && innerExpr.Text() != "" {
					colName = model.NewCIStr(innerExpr.Text())
				} else {
					colName = model.NewCIStr(field.Text())
				}
			}
		}
		col := &expression.Column{
			FromID:  proj.id,
			TblName: tblName,
			ColName: colName,
			RetType: newExpr.GetType(),
		}
		if !field.Auxiliary {
			oldLen++
		}
		schema.Append(col)
		col.Position = schema.Len()
	}
	proj.SetSchema(schema)
	addChild(proj, p)
	proj.SetCorrelated()
	return proj, oldLen
}
1280644
func (builder *DictEdgeBuilder) Build(context *EdgeBuildingContext) *Edge {
	builder.pointers = append(builder.pointers, &dictBuilderPointer{S: context.I})

	newIndex := 0
	for i, _ := range builder.pointers {
		newPointer := builder.updatePointer(builder.pointers[i], context.Ch)
		if newPointer != nil {
			builder.pointers[newIndex] = newPointer
			newIndex++
		}
	}

	builder.pointers = builder.pointers[:newIndex]
	var bestEdge *Edge

	for _, pointer := range builder.pointers {
		if pointer.IsFinal {
			s := 1 + context.I - pointer.Offset
			source := context.Path[s]
			edge := &Edge{
				S:         s,
				EdgeType:  DICT,
				WordCount: source.WordCount + 1,
				UnkCount:  source.UnkCount}
			if !bestEdge.IsBetterThan(edge) {
				bestEdge = edge
			}
		}
	}

	return bestEdge
}
1324559
func (f *Builder) Build(ctx context.Context, names []string) func(*http.Response) error {
	var modifiers []func(*http.Response) error

	for _, middleName := range names {
		if conf, ok := f.configs[middleName]; ok {
			if conf.Headers != nil {
				getLogger(ctx, middleName, "Headers").Debug("Creating Middleware (ResponseModifier)")

				modifiers = append(modifiers, buildHeaders(conf.Headers))
			} else if conf.Chain != nil {
				getLogger(ctx, middleName, "Chain").Debug("Creating Middleware (ResponseModifier)")

				modifiers = append(modifiers, f.Build(ctx, conf.Chain.Middlewares))
			}
		}
	}

	if len(modifiers) > 0 {
		return func(resp *http.Response) error {
			for i := len(modifiers); i > 0; i-- {
				err := modifiers[i-1](resp)
				if err != nil {
					return err
				}
			}
			return nil
		}
	}

	return func(response *http.Response) error { return nil }
}
561429
func (f fieldsPrinterBuilder) BuildFieldsPrinter(writer *Formatter) fieldsPrinter {
	if f.Recursive {
		return &recursiveFieldsPrinter{
			Writer: writer,
		}
	}

	return &regularFieldsPrinter{
		Writer: writer,
	}
}
1083409
func buildDsn(dsnMap map[string]string) string {
	dsn := ""
	for param, value := range dsnMap {
		if dsn != "" {
			dsn += " "
		}
		dsn += fmt.Sprintf("%v=%v", param, value)
	}
	return dsn
}
1021087
func (o *GetMapURL) Build() (*url.URL, error) {
	var _result url.URL

	var _path = "/map"

	_basePath := o._basePath
	if _basePath == "" {
		_basePath = "/v1"
	}
	_result.Path = golangswaggerpaths.Join(_basePath, _path)

	return &_result, nil
}
1136818
func (p *Projection) buildSchemaByExprs() expression.Schema {
	schema := expression.NewSchema(make([]*expression.Column, 0, p.schema.Len()))
	for _, expr := range p.Exprs {
		if col, isCol := expr.(*expression.Column); isCol {
			schema.Append(col)
		} else {
			// If the expression is not a column, we add a column to occupy the position.
			schema.Append(&expression.Column{
				Position: -1})
		}
	}
	return schema
}
878312
func (b *GCSBuilder) Build() (*gcs.Filter, error) {
	// Do nothing if the builder's already errored out.
	if b.err != nil {
		return nil, b.err
	}

	// We'll ensure that all the parmaters we need to actually build the
	// filter properly are set.
	if b.p == 0 {
		return nil, fmt.Errorf("p value is not set, cannot build")
	}
	if b.m == 0 {
		return nil, fmt.Errorf("m value is not set, cannot build")
	}

	dataSlice := make([][]byte, 0, len(b.data))
	for item := range b.data {
		dataSlice = append(dataSlice, []byte(item))
	}

	return gcs.BuildGCSFilter(b.p, b.m, b.key, dataSlice)
}
421748
func BuildURLFromMap(baseUrl string, queryParams map[string]string) string {
	if len(queryParams) < 1 {
		return baseUrl
	}
	queryValues := url.Values{}
	for key, val := range queryParams {
		queryValues.Set(key, val)
	}
	return BuildURL(baseUrl, queryValues)
}
25931
func BuildJSON(v interface{}) ([]byte, error) {
	var buf bytes.Buffer

	err := buildAny(reflect.ValueOf(v), &buf, "")
	return buf.Bytes(), err
}
1368894
func (b ShapeValueBuilder) BuildScalar(name, memName string, ref *ShapeRef, shape interface{}, isPayload bool) string {
	if ref == nil || ref.Shape == nil {
		return ""
	}

	switch v := shape.(type) {
	case bool:
		return convertToCorrectType(memName, ref.Shape.Type, fmt.Sprintf("%t", v))
	case int:
		if ref.Shape.Type == "timestamp" {
			return parseTimeString(ref, memName, fmt.Sprintf("%d", v))
		}
		return convertToCorrectType(memName, ref.Shape.Type, fmt.Sprintf("%d", v))
	case float64:
		dataType := ref.Shape.Type
		if dataType == "integer" || dataType == "int64" || dataType == "long" {
			return convertToCorrectType(memName, ref.Shape.Type, fmt.Sprintf("%d", int(shape.(float64))))
		}
		return convertToCorrectType(memName, ref.Shape.Type, fmt.Sprintf("%f", v))
	case string:
		t := ref.Shape.Type
		switch t {
		case "timestamp":
			return parseTimeString(ref, memName, fmt.Sprintf("%s", v))
		case "blob":
			if (ref.Streaming || ref.Shape.Streaming) && isPayload {
				return fmt.Sprintf("%s: aws.ReadSeekCloser(strings.NewReader(%q)),\n", memName, v)
			}

			return fmt.Sprintf("%s: []byte(%q),\n", memName, v)
		default:
			return convertToCorrectType(memName, t, v)
		}
	default:
		panic(fmt.Errorf("Unsupported scalar type: %v", reflect.TypeOf(v)))
	}
}
605294
func (g *Generator) buildNestedDescriptors(descs []*Descriptor) {
	for _, desc := range descs {
		if len(desc.NestedType) != 0 {
			for _, nest := range descs {
				if nest.parent == desc {
					desc.nested = append(desc.nested, nest)
				}
			}
			if len(desc.nested) != len(desc.NestedType) {
				g.Fail("internal error: nesting failure for", desc.GetName())
			}
		}
	}
}
469377
func BuildMap(rawProperties map[interface{}]interface{}) (Map, error) {
	result := make(Map, len(rawProperties))

	for name, val := range rawProperties {
		nameStr, ok := name.(string)
		if !ok {
			return result, bosherr.Errorf("Map contains non-string key %#v", name)
		}

		convertedVal, err := Build(val)
		if err != nil {
			return result, err
		}

		result[nameStr] = convertedVal
	}

	return result, nil
}
97372
func buildMap(v reflect.Value, onlyFields []string) map[string]interface{} {
	res := make(map[string]interface{})
	if onlyFields != nil {
		for _, onlyField := range onlyFields {
			fieldType, exist := v.Type().FieldByName(onlyField)
			if exist {
				addFieldToMap(true, fieldType, v.FieldByName(onlyField), res)
			}
		}
	} else {
		for i := 0; i < v.NumField(); i++ {
			addFieldToMap(false, v.Type().Field(i), v.Field(i), res)
		}
	}
	return res
}
1335649
func buildGroupMap(specs []*loads.Document) map[string]string {
	mapping := map[string]string{}
	mapping["apiregistration"] = "apiregistration.k8s.io"
	mapping["apiextensions"] = "apiextensions.k8s.io"
	mapping["certificates"] = "certificates.k8s.io"
	mapping["meta"] = "meta"
	mapping["core"] = "core"
	mapping["extensions"] = "extensions"

	for _, spec := range specs {
		for name, spec := range spec.Spec().Definitions {
			group, _, _ := GuessGVK(name)
			if _, found := mapping[group]; found {
				continue
			}
			// special groups where group name from extension is empty!
			if group == "meta" || group == "core" {
				continue
			}

			// full group not exposed as x-kubernetes- openapi extensions
			// from kube-aggregator project or apiextensions-apiserver project
			if group == "apiregistration" || group == "apiextensions" {
				continue
			}

			if extension, found := spec.Extensions[typeKey]; found {
				gvks, ok := extension.([]interface{})
				if ok {
					for _, item := range gvks {
						gvk, ok := item.(map[string]interface{})
						if ok {
							mapping[group] = gvk["group"].(string)
							break
						}
					}
				}
			}
		}
	}
	return mapping
}