private FieldValue convertStructured(StructuredFieldValue val) { StructuredFieldValue ret = val.getDataType().createFieldValue(); for (Iterator<Map.Entry<Field, FieldValue>> it = val.iterator(); it.hasNext();) { Map.Entry<Field, FieldValue> entry = it.next(); FieldValue prev = entry.getValue(); FieldValue next = convert(prev); if (next == null) { continue; } ret.setFieldValue(entry.getKey(), next); } return ret; }
/** * Convenience method to set the value of a named field. This is the same as calling {@link #getField(String)}, and * using the returned value to call {@link #setFieldValue(Field, FieldValue)}. If the named field does not exist, * this method returns null. * * @param fieldName The name of the field whose value to set. * @param value The value to set. * @return The previous value of the field, or null. */ public FieldValue setFieldValue(String fieldName, FieldValue value) { Field field = getField(fieldName); if (field == null) { return null; } return setFieldValue(field, value); }
private boolean removeObsoleteReferencesFromStructuredType(StructuredFieldValue struct, Map<Annotation, Annotation> selectedAnnotations, boolean removeIfPresent) { for (Field f : struct.getDataType().getFields()) { FieldValue fValue = struct.getFieldValue(f); if (removeObsoleteReferencesFromFieldValue(fValue, selectedAnnotations, removeIfPresent)) { struct.removeFieldValue(f); } } return false; }
/** * Convenience method to return the value of a named field. This is the same as calling {@link #getField(String)}, * and using the returned value to call {@link #getFieldValue(Field)}. If the named field does not exist, this * method returns null. * * @param fieldName The name of the field whose value to return. * @return The value of the field, or null. */ public FieldValue getFieldValue(String fieldName) { Field field = getField(fieldName); if (field == null) { return null; } return getFieldValue(field); }
/** * Convenience method to remove the value of a named field. This is the same as calling {@link #getField(String)}, * and using the returned value to call {@link #removeFieldValue(Field)}. If the named field does not exist, this * method returns null. * * @param fieldName The name of the field whose value to remove. * @return The previous value of the field, or null. */ public FieldValue removeFieldValue(String fieldName) { Field field = getField(fieldName); if (field == null) { return null; } return removeFieldValue(field); }
if (pos < fieldPath.size()) { if (fieldPath.get(pos).getType() == FieldPathEntry.Type.STRUCT_FIELD) { FieldValue fieldVal = getFieldValue(fieldPath.get(pos).getFieldRef()); if (fieldVal != null) { FieldPathIteratorHandler.ModificationStatus status = fieldVal.iterateNested(fieldPath, pos + 1, handler); if (status == FieldPathIteratorHandler.ModificationStatus.REMOVED) { removeFieldValue(fieldPath.get(pos).getFieldRef()); return FieldPathIteratorHandler.ModificationStatus.MODIFIED; } else { if (isGenerated()) { setFieldValue(fieldPath.get(pos).getFieldRef(), fieldVal); FieldPathIteratorHandler.ModificationStatus status = newVal.iterateNested(fieldPath, pos + 1, handler); if (status == FieldPathIteratorHandler.ModificationStatus.MODIFIED) { setFieldValue(fieldPath.get(pos).getFieldRef(), newVal); return status; for (Iterator<Map.Entry<Field, FieldValue>> iter = iterator(); iter.hasNext();) { Map.Entry<Field, FieldValue> entry = iter.next(); FieldPathIteratorHandler.ModificationStatus currStatus = entry.getValue().iterateNested(fieldPath, pos, handler); removeFieldValue(field);
@Override protected void doExecute(ExecutionContext ctx) { FieldValue input = ctx.getValue(); if (!(input instanceof StructuredFieldValue)) { throw new IllegalArgumentException("Expected structured input, got " + input.getDataType().getName() + "."); } StructuredFieldValue struct = (StructuredFieldValue)input; Field field = struct.getField(fieldName); if (field == null) { throw new IllegalArgumentException("Field '" + fieldName + "' not found in struct type '" + struct.getDataType().getName() + "'"); } ctx.setValue(struct.getFieldValue(field)); }
public final FieldValue setFieldValue(String field, Byte value) { return setFieldValue(field, new ByteFieldValue(value)); } /**
private void setCorrectAnnotationReference(StructuredFieldValue struct, IdentityHashMap<Annotation, Integer> originalAnnotations, List<Annotation> newAnnotations) { for (Field f : struct.getDataType().getFields()) { setCorrectAnnotationReference(struct.getFieldValue(f), originalAnnotations, newAnnotations); } }
public static Field getField(TokenBuffer buffer, StructuredFieldValue parent) { Field f = parent.getField(buffer.currentName()); if (f == null) { throw new NullPointerException("Could not get field \"" + buffer.currentName() + "\" in the structure of type \"" + parent.getDataType().getDataTypeName() + "\"."); } return f; }
/** * Sets the value of the given field. The type of the value must match the type of this field, i.e. * <pre>field.getDataType().getValueClass().isAssignableFrom(value.getClass())</pre> must be true. * * @param field The field whose value to set. * @param value The value to set. * @return The previous value of the field, or null. * @throws IllegalArgumentException If the value is not compatible with the field. */ public FieldValue setFieldValue(Field field, FieldValue value) { if (value == null) { return removeFieldValue(field); } DataType type = field.getDataType(); if (!type.getValueClass().isAssignableFrom(value.getClass())) { FieldValue tmp = type.createFieldValue(); tmp.assign(value); value = tmp; } FieldValue ret = getFieldValue(field); doSetFieldValue(field, value); return ret; }
/** * Clears this and assigns from the given {@link StructuredFieldValue} */ public void assignFrom(StructuredFieldValue sfv) { clear(); Iterator<Map.Entry<Field,FieldValue>> otherValues = sfv.iterator(); while (otherValues.hasNext()) { Map.Entry<Field, FieldValue> otherEntry = otherValues.next(); setFieldValue(otherEntry.getKey(), otherEntry.getValue()); } }
@Override public StructDataType getDataType() { return (StructDataType)super.getDataType(); }
public static Object get(StructuredFieldValue struct, Field field) { return field == null ? null : unwrapValue(struct.getFieldValue(field)); }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Struct)) return false; if (!super.equals(o)) return false; Struct struct = (Struct) o; return values.equals(struct.values); }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + values.hashCode(); return result; }
@Override public Document clone() { Document doc = (Document) super.clone(); doc.docId = docId.clone(); doc.header = header.clone(); doc.body = body.clone(); return doc; }
@Override public int compareTo(FieldValue fieldValue) { int comp = super.compareTo(fieldValue); if (comp != 0) { return comp; } //types are equal, this must be of this type Document otherValue = (Document) fieldValue; comp = getId().compareTo(otherValue.getId()); if (comp != 0) { return comp; } comp = header.compareTo(otherValue.header); if (comp != 0) { return comp; } comp = body.compareTo(otherValue.body); return comp; }
public final FieldValue setFieldValue(Field field, Integer value) { return setFieldValue(field, new IntegerFieldValue(value)); }
public static void serializeStructuredField(FieldWriter fieldWriter, JsonGenerator generator, FieldBase field, StructuredFieldValue value) { fieldNameIfNotNull(generator, field); wrapIOException(() -> { generator.writeStartObject(); Iterator<Map.Entry<Field, FieldValue>> i = value.iterator(); while (i.hasNext()) { Map.Entry<Field, FieldValue> entry = i.next(); entry.getValue().serialize(entry.getKey(), fieldWriter); } generator.writeEndObject(); }); }