Ignore:
Timestamp:
2017-12-23T02:40:43+01:00 (6 years ago)
Author:
Don-vip
Message:

see #15682 - upgrade to JSR 374 (JSON Processing) API 1.1.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/javax/json/JsonArray.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2011-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2011-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * 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
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * 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.
    1717 *
    1818 * GPL Classpath Exception:
     
    4242
    4343import java.util.List;
     44import java.util.function.Function;
     45import java.util.stream.Collectors;
     46import java.util.stream.Stream;
    4447
    4548/**
     
    111114 * whether directly or using its collection views, results in an
    112115 * {@code UnsupportedOperationException}.
    113  *
    114  * @author Jitendra Kotamraju
    115116 */
    116117public interface JsonArray extends JsonStructure, List<JsonValue> {
     
    165166
    166167    /**
    167      * Returns a list a view of the specified type for the array. This method
     168     * Returns a list view of the specified type for the array. This method
    168169     * does not verify if there is a value of wrong type in the array. Providing
    169170     * this typesafe view dynamically may cause a program fail with a
     
    172173     * method returns.
    173174     *
     175     * @param <T> The type of the List for the array
    174176     * @param clazz a JsonValue type
    175      * @return a list view of the  specified type
     177     * @return a list view of the specified type
    176178     */
    177179    <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    }
    178206
    179207    /**
     
    195223     * the specified default value is returned.
    196224     *
    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}
    198228     * @return the String value at the specified position in this array,
    199229     * or the specified default value
     
    220250     *
    221251     * @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}
    222254     * @return the int value at the specified position in this array,
    223255     * or the specified default value
     
    247279     *
    248280     * @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
    249283     * @return the boolean value at the specified position,
    250284     * or the specified default value
     
    258292     * @param index index of the JSON null value
    259293     * @return return true if the value at the specified location is
    260      * {@code JsonValue.NUL}, otherwise false
     294     * {@code JsonValue.NULL}, otherwise false
    261295     * @throws IndexOutOfBoundsException if the index is out of range
    262296     */
    263297    boolean isNull(int index);
    264 
    265298}
Note: See TracChangeset for help on using the changeset viewer.