From 5223aadd67df246b4347731bd025dbbb0d4d53a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Er=C5=91s?= Date: Wed, 27 Apr 2016 00:10:06 +0200 Subject: [PATCH] added some javadoc to JSONPointer --- JSONPointer.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/JSONPointer.java b/JSONPointer.java index e5bc125..2b8bcd3 100644 --- a/JSONPointer.java +++ b/JSONPointer.java @@ -8,10 +8,22 @@ import java.net.URLDecoder; import java.util.ArrayList; import java.util.List; +/** + * A JSON Pointer is a simple query language defined for JSON documents by + * RFC 6901. + */ public class JSONPointer { private List refTokens; + /** + * Pre-parses and initializes a new {@code JSONPointer} instance. If you want to + * evaluate the same JSON Pointer on different JSON documents then it is recommended + * to keep the {@code JSONPointer} instances due to performance considerations. + * + * @param pointer the JSON String or URI Fragment representation of the JSON pointer. + * @throws IllegalArgumentException if {@code pointer} is not a valid JSON pointer + */ public JSONPointer(String pointer) { if (pointer == null) { throw new NullPointerException("pointer cannot be null"); @@ -44,6 +56,16 @@ public class JSONPointer { .replace("\\\\", "\\"); } + /** + * Evaluates this JSON Pointer on the given {@code document}. The {@code document} + * is usually a {@link JSONObject} or a {@link JSONArray} instance, but the empty + * JSON Pointer ({@code ""}) can be evaluated on any JSON values and in such case the + * returned value will be {@code document} itself. + * + * @param document the JSON document which should be the subject of querying. + * @return the result of the evaluation + * @throws JSONPointerException if an error occurs during evaluation + */ public Object queryFrom(Object document) { if (refTokens.isEmpty()) { return document;