Changeset 13231 in josm for trunk/src/javax/json/JsonArray.java
- Timestamp:
- 2017-12-23T02:40:43+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/javax/json/JsonArray.java
r6756 r13231 2 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 3 * 4 * Copyright (c) 2011-201 3Oracle and/or its affiliates. All rights reserved.4 * Copyright (c) 2011-2017 Oracle and/or its affiliates. All rights reserved. 5 5 * 6 6 * The contents of this file are subject to the terms of either the GNU … … 9 9 * may not use this file except in compliance with the License. You can 10 10 * obtain a copy of the License at 11 * https:// glassfish.dev.java.net/public/CDDL+GPL_1_1.html12 * or packager/legal/LICENSE.txt. See the License for the specific11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 * or LICENSE.txt. See the License for the specific 13 13 * language governing permissions and limitations under the License. 14 14 * 15 15 * When distributing the software, include this License Header Notice in each 16 * file and include the License file at packager/legal/LICENSE.txt.16 * file and include the License file at LICENSE.txt. 17 17 * 18 18 * GPL Classpath Exception: … … 42 42 43 43 import java.util.List; 44 import java.util.function.Function; 45 import java.util.stream.Collectors; 46 import java.util.stream.Stream; 44 47 45 48 /** … … 111 114 * whether directly or using its collection views, results in an 112 115 * {@code UnsupportedOperationException}. 113 *114 * @author Jitendra Kotamraju115 116 */ 116 117 public interface JsonArray extends JsonStructure, List<JsonValue> { … … 165 166 166 167 /** 167 * Returns a list aview of the specified type for the array. This method168 * Returns a list view of the specified type for the array. This method 168 169 * does not verify if there is a value of wrong type in the array. Providing 169 170 * this typesafe view dynamically may cause a program fail with a … … 172 173 * method returns. 173 174 * 175 * @param <T> The type of the List for the array 174 176 * @param clazz a JsonValue type 175 * @return a list view of the 177 * @return a list view of the specified type 176 178 */ 177 179 <T extends JsonValue> List<T> getValuesAs(Class<T> clazz); 180 181 /** 182 * Returns a list view for the array. The value and the type of the elements 183 * in the list is specified by the {@code func} argument. 184 * <p>This method can be used to obtain a list of the unwrapped types, such as 185 * <pre>{@code 186 * List<String> strings = ary1.getValuesAs(JsonString::getString); 187 * List<Integer> ints = ary2.getValuesAs(JsonNumber::intValue); 188 * } </pre> 189 * or a list of simple projections, such as 190 * <pre> {@code 191 * List<Integer> stringsizes = ary1.getValueAs((JsonString v)->v.getString().length(); 192 * } </pre> 193 * @param <K> The element type (must be a subtype of JsonValue) of this JsonArray. 194 * @param <T> The element type of the returned List 195 * @param func The function that maps the elements of this JsonArray to the target elements. 196 * @return A List of the specified values and type. 197 * @throws ClassCastException if the {@code JsonArray} contains a value of wrong type 198 * 199 * @since 1.1 200 */ 201 default <T, K extends JsonValue> List<T> getValuesAs(Function<K, T> func) { 202 @SuppressWarnings("unchecked") 203 Stream<K> stream = (Stream<K>) stream(); 204 return stream.map(func).collect(Collectors.toList()); 205 } 178 206 179 207 /** … … 195 223 * the specified default value is returned. 196 224 * 197 * @param index index of the JsonString value 225 * @param index index of the {@code JsonString} value 226 * @param defaultValue the String to return if the {@code JsonValue} at the 227 * specified position is not a {@code JsonString} 198 228 * @return the String value at the specified position in this array, 199 229 * or the specified default value … … 220 250 * 221 251 * @param index index of the {@code JsonNumber} value 252 * @param defaultValue the int value to return if the {@code JsonValue} at 253 * the specified position is not a {@code JsonNumber} 222 254 * @return the int value at the specified position in this array, 223 255 * or the specified default value … … 247 279 * 248 280 * @param index index of the JSON boolean value 281 * @param defaultValue the boolean value to return if the {@code JsonValue} 282 * at the specified position is neither TRUE nor FALSE 249 283 * @return the boolean value at the specified position, 250 284 * or the specified default value … … 258 292 * @param index index of the JSON null value 259 293 * @return return true if the value at the specified location is 260 * {@code JsonValue.NUL }, otherwise false294 * {@code JsonValue.NULL}, otherwise false 261 295 * @throws IndexOutOfBoundsException if the index is out of range 262 296 */ 263 297 boolean isNull(int index); 264 265 298 }
Note:
See TracChangeset
for help on using the changeset viewer.