@Override public InventoryStructure.Offline<?> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { JsonNode tree = jsonParser.readValueAsTree(); if (tree == null) { throw new JsonParseException("Inventory structure expected but got nothing.", jsonParser.getCurrentLocation()); } JsonToken token = tree.asToken(); if (token != JsonToken.START_OBJECT) { throw new JsonParseException("Expected object but got " + token.asString(), JsonLocation.NA); } JsonNode typeNode = tree.get("type"); if (!typeNode.isTextual()) { throw new JsonParseException("'type' must be a text", JsonLocation.NA); } String typeName = typeNode.textValue(); InventoryStructure.EntityType type; try { type = InventoryStructure.EntityType.valueOf(typeName); } catch (IllegalArgumentException e) { throw new JsonParseException("Unrecognized value of 'type'. Supported values are " + LEGAL_ENTITY_TYPES + " but got '" + typeName + "'.", JsonLocation.NA); } Entity.Blueprint root = deserializationContext.readValue( prepareTraverse(tree.get("data"), deserializationContext), type.blueprintType); InventoryStructure.Builder bld = InventoryStructure.Offline.of(root); parseChildren(tree, bld, deserializationContext); return bld.build(); }
return new Offline<>(root, blueprints, children);
return new Offline<>(root, blueprints, children);
public Offline<Root> build() { return new Offline<>(root, blueprints, children); }
public static <R extends Entity.Blueprint> Builder<R> of(R root) { return of(root, null); }
public Offline<Root> build() { return new Offline<>(root, blueprints, children); }
public static <R extends Entity.Blueprint> Builder<R> of(R root) { return of(root, null); }
public static <R extends Entity.Blueprint> Offline<R> copy(InventoryStructure<R> other) { return copy(other, false); }
public static <R extends Entity.Blueprint> Offline<R> copy(InventoryStructure<R> other) { return copy(other, false); }
private InventoryStructure<B> mergeTree(InventoryStructure<B> currentTree, InventoryStructure<B> newTree, SyncConfiguration configuration) { if (configuration.isDeepSearch()) { return mergeDeepTree(currentTree, RelativePath.empty().get(), InventoryStructure.Offline.copy(newTree).asBuilder(), configuration.getSyncedTypes()).build(); } else { return mergeShallowTree(currentTree, RelativePath.empty().get(), InventoryStructure.Offline.copy(newTree).asBuilder(), configuration.getSyncedTypes()).build(); } }
/** * You can use this method if you have an existing inventory structure and want to make modifications to it. * * @return a builder seeded with this inventory structure */ public InventoryStructure.Builder<Root> asBuilder() { RelativePath rootPath = EmptyRelativePath.I; Object attachment = getNode(rootPath).getAttachment(); return new InventoryStructure.Builder<>(root, attachment, EmptyRelativePath.I, entities, children); }
/** * Shortcut method, exactly identical to calling {@link Offline#of(Entity.Blueprint, Object)}. * * @param root the root blueprint * @param attachment the attachment of the blueprint * @param <B> the type of the blueprint * @return the builder to build an offline inventory structure */ static <B extends Entity.Blueprint> InventoryStructure.Offline.Builder<B> of(B root, Object attachment) { return Offline.of(root, attachment); }
/** * You can use this method if you have an existing inventory structure and want to make modifications to it. * * @return a builder seeded with this inventory structure */ public InventoryStructure.Builder<Root> asBuilder() { RelativePath rootPath = EmptyRelativePath.I; Object attachment = getNode(rootPath).getAttachment(); return new InventoryStructure.Builder<>(root, attachment, EmptyRelativePath.I, entities, children); }
/** * Shortcut method, exactly identical to calling {@link Offline#of(Entity.Blueprint, Object)}. * * @param root the root blueprint * @param attachment the attachment of the blueprint * @param <B> the type of the blueprint * @return the builder to build an offline inventory structure */ static <B extends Entity.Blueprint> InventoryStructure.Offline.Builder<B> of(B root, Object attachment) { return Offline.of(root, attachment); }