Skip to content

Commit e6d2546

Browse files
Matthew J GreenwoodMatthew J Greenwood
authored andcommitted
removed getLastElement
1 parent 5e2ef13 commit e6d2546

File tree

3 files changed

+2
-24
lines changed

3 files changed

+2
-24
lines changed

json-path/src/main/java/com/jayway/jsonpath/internal/path/EvaluationContextImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ public <T> T getValue(boolean unwrap) {
130130
if(resultIndex == 0){
131131
throw new PathNotFoundException("No results for path: " + path.toString());
132132
}
133-
Object value = jsonProvider().getLastElement(valueResult);
133+
int len = jsonProvider().length(valueResult);
134+
Object value = (len > 0) ? jsonProvider().getArrayIndex(valueResult, len-1) : null;
134135
if (value != null && unwrap){
135136
value = jsonProvider().unwrap(value);
136137
}

json-path/src/main/java/com/jayway/jsonpath/spi/json/AbstractJsonProvider.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,6 @@ public Object getArrayIndex(Object obj, int idx) {
4343
return ((List) obj).get(idx);
4444
}
4545

46-
/**
47-
* Extracts the last value from an array
48-
*
49-
* @param obj an array
50-
* @return the entry at the given index
51-
*/
52-
public Object getLastElement(Object obj) {
53-
if (null != obj) {
54-
int len = this.length(obj);
55-
return getArrayIndex(obj, len-1);
56-
}
57-
return null;
58-
}
59-
6046
public final Object getArrayIndex(Object obj, int idx, boolean unwrap){
6147
return getArrayIndex(obj, idx);
6248
}

json-path/src/main/java/com/jayway/jsonpath/spi/json/JsonProvider.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,4 @@ public interface JsonProvider {
163163
* @return the unwrapped value.
164164
*/
165165
Object unwrap(Object obj);
166-
167-
168-
/**
169-
* Get the last element of the array
170-
*
171-
* @param obj an array
172-
* @return the unwrapped value
173-
*/
174-
Object getLastElement(Object obj);
175166
}

0 commit comments

Comments
 (0)