Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit bca8497

Browse files
committed
Update early exit to ignore wildcards; allow null primitives
1 parent 3202d99 commit bca8497

17 files changed

Lines changed: 378 additions & 14 deletions

File tree

‎build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'maven'
33

44
group = 'com.trunk.rx.json'
55

6-
def baseVersion = '0.5.1'
6+
def baseVersion = '0.5.3'
77

88
sourceCompatibility = JavaVersion.VERSION_1_8
99
targetCompatibility = JavaVersion.VERSION_1_8

‎rxjava-json-core/src/main/java/com/trunk/rx/json/element/JsonValueBuilder.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ public JsonValueBuilder rawInfiniteAndNaN() {
116116
* A single JSON string.
117117
*/
118118
public JsonElement create(String value) {
119+
if (value == null) {
120+
return Null();
121+
}
119122
return new JsonElement(Observable.just(JsonQuote.instance(), JsonString.of(value), JsonQuote.instance()));
120123
}
121124

@@ -145,6 +148,9 @@ public JsonElement create(boolean value) {
145148
* A single JSON number.
146149
*/
147150
public JsonElement create(Number value) {
151+
if (value == null) {
152+
return Null();
153+
}
148154
boolean infiniteOrNotANumber = isInfiniteOrNotANumber(value);
149155
if (quoteInfiniteAndNaN && infiniteOrNotANumber) {
150156
return create(value.toString());
@@ -164,6 +170,9 @@ public JsonElement create(Number value) {
164170
* @return a single JSON number
165171
*/
166172
public JsonElement createNumberFromString(String numericValue) {
173+
if (numericValue == null) {
174+
return Null();
175+
}
167176
return new JsonElement(JsonNumber.of(numericValue));
168177
}
169178

‎rxjava-json-core/src/main/java/com/trunk/rx/json/path/ArrayIndexToken.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ AccessorType accessorType() {
4545
}
4646

4747
@Override
48-
boolean tokenEquals(JsonPath jsonPath) {
48+
public boolean tokenEquals(JsonPath jsonPath) {
4949
return jsonPath instanceof ArrayIndexToken && ((ArrayIndexToken) jsonPath).index == index;
5050
}
5151
}

‎rxjava-json-core/src/main/java/com/trunk/rx/json/path/ArraySliceToken.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ AccessorType accessorType() {
5555
}
5656

5757
@Override
58-
boolean tokenEquals(JsonPath jsonPath) {
58+
public boolean tokenEquals(JsonPath jsonPath) {
5959
return
6060
jsonPath instanceof ArraySliceToken &&
6161
((ArraySliceToken) jsonPath).start == start &&

‎rxjava-json-core/src/main/java/com/trunk/rx/json/path/ArrayStepToken.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ AccessorType accessorType() {
6161
}
6262

6363
@Override
64-
boolean tokenEquals(JsonPath jsonPath) {
64+
public boolean tokenEquals(JsonPath jsonPath) {
6565
return jsonPath instanceof ArrayStepToken &&
6666
((ArrayStepToken) jsonPath).start == start &&
6767
((ArrayStepToken) jsonPath).end == end &&

‎rxjava-json-core/src/main/java/com/trunk/rx/json/path/ArrayToken.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ final Optional<List<JsonPath>> doMatch(Optional<JsonPath> pathToTest, List<JsonP
3535
.flatMap(p -> matchNextFragment(p, matchedFragments));
3636
}
3737

38+
@Override
39+
public boolean isWildcard() {
40+
return false;
41+
}
42+
3843
abstract boolean doesMatch(JsonPath pathToTest);
3944

4045
abstract String arrayValue();

‎rxjava-json-core/src/main/java/com/trunk/rx/json/path/ArrayUnionToken.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ AccessorType accessorType() {
5858
}
5959

6060
@Override
61-
boolean tokenEquals(JsonPath jsonPath) {
61+
public boolean tokenEquals(JsonPath jsonPath) {
6262
return jsonPath instanceof ArrayUnionToken && Objects.equals(delegates, ((ArrayUnionToken) jsonPath).delegates);
6363
}
6464
}

‎rxjava-json-core/src/main/java/com/trunk/rx/json/path/JsonPath.java‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ public int length() {
8282
return length != null ? length : (length = 1 + nextPathToken.map(JsonPath::length).orElse(0));
8383
}
8484

85+
public abstract boolean isWildcard();
86+
87+
public abstract boolean tokenEquals(JsonPath jsonPath);
88+
8589
abstract int tokenHash();
8690

8791
abstract Optional<List<JsonPath>> doMatch(Optional<JsonPath> pathToTest, List<JsonPath> matchedFragments);
@@ -92,13 +96,15 @@ public int length() {
9296

9397
abstract AccessorType accessorType();
9498

95-
abstract boolean tokenEquals(JsonPath jsonPath);
96-
9799
Optional<List<JsonPath>> matchNextFragment(JsonPath pathToTest, List<JsonPath> matchedFragments) {
98100
List<JsonPath> newMatchedFragments = new ArrayList<>(matchedFragments);
99101
newMatchedFragments.add(pathToTest);
100102
return nextPathToken
101103
.map(myNext -> myNext.doMatch(pathToTest.nextPathToken, newMatchedFragments))
102104
.orElse(Optional.of(newMatchedFragments));
103105
}
106+
107+
public Optional<JsonPath> getNextPathToken() {
108+
return nextPathToken;
109+
}
104110
}

‎rxjava-json-core/src/main/java/com/trunk/rx/json/path/NoopToken.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public int length() {
2222
return Integer.MAX_VALUE;
2323
}
2424

25+
@Override
26+
public boolean isWildcard() {
27+
return false;
28+
}
29+
2530
@Override
2631
int tokenHash() {
2732
return 0;
@@ -48,7 +53,7 @@ AccessorType accessorType() {
4853
}
4954

5055
@Override
51-
boolean tokenEquals(JsonPath jsonPath) {
56+
public boolean tokenEquals(JsonPath jsonPath) {
5257
return false;
5358
}
5459
}

‎rxjava-json-core/src/main/java/com/trunk/rx/json/path/ObjectToken.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ private ObjectToken(String name, JsonPath nextPathToken) {
2222
accessorType = validName.matcher(name).matches() ? AccessorType.OBJECT : AccessorType.ARRAY;
2323
}
2424

25+
@Override
26+
public boolean isWildcard() {
27+
return false;
28+
}
29+
2530
@Override
2631
int tokenHash() {
2732
return Objects.hashCode(name);
@@ -50,7 +55,7 @@ AccessorType accessorType() {
5055
}
5156

5257
@Override
53-
boolean tokenEquals(JsonPath jsonPath) {
58+
public boolean tokenEquals(JsonPath jsonPath) {
5459
return jsonPath instanceof ObjectToken && Objects.equals(((ObjectToken) jsonPath).name, name);
5560
}
5661

0 commit comments

Comments
 (0)