~jd-team/jdownloader/appwork-utils

« back to all changes in this revision

Viewing changes to src/org/appwork/storage/flexijson/FlexiJSonArray.java

  • Committer: thomas
  • Date: 2021-06-15 09:46:56 UTC
  • Revision ID: svn-v4:21714237-3853-44ef-a1f0-ef8f03a7d1fe::3520
ContextMenuAdapter: Added MouseEvent
Added $THIS and $SIZE to Condition
JSONFactory:
Refactoring for EditorDialog
Added String Dedupe
StorableDoc Annotations: Annotate Storables., these Annotations are used in the EditorDialog
Files.deleteRecursive: TO Discuss!
ReflectionUtils: Added is<NUMBER>Range Methods
ReflectionUtils: changed cast function to cast *.0 floatingpoints to the correct fixedpoint number
FlexiJSON: Added a very flexible, error prone JSON Parser - supports Streams in parsing and stringify. Different JSON Types are supported, including JSON5, comments, JS Objects,...Added compact Stringifer, pretty Printer and Properties Style Printer. 
Added JSON to Properties and Properties to JSON Converter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 *
 
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
 
9
 *         90763 Fürth
 
10
 *         Germany
 
11
 * === Preamble ===
 
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.
 
15
 *
 
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.
 
19
 *
 
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).
 
30
 *
 
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;
 
35
 
 
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;
 
41
 
 
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;
 
46
 
 
47
/**
 
48
 * @author thomas
 
49
 *
 
50
 */
 
51
public class FlexiJSonArray extends ArrayList<FlexiJSonNode> implements FlexiJSonNode {
 
52
 
 
53
    /**
 
54
     *
 
55
     */
 
56
    private static final long serialVersionUID = 1L;
 
57
 
 
58
    public FlexiJSonArray() {
 
59
        super();
 
60
    }
 
61
 
 
62
    private FlexiJSonComments commentsBefore;
 
63
    private FlexiJSonComments commentsInside;
 
64
 
 
65
    @Override
 
66
    public String toString() {
 
67
        return getClass().getSimpleName() + " - " + new FlexiJSonPrettyStringify().toJSONString(this);
 
68
    }
 
69
 
 
70
    /*
 
71
     * (non-Javadoc)
 
72
     *
 
73
     * @see org.appwork.storage.simplejson.JSonNode#toPrettyString()
 
74
     */
 
75
 
 
76
    public String toPrettyString() {
 
77
        return new FlexiJSonPrettyStringify().toJSONString(this);
 
78
    }
 
79
 
 
80
    /*
 
81
     * (non-Javadoc)
 
82
     *
 
83
     * @see java.util.ArrayList#add(java.lang.Object)
 
84
     */
 
85
    @Override
 
86
    public boolean add(FlexiJSonNode e) {
 
87
        e.setParent(this);
 
88
        return super.add(e);
 
89
    }
 
90
 
 
91
    /*
 
92
     * (non-Javadoc)
 
93
     *
 
94
     * @see java.util.ArrayList#add(int, java.lang.Object)
 
95
     */
 
96
    @Override
 
97
    public void add(int index, FlexiJSonNode e) {
 
98
        e.setParent(this);
 
99
        super.add(index, e);
 
100
    }
 
101
 
 
102
    /*
 
103
     * (non-Javadoc)
 
104
     *
 
105
     * @see java.util.ArrayList#set(int, java.lang.Object)
 
106
     */
 
107
    @Override
 
108
    public FlexiJSonNode set(int index, FlexiJSonNode e) {
 
109
        e.setParent(this);
 
110
        return super.set(index, e);
 
111
    }
 
112
 
 
113
    /*
 
114
     * (non-Javadoc)
 
115
     *
 
116
     * @see java.util.ArrayList#addAll(java.util.Collection)
 
117
     */
 
118
    @Override
 
119
    public boolean addAll(Collection<? extends FlexiJSonNode> c) {
 
120
        throw new WTFException("Not supported");
 
121
    }
 
122
 
 
123
    /*
 
124
     * (non-Javadoc)
 
125
     *
 
126
     * @see java.util.ArrayList#addAll(int, java.util.Collection)
 
127
     */
 
128
    @Override
 
129
    public boolean addAll(int index, Collection<? extends FlexiJSonNode> c) {
 
130
        throw new WTFException("Not supported");
 
131
    }
 
132
 
 
133
    /*
 
134
     * (non-Javadoc)
 
135
     *
 
136
     * @see java.util.ArrayList#replaceAll(java.util.function.UnaryOperator)
 
137
     */
 
138
    @Override
 
139
    public void replaceAll(UnaryOperator<FlexiJSonNode> operator) {
 
140
        throw new WTFException("Not supported");
 
141
    }
 
142
 
 
143
    /*
 
144
     * (non-Javadoc)
 
145
     *
 
146
     * @see org.appwork.storage.flexijson.FlexiJSonNode#addCommentsBefore(org.appwork.storage.flexijson.FlexiJSonComments)
 
147
     */
 
148
    @Override
 
149
    public void addCommentsBefore(FlexiJSonComments comments) {
 
150
        if (comments == null) {
 
151
            return;
 
152
        }
 
153
        if (commentsBefore == null) {
 
154
            commentsBefore = comments;
 
155
        } else {
 
156
            commentsBefore.addAll(comments);
 
157
        }
 
158
 
 
159
    }
 
160
 
 
161
    /*
 
162
     * (non-Javadoc)
 
163
     *
 
164
     * @see org.appwork.storage.flexijson.FlexiJSonNode#addCommentsAfter(org.appwork.storage.flexijson.FlexiJSonComments)
 
165
     */
 
166
    @Override
 
167
    public void addCommentsAfter(FlexiJSonComments comments) {
 
168
        if (comments == null) {
 
169
            return;
 
170
        }
 
171
        if (commentsAfter == null) {
 
172
            commentsAfter = comments;
 
173
        } else {
 
174
            commentsAfter.addAll(comments);
 
175
        }
 
176
 
 
177
    }
 
178
 
 
179
    public void addCommentsInside(FlexiJSonComments comments) {
 
180
        if (comments == null) {
 
181
            return;
 
182
        }
 
183
        if (commentsInside == null) {
 
184
            commentsInside = comments;
 
185
        } else {
 
186
            commentsInside.addAll(comments);
 
187
        }
 
188
 
 
189
    }
 
190
 
 
191
    public FlexiJSonComments getCommentsInside() {
 
192
        return commentsInside;
 
193
    }
 
194
 
 
195
    public void setCommentsInside(FlexiJSonComments commentsInside) {
 
196
        this.commentsInside = commentsInside;
 
197
    }
 
198
 
 
199
    @Override
 
200
    public FlexiJSonComments getCommentsBefore() {
 
201
        return commentsBefore;
 
202
    }
 
203
 
 
204
    @Override
 
205
    public void setCommentsBefore(FlexiJSonComments commentsBefore) {
 
206
        this.commentsBefore = commentsBefore;
 
207
    }
 
208
 
 
209
    @Override
 
210
    public FlexiJSonComments getCommentsAfter() {
 
211
        return commentsAfter;
 
212
    }
 
213
 
 
214
    @Override
 
215
    public void setCommentsAfter(FlexiJSonComments commentsAfter) {
 
216
        this.commentsAfter = commentsAfter;
 
217
    }
 
218
 
 
219
    private FlexiJSonComments commentsAfter;
 
220
 
 
221
    /*
 
222
     * (non-Javadoc)
 
223
     *
 
224
     * @see org.appwork.storage.flexijson.FlexiJSonNode#toJSONString(org.appwork.storage.flexijson.FlexiJSonStringBuilder,
 
225
     * java.io.OutputStream)
 
226
     */
 
227
    @Override
 
228
    public void writeToStream(FlexiJSonStringBuilder stringifier, JSONBuilderOutputStream out, int layer, LinkedList<String> path) throws IOException {
 
229
        stringifier.appendArray(this, out, layer, path);
 
230
 
 
231
    }
 
232
 
 
233
    /*
 
234
     * (non-Javadoc)
 
235
     *
 
236
     * @see org.appwork.storage.flexijson.FlexiJSonNode#setParent(org.appwork.storage.flexijson.FlexiJSonNode)
 
237
     */
 
238
    private FlexiJSonNode parent;
 
239
 
 
240
    @Override
 
241
    public void setParent(FlexiJSonNode parent) {
 
242
        this.parent = parent;
 
243
 
 
244
    }
 
245
 
 
246
    /*
 
247
     * (non-Javadoc)
 
248
     *
 
249
     * @see org.appwork.storage.flexijson.FlexiJSonNode#getParent()
 
250
     */
 
251
    @Override
 
252
    public FlexiJSonNode getParent() {
 
253
        return parent;
 
254
    }
 
255
}