/** * Check if path segment at given index (relative to head) is an array * index. * * @param i * @return */ public boolean isIndex(int i) { return Util.isNumber(data.get(i)); }
/** * Check if path segment at given index (relative to head) is an array * index. * * @param i * @return */ public boolean isIndex(int i) { return Util.isNumber(data.get(i)); }
/** * Check if path segment at given index (relative to head) is an array * index. * * @param i * @return */ public boolean isIndex(int i) { return Util.isNumber(data.get(i)); }
private JsonNode modifyObjectNode(JsonNode parentNode, JsonNode newValue, String last, Path p) { JsonNode oldValue; if (Util.isNumber(last)) { throw new IllegalArgumentException(UtilConstants.ERR_INVALID_INDEXED_ACCESS + p); } ObjectNode obj = (ObjectNode) parentNode; if (newValue == null) { oldValue = obj.get(last); obj.remove(last); } else { oldValue = obj.replace(last, newValue); } return oldValue; }
private static JsonNode modifyObjectNode(JsonNode parentNode, JsonNode newValue, String last, Path p) { JsonNode oldValue; if (Util.isNumber(last)) { throw new IllegalArgumentException(UtilConstants.ERR_INVALID_INDEXED_ACCESS + p); } ObjectNode obj = (ObjectNode) parentNode; if (newValue == null) { oldValue = obj.get(last); obj.remove(last); } else { oldValue = obj.replace(last, newValue); } return oldValue; }
private static JsonNode modifyObjectNode(JsonNode parentNode, JsonNode newValue, String last, Path p) { JsonNode oldValue; if (Util.isNumber(last)) { throw new IllegalArgumentException(UtilConstants.ERR_INVALID_INDEXED_ACCESS + p); } ObjectNode obj = (ObjectNode) parentNode; if (newValue == null) { oldValue = obj.get(last); obj.remove(last); } else { oldValue = obj.replace(last, newValue); } return oldValue; }
public static Object getDBObject(DBObject start, Path p) { int n = p.numSegments(); Object trc = start; for (int seg = 0; seg < n; seg++) { String segment = p.head(seg); if (segment.equals(Path.ANY)) { throw Error.get(MongoCrudConstants.ERR_TRANSLATION_ERROR, p.toString()); } else if (trc != null && Util.isNumber(segment)) { trc = ((List) trc).get(Integer.valueOf(segment)); } else if (trc != null) { trc = ((DBObject) trc).get(segment); } if (trc == null && seg + 1 < n) { //At least one element in the Path is optional and does not exist in the document. Just return null. LOGGER.debug("Error retrieving path {} with {} segments from {}", p, p.numSegments(), start); return null; } } return trc; }
public static Object getDBObject(DBObject start, Path p) { int n = p.numSegments(); Object trc = start; for (int seg = 0; seg < n; seg++) { String segment = p.head(seg); if (segment.equals(Path.ANY)) { throw Error.get(MongoCrudConstants.ERR_TRANSLATION_ERROR, p.toString()); } else if (Util.isNumber(segment)) { trc = ((List) trc).get(Integer.valueOf(segment)); } else { trc = ((DBObject) trc).get(segment); } if (trc == null&&seg+1<n) { throw Error.get(MongoCrudConstants.ERR_TRANSLATION_ERROR, p.toString()); } } return trc; }