@SuppressFBWarnings("SIC_INNER_SHOULD_BE_STATIC_ANON") public Iterable<Field<? extends ScalarValue<? extends Serializable>>> getSubDocFields() { final Iterator<Field<? extends ScalarValue<? extends Serializable>>> iterator = new AbstractIterator<Field<? extends ScalarValue<? extends Serializable>>>() { Iterator<String> attIt = erasuredType.getAttributeKeys().iterator(); @Override protected Field<? extends ScalarValue<? extends Serializable>> computeNext() { if (!attIt.hasNext()) { endOfData(); return null; } return (Field<? extends ScalarValue<? extends Serializable>>) field(attIt.next()); } }; return new Iterable<Field<? extends ScalarValue<? extends Serializable>>>() { @Override public Iterator<Field<? extends ScalarValue<? extends Serializable>>> iterator() { return iterator; } }; }
int attSize = structure.getElements().size() + structure.getType().getAttributeKeys().size(); List<String> attributes = Lists.newArrayListWithCapacity(attSize); attributes.addAll(structure.getElements().keySet()); attributes.addAll(structure.getType().getAttributeKeys());
private static KVDocument translateDocStructure(SubDocValueToDocValueTranslator.Argument arg) { DocStructure structure = (DocStructure) arg.structure; SplitDocument splitDocument = arg.splitDoc; LinkedHashMap<String, KVValue<?>> map = new LinkedHashMap<>(); SubDocument subDoc = splitDocument.getSubDocuments().get( structure.getType(), structure.getIndex()); for (String keyName : subDoc.getType().getAttributeKeys()) { //childStructure will be null if the child is a scalar StructureElement childStructure = structure.getElements().get(keyName); arg.structure = childStructure; map.put( keyName, subDoc.getValue(keyName).accept(VALUE_TRANSLATOR, arg) ); } for (Map.Entry<String, StructureElement> entry : structure.getElements().entrySet()) { if (entry.getValue() instanceof DocStructure) { //arrays has already been mapped as values StructureElement childStructure = structure.getElements().get(entry.getKey()); arg.structure = childStructure; map.put( entry.getKey(), translateDocStructure(arg) ); } } return new MapKVDocument(map); }
docStructure.getType().getAttributeKeys(), docStructure.getElements().keySet() );
public void setSubDoc(SubDocument subdoc) throws IllegalArgumentException { if (!table.getSubDocType().equals(subdoc.getType())) { throw new IllegalArgumentException("Type of table " + table + " is " + table.getSubDocType() + " which is " + "different than the type of the given subdocument (" + subdoc.getType() + ")"); } for (String key : subdoc.getType().getAttributeKeys()) { String fieldName = table.subDocHelper().toColumnName(key); //@gortiz: I think we can not use types here! Field f = field(fieldName); ScalarValue<?> v = subdoc.getValue(key); setValue(f, v); } }