@Override public String format(Object path, ValueType valueType, FormatContext formatCtx) throws InterruptedException { StringBuilder builder = new StringBuilder(); for (Object value : (HierarchyPath)path) { String formatted = formatCtx.format(value, valueType.getNestedValueType(), formatCtx); builder.append("/"); builder.append(formatted); } return returnBuilderResult(builder); } }
public static List flatList(Object value, ValueType type) { if (type.getBaseName().equals("LIST")) { if (type.getNestedValueType().getBaseName() != "LIST") { return (List)value; } else { List result = Lists.newArrayList(); for (Object nValue: (List)value) { result.addAll(flatList(nValue, type.getNestedValueType())); } return result; } } else { return Collections.singletonList(value); } }
@Override public String format(Object list, ValueType valueType, FormatContext formatCtx) throws InterruptedException { StringBuilder builder = new StringBuilder(); for (Object value : (List)list) { String formatted = formatCtx.format(value, valueType.getNestedValueType(), formatCtx); // separate the values by a space if (builder.length() > 0) { builder.append(" "); } builder.append(formatted); } return returnBuilderResult(builder); } }
@Override public List<String> format(List<IndexValue> indexValues, LRepository repository) throws InterruptedException { List<String> result = new ArrayList<String>(); for (IndexValue indexValue : indexValues) { ValueType valueType = indexValue.fieldType.getValueType(); if (valueType.getBaseName().equals("LIST")) { // The values of the first list-level are supplied as individual IndexValues valueType = valueType.getNestedValueType(); } if (!valueType.getName().equals("STRING")) { throw new RuntimeException(this.getClass().getSimpleName() + " only supports string values, but got: " + valueType.getName()); } processPath((String)indexValue.value, result); } return result; }
protected List<Object> readList(ValueHandle handle, ReadContext context) throws JsonFormatException, RepositoryException, InterruptedException { JsonNode node = handle.node; if (!node.isArray()) { throw new JsonFormatException("List value should be specified as array in " + handle.prop); } List<Object> value = new ArrayList<Object>(); for (int i = 0; i < node.size(); i++) { ValueHandle subHandle = new ValueHandle(node.get(i), handle.prop + "[" + i + "]", handle.valueType.getNestedValueType()); Object subValue = readValue(subHandle, context); if (subValue != null) { value.add(subValue); } } return value; }
@Override public List<String> format(List<IndexValue> indexValues, LRepository repository) throws InterruptedException { List<String> results = new ArrayList<String>(); for (IndexValue value : filterValues(indexValues)) { FormatContext formatCtx = new FormatContext(repository); ValueType valueType = value.fieldType.getValueType(); if (valueType.getBaseName().equals("LIST")) { // The values of the first list-level are supplied as individual IndexValues valueType = valueType.getNestedValueType(); } String result = formatCtx.format(value.value, valueType, formatCtx); if (result != null) { results.add(result); } else { results.addAll(formatCtx.results); } } return results; }
protected List<Object> readPath(ValueHandle handle, ReadContext context) throws JsonFormatException, RepositoryException, InterruptedException { JsonNode node = handle.node; if (!node.isArray()) { throw new JsonFormatException("Path value should be specified as an array in " + handle.prop); } List<Object> elements = new ArrayList<Object>(node.size()); for (int i = 0; i < node.size(); i++) { ValueHandle subHandle = new ValueHandle(node.get(i), handle.prop, handle.valueType.getNestedValueType()); Object subValue = readValue(subHandle, context); if (subValue != null) { elements.add(subValue); } } return new HierarchyPath(elements.toArray(new Object[elements.size()])); }
result = listToJson(value, valueType.getNestedValueType(), options, namespaces, repository); } else if (name.equals("PATH")) { result = pathToJson(value, valueType.getNestedValueType(), options, namespaces, repository); } else if (name.equals("STRING")) { result = factory.textNode((String)value);
private Follow processFieldDeref(Element fieldEl, String derefPart) throws IndexerConfException, InterruptedException, RepositoryException { FieldType followField = ConfUtil.getFieldType(derefPart, fieldEl, systemFields, typeManager); String type = followField.getValueType().getBaseName(); if (type.equals("LIST")) { type = followField.getValueType().getNestedValueType().getBaseName(); } if (type.equals("RECORD")) { return new RecordFieldFollow(followField); } else if (type.equals("LINK")) { return new LinkFieldFollow(followField); } else { throw new IndexerConfException("Dereferencing is not possible on field of type " + followField.getValueType().getName() + ". Field: '" + derefPart); } }
if (valueType.getBaseName().equals("LIST")) { value = ((List<Object>) value).get(index); valueType = valueType.getNestedValueType(); continue; valueType = valueType.getNestedValueType(); continue;