Browse Source

removed getLastElement

pull/167/head
Matthew J Greenwood 9 years ago
parent
commit
e6d2546c42
  1. 3
      json-path/src/main/java/com/jayway/jsonpath/internal/path/EvaluationContextImpl.java
  2. 14
      json-path/src/main/java/com/jayway/jsonpath/spi/json/AbstractJsonProvider.java
  3. 9
      json-path/src/main/java/com/jayway/jsonpath/spi/json/JsonProvider.java

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

@ -130,7 +130,8 @@ public class EvaluationContextImpl implements EvaluationContext {
if(resultIndex == 0){
throw new PathNotFoundException("No results for path: " + path.toString());
}
Object value = jsonProvider().getLastElement(valueResult);
int len = jsonProvider().length(valueResult);
Object value = (len > 0) ? jsonProvider().getArrayIndex(valueResult, len-1) : null;
if (value != null && unwrap){
value = jsonProvider().unwrap(value);
}

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

@ -43,20 +43,6 @@ public abstract class AbstractJsonProvider implements JsonProvider {
return ((List) obj).get(idx);
}
/**
* Extracts the last value from an array
*
* @param obj an array
* @return the entry at the given index
*/
public Object getLastElement(Object obj) {
if (null != obj) {
int len = this.length(obj);
return getArrayIndex(obj, len-1);
}
return null;
}
public final Object getArrayIndex(Object obj, int idx, boolean unwrap){
return getArrayIndex(obj, idx);
}

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

@ -163,13 +163,4 @@ public interface JsonProvider {
* @return the unwrapped value.
*/
Object unwrap(Object obj);
/**
* Get the last element of the array
*
* @param obj an array
* @return the unwrapped value
*/
Object getLastElement(Object obj);
}

Loading…
Cancel
Save