@Override public final boolean equals(final Object obj) { if (obj == null) return false; if (this == obj) return true; if (getClass() != obj.getClass()) return false; final TokenResolver<?> other = (TokenResolver<?>) obj; return token.equals(other.token); }
/** * Generate a reference token from a decoded (raw) representation * * @param raw the input * @return a token * @throws NullPointerException null input */ public static ReferenceToken fromRaw(final String raw) { BUNDLE.checkNotNull(raw, "nullInput"); return new ReferenceToken(asCooked(raw), raw); }
/** * Generate a reference token from an encoded (cooked) representation * * @param cooked the input * @return a token * @throws JsonPointerException illegal token (bad encode sequence) * @throws NullPointerException null input */ public static ReferenceToken fromCooked(final String cooked) throws JsonPointerException { BUNDLE.checkNotNull(cooked, "nullInput"); return new ReferenceToken(cooked, asRaw(cooked)); }
@Override public JsonNode get(final JsonNode node) { if (node == null || !node.isContainerNode()) return null; final String raw = token.getRaw(); return node.isObject() ? node.get(raw) : node.get(arrayIndexFor(raw)); }
/** * Build a JSON Pointer out of a series of reference tokens * * <p>These tokens can be everything; be sure however that they implement * {@link Object#toString()} correctly!</p> * * <p>Each of these tokens are treated as <b>raw</b> tokens (ie, not * encoded).</p> * * @param first the first token * @param other other tokens * @return a JSON Pointer * @throws NullPointerException one input token is null */ public static JsonPointer of(final Object first, final Object... other) { final List<ReferenceToken> tokens = Lists.newArrayList(); tokens.add(ReferenceToken.fromRaw(first.toString())); for (final Object o: other) tokens.add(ReferenceToken.fromRaw(o.toString())); return new JsonPointer(fromTokens(tokens)); }
/** * Generate a reference token from an integer * * @param index the integer * @return a token */ public static ReferenceToken fromInt(final int index) { final String s = Integer.toString(index); return new ReferenceToken(s, s); }
@Override public final String toString() { return token.toString(); } }
@Override public final int hashCode() { return token.hashCode(); }
index = s.indexOf(SLASH); cooked = index == -1 ? s : s.substring(0, index); ret.add(ReferenceToken.fromCooked(cooked)); if (index == -1) break;
c = buffer.get(); if (inEscape) { appendEscaped(raw, c); inEscape = false; continue;
@Override public JsonNode get(final JsonNode node) { if (node == null || !node.isContainerNode()) return null; final String raw = token.getRaw(); return node.isObject() ? node.get(raw) : node.get(arrayIndexFor(raw)); }
/** * Build a JSON Pointer out of a series of reference tokens * * <p>These tokens can be everything; be sure however that they implement * {@link Object#toString()} correctly!</p> * * <p>Each of these tokens are treated as <b>raw</b> tokens (ie, not * encoded).</p> * * @param first the first token * @param other other tokens * @return a JSON Pointer * @throws NullPointerException one input token is null */ public static JsonPointer of(final Object first, final Object... other) { final List<ReferenceToken> tokens = Lists.newArrayList(); tokens.add(ReferenceToken.fromRaw(first.toString())); for (final Object o: other) tokens.add(ReferenceToken.fromRaw(o.toString())); return new JsonPointer(fromTokens(tokens)); }
/** * Generate a reference token from an integer * * @param index the integer * @return a token */ public static ReferenceToken fromInt(final int index) { final String s = Integer.toString(index); return new ReferenceToken(s, s); }
@Override public final String toString() { return token.toString(); } }
@Override public final int hashCode() { return token.hashCode(); }
index = s.indexOf(SLASH); cooked = index == -1 ? s : s.substring(0, index); ret.add(ReferenceToken.fromCooked(cooked)); if (index == -1) break;
c = buffer.get(); if (inEscape) { appendEscaped(raw, c); inEscape = false; continue;
private JsonNode addToObject(final JsonPointer path, final JsonNode node) { final JsonNode ret = node.deepCopy(); final ObjectNode target = (ObjectNode) path.parent().get(ret); target.put(Iterables.getLast(path).getToken().getRaw(), value); return ret; } }
/** * Generate a reference token from a decoded (raw) representation * * @param raw the input * @return a token * @throws NullPointerException null input */ public static ReferenceToken fromRaw(final String raw) { BUNDLE.checkNotNull(raw, "nullInput"); return new ReferenceToken(asCooked(raw), raw); }
/** * Generate a reference token from an encoded (cooked) representation * * @param cooked the input * @return a token * @throws JsonPointerException illegal token (bad encode sequence) * @throws NullPointerException null input */ public static ReferenceToken fromCooked(final String cooked) throws JsonPointerException { BUNDLE.checkNotNull(cooked, "nullInput"); return new ReferenceToken(cooked, asRaw(cooked)); }