1 | /*
|
---|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
---|
3 | *
|
---|
4 | * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
|
---|
5 | *
|
---|
6 | * The contents of this file are subject to the terms of either the GNU
|
---|
7 | * General Public License Version 2 only ("GPL") or the Common Development
|
---|
8 | * and Distribution License("CDDL") (collectively, the "License"). You
|
---|
9 | * may not use this file except in compliance with the License. You can
|
---|
10 | * obtain a copy of the License at
|
---|
11 | * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
|
---|
12 | * or packager/legal/LICENSE.txt. See the License for the specific
|
---|
13 | * language governing permissions and limitations under the License.
|
---|
14 | *
|
---|
15 | * When distributing the software, include this License Header Notice in each
|
---|
16 | * file and include the License file at packager/legal/LICENSE.txt.
|
---|
17 | *
|
---|
18 | * GPL Classpath Exception:
|
---|
19 | * Oracle designates this particular file as subject to the "Classpath"
|
---|
20 | * exception as provided by Oracle in the GPL Version 2 section of the License
|
---|
21 | * file that accompanied this code.
|
---|
22 | *
|
---|
23 | * Modifications:
|
---|
24 | * If applicable, add the following below the License Header, with the fields
|
---|
25 | * enclosed by brackets [] replaced by your own identifying information:
|
---|
26 | * "Portions Copyright [year] [name of copyright owner]"
|
---|
27 | *
|
---|
28 | * Contributor(s):
|
---|
29 | * If you wish your version of this file to be governed by only the CDDL or
|
---|
30 | * only the GPL Version 2, indicate your decision by adding "[Contributor]
|
---|
31 | * elects to include this software in this distribution under the [CDDL or GPL
|
---|
32 | * Version 2] license." If you don't indicate a single choice of license, a
|
---|
33 | * recipient has the option to distribute your version of this file under
|
---|
34 | * either the CDDL, the GPL Version 2 or to extend the choice of license to
|
---|
35 | * its licensees as provided above. However, if you add GPL Version 2 code
|
---|
36 | * and therefore, elected the GPL Version 2 license, then the option applies
|
---|
37 | * only if the new code is made subject to such option by the copyright
|
---|
38 | * holder.
|
---|
39 | */
|
---|
40 |
|
---|
41 | package javax.json;
|
---|
42 |
|
---|
43 | import java.math.BigDecimal;
|
---|
44 | import java.math.BigInteger;
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * A builder for creating {@link JsonArray} models from scratch. This
|
---|
48 | * interface initializes an empty JSON array model and provides methods to add
|
---|
49 | * values to the array model and to return the resulting array. The methods
|
---|
50 | * in this class can be chained to add multiple values to the array.
|
---|
51 | *
|
---|
52 | * <p>The class {@link javax.json.Json} contains methods to create the builder
|
---|
53 | * object. The example code below shows how to build an empty {@code JsonArray}
|
---|
54 | * instance.
|
---|
55 | * <pre>
|
---|
56 | * <code>
|
---|
57 | * JsonArray array = Json.createArrayBuilder().build();
|
---|
58 | * </code>
|
---|
59 | * </pre>
|
---|
60 | *
|
---|
61 | * <p>The class {@link JsonBuilderFactory} also contains methods to create
|
---|
62 | * {@code JsonArrayBuilder} instances. A factory instance can be used to create
|
---|
63 | * multiple builder instances with the same configuration. This the preferred
|
---|
64 | * way to create multiple instances.
|
---|
65 | *
|
---|
66 | * <a id="JsonArrayBuilderExample1"/>
|
---|
67 | * The example code below shows how to build a {@code JsonArray} object
|
---|
68 | * that represents the following JSON array:
|
---|
69 | *
|
---|
70 | * <pre>
|
---|
71 | * <code>
|
---|
72 | * [
|
---|
73 | * { "type": "home", "number": "212 555-1234" },
|
---|
74 | * { "type": "fax", "number": "646 555-4567" }
|
---|
75 | * ]
|
---|
76 | * </code>
|
---|
77 | * </pre>
|
---|
78 | *
|
---|
79 | * <p>The following code creates the JSON array above:
|
---|
80 | *
|
---|
81 | * <pre>
|
---|
82 | * <code>
|
---|
83 | * JsonBuilderFactory factory = Json.createBuilderFactory(config);
|
---|
84 | * JsonArray value = factory.createArrayBuilder()
|
---|
85 | * .add(factory.createObjectBuilder()
|
---|
86 | * .add("type", "home")
|
---|
87 | * .add("number", "212 555-1234"))
|
---|
88 | * .add(factory.createObjectBuilder()
|
---|
89 | * .add("type", "fax")
|
---|
90 | * .add("number", "646 555-4567"))
|
---|
91 | * .build();
|
---|
92 | * </code>
|
---|
93 | * </pre>
|
---|
94 | *
|
---|
95 | * <p>This class does <em>not</em> allow <tt>null</tt> to be used as a
|
---|
96 | * value while building the JSON array
|
---|
97 | *
|
---|
98 | * @see JsonObjectBuilder
|
---|
99 | */
|
---|
100 | public interface JsonArrayBuilder {
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Adds a value to the array.
|
---|
104 | *
|
---|
105 | * @param value the JSON value
|
---|
106 | * @return this array builder
|
---|
107 | * @throws NullPointerException if the specified value is null
|
---|
108 | */
|
---|
109 | JsonArrayBuilder add(JsonValue value);
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Adds a value to the array as a {@link JsonString}.
|
---|
113 | *
|
---|
114 | * @param value the string value
|
---|
115 | * @return this array builder
|
---|
116 | * @throws NullPointerException if the specified value is null
|
---|
117 | */
|
---|
118 | JsonArrayBuilder add(String value);
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Adds a value to the array as a {@link JsonNumber}.
|
---|
122 | *
|
---|
123 | * @param value the number value
|
---|
124 | * @return this array builder
|
---|
125 | * @throws NullPointerException if the specified value is null
|
---|
126 | *
|
---|
127 | * @see JsonNumber
|
---|
128 | */
|
---|
129 | JsonArrayBuilder add(BigDecimal value);
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Adds a value to the array as a {@link JsonNumber}.
|
---|
133 | *
|
---|
134 | * @param value the number value
|
---|
135 | * @return this array builder
|
---|
136 | * @throws NullPointerException if the specified value is null
|
---|
137 | *
|
---|
138 | * @see JsonNumber
|
---|
139 | */
|
---|
140 | JsonArrayBuilder add(BigInteger value);
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * Adds a value to the array as a {@link JsonNumber}.
|
---|
144 | *
|
---|
145 | * @param value the number value
|
---|
146 | * @return this array builder
|
---|
147 | *
|
---|
148 | * @see JsonNumber
|
---|
149 | */
|
---|
150 | JsonArrayBuilder add(int value);
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Adds a value to the array as a {@link JsonNumber}.
|
---|
154 | *
|
---|
155 | * @param value the number value
|
---|
156 | * @return this array builder
|
---|
157 | *
|
---|
158 | * @see JsonNumber
|
---|
159 | */
|
---|
160 | JsonArrayBuilder add(long value);
|
---|
161 |
|
---|
162 | /**
|
---|
163 | * Adds a value to the array as a {@link JsonNumber}.
|
---|
164 | *
|
---|
165 | * @param value the number value
|
---|
166 | * @return this array builder
|
---|
167 | * @throws NumberFormatException if the value is Not-a-Number(NaN) or
|
---|
168 | * infinity
|
---|
169 | *
|
---|
170 | * @see JsonNumber
|
---|
171 | */
|
---|
172 | JsonArrayBuilder add(double value);
|
---|
173 |
|
---|
174 | /**
|
---|
175 | * Adds a {@link JsonValue#TRUE} or {@link JsonValue#FALSE} value to the
|
---|
176 | * array.
|
---|
177 | *
|
---|
178 | * @param value the boolean value
|
---|
179 | * @return this array builder
|
---|
180 | */
|
---|
181 | JsonArrayBuilder add(boolean value);
|
---|
182 |
|
---|
183 | /**
|
---|
184 | * Adds a {@link JsonValue#NULL} value to the array.
|
---|
185 | *
|
---|
186 | * @return this array builder
|
---|
187 | */
|
---|
188 | JsonArrayBuilder addNull();
|
---|
189 |
|
---|
190 | /**
|
---|
191 | * Adds a {@link JsonObject} from an object builder to the array.
|
---|
192 | *
|
---|
193 | * @param builder the object builder
|
---|
194 | * @return this array builder
|
---|
195 | * @throws NullPointerException if the specified builder is null
|
---|
196 | */
|
---|
197 | JsonArrayBuilder add(JsonObjectBuilder builder);
|
---|
198 |
|
---|
199 | /**
|
---|
200 | * Adds a {@link JsonArray} from an array builder to the array.
|
---|
201 | *
|
---|
202 | * @param builder the array builder
|
---|
203 | * @return this array builder
|
---|
204 | * @throws NullPointerException if the specified builder is null
|
---|
205 | */
|
---|
206 | JsonArrayBuilder add(JsonArrayBuilder builder);
|
---|
207 |
|
---|
208 | /**
|
---|
209 | * Returns the current array.
|
---|
210 | *
|
---|
211 | * @return the current JSON array
|
---|
212 | */
|
---|
213 | JsonArray build();
|
---|
214 |
|
---|
215 | }
|
---|
216 |
|
---|