Browse Source

Renamed Function interface to avoid name clash with java.util.function.Function.

pull/183/merge
Kalle Stenflo 9 years ago
parent
commit
83c1acf193
  1. 2
      json-path/src/main/java/com/jayway/jsonpath/internal/function/Length.java
  2. 2
      json-path/src/main/java/com/jayway/jsonpath/internal/function/PassthruPathFunction.java
  3. 2
      json-path/src/main/java/com/jayway/jsonpath/internal/function/PathFunction.java
  4. 12
      json-path/src/main/java/com/jayway/jsonpath/internal/function/PathFunctionFactory.java
  5. 4
      json-path/src/main/java/com/jayway/jsonpath/internal/function/numeric/AbstractAggregation.java
  6. 10
      json-path/src/main/java/com/jayway/jsonpath/internal/token/FunctionPathToken.java
  7. 6
      json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java
  8. 2
      json-path/src/test/java/com/jayway/jsonpath/functions/JSONEntityPathFunctionTest.java
  9. 6
      json-path/src/test/java/com/jayway/jsonpath/functions/NumericPathFunctionTest.java

2
json-path/src/main/java/com/jayway/jsonpath/internal/function/Length.java

@ -8,7 +8,7 @@ import com.jayway.jsonpath.internal.PathRef;
*
* Created by mattg on 6/26/15.
*/
public class Length implements Function {
public class Length implements PathFunction {
@Override
public Object invoke(String currentPath, PathRef parent, Object model, EvaluationContext ctx) {

2
json-path/src/main/java/com/jayway/jsonpath/internal/function/PassthruFunction.java → json-path/src/main/java/com/jayway/jsonpath/internal/function/PassthruPathFunction.java

@ -8,7 +8,7 @@ import com.jayway.jsonpath.internal.PathRef;
*
* Created by mattg on 6/26/15.
*/
public class PassthruFunction implements Function {
public class PassthruPathFunction implements PathFunction {
@Override
public Object invoke(String currentPath, PathRef parent, Object model, EvaluationContext ctx) {

2
json-path/src/main/java/com/jayway/jsonpath/internal/function/Function.java → json-path/src/main/java/com/jayway/jsonpath/internal/function/PathFunction.java

@ -11,7 +11,7 @@ import com.jayway.jsonpath.internal.PathRef;
*
* Created by matt@mjgreenwood.net on 6/26/15.
*/
public interface Function {
public interface PathFunction {
/**
* Invoke the function and output a JSON object (or scalar) value which will be the result of executing the path

12
json-path/src/main/java/com/jayway/jsonpath/internal/function/FunctionFactory.java → json-path/src/main/java/com/jayway/jsonpath/internal/function/PathFunctionFactory.java

@ -20,7 +20,7 @@ import java.util.Map;
*
* Created by mattg on 6/27/15.
*/
public class FunctionFactory {
public class PathFunctionFactory {
public static final Map<String, Class> FUNCTIONS;
@ -46,7 +46,7 @@ public class FunctionFactory {
* implementation based on the name using the internal FUNCTION map
*
* @see #FUNCTIONS
* @see Function
* @see PathFunction
*
* @param name
* The name of the function
@ -56,12 +56,12 @@ public class FunctionFactory {
*
* @throws InvalidPathException
*/
public static Function newFunction(String name) throws InvalidPathException {
Function result = new PassthruFunction();
public static PathFunction newFunction(String name) throws InvalidPathException {
PathFunction result = new PassthruPathFunction();
if (null != name && FUNCTIONS.containsKey(name) && Function.class.isAssignableFrom(FUNCTIONS.get(name))) {
if (null != name && FUNCTIONS.containsKey(name) && PathFunction.class.isAssignableFrom(FUNCTIONS.get(name))) {
try {
result = (Function)FUNCTIONS.get(name).newInstance();
result = (PathFunction)FUNCTIONS.get(name).newInstance();
} catch (InstantiationException e) {
throw new InvalidPathException("Function of name: " + name + " cannot be created", e);
} catch (IllegalAccessException e) {

4
json-path/src/main/java/com/jayway/jsonpath/internal/function/numeric/AbstractAggregation.java

@ -2,7 +2,7 @@ package com.jayway.jsonpath.internal.function.numeric;
import com.jayway.jsonpath.internal.EvaluationContext;
import com.jayway.jsonpath.internal.PathRef;
import com.jayway.jsonpath.internal.function.Function;
import com.jayway.jsonpath.internal.function.PathFunction;
/**
* Defines the pattern for processing numerical values via an abstract implementation that iterates over the collection
@ -11,7 +11,7 @@ import com.jayway.jsonpath.internal.function.Function;
*
* Created by mattg on 6/26/15.
*/
public abstract class AbstractAggregation implements Function {
public abstract class AbstractAggregation implements PathFunction {
/**
* Defines the next value in the array to the mathmatical function

10
json-path/src/main/java/com/jayway/jsonpath/internal/token/FunctionPathToken.java

@ -1,13 +1,13 @@
package com.jayway.jsonpath.internal.token;
import com.jayway.jsonpath.internal.PathRef;
import com.jayway.jsonpath.internal.function.Function;
import com.jayway.jsonpath.internal.function.FunctionFactory;
import com.jayway.jsonpath.internal.function.PathFunction;
import com.jayway.jsonpath.internal.function.PathFunctionFactory;
/**
* Token representing a Function call to one of the functions produced via the FunctionFactory
*
* @see FunctionFactory
* @see PathFunctionFactory
*
* Created by mattg on 6/27/15.
*/
@ -27,8 +27,8 @@ public class FunctionPathToken extends PathToken {
@Override
public void evaluate(String currentPath, PathRef parent, Object model, EvaluationContextImpl ctx) {
Function function = FunctionFactory.newFunction(functionName);
Object result = function.invoke(currentPath, parent, model, ctx);
PathFunction pathFunction = PathFunctionFactory.newFunction(functionName);
Object result = pathFunction.invoke(currentPath, parent, model, ctx);
ctx.addResult(currentPath, parent, result);
}

6
json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java

@ -18,7 +18,7 @@ import com.jayway.jsonpath.Option;
import com.jayway.jsonpath.PathNotFoundException;
import com.jayway.jsonpath.internal.PathRef;
import com.jayway.jsonpath.internal.Utils;
import com.jayway.jsonpath.internal.function.Function;
import com.jayway.jsonpath.internal.function.PathFunction;
import com.jayway.jsonpath.spi.json.JsonProvider;
import java.util.List;
@ -204,8 +204,8 @@ public abstract class PathToken {
return super.equals(obj);
}
public void invoke(Function function, String currentPath, PathRef parent, Object model, EvaluationContextImpl ctx) {
ctx.addResult(currentPath, parent, function.invoke(currentPath, parent, model, ctx));
public void invoke(PathFunction pathFunction, String currentPath, PathRef parent, Object model, EvaluationContextImpl ctx) {
ctx.addResult(currentPath, parent, pathFunction.invoke(currentPath, parent, model, ctx));
}
public abstract void evaluate(String currentPath, PathRef parent, Object model, EvaluationContextImpl ctx);

2
json-path/src/test/java/com/jayway/jsonpath/functions/JSONEntityFunctionTest.java → json-path/src/test/java/com/jayway/jsonpath/functions/JSONEntityPathFunctionTest.java

@ -11,7 +11,7 @@ import org.junit.Test;
*
* Created by mattg on 6/27/15.
*/
public class JSONEntityFunctionTest extends BaseFunctionTest {
public class JSONEntityPathFunctionTest extends BaseFunctionTest {
private static final String BATCH_JSON = "{\n" +

6
json-path/src/test/java/com/jayway/jsonpath/functions/NumericFunctionTest.java → json-path/src/test/java/com/jayway/jsonpath/functions/NumericPathFunctionTest.java

@ -23,13 +23,13 @@ import static org.junit.runners.Parameterized.Parameters;
* Created by mattg on 6/26/15.
*/
@RunWith(Parameterized.class)
public class NumericFunctionTest extends BaseFunctionTest {
public class NumericPathFunctionTest extends BaseFunctionTest {
private static final Logger logger = LoggerFactory.getLogger(NumericFunctionTest.class);
private static final Logger logger = LoggerFactory.getLogger(NumericPathFunctionTest.class);
private Configuration conf = Configurations.GSON_CONFIGURATION;
public NumericFunctionTest(Configuration conf) {
public NumericPathFunctionTest(Configuration conf) {
logger.debug("Testing with configuration {}", conf.getClass().getName());
this.conf = conf;
}
Loading…
Cancel
Save