@Override public MetadataFieldMapper.Builder parse( String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { Builder builder = new Builder(parserContext.type()); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext(); ) { Map.Entry<String, Object> entry = iterator.next(); String fieldName = Strings.toUnderscoreCase(entry.getKey()); Object fieldNode = entry.getValue(); if (fieldName.equals("type")) { builder.type(fieldNode.toString()); iterator.remove(); } else if (fieldName.equals("postings_format") && parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) { // ignore before 2.0, reject on and after 2.0 iterator.remove(); } else if (fieldName.equals("fielddata")) { // Only take over `loading`, since that is the only option now that is configurable: Map<String, String> fieldDataSettings = SettingsLoader.Helper.loadNestedFromMap(nodeMapValue(fieldNode, "fielddata")); if (fieldDataSettings.containsKey(MappedFieldType.Loading.KEY)) { Settings settings = settingsBuilder() .put( MappedFieldType.Loading.KEY, fieldDataSettings.get(MappedFieldType.Loading.KEY)) .build(); builder.fieldDataSettings(settings); } iterator.remove(); } } return builder; }
public static Builder newBuilder(Wheel copy) { Builder builder = new Builder(); builder.size = copy.size; builder.type = copy.type; builder.colour = copy.colour; return builder; }
@Override public FieldDescriptorProto decode(ProtoReader reader) throws IOException { Builder builder = new Builder(); long token = reader.beginMessage(); for (int tag; (tag = reader.nextTag()) != -1; ) { switch (tag) { case 1: builder.name(ProtoAdapter.STRING.decode(reader)); break; case 9: builder.doc(ProtoAdapter.STRING.decode(reader)); break; case 3: builder.number(ProtoAdapter.INT32.decode(reader)); break; case 4: { try { builder.label(Label.ADAPTER.decode(reader)); } catch (ProtoAdapter.EnumConstantNotFoundException e) { builder.addUnknownField(tag, FieldEncoding.VARINT, (long) e.value); } break; } case 5: { try { builder.type(Type.ADAPTER.decode(reader)); } catch (ProtoAdapter.EnumConstantNotFoundException e) { builder.addUnknownField(tag, FieldEncoding.VARINT, (long) e.value); } break; } case 6: builder.type_name(ProtoAdapter.STRING.decode(reader)); break; case 2: builder.extendee(ProtoAdapter.STRING.decode(reader)); break; case 7: builder.default_value(ProtoAdapter.STRING.decode(reader)); break; case 8: builder.options(FieldOptions.ADAPTER.decode(reader)); break; default: { FieldEncoding fieldEncoding = reader.peekFieldEncoding(); Object value = fieldEncoding.rawProtoAdapter().decode(reader); builder.addUnknownField(tag, fieldEncoding, value); } } } reader.endMessage(token); return builder.build(); }
@Override public Builder newBuilder() { Builder builder = new Builder(); builder.name = name; builder.doc = doc; builder.number = number; builder.label = label; builder.type = type; builder.type_name = type_name; builder.extendee = extendee; builder.default_value = default_value; builder.options = options; builder.addUnknownFields(unknownFields()); return builder; }
public static Builder create(final ContentTypeName type) { if (type.isPageTemplate()) { final PageTemplate.Builder builder = PageTemplate.newPageTemplate(); builder.type(type); return builder; } else if (type.isSite()) { Site.Builder builder = Site.create(); builder.type(type); return builder; } else if (type.isDescendantOfMedia()) { Media.Builder builder = Media.create(); builder.type(type); return builder; } else { Builder builder = Content.create(); builder.type(type); return builder; } }
protected Content(final Builder builder) { Preconditions.checkNotNull(builder.name, "name is required for a Content"); Preconditions.checkNotNull(builder.parentPath, "parentPath is required for a Content"); Preconditions.checkNotNull(builder.data, "data is required for a Content"); if (builder.page != null) { Preconditions.checkArgument( !(builder.page.getController() != null && builder.page.getTemplate() != null), "A Page cannot have both have a controller and a template set"); } if (builder.type == null) { builder.type = ContentTypeName.unstructured(); } this.valid = builder.valid; this.displayName = builder.displayName; this.type = builder.type; this.name = builder.name; this.parentPath = builder.parentPath; this.path = ContentPath.from(builder.parentPath, builder.name.toString()); this.id = builder.id; this.data = builder.data; this.attachments = builder.attachments; this.extraDatas = builder.extraDatas; this.createdTime = builder.createdTime; this.modifiedTime = builder.modifiedTime; this.creator = builder.creator; this.modifier = builder.modifier; this.owner = builder.owner; this.page = builder.page; this.thumbnail = builder.thumbnail; this.hasChildren = builder.hasChildren; this.childOrder = builder.childOrder; this.permissions = builder.permissions == null ? AccessControlList.empty() : builder.permissions; this.inheritPermissions = builder.inheritPermissions; this.language = builder.language; this.contentState = builder.contentState == null ? ContentState.DEFAULT : builder.contentState; }