default void forEach(BiConsumer<Path, Value> consumer) { Path root = Path.root(); stream().forEach((field) -> { Path path = root.append(field.getName().toString()); Value value = field.getValue(); if (value.isDocument()) { value.asDocument().forEach((p, v) -> { consumer.accept(path.append(p), v); }); } else if (value.isArray()) { value.asArray().forEach((entry) -> { consumer.accept(path.append(Integer.toString(entry.getIndex())), entry.getValue()); }); } else { consumer.accept(path, value); } }); }
@Override public boolean equals(Object obj) { if ( obj == this ) return true; if ( obj instanceof Array.Entry ) { Array.Entry that = (Array.Entry)obj; return this.getIndex() == that.getIndex() && Objects.equals(this.getValue(),that.getValue()); } return false; }
/** * Sets on this object all key/value pairs from the supplied map. If the supplied map is null, this method does nothing. * * @param entries the entries that are to be used to modify this array * @return this array to allow for chaining methods */ default Array putAll(Iterable<Entry> entries) { if (entries != null) { entries.forEach(entry -> { if (entry != null) { Value value = entry.getValue().clone(); setValue(entry.getIndex(), value); } }); } return this; }
default void forEach(BiConsumer<Path, Value> consumer) { Path root = Path.root(); stream().forEach((field) -> { Path path = root.append(field.getName().toString()); Value value = field.getValue(); if (value.isDocument()) { value.asDocument().forEach((p, v) -> { consumer.accept(path.append(p), v); }); } else if (value.isArray()) { value.asArray().forEach((entry) -> { consumer.accept(path.append(Integer.toString(entry.getIndex())), entry.getValue()); }); } else { consumer.accept(path, value); } }); }
/** * Sets on this object all key/value pairs from the supplied map. If the supplied map is null, this method does nothing. * * @param entries the entries that are to be used to modify this array * @return this array to allow for chaining methods */ default Array putAll(Iterable<Entry> entries) { if (entries != null) { entries.forEach(entry -> { if (entry != null) { Value value = entry.getValue().clone(); setValue(entry.getIndex(), value); } }); } return this; }
@Override public boolean equals(Object obj) { if ( obj == this ) return true; if ( obj instanceof Array.Entry ) { Array.Entry that = (Array.Entry)obj; return this.getIndex() == that.getIndex() && Objects.equals(this.getValue(),that.getValue()); } return false; }