Skip to contentMethod: prependItem(JsonNode)
1: /*
2: * JB4JSON-LD
3: * Copyright (C) 2023 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jsonld.serialization.model;
19:
20: import cz.cvut.kbss.jsonld.serialization.JsonGenerator;
21:
22: import java.io.IOException;
23: import java.util.ArrayList;
24: import java.util.List;
25:
26: /**
27: * Represents a JSON object node.
28: * <p>
29: * I.e. it is a set of key-value pairs, which constitute the state of the object.
30: */
31: public class ObjectNode extends CompositeNode<List<JsonNode>> {
32:
33: public ObjectNode() {
34: }
35:
36: public ObjectNode(String name) {
37: super(name);
38: }
39:
40: @Override
41: List<JsonNode> initItems() {
42: return new ArrayList<>();
43: }
44:
45: public void prependItem(JsonNode node) {
46: items.add(0, node);
47: }
48:
49: @Override
50: protected void writeValue(JsonGenerator writer) throws IOException {
51: writer.writeObjectStart();
52: items.forEach(child -> child.write(writer));
53: writer.writeObjectEnd();
54: }
55:
56: @Override
57: public String toString() {
58: return super.toString() + items + "}";
59: }
60: }