Ignore:
Timestamp:
2017-12-23T02:40:43+01:00 (8 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/JsonValue.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:
     
    4444 * <code>JsonValue</code> represents an immutable JSON value.
    4545 *
    46  * 
     46 *
    4747 * <p>A JSON value is one of the following:
    4848 * an object ({@link JsonObject}), an array ({@link JsonArray}),
    4949 * a number ({@link JsonNumber}), a string ({@link JsonString}),
    50  * {@code true} ({@link JsonValue#TRUE JsonValue.TRUE}), {@code false} 
     50 * {@code true} ({@link JsonValue#TRUE JsonValue.TRUE}), {@code false}
    5151 * ({@link JsonValue#FALSE JsonValue.FALSE}),
    5252 * or {@code null} ({@link JsonValue#NULL JsonValue.NULL}).
    53  *
    54  * @author Jitendra Kotamraju
    5553 */
    5654public interface JsonValue {
     55
     56    /**
     57     * The empty JSON object.
     58     *
     59     * @since 1.1
     60     */
     61    static final JsonObject EMPTY_JSON_OBJECT = new EmptyObject();
     62
     63    /**
     64     * The empty JSON array.
     65     *
     66     * @since 1.1
     67     */
     68    static final JsonArray EMPTY_JSON_ARRAY = new EmptyArray();
    5769
    5870    /**
     
    99111     * JSON null value.
    100112     */
    101     static final JsonValue NULL = new JsonValue() {
    102         @Override
    103         public ValueType getValueType() {
    104             return ValueType.NULL;
    105         }
    106 
    107         /**
    108          * Compares the specified object with this {@link JsonValue#NULL}
    109          * object for equality. Returns {@code true} if and only if the
    110          * specified object is also a {@code JsonValue}, and their
    111          * {@link #getValueType()} objects are <i>equal</i>.
    112          *
    113          * @param obj the object to be compared for equality with this
    114          *      {@code JsonValue}
    115          * @return {@code true} if the specified object is equal to this
    116          *      {@code JsonValue}
    117          */
    118         @Override
    119         public boolean equals(Object obj) {
    120             if (obj instanceof JsonValue) {
    121                 return getValueType().equals(((JsonValue)obj).getValueType());
    122             }
    123             return false;
    124         }
    125 
    126         /**
    127          * Returns the hash code value for this {@link JsonValue#NULL} object.
    128          * The hash code of the {@link JsonValue#NULL} object is defined to be
    129          * its {@link #getValueType()} object's hash code.
    130          *
    131          * @return the hash code value for this JsonString object
    132          */
    133         @Override
    134         public int hashCode() {
    135             return ValueType.NULL.hashCode();
    136         }
    137 
    138         /**
    139          * Returns a "null" string.
    140          *
    141          * @return "null"
    142          */
    143         @Override
    144         public String toString() {
    145             return "null";
    146         }
    147     };
     113    static final JsonValue NULL = new JsonValueImpl(ValueType.NULL);
    148114
    149115    /**
    150116     * JSON true value.
    151117     */
    152     static final JsonValue TRUE = new JsonValue() {
    153         @Override
    154         public ValueType getValueType() {
    155             return ValueType.TRUE;
    156         }
    157 
    158         /**
    159          * Compares the specified object with this {@link JsonValue#TRUE}
    160          * object for equality. Returns {@code true} if and only if the
    161          * specified object is also a JsonValue, and their
    162          * {@link #getValueType()} objects are <i>equal</i>.
    163          *
    164          * @param obj the object to be compared for equality with this JsonValue.
    165          * @return {@code true} if the specified object is equal to this JsonValue.
    166          */
    167         @Override
    168         public boolean equals(Object obj) {
    169             if (obj instanceof JsonValue) {
    170                 return getValueType().equals(((JsonValue)obj).getValueType());
    171             }
    172             return false;
    173         }
    174 
    175         /**
    176          * Returns the hash code value for this {@link JsonValue#TRUE} object.
    177          * The hash code of the {@link JsonValue#TRUE} object is defined to be
    178          * its {@link #getValueType()} object's hash code.
    179          *
    180          * @return the hash code value for this JsonString object
    181          */
    182         @Override
    183         public int hashCode() {
    184             return ValueType.TRUE.hashCode();
    185         }
    186 
    187         /**
    188          * Returns "true" string
    189          *
    190          * @return "true"
    191          */
    192         @Override
    193         public String toString() {
    194             return "true";
    195         }
    196     };
     118    static final JsonValue TRUE = new JsonValueImpl(ValueType.TRUE);
    197119
    198120    /**
    199      * JSON false value
     121     * JSON false value.
    200122     */
    201     static final JsonValue FALSE = new JsonValue() {
    202         @Override
    203         public ValueType getValueType() {
    204             return ValueType.FALSE;
    205         }
    206 
    207         /**
    208          * Compares the specified object with this {@link JsonValue#FALSE}
    209          * object for equality. Returns {@code true} if and only if the
    210          * specified object is also a JsonValue, and their
    211          * {@link #getValueType()} objects are <i>equal</i>.
    212          *
    213          * @param obj the object to be compared for equality with this JsonValue
    214          * @return {@code true} if the specified object is equal to this JsonValue
    215          */
    216         @Override
    217         public boolean equals(Object obj) {
    218             if (obj instanceof JsonValue) {
    219                 return getValueType().equals(((JsonValue)obj).getValueType());
    220             }
    221             return false;
    222         }
    223 
    224         /**
    225          * Returns the hash code value for this {@link JsonValue#FALSE} object.
    226          * The hash code of the {@link JsonValue#FALSE} object is defined to be
    227          * its {@link #getValueType()} object's hash code.
    228          *
    229          * @return the hash code value for this JsonString object
    230          */
    231         @Override
    232         public int hashCode() {
    233             return ValueType.FALSE.hashCode();
    234         }
    235 
    236         /**
    237          * Returns "false" string
    238          *
    239          * @return "false"
    240          */
    241         @Override
    242         public String toString() {
    243             return "false";
    244         }
    245     };
     123    static final JsonValue FALSE = new JsonValueImpl(ValueType.FALSE);
    246124
    247125    /**
     
    251129     */
    252130    ValueType getValueType();
     131
     132    /**
     133     * Return the JsonValue as a JsonObject
     134     *
     135     * @return the JsonValue as a JsonObject
     136     * @throws ClassCastException if the JsonValue is not a JsonObject
     137     *
     138     * @since 1.1
     139     */
     140    default JsonObject asJsonObject() {
     141        return JsonObject.class.cast(this);
     142    }
     143
     144    /**
     145     * Return the JsonValue as a JsonArray
     146     *
     147     * @return the JsonValue as a JsonArray
     148     * @throws ClassCastException if the JsonValue is not a JsonArray
     149     *
     150     * @since 1.1
     151     */
     152    default JsonArray asJsonArray() {
     153        return JsonArray.class.cast(this);
     154    }
    253155
    254156    /**
Note: See TracChangeset for help on using the changeset viewer.