3
* ====================================================================================================================================================
4
* "AppWork Utilities" License
5
* The "AppWork Utilities" will be called [The Product] from now on.
6
* ====================================================================================================================================================
7
* Copyright (c) 2009-2015, AppWork GmbH <e-mail@appwork.org>
8
* Schwabacher Straße 117
12
* This license establishes the terms under which the [The Product] Source Code & Binary files may be used, copied, modified, distributed, and/or redistributed.
13
* The intent is that the AppWork GmbH is able to provide their utilities library for free to non-commercial projects whereas commercial usage is only permitted after obtaining a commercial license.
14
* These terms apply to all files that have the [The Product] License header (IN the file), a <filename>.license or <filename>.info (like mylib.jar.info) file that contains a reference to this license.
16
* === 3rd Party Licences ===
17
* Some parts of the [The Product] use or reference 3rd party libraries and classes. These parts may have different licensing conditions. Please check the *.license and *.info files of included libraries
18
* to ensure that they are compatible to your use-case. Further more, some *.java have their own license. In this case, they have their license terms in the java file header.
20
* === Definition: Commercial Usage ===
21
* If anybody or any organization is generating income (directly or indirectly) by using [The Product] or if there's any commercial interest or aspect in what you are doing, we consider this as a commercial usage.
22
* If your use-case is neither strictly private nor strictly educational, it is commercial. If you are unsure whether your use-case is commercial or not, consider it as commercial or contact us.
23
* === Dual Licensing ===
24
* === Commercial Usage ===
25
* If you want to use [The Product] in a commercial way (see definition above), you have to obtain a paid license from AppWork GmbH.
26
* Contact AppWork for further details: <e-mail@appwork.org>
27
* === Non-Commercial Usage ===
28
* If there is no commercial usage (see definition above), you may use [The Product] under the terms of the
29
* "GNU Affero General Public License" (http://www.gnu.org/licenses/agpl-3.0.en.html).
31
* If the AGPL does not fit your needs, please contact us. We'll find a solution.
32
* ====================================================================================================================================================
33
* ==================================================================================================================================================== */
34
package org.appwork.storage.flexijson;
36
import java.io.IOException;
37
import java.util.ArrayList;
38
import java.util.Collection;
39
import java.util.LinkedList;
40
import java.util.function.UnaryOperator;
42
import org.appwork.exceptions.WTFException;
43
import org.appwork.storage.flexijson.stringify.FlexiJSonPrettyStringify;
44
import org.appwork.storage.flexijson.stringify.FlexiJSonStringBuilder;
45
import org.appwork.storage.flexijson.stringify.FlexiJSonStringBuilder.JSONBuilderOutputStream;
51
public class FlexiJSonArray extends ArrayList<FlexiJSonNode> implements FlexiJSonNode {
56
private static final long serialVersionUID = 1L;
58
public FlexiJSonArray() {
62
private FlexiJSonComments commentsBefore;
63
private FlexiJSonComments commentsInside;
66
public String toString() {
67
return getClass().getSimpleName() + " - " + new FlexiJSonPrettyStringify().toJSONString(this);
73
* @see org.appwork.storage.simplejson.JSonNode#toPrettyString()
76
public String toPrettyString() {
77
return new FlexiJSonPrettyStringify().toJSONString(this);
83
* @see java.util.ArrayList#add(java.lang.Object)
86
public boolean add(FlexiJSonNode e) {
94
* @see java.util.ArrayList#add(int, java.lang.Object)
97
public void add(int index, FlexiJSonNode e) {
105
* @see java.util.ArrayList#set(int, java.lang.Object)
108
public FlexiJSonNode set(int index, FlexiJSonNode e) {
110
return super.set(index, e);
116
* @see java.util.ArrayList#addAll(java.util.Collection)
119
public boolean addAll(Collection<? extends FlexiJSonNode> c) {
120
throw new WTFException("Not supported");
126
* @see java.util.ArrayList#addAll(int, java.util.Collection)
129
public boolean addAll(int index, Collection<? extends FlexiJSonNode> c) {
130
throw new WTFException("Not supported");
136
* @see java.util.ArrayList#replaceAll(java.util.function.UnaryOperator)
139
public void replaceAll(UnaryOperator<FlexiJSonNode> operator) {
140
throw new WTFException("Not supported");
146
* @see org.appwork.storage.flexijson.FlexiJSonNode#addCommentsBefore(org.appwork.storage.flexijson.FlexiJSonComments)
149
public void addCommentsBefore(FlexiJSonComments comments) {
150
if (comments == null) {
153
if (commentsBefore == null) {
154
commentsBefore = comments;
156
commentsBefore.addAll(comments);
164
* @see org.appwork.storage.flexijson.FlexiJSonNode#addCommentsAfter(org.appwork.storage.flexijson.FlexiJSonComments)
167
public void addCommentsAfter(FlexiJSonComments comments) {
168
if (comments == null) {
171
if (commentsAfter == null) {
172
commentsAfter = comments;
174
commentsAfter.addAll(comments);
179
public void addCommentsInside(FlexiJSonComments comments) {
180
if (comments == null) {
183
if (commentsInside == null) {
184
commentsInside = comments;
186
commentsInside.addAll(comments);
191
public FlexiJSonComments getCommentsInside() {
192
return commentsInside;
195
public void setCommentsInside(FlexiJSonComments commentsInside) {
196
this.commentsInside = commentsInside;
200
public FlexiJSonComments getCommentsBefore() {
201
return commentsBefore;
205
public void setCommentsBefore(FlexiJSonComments commentsBefore) {
206
this.commentsBefore = commentsBefore;
210
public FlexiJSonComments getCommentsAfter() {
211
return commentsAfter;
215
public void setCommentsAfter(FlexiJSonComments commentsAfter) {
216
this.commentsAfter = commentsAfter;
219
private FlexiJSonComments commentsAfter;
224
* @see org.appwork.storage.flexijson.FlexiJSonNode#toJSONString(org.appwork.storage.flexijson.FlexiJSonStringBuilder,
225
* java.io.OutputStream)
228
public void writeToStream(FlexiJSonStringBuilder stringifier, JSONBuilderOutputStream out, int layer, LinkedList<String> path) throws IOException {
229
stringifier.appendArray(this, out, layer, path);
236
* @see org.appwork.storage.flexijson.FlexiJSonNode#setParent(org.appwork.storage.flexijson.FlexiJSonNode)
238
private FlexiJSonNode parent;
241
public void setParent(FlexiJSonNode parent) {
242
this.parent = parent;
249
* @see org.appwork.storage.flexijson.FlexiJSonNode#getParent()
252
public FlexiJSonNode getParent() {