/** * Compares this field path with the given field path, returns true if the field path starts with the other. * * @param other The field path to compare with. * @return Returns true if this field path starts with the other field path, otherwise false */ public boolean startsWith(FieldPath other) { if (other.size() > size()) { return false; } for (int i = 0; i < other.size(); i++) { if (!other.get(i).equals(get(i))) { return false; } } return true; }
/** * Iterates through the document using the given fieldpath, calling callbacks in the given iterator * handler. */ FieldPathIteratorHandler.ModificationStatus iterateNested(FieldPath fieldPath, int pos, FieldPathIteratorHandler handler) { if (pos >= fieldPath.size()) { handler.onPrimitive(this); return handler.modify(this); } else { throw new IllegalArgumentException("Primitive types can't be iterated through"); } }
private FieldPath getFieldPath(String fieldName) { if (fieldMap != null && fieldMap.containsKey(fieldName)) { fieldName = fieldMap.get(fieldName); } checkAccess(new Field(fieldName)); FieldPath path = FieldPath.newInstance(getDataType(), fieldName); if (path == null || path.size() == 0) { throw new IllegalArgumentException("Malformed schema mapping '" + fieldName + "'."); } return path; }
/** * note that the returned Field may not be in this Document * directly, but may refer to a field in a struct contained in it, * in which case the returned Field is only useful for obtaining * the field type; it can't be used for get() and set(). **/ @Override public Field getField(String fieldName) { if (fieldMap != null && fieldMap.containsKey(fieldName)) { fieldName = fieldMap.get(fieldName); } FieldPath path = getFieldPath(fieldName); Field ret = path.get(path.size() - 1).getFieldRef(); checkAccess(ret); return ret; }
/** * @return Returns the datatype we can expect this field path to return. */ public DataType getResultingDataType() { if (isEmpty()) { return null; } return get(size() - 1).getResultingDataType(); }
public static boolean isComplete(FieldPathUpdate update) { if (!(update instanceof AssignFieldPathUpdate)) { return false; } // Only consider field path updates that touch a top-level field as 'complete', // as these may be converted to regular field value updates. return ((update.getFieldPath().size() == 1) && update.getFieldPath().get(0).getType() == FieldPathEntry.Type.STRUCT_FIELD); }
@SuppressWarnings({ "unchecked", "rawtypes" }) private void createUpdatesAt(List<FieldPathEntry> path, FieldValue value, int idx, DocumentUpdate out) { FieldPath updatePath = update.getFieldPath(); if (idx < updatePath.size()) { FieldPathEntry pathEntry = updatePath.get(idx); FieldPathEntry.Type type = pathEntry.getType();
@Override FieldPathIteratorHandler.ModificationStatus iterateNested(FieldPath fieldPath, int pos, FieldPathIteratorHandler handler) { if (pos < fieldPath.size()) { switch (fieldPath.get(pos).getType()) { case ARRAY_INDEX:
boolean wasModified = false; if (pos < fieldPath.size()) { switch (fieldPath.get(pos).getType()) { case MAP_KEY:
@Override public FieldPathIteratorHandler.ModificationStatus iterateNested(FieldPath fieldPath, int pos, FieldPathIteratorHandler handler) { if (pos < fieldPath.size()) { if (fieldPath.get(pos).getType() == FieldPathEntry.Type.STRUCT_FIELD) { FieldValue fieldVal = getFieldValue(fieldPath.get(pos).getFieldRef());