}
@Override
public Object filter(Object obj, Configuration configuration) {
JsonProvider jsonProvider = configuration.getProvider();
Object result = jsonProvider.createArray();
if (trimmedCondition.contains(OPERATOR)) {
if (trimmedCondition.startsWith(OPERATOR)) {
String trimmedCondition = trim(this.trimmedCondition, 1, 0);
int get = Integer.parseInt(trimmedCondition);
for (int i = 0; i < get; i++) {
try {
jsonProvider.setProperty(result, jsonProvider.length(result), jsonProvider.getProperty(obj, i));
} catch (IndexOutOfBoundsException e){
break;
}
}
return result;
} else if (trimmedCondition.endsWith(OPERATOR)) {
String trimmedCondition = trim(SPACE.matcher(this.trimmedCondition).replaceAll(""), 0, 1);
int get = Integer.parseInt(trimmedCondition);
if(get > 0 || usesLenght){
if(get > 0){
get = get * -1;
}
return jsonProvider.getProperty(obj, jsonProvider.length(obj) + get);
} else {
int start = jsonProvider.length(obj) + get;
int stop = jsonProvider.length(obj);
if(start < 0){
start = 0;
}
for (int i = start; i < stop; i ++){
jsonProvider.setProperty(result, jsonProvider.length(result), jsonProvider.getProperty(obj, i));
}
return result;
}
} else {
String[] indexes = this.trimmedCondition.split(OPERATOR);
int start = Integer.parseInt(indexes[0]);
int stop = Integer.parseInt(indexes[1]);
for (int i = start; i < stop; i ++){
try {
jsonProvider.setProperty(result, jsonProvider.length(result), jsonProvider.getProperty(obj, i));
} catch (IndexOutOfBoundsException e){
break;
}
}
return result;
}
} else {
String[] indexArr = COMMA.split(trimmedCondition);
//if(obj == null || jsonProvider.length(obj) == 0){
if(obj == null){
return result;
}
try {
if (indexArr.length == 1) {
/*
if(jsonProvider.length(obj) == 0){
throw new PathNotFoundException("Array index [" + indexArr[0] + "] not found in path");
}
*/
return jsonProvider.getProperty(obj, indexArr[0]);
} else {
for (String idx : indexArr) {
jsonProvider.setProperty(result, jsonProvider.length(result), jsonProvider.getProperty(obj, idx.trim()));
}
return result;
}
} catch (IndexOutOfBoundsException e){
throw new PathNotFoundException("Array index " + indexArr + " not found in path", e);