source: josm/trunk/src/javax/json/JsonPointer.java@ 15842

Last change on this file since 15842 was 13231, checked in by Don-vip, 7 years ago

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

File size: 6.8 KB
Line 
1/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright (c) 2015-2017 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://oss.oracle.com/licenses/CDDL+GPL-1.1
12 * or 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 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
41package javax.json;
42
43/**
44 * <p>This interface represents an immutable implementation of a JSON Pointer
45 * as defined by <a href="http://tools.ietf.org/html/rfc6901">RFC 6901</a>.
46 * </p>
47 * <p> A JSON Pointer, when applied to a target {@link JsonValue},
48 * defines a reference location in the target.</p>
49 * <p> An empty JSON Pointer string defines a reference to the target itself.</p>
50 * <p> If the JSON Pointer string is non-empty, it must be a sequence
51 * of '/' prefixed tokens, and the target must either be a {@link JsonArray}
52 * or {@link JsonObject}. If the target is a {@code JsonArray}, the pointer
53 * defines a reference to an array element, and the last token specifies the index.
54 * If the target is a {@link JsonObject}, the pointer defines a reference to a
55 * name/value pair, and the last token specifies the name.
56 * </p>
57 * <p> The method {@link #getValue getValue()} returns the referenced value.
58 * Methods {@link #add add()}, {@link #replace replace()},
59 * and {@link #remove remove()} execute operations specified in
60 * <a href="http://tools.ietf.org/html/rfc6902">RFC 6902</a>. </p>
61 *
62 * @see <a href="http://tools.ietf.org/html/rfc6901">RFC 6901</a>
63 * @see <a href="http://tools.ietf.org/html/rfc6902">RFC 6902</a>
64 *
65 * @since 1.1
66 */
67public interface JsonPointer {
68
69 /**
70 * Adds or replaces a value at the referenced location in the specified
71 * {@code target} with the specified {@code value}.
72 * <ol>
73 * <li>If the reference is the target (empty JSON Pointer string),
74 * the specified {@code value}, which must be the same type as
75 * specified {@code target}, is returned.</li>
76 * <li>If the reference is an array element, the specified {@code value} is inserted
77 * into the array, at the referenced index. The value currently at that location, and
78 * any subsequent values, are shifted to the right (adds one to the indices).
79 * Index starts with 0. If the reference is specified with a "-", or if the
80 * index is equal to the size of the array, the value is appended to the array.</li>
81 * <li>If the reference is a name/value pair of a {@code JsonObject}, and the
82 * referenced value exists, the value is replaced by the specified {@code value}.
83 * If the value does not exist, a new name/value pair is added to the object.</li>
84 * </ol>
85 *
86 * @param <T> the target type, must be a subtype of {@link JsonValue}
87 * @param target the target referenced by this {@code JsonPointer}
88 * @param value the value to be added
89 * @return the transformed {@code target} after the value is added.
90 * @throws NullPointerException if {@code target} is {@code null}
91 * @throws JsonException if the reference is an array element and
92 * the index is out of range ({@code index < 0 || index > array size}),
93 * or if the pointer contains references to non-existing objects or arrays.
94 */
95 <T extends JsonStructure> T add(T target, JsonValue value);
96
97 /**
98 * Removes the value at the reference location in the specified {@code target}.
99 *
100 * @param <T> the target type, must be a subtype of {@link JsonValue}
101 * @param target the target referenced by this {@code JsonPointer}
102 * @return the transformed {@code target} after the value is removed.
103 * @throws NullPointerException if {@code target} is {@code null}
104 * @throws JsonException if the referenced value does not exist,
105 * or if the reference is the target.
106 */
107 <T extends JsonStructure> T remove(T target);
108
109 /**
110 * Replaces the value at the referenced location in the specified
111 * {@code target} with the specified {@code value}.
112 *
113 * @param <T> the target type, must be a subtype of {@link JsonValue}
114 * @param target the target referenced by this {@code JsonPointer}
115 * @param value the value to be stored at the referenced location
116 * @return the transformed {@code target} after the value is replaced.
117 * @throws NullPointerException if {@code target} is {@code null}
118 * @throws JsonException if the referenced value does not exist,
119 * or if the reference is the target.
120 */
121 <T extends JsonStructure> T replace(T target, JsonValue value);
122
123 /**
124 * Returns {@code true} if there is a value at the referenced location in the specified {@code target}.
125 *
126 * @param target the target referenced by this {@code JsonPointer}
127 * @return {@code true} if this pointer points to a value in a specified {@code target}.
128 */
129 boolean containsValue(JsonStructure target);
130
131 /**
132 * Returns the value at the referenced location in the specified {@code target}.
133 *
134 * @param target the target referenced by this {@code JsonPointer}
135 * @return the referenced value in the target.
136 * @throws NullPointerException if {@code target} is null
137 * @throws JsonException if the referenced value does not exist
138 */
139 JsonValue getValue(JsonStructure target);
140}
Note: See TracBrowser for help on using the repository browser.