repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/NotNullFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class NotNullFunction extends BaseFunction { public NotNullFunction() { super(ArgumentConstraints.listOf(1, Integer.MAX_VALUE, ArgumentConstraints.anyValue())); } @Override protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) { for (FunctionArgument<T> argument : arguments) {
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/NotNullFunction.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class NotNullFunction extends BaseFunction { public NotNullFunction() { super(ArgumentConstraints.listOf(1, Integer.MAX_VALUE, ArgumentConstraints.anyValue())); } @Override protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) { for (FunctionArgument<T> argument : arguments) {
if (runtime.typeOf(argument.value()) != JmesPathType.NULL) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/ExpressionReferenceNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // }
import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression;
package io.burt.jmespath.node; public class ExpressionReferenceNode<T> extends Node<T> { private final Expression<T> expression;
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/ExpressionReferenceNode.java import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; package io.burt.jmespath.node; public class ExpressionReferenceNode<T> extends Node<T> { private final Expression<T> expression;
public ExpressionReferenceNode(Adapter<T> runtime, Expression<T> expression) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/FunctionArgument.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // }
import io.burt.jmespath.Expression;
package io.burt.jmespath.function; /** * In JMESPath most functions take regular values as arguments, but some are * higher order functions and take expressions. This class exists so that * argument lists can have a single type, while still contain a mix of values * and expressions. */ public abstract class FunctionArgument<T> { private static class V<U> extends FunctionArgument<U> { private final U value; public V(U value) { this.value = value; } @Override public U value() { return value; } @Override public boolean isValue() { return true; } } private static class E<U> extends FunctionArgument<U> {
// Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/FunctionArgument.java import io.burt.jmespath.Expression; package io.burt.jmespath.function; /** * In JMESPath most functions take regular values as arguments, but some are * higher order functions and take expressions. This class exists so that * argument lists can have a single type, while still contain a mix of values * and expressions. */ public abstract class FunctionArgument<T> { private static class V<U> extends FunctionArgument<U> { private final U value; public V(U value) { this.value = value; } @Override public U value() { return value; } @Override public boolean isValue() { return true; } } private static class E<U> extends FunctionArgument<U> {
private final Expression<U> expression;
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/KeysFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class KeysFunction extends BaseFunction { public KeysFunction() {
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/KeysFunction.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class KeysFunction extends BaseFunction { public KeysFunction() {
super(ArgumentConstraints.typeOf(JmesPathType.OBJECT));
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/KeysFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class KeysFunction extends BaseFunction { public KeysFunction() { super(ArgumentConstraints.typeOf(JmesPathType.OBJECT)); } @Override
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/KeysFunction.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class KeysFunction extends BaseFunction { public KeysFunction() { super(ArgumentConstraints.typeOf(JmesPathType.OBJECT)); } @Override
protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/StartsWithFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class StartsWithFunction extends BaseFunction { public StartsWithFunction() { super(
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/StartsWithFunction.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class StartsWithFunction extends BaseFunction { public StartsWithFunction() { super(
ArgumentConstraints.typeOf(JmesPathType.STRING),
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/StartsWithFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class StartsWithFunction extends BaseFunction { public StartsWithFunction() { super( ArgumentConstraints.typeOf(JmesPathType.STRING), ArgumentConstraints.typeOf(JmesPathType.STRING) ); } @Override
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/StartsWithFunction.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class StartsWithFunction extends BaseFunction { public StartsWithFunction() { super( ArgumentConstraints.typeOf(JmesPathType.STRING), ArgumentConstraints.typeOf(JmesPathType.STRING) ); } @Override
protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/NegateNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // }
import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression;
package io.burt.jmespath.node; public class NegateNode<T> extends Node<T> { private final Expression<T> negated;
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/NegateNode.java import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; package io.burt.jmespath.node; public class NegateNode<T> extends Node<T> { private final Expression<T> negated;
public NegateNode(Adapter<T> runtime, Expression<T> negated) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/ArgumentConstraints.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.Iterator; import java.util.List; import java.util.ArrayList; import java.util.Collections; import java.util.Set; import java.util.LinkedHashSet; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
public int maxArity() { return maxArity; } @Override public boolean arityViolated(int n) { return (n < minArity || maxArity < n); } @Override public String expectedType() { return expectedTypeDescription; } protected <U> Iterator<U> singletonIterator(U obj) { return Collections.singleton(obj).iterator(); } protected <U> Iterator<U> emptyIterator() { return Collections.emptyIterator(); } } private static class HomogeneousListOf extends BaseArgumentConstraint { private final ArgumentConstraint subConstraint; public HomogeneousListOf(int minArity, int maxArity, ArgumentConstraint subConstraint) { super(minArity, maxArity, subConstraint.expectedType()); this.subConstraint = subConstraint; } @Override
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/ArgumentConstraints.java import java.util.Iterator; import java.util.List; import java.util.ArrayList; import java.util.Collections; import java.util.Set; import java.util.LinkedHashSet; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; public int maxArity() { return maxArity; } @Override public boolean arityViolated(int n) { return (n < minArity || maxArity < n); } @Override public String expectedType() { return expectedTypeDescription; } protected <U> Iterator<U> singletonIterator(U obj) { return Collections.singleton(obj).iterator(); } protected <U> Iterator<U> emptyIterator() { return Collections.emptyIterator(); } } private static class HomogeneousListOf extends BaseArgumentConstraint { private final ArgumentConstraint subConstraint; public HomogeneousListOf(int minArity, int maxArity, ArgumentConstraint subConstraint) { super(minArity, maxArity, subConstraint.expectedType()); this.subConstraint = subConstraint; } @Override
public <T> Iterator<ArgumentError> check(Adapter<T> runtime, Iterator<FunctionArgument<T>> arguments, boolean expectNoRemainingArguments) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/CompareFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import java.util.Iterator; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; /** * Helper base class for comparison functions like max and min. */ public abstract class CompareFunction extends ArrayMathFunction { public CompareFunction() {
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/CompareFunction.java import java.util.List; import java.util.Iterator; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; /** * Helper base class for comparison functions like max and min. */ public abstract class CompareFunction extends ArrayMathFunction { public CompareFunction() {
super(ArgumentConstraints.typeOf(JmesPathType.NUMBER, JmesPathType.STRING));
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/CompareFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import java.util.Iterator; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; /** * Helper base class for comparison functions like max and min. */ public abstract class CompareFunction extends ArrayMathFunction { public CompareFunction() { super(ArgumentConstraints.typeOf(JmesPathType.NUMBER, JmesPathType.STRING)); } /** * Subclasses override this method to decide whether the greatest or least * element sorts first. */ protected abstract boolean sortsBefore(int compareResult); @Override
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/CompareFunction.java import java.util.List; import java.util.Iterator; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; /** * Helper base class for comparison functions like max and min. */ public abstract class CompareFunction extends ArrayMathFunction { public CompareFunction() { super(ArgumentConstraints.typeOf(JmesPathType.NUMBER, JmesPathType.STRING)); } /** * Subclasses override this method to decide whether the greatest or least * element sorts first. */ protected abstract boolean sortsBefore(int compareResult); @Override
protected <T> T performMathOperation(Adapter<T> runtime, List<T> values) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/SumFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class SumFunction extends ArrayMathFunction { public SumFunction() {
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/SumFunction.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class SumFunction extends ArrayMathFunction { public SumFunction() {
super(ArgumentConstraints.typeOf(JmesPathType.NUMBER));
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/SumFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class SumFunction extends ArrayMathFunction { public SumFunction() { super(ArgumentConstraints.typeOf(JmesPathType.NUMBER)); } @Override
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/SumFunction.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class SumFunction extends ArrayMathFunction { public SumFunction() { super(ArgumentConstraints.typeOf(JmesPathType.NUMBER)); } @Override
protected <T> T performMathOperation(Adapter<T> runtime, List<T> values) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/AvgFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class AvgFunction extends ArrayMathFunction { public AvgFunction() {
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/AvgFunction.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class AvgFunction extends ArrayMathFunction { public AvgFunction() {
super(ArgumentConstraints.typeOf(JmesPathType.NUMBER));
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/AvgFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class AvgFunction extends ArrayMathFunction { public AvgFunction() { super(ArgumentConstraints.typeOf(JmesPathType.NUMBER)); } @Override
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/AvgFunction.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class AvgFunction extends ArrayMathFunction { public AvgFunction() { super(ArgumentConstraints.typeOf(JmesPathType.NUMBER)); } @Override
protected <T> T performMathOperation(Adapter<T> runtime, List<T> values) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/MergeFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import java.util.Map; import java.util.LinkedHashMap; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class MergeFunction extends BaseFunction { public MergeFunction() {
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/MergeFunction.java import java.util.List; import java.util.Map; import java.util.LinkedHashMap; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class MergeFunction extends BaseFunction { public MergeFunction() {
super(ArgumentConstraints.listOf(1, Integer.MAX_VALUE, ArgumentConstraints.typeOf(JmesPathType.OBJECT)));
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/MergeFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import java.util.Map; import java.util.LinkedHashMap; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class MergeFunction extends BaseFunction { public MergeFunction() { super(ArgumentConstraints.listOf(1, Integer.MAX_VALUE, ArgumentConstraints.typeOf(JmesPathType.OBJECT))); } @Override
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/MergeFunction.java import java.util.List; import java.util.Map; import java.util.LinkedHashMap; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class MergeFunction extends BaseFunction { public MergeFunction() { super(ArgumentConstraints.listOf(1, Integer.MAX_VALUE, ArgumentConstraints.typeOf(JmesPathType.OBJECT))); } @Override
protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/ToArrayFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.Collections; import java.util.List; import java.util.Arrays; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class ToArrayFunction extends BaseFunction { public ToArrayFunction() { super(ArgumentConstraints.anyValue()); } @Override
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/ToArrayFunction.java import java.util.Collections; import java.util.List; import java.util.Arrays; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class ToArrayFunction extends BaseFunction { public ToArrayFunction() { super(ArgumentConstraints.anyValue()); } @Override
protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/ToArrayFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.Collections; import java.util.List; import java.util.Arrays; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class ToArrayFunction extends BaseFunction { public ToArrayFunction() { super(ArgumentConstraints.anyValue()); } @Override protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) { T subject = arguments.get(0).value();
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/ToArrayFunction.java import java.util.Collections; import java.util.List; import java.util.Arrays; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class ToArrayFunction extends BaseFunction { public ToArrayFunction() { super(ArgumentConstraints.anyValue()); } @Override protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) { T subject = arguments.get(0).value();
if (runtime.typeOf(subject) == JmesPathType.ARRAY) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/FlattenObjectNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.node; public class FlattenObjectNode<T> extends Node<T> { public FlattenObjectNode(Adapter<T> runtime) { super(runtime); } @Override public T search(T input) {
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/FlattenObjectNode.java import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.node; public class FlattenObjectNode<T> extends Node<T> { public FlattenObjectNode(Adapter<T> runtime) { super(runtime); } @Override public T search(T input) {
if (runtime.typeOf(input) == JmesPathType.OBJECT) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/ValuesFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class ValuesFunction extends BaseFunction { public ValuesFunction() {
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/ValuesFunction.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class ValuesFunction extends BaseFunction { public ValuesFunction() {
super(ArgumentConstraints.typeOf(JmesPathType.OBJECT));
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/ValuesFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class ValuesFunction extends BaseFunction { public ValuesFunction() { super(ArgumentConstraints.typeOf(JmesPathType.OBJECT)); } @Override
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/ValuesFunction.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class ValuesFunction extends BaseFunction { public ValuesFunction() { super(ArgumentConstraints.typeOf(JmesPathType.OBJECT)); } @Override
protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/SelectionNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import java.util.LinkedList; import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.node; public class SelectionNode<T> extends Node<T> { private final Expression<T> test;
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/SelectionNode.java import java.util.List; import java.util.LinkedList; import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.node; public class SelectionNode<T> extends Node<T> { private final Expression<T> test;
public SelectionNode(Adapter<T> runtime, Expression<T> test) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/SelectionNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import java.util.LinkedList; import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.node; public class SelectionNode<T> extends Node<T> { private final Expression<T> test; public SelectionNode(Adapter<T> runtime, Expression<T> test) { super(runtime); this.test = test; } @Override public T search(T input) {
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/SelectionNode.java import java.util.List; import java.util.LinkedList; import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.node; public class SelectionNode<T> extends Node<T> { private final Expression<T> test; public SelectionNode(Adapter<T> runtime, Expression<T> test) { super(runtime); this.test = test; } @Override public T search(T input) {
if (runtime.typeOf(input) == JmesPathType.ARRAY) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/SequenceNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // }
import java.util.List; import io.burt.jmespath.Adapter;
package io.burt.jmespath.node; public class SequenceNode<T> extends Node<T> { private final List<Node<T>> nodes;
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/SequenceNode.java import java.util.List; import io.burt.jmespath.Adapter; package io.burt.jmespath.node; public class SequenceNode<T> extends Node<T> { private final List<Node<T>> nodes;
public SequenceNode(Adapter<T> runtime, List<Node<T>> nodes) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/SortByFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // }
import java.util.Collections; import java.util.List; import java.util.ArrayList; import java.util.Comparator; import io.burt.jmespath.Adapter;
package io.burt.jmespath.function; public class SortByFunction extends TransformByFunction { @Override
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/SortByFunction.java import java.util.Collections; import java.util.List; import java.util.ArrayList; import java.util.Comparator; import io.burt.jmespath.Adapter; package io.burt.jmespath.function; public class SortByFunction extends TransformByFunction { @Override
protected <T> TransformByFunction.Aggregator<T> createAggregator(Adapter<T> runtime, int elementCount, T element, T elementValue) {
burtcorp/jmespath-java
jmespath-core/src/test/java/io/burt/jmespath/JmesPathRuntimeTest.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/RuntimeConfiguration.java // public class RuntimeConfiguration { // private final FunctionRegistry functionRegistry; // private final boolean silentTypeErrors; // // private RuntimeConfiguration(Builder builder) { // this.functionRegistry = builder.functionRegistry; // this.silentTypeErrors = builder.silentTypeErrors; // } // // public FunctionRegistry functionRegistry() { // return functionRegistry; // } // // public boolean silentTypeErrors() { // return silentTypeErrors; // } // // public static Builder builder() { // return new Builder(); // } // // public static RuntimeConfiguration defaultConfiguration() { // return builder().build(); // } // // public static class Builder { // protected FunctionRegistry functionRegistry; // protected boolean silentTypeErrors; // // public Builder() { // this.functionRegistry = FunctionRegistry.defaultRegistry(); // } // // public RuntimeConfiguration build() { // return new RuntimeConfiguration(this); // } // // public Builder withFunctionRegistry(FunctionRegistry functionRegistry) { // this.functionRegistry = functionRegistry; // return this; // } // // public Builder withSilentTypeErrors(boolean silentTypeErrors) { // this.silentTypeErrors = silentTypeErrors; // return this; // } // } // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/parser/ParseException.java // @SuppressWarnings("serial") // public class ParseException extends JmesPathException implements Iterable<ParseError> { // private final Iterable<ParseError> errors; // // public ParseException(String query, Iterable<ParseError> errors) { // super(String.format("Unable to compile expression \"%s\": %s", query, joinMessages(errors))); // this.errors = errors; // } // // private static String joinMessages(Iterable<ParseError> errors) { // StringBuilder s = new StringBuilder(); // for (ParseError e : errors) { // s.append(String.format("%s at position %d, ", e.message(), e.position())); // } // s.setLength(s.length() - 2); // return s.toString(); // } // // @Override // public Iterator<ParseError> iterator() { return errors.iterator(); } // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/function/ArgumentTypeException.java // @SuppressWarnings("serial") // public class ArgumentTypeException extends FunctionCallException { // public ArgumentTypeException(Function function, String expectedType, String actualType) { // this(function, expectedType, actualType, null); // } // // public ArgumentTypeException(Function function, String expectedType, String actualType, Throwable cause) { // super(String.format("Invalid argument type calling \"%s\": expected %s but was %s", function.name(), expectedType, actualType), cause); // } // }
import org.junit.Before; import org.junit.Test; import org.hamcrest.Matcher; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.nio.charset.Charset; import java.util.Arrays; import java.util.List; import java.util.Collection; import java.util.Collections; import io.burt.jmespath.RuntimeConfiguration; import io.burt.jmespath.parser.ParseException; import io.burt.jmespath.function.ArgumentTypeException; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.both; import static org.hamcrest.Matchers.containsString;
@Test public void anEmptyObjectIsNotTruthy() { T result = search("!@", parse("{}")); assertThat(result, is(jsonBoolean(true))); } @Test public void callFunction() { T result = search("type(@)", parse("{}")); assertThat(result, is(jsonString("object"))); } @Test public void callFunctionWithExpressionReference() { T result = search("map(&userIdentity.userName, Records)", cloudtrail); assertThat(result, is(jsonArrayOfStrings("Alice", "Bob", "Alice"))); } @Test public void callVariadicFunction() { T result = search("not_null(Records[0].requestParameters.keyName, Records[1].requestParameters.keyName, Records[2].requestParameters.keyName)", cloudtrail); assertThat(result, is(jsonString("mykeypair"))); } @Test public void callingNonExistentFunctionThrowsParseException() { try { search("bork()", parse("{}")); fail("Expected ParseException to have been thrown");
// Path: jmespath-core/src/main/java/io/burt/jmespath/RuntimeConfiguration.java // public class RuntimeConfiguration { // private final FunctionRegistry functionRegistry; // private final boolean silentTypeErrors; // // private RuntimeConfiguration(Builder builder) { // this.functionRegistry = builder.functionRegistry; // this.silentTypeErrors = builder.silentTypeErrors; // } // // public FunctionRegistry functionRegistry() { // return functionRegistry; // } // // public boolean silentTypeErrors() { // return silentTypeErrors; // } // // public static Builder builder() { // return new Builder(); // } // // public static RuntimeConfiguration defaultConfiguration() { // return builder().build(); // } // // public static class Builder { // protected FunctionRegistry functionRegistry; // protected boolean silentTypeErrors; // // public Builder() { // this.functionRegistry = FunctionRegistry.defaultRegistry(); // } // // public RuntimeConfiguration build() { // return new RuntimeConfiguration(this); // } // // public Builder withFunctionRegistry(FunctionRegistry functionRegistry) { // this.functionRegistry = functionRegistry; // return this; // } // // public Builder withSilentTypeErrors(boolean silentTypeErrors) { // this.silentTypeErrors = silentTypeErrors; // return this; // } // } // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/parser/ParseException.java // @SuppressWarnings("serial") // public class ParseException extends JmesPathException implements Iterable<ParseError> { // private final Iterable<ParseError> errors; // // public ParseException(String query, Iterable<ParseError> errors) { // super(String.format("Unable to compile expression \"%s\": %s", query, joinMessages(errors))); // this.errors = errors; // } // // private static String joinMessages(Iterable<ParseError> errors) { // StringBuilder s = new StringBuilder(); // for (ParseError e : errors) { // s.append(String.format("%s at position %d, ", e.message(), e.position())); // } // s.setLength(s.length() - 2); // return s.toString(); // } // // @Override // public Iterator<ParseError> iterator() { return errors.iterator(); } // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/function/ArgumentTypeException.java // @SuppressWarnings("serial") // public class ArgumentTypeException extends FunctionCallException { // public ArgumentTypeException(Function function, String expectedType, String actualType) { // this(function, expectedType, actualType, null); // } // // public ArgumentTypeException(Function function, String expectedType, String actualType, Throwable cause) { // super(String.format("Invalid argument type calling \"%s\": expected %s but was %s", function.name(), expectedType, actualType), cause); // } // } // Path: jmespath-core/src/test/java/io/burt/jmespath/JmesPathRuntimeTest.java import org.junit.Before; import org.junit.Test; import org.hamcrest.Matcher; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.nio.charset.Charset; import java.util.Arrays; import java.util.List; import java.util.Collection; import java.util.Collections; import io.burt.jmespath.RuntimeConfiguration; import io.burt.jmespath.parser.ParseException; import io.burt.jmespath.function.ArgumentTypeException; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.both; import static org.hamcrest.Matchers.containsString; @Test public void anEmptyObjectIsNotTruthy() { T result = search("!@", parse("{}")); assertThat(result, is(jsonBoolean(true))); } @Test public void callFunction() { T result = search("type(@)", parse("{}")); assertThat(result, is(jsonString("object"))); } @Test public void callFunctionWithExpressionReference() { T result = search("map(&userIdentity.userName, Records)", cloudtrail); assertThat(result, is(jsonArrayOfStrings("Alice", "Bob", "Alice"))); } @Test public void callVariadicFunction() { T result = search("not_null(Records[0].requestParameters.keyName, Records[1].requestParameters.keyName, Records[2].requestParameters.keyName)", cloudtrail); assertThat(result, is(jsonString("mykeypair"))); } @Test public void callingNonExistentFunctionThrowsParseException() { try { search("bork()", parse("{}")); fail("Expected ParseException to have been thrown");
} catch (ParseException pe) {
burtcorp/jmespath-java
jmespath-core/src/test/java/io/burt/jmespath/JmesPathRuntimeTest.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/RuntimeConfiguration.java // public class RuntimeConfiguration { // private final FunctionRegistry functionRegistry; // private final boolean silentTypeErrors; // // private RuntimeConfiguration(Builder builder) { // this.functionRegistry = builder.functionRegistry; // this.silentTypeErrors = builder.silentTypeErrors; // } // // public FunctionRegistry functionRegistry() { // return functionRegistry; // } // // public boolean silentTypeErrors() { // return silentTypeErrors; // } // // public static Builder builder() { // return new Builder(); // } // // public static RuntimeConfiguration defaultConfiguration() { // return builder().build(); // } // // public static class Builder { // protected FunctionRegistry functionRegistry; // protected boolean silentTypeErrors; // // public Builder() { // this.functionRegistry = FunctionRegistry.defaultRegistry(); // } // // public RuntimeConfiguration build() { // return new RuntimeConfiguration(this); // } // // public Builder withFunctionRegistry(FunctionRegistry functionRegistry) { // this.functionRegistry = functionRegistry; // return this; // } // // public Builder withSilentTypeErrors(boolean silentTypeErrors) { // this.silentTypeErrors = silentTypeErrors; // return this; // } // } // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/parser/ParseException.java // @SuppressWarnings("serial") // public class ParseException extends JmesPathException implements Iterable<ParseError> { // private final Iterable<ParseError> errors; // // public ParseException(String query, Iterable<ParseError> errors) { // super(String.format("Unable to compile expression \"%s\": %s", query, joinMessages(errors))); // this.errors = errors; // } // // private static String joinMessages(Iterable<ParseError> errors) { // StringBuilder s = new StringBuilder(); // for (ParseError e : errors) { // s.append(String.format("%s at position %d, ", e.message(), e.position())); // } // s.setLength(s.length() - 2); // return s.toString(); // } // // @Override // public Iterator<ParseError> iterator() { return errors.iterator(); } // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/function/ArgumentTypeException.java // @SuppressWarnings("serial") // public class ArgumentTypeException extends FunctionCallException { // public ArgumentTypeException(Function function, String expectedType, String actualType) { // this(function, expectedType, actualType, null); // } // // public ArgumentTypeException(Function function, String expectedType, String actualType, Throwable cause) { // super(String.format("Invalid argument type calling \"%s\": expected %s but was %s", function.name(), expectedType, actualType), cause); // } // }
import org.junit.Before; import org.junit.Test; import org.hamcrest.Matcher; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.nio.charset.Charset; import java.util.Arrays; import java.util.List; import java.util.Collection; import java.util.Collections; import io.burt.jmespath.RuntimeConfiguration; import io.burt.jmespath.parser.ParseException; import io.burt.jmespath.function.ArgumentTypeException; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.both; import static org.hamcrest.Matchers.containsString;
@Test public void withSilentTypeErrorsTheWrongTypeOfArgumentMakesFunctionsReturnNull() { Adapter<T> rt = createRuntime(RuntimeConfiguration.builder().withSilentTypeErrors(true).build()); T result = rt.compile("abs('foo')").search(parse("{}")); assertThat(result, is(jsonNull())); } @Test public void withSilentTypeErrorsTheWrongTypeOfArgumentMakesHigherOrderFunctionsReturnNull() { Adapter<T> rt = createRuntime(RuntimeConfiguration.builder().withSilentTypeErrors(true).build()); T result1 = rt.compile("sort_by(@, &foo)").search(parse("[{\"foo\": 3}, {\"foo\": \"bar\"}, {\"foo\": 1}]")); T result2 = rt.compile("min_by(@, &foo)").search(parse("[{\"foo\": 3}, {\"foo\": \"bar\"}, {\"foo\": 1}]")); assertThat(result1, is(jsonNull())); assertThat(result2, is(jsonNull())); } @Test public void absReturnsTheAbsoluteValueOfANumber() { T result1 = search("abs(`-1`)", parse("{}")); T result2 = search("abs(`1`)", parse("{}")); assertThat(result1, is(jsonNumber(1))); assertThat(result2, is(jsonNumber(1))); } @Test public void absRequiresANumberArgument() { try { search("abs('foo')", parse("{}")); fail("Expected ArgumentTypeException to have been thrown");
// Path: jmespath-core/src/main/java/io/burt/jmespath/RuntimeConfiguration.java // public class RuntimeConfiguration { // private final FunctionRegistry functionRegistry; // private final boolean silentTypeErrors; // // private RuntimeConfiguration(Builder builder) { // this.functionRegistry = builder.functionRegistry; // this.silentTypeErrors = builder.silentTypeErrors; // } // // public FunctionRegistry functionRegistry() { // return functionRegistry; // } // // public boolean silentTypeErrors() { // return silentTypeErrors; // } // // public static Builder builder() { // return new Builder(); // } // // public static RuntimeConfiguration defaultConfiguration() { // return builder().build(); // } // // public static class Builder { // protected FunctionRegistry functionRegistry; // protected boolean silentTypeErrors; // // public Builder() { // this.functionRegistry = FunctionRegistry.defaultRegistry(); // } // // public RuntimeConfiguration build() { // return new RuntimeConfiguration(this); // } // // public Builder withFunctionRegistry(FunctionRegistry functionRegistry) { // this.functionRegistry = functionRegistry; // return this; // } // // public Builder withSilentTypeErrors(boolean silentTypeErrors) { // this.silentTypeErrors = silentTypeErrors; // return this; // } // } // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/parser/ParseException.java // @SuppressWarnings("serial") // public class ParseException extends JmesPathException implements Iterable<ParseError> { // private final Iterable<ParseError> errors; // // public ParseException(String query, Iterable<ParseError> errors) { // super(String.format("Unable to compile expression \"%s\": %s", query, joinMessages(errors))); // this.errors = errors; // } // // private static String joinMessages(Iterable<ParseError> errors) { // StringBuilder s = new StringBuilder(); // for (ParseError e : errors) { // s.append(String.format("%s at position %d, ", e.message(), e.position())); // } // s.setLength(s.length() - 2); // return s.toString(); // } // // @Override // public Iterator<ParseError> iterator() { return errors.iterator(); } // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/function/ArgumentTypeException.java // @SuppressWarnings("serial") // public class ArgumentTypeException extends FunctionCallException { // public ArgumentTypeException(Function function, String expectedType, String actualType) { // this(function, expectedType, actualType, null); // } // // public ArgumentTypeException(Function function, String expectedType, String actualType, Throwable cause) { // super(String.format("Invalid argument type calling \"%s\": expected %s but was %s", function.name(), expectedType, actualType), cause); // } // } // Path: jmespath-core/src/test/java/io/burt/jmespath/JmesPathRuntimeTest.java import org.junit.Before; import org.junit.Test; import org.hamcrest.Matcher; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.nio.charset.Charset; import java.util.Arrays; import java.util.List; import java.util.Collection; import java.util.Collections; import io.burt.jmespath.RuntimeConfiguration; import io.burt.jmespath.parser.ParseException; import io.burt.jmespath.function.ArgumentTypeException; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.both; import static org.hamcrest.Matchers.containsString; @Test public void withSilentTypeErrorsTheWrongTypeOfArgumentMakesFunctionsReturnNull() { Adapter<T> rt = createRuntime(RuntimeConfiguration.builder().withSilentTypeErrors(true).build()); T result = rt.compile("abs('foo')").search(parse("{}")); assertThat(result, is(jsonNull())); } @Test public void withSilentTypeErrorsTheWrongTypeOfArgumentMakesHigherOrderFunctionsReturnNull() { Adapter<T> rt = createRuntime(RuntimeConfiguration.builder().withSilentTypeErrors(true).build()); T result1 = rt.compile("sort_by(@, &foo)").search(parse("[{\"foo\": 3}, {\"foo\": \"bar\"}, {\"foo\": 1}]")); T result2 = rt.compile("min_by(@, &foo)").search(parse("[{\"foo\": 3}, {\"foo\": \"bar\"}, {\"foo\": 1}]")); assertThat(result1, is(jsonNull())); assertThat(result2, is(jsonNull())); } @Test public void absReturnsTheAbsoluteValueOfANumber() { T result1 = search("abs(`-1`)", parse("{}")); T result2 = search("abs(`1`)", parse("{}")); assertThat(result1, is(jsonNumber(1))); assertThat(result2, is(jsonNumber(1))); } @Test public void absRequiresANumberArgument() { try { search("abs('foo')", parse("{}")); fail("Expected ArgumentTypeException to have been thrown");
} catch (ArgumentTypeException ate) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/PropertyNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // }
import io.burt.jmespath.Adapter;
package io.burt.jmespath.node; public class PropertyNode<T> extends Node<T> { private final String rawPropertyName; private final T propertyName;
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/PropertyNode.java import io.burt.jmespath.Adapter; package io.burt.jmespath.node; public class PropertyNode<T> extends Node<T> { private final String rawPropertyName; private final T propertyName;
public PropertyNode(Adapter<T> runtime, String rawPropertyName) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/SliceNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // }
import java.util.ArrayList; import java.util.List; import io.burt.jmespath.Adapter;
package io.burt.jmespath.node; public class SliceNode<T> extends Node<T> { private final boolean absoluteStart; private final boolean absoluteStop; private final boolean absoluteStep; private final int start; private final int stop; private final int step; private final int limit; private final int rounding;
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/SliceNode.java import java.util.ArrayList; import java.util.List; import io.burt.jmespath.Adapter; package io.burt.jmespath.node; public class SliceNode<T> extends Node<T> { private final boolean absoluteStart; private final boolean absoluteStop; private final boolean absoluteStep; private final int start; private final int stop; private final int step; private final int limit; private final int rounding;
public SliceNode(Adapter<T> runtime, Integer start, Integer stop, Integer step) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/IndexNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.node; public class IndexNode<T> extends Node<T> { private final int index;
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/IndexNode.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.node; public class IndexNode<T> extends Node<T> { private final int index;
public IndexNode(Adapter<T> runtime, int index) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/IndexNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.node; public class IndexNode<T> extends Node<T> { private final int index; public IndexNode(Adapter<T> runtime, int index) { super(runtime); this.index = index; } @Override public T search(T input) {
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/IndexNode.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.node; public class IndexNode<T> extends Node<T> { private final int index; public IndexNode(Adapter<T> runtime, int index) { super(runtime); this.index = index; } @Override public T search(T input) {
if (runtime.typeOf(input) == JmesPathType.ARRAY) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/TypeFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // }
import java.util.List; import io.burt.jmespath.Adapter;
package io.burt.jmespath.function; public class TypeFunction extends BaseFunction { public TypeFunction() { super(ArgumentConstraints.anyValue()); } @Override
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/TypeFunction.java import java.util.List; import io.burt.jmespath.Adapter; package io.burt.jmespath.function; public class TypeFunction extends BaseFunction { public TypeFunction() { super(ArgumentConstraints.anyValue()); } @Override
protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/CompareByFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // }
import io.burt.jmespath.Adapter;
package io.burt.jmespath.function; /** * Helper base class for higher order comparison functions like max_by and min_by. */ public abstract class CompareByFunction extends TransformByFunction { /** * Subclasses override this method to decide whether the greatest or least * element sorts first. */ protected abstract boolean sortsBefore(int compareResult); @Override
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/CompareByFunction.java import io.burt.jmespath.Adapter; package io.burt.jmespath.function; /** * Helper base class for higher order comparison functions like max_by and min_by. */ public abstract class CompareByFunction extends TransformByFunction { /** * Subclasses override this method to decide whether the greatest or least * element sorts first. */ protected abstract boolean sortsBefore(int compareResult); @Override
protected <T> TransformByFunction.Aggregator<T> createAggregator(Adapter<T> runtime, int elementCount, T element, T elementValue) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/ToNumberFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class ToNumberFunction extends BaseFunction { public ToNumberFunction() { super(ArgumentConstraints.anyValue()); } @Override
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/ToNumberFunction.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class ToNumberFunction extends BaseFunction { public ToNumberFunction() { super(ArgumentConstraints.anyValue()); } @Override
protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/ToNumberFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class ToNumberFunction extends BaseFunction { public ToNumberFunction() { super(ArgumentConstraints.anyValue()); } @Override protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) { T subject = arguments.get(0).value();
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/ToNumberFunction.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class ToNumberFunction extends BaseFunction { public ToNumberFunction() { super(ArgumentConstraints.anyValue()); } @Override protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) { T subject = arguments.get(0).value();
JmesPathType subjectType = runtime.typeOf(subject);
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/ComparisonNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.node; public abstract class ComparisonNode<T> extends OperatorNode<T> { public static class EqualsNode<T> extends ComparisonNode<T> {
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/ComparisonNode.java import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.node; public abstract class ComparisonNode<T> extends OperatorNode<T> { public static class EqualsNode<T> extends ComparisonNode<T> {
public EqualsNode(Adapter<T> runtime, Expression<T> left, Expression<T> right) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/ComparisonNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.node; public abstract class ComparisonNode<T> extends OperatorNode<T> { public static class EqualsNode<T> extends ComparisonNode<T> {
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/ComparisonNode.java import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.node; public abstract class ComparisonNode<T> extends OperatorNode<T> { public static class EqualsNode<T> extends ComparisonNode<T> {
public EqualsNode(Adapter<T> runtime, Expression<T> left, Expression<T> right) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/ComparisonNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType;
} } protected ComparisonNode(Adapter<T> runtime, Expression<T> left, Expression<T> right) { super(runtime, left, right); } public static <U> Node<U> create(Adapter<U> runtime, Operator operator, Expression<U> left, Expression<U> right) { switch (operator) { case EQUALS: return new EqualsNode<>(runtime, left, right); case NOT_EQUALS: return new NotEqualsNode<>(runtime, left, right); case GREATER_THAN: return new GreaterThanNode<>(runtime, left, right); case GREATER_THAN_OR_EQUALS: return new GreaterThanOrEqualsNode<>(runtime, left, right); case LESS_THAN: return new LessThanNode<>(runtime, left, right); case LESS_THAN_OR_EQUALS: return new LessThanOrEqualsNode<>(runtime, left, right); default: throw new IllegalStateException(String.format("Unknown operator encountered: %s", operator)); } } @Override public T search(T input) { T leftResult = operand(0).search(input); T rightResult = operand(1).search(input);
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/ComparisonNode.java import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType; } } protected ComparisonNode(Adapter<T> runtime, Expression<T> left, Expression<T> right) { super(runtime, left, right); } public static <U> Node<U> create(Adapter<U> runtime, Operator operator, Expression<U> left, Expression<U> right) { switch (operator) { case EQUALS: return new EqualsNode<>(runtime, left, right); case NOT_EQUALS: return new NotEqualsNode<>(runtime, left, right); case GREATER_THAN: return new GreaterThanNode<>(runtime, left, right); case GREATER_THAN_OR_EQUALS: return new GreaterThanOrEqualsNode<>(runtime, left, right); case LESS_THAN: return new LessThanNode<>(runtime, left, right); case LESS_THAN_OR_EQUALS: return new LessThanOrEqualsNode<>(runtime, left, right); default: throw new IllegalStateException(String.format("Unknown operator encountered: %s", operator)); } } @Override public T search(T input) { T leftResult = operand(0).search(input); T rightResult = operand(1).search(input);
JmesPathType leftType = runtime.typeOf(leftResult);
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/StringNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // }
import io.burt.jmespath.Adapter;
package io.burt.jmespath.node; public class StringNode<T> extends Node<T> { private final String rawString; private final T string;
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/StringNode.java import io.burt.jmespath.Adapter; package io.burt.jmespath.node; public class StringNode<T> extends Node<T> { private final String rawString; private final T string;
public StringNode(Adapter<T> runtime, String rawString) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/CreateArrayNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import java.util.ArrayList; import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.node; public class CreateArrayNode<T> extends Node<T> { private final List<Expression<T>> entries;
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/CreateArrayNode.java import java.util.List; import java.util.ArrayList; import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.node; public class CreateArrayNode<T> extends Node<T> { private final List<Expression<T>> entries;
public CreateArrayNode(Adapter<T> runtime, List<? extends Expression<T>> entries) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/CreateArrayNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import java.util.ArrayList; import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.node; public class CreateArrayNode<T> extends Node<T> { private final List<Expression<T>> entries; public CreateArrayNode(Adapter<T> runtime, List<? extends Expression<T>> entries) { super(runtime); this.entries = new ArrayList<>(entries); } @Override public T search(T input) {
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/CreateArrayNode.java import java.util.List; import java.util.ArrayList; import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.node; public class CreateArrayNode<T> extends Node<T> { private final List<Expression<T>> entries; public CreateArrayNode(Adapter<T> runtime, List<? extends Expression<T>> entries) { super(runtime); this.entries = new ArrayList<>(entries); } @Override public T search(T input) {
if (runtime.typeOf(input) == JmesPathType.NULL) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/ArrayMathFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // }
import java.util.List; import io.burt.jmespath.Adapter;
package io.burt.jmespath.function; /** * Helper base class for functions that take an array and return a single value, * like calculating the max, min or sum. * <p> * Subclasses can operate on any type of elements, and must provide that type * as argument when calling <code>super</code>. */ public abstract class ArrayMathFunction extends BaseFunction { public ArrayMathFunction(ArgumentConstraint innerConstraint) { super(ArgumentConstraints.arrayOf(innerConstraint)); } @Override
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/ArrayMathFunction.java import java.util.List; import io.burt.jmespath.Adapter; package io.burt.jmespath.function; /** * Helper base class for functions that take an array and return a single value, * like calculating the max, min or sum. * <p> * Subclasses can operate on any type of elements, and must provide that type * as argument when calling <code>super</code>. */ public abstract class ArrayMathFunction extends BaseFunction { public ArrayMathFunction(ArgumentConstraint innerConstraint) { super(ArgumentConstraints.arrayOf(innerConstraint)); } @Override
protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/MathFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; /** * Helper base class for functions that perform operations on a single numerical * argument, like calculating the absolute value, rounding, etc. */ public abstract class MathFunction extends BaseFunction { public MathFunction() {
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/MathFunction.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; /** * Helper base class for functions that perform operations on a single numerical * argument, like calculating the absolute value, rounding, etc. */ public abstract class MathFunction extends BaseFunction { public MathFunction() {
super(ArgumentConstraints.typeOf(JmesPathType.NUMBER));
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/MathFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; /** * Helper base class for functions that perform operations on a single numerical * argument, like calculating the absolute value, rounding, etc. */ public abstract class MathFunction extends BaseFunction { public MathFunction() { super(ArgumentConstraints.typeOf(JmesPathType.NUMBER)); } @Override
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/MathFunction.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; /** * Helper base class for functions that perform operations on a single numerical * argument, like calculating the absolute value, rounding, etc. */ public abstract class MathFunction extends BaseFunction { public MathFunction() { super(ArgumentConstraints.typeOf(JmesPathType.NUMBER)); } @Override
protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/JsonLiteralNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // }
import io.burt.jmespath.Adapter;
package io.burt.jmespath.node; public class JsonLiteralNode<T> extends Node<T> { private final String rawValue; private final T value;
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/JsonLiteralNode.java import io.burt.jmespath.Adapter; package io.burt.jmespath.node; public class JsonLiteralNode<T> extends Node<T> { private final String rawValue; private final T value;
public JsonLiteralNode(Adapter<T> runtime, String rawValue) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/NodeFactory.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/function/Function.java // public interface Function { // /** // * Returns the name of the function. // * <p> // * The name is either automatically generated from the class name, or // * explicitly specified in the constructor. // */ // String name(); // // /** // * Returns the constraints to use when checking the list of arguments before // * the function is called. // */ // ArgumentConstraint argumentConstraints(); // // /** // * Call this function with a list of arguments. // * <p> // * The arguments can be either values or expressions, and their types will be // * checked before proceeding with the call. // * // * @throws ArgumentTypeException when the function is called with arguments of the wrong type // * @throws ArityException when the function is called with the wrong number of arguments // */ // <T> T call(Adapter<T> runtime, List<FunctionArgument<T>> arguments); // }
import java.util.List; import io.burt.jmespath.Expression; import io.burt.jmespath.function.Function;
package io.burt.jmespath.node; /** * A node factory is used by the expression compiler to create AST nodes. */ public interface NodeFactory<T> { Node<T> createCurrent(); Node<T> createProperty(String name); Node<T> createIndex(int index); Node<T> createSlice(Integer start, Integer stop, Integer step);
// Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/function/Function.java // public interface Function { // /** // * Returns the name of the function. // * <p> // * The name is either automatically generated from the class name, or // * explicitly specified in the constructor. // */ // String name(); // // /** // * Returns the constraints to use when checking the list of arguments before // * the function is called. // */ // ArgumentConstraint argumentConstraints(); // // /** // * Call this function with a list of arguments. // * <p> // * The arguments can be either values or expressions, and their types will be // * checked before proceeding with the call. // * // * @throws ArgumentTypeException when the function is called with arguments of the wrong type // * @throws ArityException when the function is called with the wrong number of arguments // */ // <T> T call(Adapter<T> runtime, List<FunctionArgument<T>> arguments); // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/NodeFactory.java import java.util.List; import io.burt.jmespath.Expression; import io.burt.jmespath.function.Function; package io.burt.jmespath.node; /** * A node factory is used by the expression compiler to create AST nodes. */ public interface NodeFactory<T> { Node<T> createCurrent(); Node<T> createProperty(String name); Node<T> createIndex(int index); Node<T> createSlice(Integer start, Integer stop, Integer step);
Node<T> createProjection(Expression<T> expression);
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/NodeFactory.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/function/Function.java // public interface Function { // /** // * Returns the name of the function. // * <p> // * The name is either automatically generated from the class name, or // * explicitly specified in the constructor. // */ // String name(); // // /** // * Returns the constraints to use when checking the list of arguments before // * the function is called. // */ // ArgumentConstraint argumentConstraints(); // // /** // * Call this function with a list of arguments. // * <p> // * The arguments can be either values or expressions, and their types will be // * checked before proceeding with the call. // * // * @throws ArgumentTypeException when the function is called with arguments of the wrong type // * @throws ArityException when the function is called with the wrong number of arguments // */ // <T> T call(Adapter<T> runtime, List<FunctionArgument<T>> arguments); // }
import java.util.List; import io.burt.jmespath.Expression; import io.burt.jmespath.function.Function;
package io.burt.jmespath.node; /** * A node factory is used by the expression compiler to create AST nodes. */ public interface NodeFactory<T> { Node<T> createCurrent(); Node<T> createProperty(String name); Node<T> createIndex(int index); Node<T> createSlice(Integer start, Integer stop, Integer step); Node<T> createProjection(Expression<T> expression); Node<T> createFlattenArray(); Node<T> createFlattenObject(); Node<T> createSelection(Expression<T> test); Node<T> createComparison(Operator operator, Expression<T> left, Expression<T> right); Node<T> createOr(Expression<T> left, Expression<T> right); Node<T> createAnd(Expression<T> left, Expression<T> right); Node<T> createFunctionCall(String functionName, List<? extends Expression<T>> args);
// Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/function/Function.java // public interface Function { // /** // * Returns the name of the function. // * <p> // * The name is either automatically generated from the class name, or // * explicitly specified in the constructor. // */ // String name(); // // /** // * Returns the constraints to use when checking the list of arguments before // * the function is called. // */ // ArgumentConstraint argumentConstraints(); // // /** // * Call this function with a list of arguments. // * <p> // * The arguments can be either values or expressions, and their types will be // * checked before proceeding with the call. // * // * @throws ArgumentTypeException when the function is called with arguments of the wrong type // * @throws ArityException when the function is called with the wrong number of arguments // */ // <T> T call(Adapter<T> runtime, List<FunctionArgument<T>> arguments); // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/NodeFactory.java import java.util.List; import io.burt.jmespath.Expression; import io.burt.jmespath.function.Function; package io.burt.jmespath.node; /** * A node factory is used by the expression compiler to create AST nodes. */ public interface NodeFactory<T> { Node<T> createCurrent(); Node<T> createProperty(String name); Node<T> createIndex(int index); Node<T> createSlice(Integer start, Integer stop, Integer step); Node<T> createProjection(Expression<T> expression); Node<T> createFlattenArray(); Node<T> createFlattenObject(); Node<T> createSelection(Expression<T> test); Node<T> createComparison(Operator operator, Expression<T> left, Expression<T> right); Node<T> createOr(Expression<T> left, Expression<T> right); Node<T> createAnd(Expression<T> left, Expression<T> right); Node<T> createFunctionCall(String functionName, List<? extends Expression<T>> args);
Node<T> createFunctionCall(Function function, List<? extends Expression<T>> args);
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/LengthFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class LengthFunction extends BaseFunction { public LengthFunction() {
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/LengthFunction.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class LengthFunction extends BaseFunction { public LengthFunction() {
super(ArgumentConstraints.typeOf(JmesPathType.STRING, JmesPathType.ARRAY, JmesPathType.OBJECT));
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/LengthFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class LengthFunction extends BaseFunction { public LengthFunction() { super(ArgumentConstraints.typeOf(JmesPathType.STRING, JmesPathType.ARRAY, JmesPathType.OBJECT)); } @Override
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/LengthFunction.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class LengthFunction extends BaseFunction { public LengthFunction() { super(ArgumentConstraints.typeOf(JmesPathType.STRING, JmesPathType.ARRAY, JmesPathType.OBJECT)); } @Override
protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/SortFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.Collections; import java.util.List; import java.util.ArrayList; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class SortFunction extends BaseFunction { public SortFunction() { super( ArgumentConstraints.arrayOf(
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/SortFunction.java import java.util.Collections; import java.util.List; import java.util.ArrayList; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class SortFunction extends BaseFunction { public SortFunction() { super( ArgumentConstraints.arrayOf(
ArgumentConstraints.typeOf(JmesPathType.NUMBER, JmesPathType.STRING)
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/SortFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.Collections; import java.util.List; import java.util.ArrayList; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class SortFunction extends BaseFunction { public SortFunction() { super( ArgumentConstraints.arrayOf( ArgumentConstraints.typeOf(JmesPathType.NUMBER, JmesPathType.STRING) ) ); } @Override
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/SortFunction.java import java.util.Collections; import java.util.List; import java.util.ArrayList; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class SortFunction extends BaseFunction { public SortFunction() { super( ArgumentConstraints.arrayOf( ArgumentConstraints.typeOf(JmesPathType.NUMBER, JmesPathType.STRING) ) ); } @Override
protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/Function.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // }
import java.util.List; import io.burt.jmespath.Adapter;
package io.burt.jmespath.function; /** * Represents the implementation of a function available in JMESPath expressions. * * Custom function implementations should extend {@link BaseFunction} to get * argument type checking, etc. */ public interface Function { /** * Returns the name of the function. * <p> * The name is either automatically generated from the class name, or * explicitly specified in the constructor. */ String name(); /** * Returns the constraints to use when checking the list of arguments before * the function is called. */ ArgumentConstraint argumentConstraints(); /** * Call this function with a list of arguments. * <p> * The arguments can be either values or expressions, and their types will be * checked before proceeding with the call. * * @throws ArgumentTypeException when the function is called with arguments of the wrong type * @throws ArityException when the function is called with the wrong number of arguments */
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/Function.java import java.util.List; import io.burt.jmespath.Adapter; package io.burt.jmespath.function; /** * Represents the implementation of a function available in JMESPath expressions. * * Custom function implementations should extend {@link BaseFunction} to get * argument type checking, etc. */ public interface Function { /** * Returns the name of the function. * <p> * The name is either automatically generated from the class name, or * explicitly specified in the constructor. */ String name(); /** * Returns the constraints to use when checking the list of arguments before * the function is called. */ ArgumentConstraint argumentConstraints(); /** * Call this function with a list of arguments. * <p> * The arguments can be either values or expressions, and their types will be * checked before proceeding with the call. * * @throws ArgumentTypeException when the function is called with arguments of the wrong type * @throws ArityException when the function is called with the wrong number of arguments */
<T> T call(Adapter<T> runtime, List<FunctionArgument<T>> arguments);
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/ReverseFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.Collections; import java.util.List; import java.util.ArrayList; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class ReverseFunction extends BaseFunction { public ReverseFunction() {
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/ReverseFunction.java import java.util.Collections; import java.util.List; import java.util.ArrayList; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class ReverseFunction extends BaseFunction { public ReverseFunction() {
super(ArgumentConstraints.typeOf(JmesPathType.ARRAY, JmesPathType.STRING));
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/ReverseFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.Collections; import java.util.List; import java.util.ArrayList; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class ReverseFunction extends BaseFunction { public ReverseFunction() { super(ArgumentConstraints.typeOf(JmesPathType.ARRAY, JmesPathType.STRING)); } @Override
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/ReverseFunction.java import java.util.Collections; import java.util.List; import java.util.ArrayList; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class ReverseFunction extends BaseFunction { public ReverseFunction() { super(ArgumentConstraints.typeOf(JmesPathType.ARRAY, JmesPathType.STRING)); } @Override
protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/ContainsFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class ContainsFunction extends BaseFunction { public ContainsFunction() { super(
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/ContainsFunction.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class ContainsFunction extends BaseFunction { public ContainsFunction() { super(
ArgumentConstraints.typeOf(JmesPathType.ARRAY, JmesPathType.STRING),
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/ContainsFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class ContainsFunction extends BaseFunction { public ContainsFunction() { super( ArgumentConstraints.typeOf(JmesPathType.ARRAY, JmesPathType.STRING), ArgumentConstraints.anyValue() ); } @Override
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/ContainsFunction.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class ContainsFunction extends BaseFunction { public ContainsFunction() { super( ArgumentConstraints.typeOf(JmesPathType.ARRAY, JmesPathType.STRING), ArgumentConstraints.anyValue() ); } @Override
protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/TransformByFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // }
import java.util.Iterator; import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; import io.burt.jmespath.Expression;
package io.burt.jmespath.function; /** * Helper base class for higher order comparison functions like sort_by, max_by and min_by. */ public abstract class TransformByFunction extends BaseFunction { public TransformByFunction() { super(
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/TransformByFunction.java import java.util.Iterator; import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; import io.burt.jmespath.Expression; package io.burt.jmespath.function; /** * Helper base class for higher order comparison functions like sort_by, max_by and min_by. */ public abstract class TransformByFunction extends BaseFunction { public TransformByFunction() { super(
ArgumentConstraints.arrayOf(ArgumentConstraints.typeOf(JmesPathType.OBJECT)),
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/TransformByFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // }
import java.util.Iterator; import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; import io.burt.jmespath.Expression;
package io.burt.jmespath.function; /** * Helper base class for higher order comparison functions like sort_by, max_by and min_by. */ public abstract class TransformByFunction extends BaseFunction { public TransformByFunction() { super( ArgumentConstraints.arrayOf(ArgumentConstraints.typeOf(JmesPathType.OBJECT)), ArgumentConstraints.expression() ); } @Override
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/TransformByFunction.java import java.util.Iterator; import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; import io.burt.jmespath.Expression; package io.burt.jmespath.function; /** * Helper base class for higher order comparison functions like sort_by, max_by and min_by. */ public abstract class TransformByFunction extends BaseFunction { public TransformByFunction() { super( ArgumentConstraints.arrayOf(ArgumentConstraints.typeOf(JmesPathType.OBJECT)), ArgumentConstraints.expression() ); } @Override
protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/TransformByFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // }
import java.util.Iterator; import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; import io.burt.jmespath.Expression;
package io.burt.jmespath.function; /** * Helper base class for higher order comparison functions like sort_by, max_by and min_by. */ public abstract class TransformByFunction extends BaseFunction { public TransformByFunction() { super( ArgumentConstraints.arrayOf(ArgumentConstraints.typeOf(JmesPathType.OBJECT)), ArgumentConstraints.expression() ); } @Override protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) { List<T> elementsList = runtime.toList(arguments.get(0).value()); Iterator<T> elements = elementsList.iterator();
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/TransformByFunction.java import java.util.Iterator; import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; import io.burt.jmespath.Expression; package io.burt.jmespath.function; /** * Helper base class for higher order comparison functions like sort_by, max_by and min_by. */ public abstract class TransformByFunction extends BaseFunction { public TransformByFunction() { super( ArgumentConstraints.arrayOf(ArgumentConstraints.typeOf(JmesPathType.OBJECT)), ArgumentConstraints.expression() ); } @Override protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) { List<T> elementsList = runtime.toList(arguments.get(0).value()); Iterator<T> elements = elementsList.iterator();
Expression<T> expression = arguments.get(1).expression();
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/ProjectionNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import java.util.ArrayList; import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.node; public class ProjectionNode<T> extends Node<T> { private final Expression<T> projection;
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/ProjectionNode.java import java.util.List; import java.util.ArrayList; import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.node; public class ProjectionNode<T> extends Node<T> { private final Expression<T> projection;
public ProjectionNode(Adapter<T> runtime, Expression<T> projection) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/ProjectionNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import java.util.ArrayList; import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.node; public class ProjectionNode<T> extends Node<T> { private final Expression<T> projection; public ProjectionNode(Adapter<T> runtime, Expression<T> projection) { super(runtime); this.projection = projection; } @Override public T search(T input) {
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/ProjectionNode.java import java.util.List; import java.util.ArrayList; import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.node; public class ProjectionNode<T> extends Node<T> { private final Expression<T> projection; public ProjectionNode(Adapter<T> runtime, Expression<T> projection) { super(runtime); this.projection = projection; } @Override public T search(T input) {
if (runtime.typeOf(input) == JmesPathType.ARRAY) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/CreateObjectNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.Map; import java.util.LinkedHashMap; import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.node; public class CreateObjectNode<T> extends Node<T> { private final List<Entry<T>> entries; public static class Entry<U> { private final String key;
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/CreateObjectNode.java import java.util.Map; import java.util.LinkedHashMap; import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.node; public class CreateObjectNode<T> extends Node<T> { private final List<Entry<T>> entries; public static class Entry<U> { private final String key;
private final Expression<U> value;
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/CreateObjectNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.Map; import java.util.LinkedHashMap; import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType;
protected String key() { return key; } protected Expression<U> value() { return value; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Entry)) { return false; } Entry<?> other = (Entry<?>) o; return key().equals(other.key()) && value().equals(other.value()); } @Override public int hashCode() { int h = 1; h = h * 31 + key.hashCode(); h = h * 31 + value.hashCode(); return h; } }
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/CreateObjectNode.java import java.util.Map; import java.util.LinkedHashMap; import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType; protected String key() { return key; } protected Expression<U> value() { return value; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Entry)) { return false; } Entry<?> other = (Entry<?>) o; return key().equals(other.key()) && value().equals(other.value()); } @Override public int hashCode() { int h = 1; h = h * 31 + key.hashCode(); h = h * 31 + value.hashCode(); return h; } }
public CreateObjectNode(Adapter<T> runtime, List<Entry<T>> entries) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/node/CreateObjectNode.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.Map; import java.util.LinkedHashMap; import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType;
} @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Entry)) { return false; } Entry<?> other = (Entry<?>) o; return key().equals(other.key()) && value().equals(other.value()); } @Override public int hashCode() { int h = 1; h = h * 31 + key.hashCode(); h = h * 31 + value.hashCode(); return h; } } public CreateObjectNode(Adapter<T> runtime, List<Entry<T>> entries) { super(runtime); this.entries = entries; } @Override public T search(T input) {
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/Expression.java // public interface Expression<T> { // /** // * Evaluate this expression against a JSON-like structure and return the result. // */ // T search(T input); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/node/CreateObjectNode.java import java.util.Map; import java.util.LinkedHashMap; import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Entry)) { return false; } Entry<?> other = (Entry<?>) o; return key().equals(other.key()) && value().equals(other.value()); } @Override public int hashCode() { int h = 1; h = h * 31 + key.hashCode(); h = h * 31 + value.hashCode(); return h; } } public CreateObjectNode(Adapter<T> runtime, List<Entry<T>> entries) { super(runtime); this.entries = entries; } @Override public T search(T input) {
if (runtime.typeOf(input) == JmesPathType.NULL) {
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/EndsWithFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class EndsWithFunction extends BaseFunction { public EndsWithFunction() { super(
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/EndsWithFunction.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class EndsWithFunction extends BaseFunction { public EndsWithFunction() { super(
ArgumentConstraints.typeOf(JmesPathType.STRING),
burtcorp/jmespath-java
jmespath-core/src/main/java/io/burt/jmespath/function/EndsWithFunction.java
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // }
import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType;
package io.burt.jmespath.function; public class EndsWithFunction extends BaseFunction { public EndsWithFunction() { super( ArgumentConstraints.typeOf(JmesPathType.STRING), ArgumentConstraints.typeOf(JmesPathType.STRING) ); } @Override
// Path: jmespath-core/src/main/java/io/burt/jmespath/Adapter.java // public interface Adapter<T> extends JmesPath<T>, Comparator<T> { // /** // * Parse a JSON string to a value. // * // * May throw exceptions when the given string is not valid JSON. The exact // * exceptions thrown will depend on the concrete implementation. // */ // T parseString(String str); // // /** // * Converts the argument to a {@link List}. // * // * When the argument represents an array the list will contain the elements of // * the array, when the argument represents an object the result is a list of // * the object's values and for all other types the result is an empty list. // */ // List<T> toList(T value); // // /** // * Converts the argument to a {@link String}. When the argument represents a string // * its string value is returned, otherwise a string with the value encoded // * as JSON is returned. // */ // String toString(T value); // // /** // * Converts the argument to a {@link Number}, or null if the argument does not // * represent a number. // */ // Number toNumber(T value); // // /** // * Returns true when the argument is truthy. // * // * All values are truthy, except the following, as per the JMESPath // * specification: <code>false</code>, <code>null</code>, empty lists, empty // * objects, empty strings. // */ // boolean isTruthy(T value); // // /** // * Returns the JSON type of the argument. // * // * As per the JMESPath specification the types are: <code>number</code>, // * <code>string</code>, <code>boolean</code>, <code>array</code>, // * <code>object</code>, <code>null</code>. // * // * @see JmesPathType // */ // JmesPathType typeOf(T value); // // /** // * Returns the value of a property of an object. // * // * The first argument must be an object and the second argument may be // * the name of a property on that object. When the property does not exist // * a null value (<em>not</em> Java <code>null</code>) is returned. // */ // @Deprecated // T getProperty(T value, String name); // // /** // * Returns the value of a property of an object. // * // * The first argument must represent an object and the second argument may be // * the name (which must be a string value) of a property of that object. // * When the property does not exist or represents null a null value (but not // * Java null) is returned. // */ // T getProperty(T value, T name); // // /** // * Returns all the property names of the given object, or an empty collection // * when the given value does not represent an object. // * // * The property names are always string values. // */ // Collection<T> getPropertyNames(T value); // // /** // * Returns a null value (<em>not</em> Java <code>null</code>). // */ // T createNull(); // // /** // * Returns an array value with the specified elements. // */ // T createArray(Collection<T> elements); // // /** // * Returns a string value containing the specified string. // */ // T createString(String str); // // /** // * Returns a boolean value containing the specified boolean. // */ // T createBoolean(boolean b); // // /** // * Returns an object value with the specified properties. // * // * The map keys must all be string values. // * // * Creating nested objects is not supported. // */ // T createObject(Map<T, T> obj); // // /** // * Returns a number value containing the specified floating point number. // */ // T createNumber(double n); // // /** // * Returns a number value containing the specified integer. // */ // T createNumber(long n); // // /** // * Throws an exception or returns a fallback value when a type check fails // * during a function call evaluation. // */ // T handleArgumentTypeError(Function function, String expectedType, String actualType); // // /** // * Returns a function registry that can be used by the expression compiler // * to look up functions. // */ // FunctionRegistry functionRegistry(); // // /** // * Returns a node factory that can be used by the expression compiler to build // * the interpreter AST. // */ // NodeFactory<T> nodeFactory(); // } // // Path: jmespath-core/src/main/java/io/burt/jmespath/JmesPathType.java // public enum JmesPathType { // NUMBER, // STRING, // BOOLEAN, // ARRAY, // OBJECT, // NULL; // // @Override // public String toString() { // return name().toLowerCase(); // } // } // Path: jmespath-core/src/main/java/io/burt/jmespath/function/EndsWithFunction.java import java.util.List; import io.burt.jmespath.Adapter; import io.burt.jmespath.JmesPathType; package io.burt.jmespath.function; public class EndsWithFunction extends BaseFunction { public EndsWithFunction() { super( ArgumentConstraints.typeOf(JmesPathType.STRING), ArgumentConstraints.typeOf(JmesPathType.STRING) ); } @Override
protected <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments) {
real-logic/benchmarks
benchmarks-grpc/src/main/java/uk/co/real_logic/benchmarks/grpc/remote/EchoServer.java
// Path: benchmarks-grpc/src/main/java/uk/co/real_logic/benchmarks/grpc/remote/GrpcConfig.java // public static NettyServerBuilder getServerBuilder() // { // final NettyServerBuilder serverBuilder = // NettyServerBuilder.forAddress(new InetSocketAddress(getServerHost(), getServerPort())); // if (getBoolean(TLS_PROP_NAME)) // { // final Path certificatesDir = certificatesDir(); // final SslContextBuilder sslClientContextBuilder = SslContextBuilder.forServer( // certificatesDir.resolve("server.pem").toFile(), certificatesDir.resolve("server.key").toFile()) // .trustManager(certificatesDir.resolve("ca.pem").toFile()) // .clientAuth(ClientAuth.REQUIRE); // GrpcSslContexts.configure(sslClientContextBuilder); // // try // { // serverBuilder.sslContext(sslClientContextBuilder.build()); // } // catch (final SSLException ex) // { // LangUtil.rethrowUnchecked(ex); // } // } // return serverBuilder; // }
import io.grpc.Server; import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder; import org.agrona.PropertyAction; import org.agrona.SystemUtil; import org.agrona.concurrent.ShutdownSignalBarrier; import java.io.IOException; import static uk.co.real_logic.benchmarks.grpc.remote.GrpcConfig.getServerBuilder;
/* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.grpc.remote; public class EchoServer implements AutoCloseable { private final Server server; public EchoServer(final NettyServerBuilder serverBuilder) { server = serverBuilder.addService(new EchoService()).build(); } public void start() throws IOException { server.start(); System.out.println("Server started, listening on: " + server.getListenSockets()); } public void close() throws Exception { System.out.println("Shutting down server..."); server.shutdownNow(); server.awaitTermination(); } public static void main(final String[] args) throws Exception { SystemUtil.loadPropertiesFiles(PropertyAction.PRESERVE, args);
// Path: benchmarks-grpc/src/main/java/uk/co/real_logic/benchmarks/grpc/remote/GrpcConfig.java // public static NettyServerBuilder getServerBuilder() // { // final NettyServerBuilder serverBuilder = // NettyServerBuilder.forAddress(new InetSocketAddress(getServerHost(), getServerPort())); // if (getBoolean(TLS_PROP_NAME)) // { // final Path certificatesDir = certificatesDir(); // final SslContextBuilder sslClientContextBuilder = SslContextBuilder.forServer( // certificatesDir.resolve("server.pem").toFile(), certificatesDir.resolve("server.key").toFile()) // .trustManager(certificatesDir.resolve("ca.pem").toFile()) // .clientAuth(ClientAuth.REQUIRE); // GrpcSslContexts.configure(sslClientContextBuilder); // // try // { // serverBuilder.sslContext(sslClientContextBuilder.build()); // } // catch (final SSLException ex) // { // LangUtil.rethrowUnchecked(ex); // } // } // return serverBuilder; // } // Path: benchmarks-grpc/src/main/java/uk/co/real_logic/benchmarks/grpc/remote/EchoServer.java import io.grpc.Server; import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder; import org.agrona.PropertyAction; import org.agrona.SystemUtil; import org.agrona.concurrent.ShutdownSignalBarrier; import java.io.IOException; import static uk.co.real_logic.benchmarks.grpc.remote.GrpcConfig.getServerBuilder; /* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.grpc.remote; public class EchoServer implements AutoCloseable { private final Server server; public EchoServer(final NettyServerBuilder serverBuilder) { server = serverBuilder.addService(new EchoService()).build(); } public void start() throws IOException { server.start(); System.out.println("Server started, listening on: " + server.getListenSockets()); } public void close() throws Exception { System.out.println("Shutting down server..."); server.shutdownNow(); server.awaitTermination(); } public static void main(final String[] args) throws Exception { SystemUtil.loadPropertiesFiles(PropertyAction.PRESERVE, args);
try (EchoServer server = new EchoServer(getServerBuilder()))
real-logic/benchmarks
benchmarks-aeron/src/test/java/uk/co/real_logic/benchmarks/aeron/remote/LiveRecordingTest.java
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/ArchivingMediaDriver.java // static ArchivingMediaDriver launchArchiveWithEmbeddedDriver() // { // MediaDriver driver = null; // Archive archive = null; // try // { // final MediaDriver.Context driverCtx = new MediaDriver.Context() // .dirDeleteOnStart(true) // .dirDeleteOnShutdown(true) // .spiesSimulateConnection(true); // // driver = MediaDriver.launch(driverCtx); // // final Archive.Context archiveCtx = new Archive.Context() // .aeronDirectoryName(driverCtx.aeronDirectoryName()) // .deleteArchiveOnStart(true); // // final int errorCounterId = SystemCounterDescriptor.ERRORS.id(); // final AtomicCounter errorCounter = null != archiveCtx.errorCounter() ? // archiveCtx.errorCounter() : new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId); // // final ErrorHandler errorHandler = null != archiveCtx.errorHandler() ? // archiveCtx.errorHandler() : driverCtx.errorHandler(); // // archive = Archive.launch(archiveCtx // .mediaDriverAgentInvoker(driver.sharedAgentInvoker()) // .aeronDirectoryName(driverCtx.aeronDirectoryName()) // .errorHandler(errorHandler) // .errorCounter(errorCounter)); // // return new ArchivingMediaDriver(driver, archive); // } // catch (final Exception ex) // { // CloseHelper.quietCloseAll(archive, driver); // throw ex; // } // }
import io.aeron.archive.client.AeronArchive; import org.agrona.IoUtil; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import java.io.File; import java.util.concurrent.atomic.AtomicBoolean; import static io.aeron.CommonContext.IPC_CHANNEL; import static io.aeron.archive.client.AeronArchive.Configuration.RECORDING_EVENTS_CHANNEL_PROP_NAME; import static io.aeron.archive.client.AeronArchive.Configuration.RECORDING_EVENTS_ENABLED_PROP_NAME; import static io.aeron.archive.client.AeronArchive.connect; import static java.lang.System.clearProperty; import static java.lang.System.setProperty; import static uk.co.real_logic.benchmarks.aeron.remote.ArchivingMediaDriver.launchArchiveWithEmbeddedDriver;
/* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.remote; class LiveRecordingTest extends AbstractTest<ArchivingMediaDriver, AeronArchive, LiveRecordingMessageTransceiver, EchoNode> { private File archiveDir; @BeforeEach void before() { setProperty(RECORDING_EVENTS_ENABLED_PROP_NAME, "true"); setProperty(RECORDING_EVENTS_CHANNEL_PROP_NAME, IPC_CHANNEL); } @AfterEach void after() { clearProperty(RECORDING_EVENTS_ENABLED_PROP_NAME); clearProperty(RECORDING_EVENTS_CHANNEL_PROP_NAME); IoUtil.delete(archiveDir, true); } protected EchoNode createNode( final AtomicBoolean running, final ArchivingMediaDriver archivingMediaDriver, final AeronArchive aeronArchive) { return new EchoNode(running, null, aeronArchive.context().aeron(), false); } protected ArchivingMediaDriver createDriver() {
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/ArchivingMediaDriver.java // static ArchivingMediaDriver launchArchiveWithEmbeddedDriver() // { // MediaDriver driver = null; // Archive archive = null; // try // { // final MediaDriver.Context driverCtx = new MediaDriver.Context() // .dirDeleteOnStart(true) // .dirDeleteOnShutdown(true) // .spiesSimulateConnection(true); // // driver = MediaDriver.launch(driverCtx); // // final Archive.Context archiveCtx = new Archive.Context() // .aeronDirectoryName(driverCtx.aeronDirectoryName()) // .deleteArchiveOnStart(true); // // final int errorCounterId = SystemCounterDescriptor.ERRORS.id(); // final AtomicCounter errorCounter = null != archiveCtx.errorCounter() ? // archiveCtx.errorCounter() : new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId); // // final ErrorHandler errorHandler = null != archiveCtx.errorHandler() ? // archiveCtx.errorHandler() : driverCtx.errorHandler(); // // archive = Archive.launch(archiveCtx // .mediaDriverAgentInvoker(driver.sharedAgentInvoker()) // .aeronDirectoryName(driverCtx.aeronDirectoryName()) // .errorHandler(errorHandler) // .errorCounter(errorCounter)); // // return new ArchivingMediaDriver(driver, archive); // } // catch (final Exception ex) // { // CloseHelper.quietCloseAll(archive, driver); // throw ex; // } // } // Path: benchmarks-aeron/src/test/java/uk/co/real_logic/benchmarks/aeron/remote/LiveRecordingTest.java import io.aeron.archive.client.AeronArchive; import org.agrona.IoUtil; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import java.io.File; import java.util.concurrent.atomic.AtomicBoolean; import static io.aeron.CommonContext.IPC_CHANNEL; import static io.aeron.archive.client.AeronArchive.Configuration.RECORDING_EVENTS_CHANNEL_PROP_NAME; import static io.aeron.archive.client.AeronArchive.Configuration.RECORDING_EVENTS_ENABLED_PROP_NAME; import static io.aeron.archive.client.AeronArchive.connect; import static java.lang.System.clearProperty; import static java.lang.System.setProperty; import static uk.co.real_logic.benchmarks.aeron.remote.ArchivingMediaDriver.launchArchiveWithEmbeddedDriver; /* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.remote; class LiveRecordingTest extends AbstractTest<ArchivingMediaDriver, AeronArchive, LiveRecordingMessageTransceiver, EchoNode> { private File archiveDir; @BeforeEach void before() { setProperty(RECORDING_EVENTS_ENABLED_PROP_NAME, "true"); setProperty(RECORDING_EVENTS_CHANNEL_PROP_NAME, IPC_CHANNEL); } @AfterEach void after() { clearProperty(RECORDING_EVENTS_ENABLED_PROP_NAME); clearProperty(RECORDING_EVENTS_CHANNEL_PROP_NAME); IoUtil.delete(archiveDir, true); } protected EchoNode createNode( final AtomicBoolean running, final ArchivingMediaDriver archivingMediaDriver, final AeronArchive aeronArchive) { return new EchoNode(running, null, aeronArchive.context().aeron(), false); } protected ArchivingMediaDriver createDriver() {
final ArchivingMediaDriver driver = launchArchiveWithEmbeddedDriver();
real-logic/benchmarks
benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/AeronExclusiveIpcBenchmark.java
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128;
import io.aeron.Aeron; import io.aeron.CommonContext; import io.aeron.ExclusivePublication; import io.aeron.Subscription; import io.aeron.driver.MediaDriver; import io.aeron.driver.ThreadingMode; import io.aeron.logbuffer.FragmentHandler; import io.aeron.logbuffer.Header; import org.agrona.BufferUtil; import org.agrona.DirectBuffer; import org.agrona.concurrent.BusySpinIdleStrategy; import org.agrona.concurrent.IdleStrategy; import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.concurrent.UnsafeBuffer; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import static org.agrona.BitUtil.SIZE_OF_INT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY;
/* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class AeronExclusiveIpcBenchmark { static final int STREAM_ID = 1; static final int FRAGMENT_LIMIT = 128; static final Integer SENTINEL = 0; @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; int[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); MediaDriver.Context ctx; MediaDriver mediaDriver; Aeron aeron; ExclusivePublication publication; Subscription subscription; @SuppressWarnings("unchecked")
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128; // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/AeronExclusiveIpcBenchmark.java import io.aeron.Aeron; import io.aeron.CommonContext; import io.aeron.ExclusivePublication; import io.aeron.Subscription; import io.aeron.driver.MediaDriver; import io.aeron.driver.ThreadingMode; import io.aeron.logbuffer.FragmentHandler; import io.aeron.logbuffer.Header; import org.agrona.BufferUtil; import org.agrona.DirectBuffer; import org.agrona.concurrent.BusySpinIdleStrategy; import org.agrona.concurrent.IdleStrategy; import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.concurrent.UnsafeBuffer; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import static org.agrona.BitUtil.SIZE_OF_INT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY; /* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class AeronExclusiveIpcBenchmark { static final int STREAM_ID = 1; static final int FRAGMENT_LIMIT = 128; static final Integer SENTINEL = 0; @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; int[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); MediaDriver.Context ctx; MediaDriver mediaDriver; Aeron aeron; ExclusivePublication publication; Subscription subscription; @SuppressWarnings("unchecked")
final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT];
real-logic/benchmarks
benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/AeronExclusiveIpcBenchmark.java
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128;
import io.aeron.Aeron; import io.aeron.CommonContext; import io.aeron.ExclusivePublication; import io.aeron.Subscription; import io.aeron.driver.MediaDriver; import io.aeron.driver.ThreadingMode; import io.aeron.logbuffer.FragmentHandler; import io.aeron.logbuffer.Header; import org.agrona.BufferUtil; import org.agrona.DirectBuffer; import org.agrona.concurrent.BusySpinIdleStrategy; import org.agrona.concurrent.IdleStrategy; import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.concurrent.UnsafeBuffer; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import static org.agrona.BitUtil.SIZE_OF_INT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY;
/* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class AeronExclusiveIpcBenchmark { static final int STREAM_ID = 1; static final int FRAGMENT_LIMIT = 128; static final Integer SENTINEL = 0; @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; int[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); MediaDriver.Context ctx; MediaDriver mediaDriver; Aeron aeron; ExclusivePublication publication; Subscription subscription; @SuppressWarnings("unchecked") final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT]; Thread consumerThread; @Setup public synchronized void setup() { for (int i = 0; i < MAX_THREAD_COUNT; i++) {
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128; // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/AeronExclusiveIpcBenchmark.java import io.aeron.Aeron; import io.aeron.CommonContext; import io.aeron.ExclusivePublication; import io.aeron.Subscription; import io.aeron.driver.MediaDriver; import io.aeron.driver.ThreadingMode; import io.aeron.logbuffer.FragmentHandler; import io.aeron.logbuffer.Header; import org.agrona.BufferUtil; import org.agrona.DirectBuffer; import org.agrona.concurrent.BusySpinIdleStrategy; import org.agrona.concurrent.IdleStrategy; import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.concurrent.UnsafeBuffer; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import static org.agrona.BitUtil.SIZE_OF_INT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY; /* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class AeronExclusiveIpcBenchmark { static final int STREAM_ID = 1; static final int FRAGMENT_LIMIT = 128; static final Integer SENTINEL = 0; @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; int[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); MediaDriver.Context ctx; MediaDriver mediaDriver; Aeron aeron; ExclusivePublication publication; Subscription subscription; @SuppressWarnings("unchecked") final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT]; Thread consumerThread; @Setup public synchronized void setup() { for (int i = 0; i < MAX_THREAD_COUNT; i++) {
responseQueues[i] = new OneToOneConcurrentArrayQueue<>(RESPONSE_QUEUE_CAPACITY);
real-logic/benchmarks
benchmarks-api/src/test/java/uk/co/real_logic/benchmarks/remote/InMemoryMessageTransceiverTest.java
// Path: benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/MessageTransceiver.java // static final long CHECKSUM = ThreadLocalRandom.current().nextLong();
import org.HdrHistogram.Histogram; import org.agrona.collections.MutableInteger; import org.agrona.concurrent.NanoClock; import org.junit.jupiter.api.Test; import java.util.concurrent.ThreadLocalRandom; import static java.lang.Long.MAX_VALUE; import static java.lang.Long.MIN_VALUE; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; import static uk.co.real_logic.benchmarks.remote.MessageTransceiverBase.CHECKSUM;
void sendMultipleMessages() { final int result = messageTransceiver.send(4, 64, 800, -222); assertEquals(4, result); } @Test void sendReturnsZeroIfItCantFitAnEntireBatch() { messageTransceiver.send(InMemoryMessageTransceiver.SIZE, 8, 777, 100); final int result = messageTransceiver.send(1, 100, 555, 21); assertEquals(0, result); } @Test void receiveIsANoOpIfNothingWasWritten() { messageTransceiver.receive(); verifyNoInteractions(clock, histogram); } @Test void receiveIsANoOpAfterAllMessagesWereConsumed() { when(clock.nanoTime()).thenReturn(1500L);
// Path: benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/MessageTransceiver.java // static final long CHECKSUM = ThreadLocalRandom.current().nextLong(); // Path: benchmarks-api/src/test/java/uk/co/real_logic/benchmarks/remote/InMemoryMessageTransceiverTest.java import org.HdrHistogram.Histogram; import org.agrona.collections.MutableInteger; import org.agrona.concurrent.NanoClock; import org.junit.jupiter.api.Test; import java.util.concurrent.ThreadLocalRandom; import static java.lang.Long.MAX_VALUE; import static java.lang.Long.MIN_VALUE; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; import static uk.co.real_logic.benchmarks.remote.MessageTransceiverBase.CHECKSUM; void sendMultipleMessages() { final int result = messageTransceiver.send(4, 64, 800, -222); assertEquals(4, result); } @Test void sendReturnsZeroIfItCantFitAnEntireBatch() { messageTransceiver.send(InMemoryMessageTransceiver.SIZE, 8, 777, 100); final int result = messageTransceiver.send(1, 100, 555, 21); assertEquals(0, result); } @Test void receiveIsANoOpIfNothingWasWritten() { messageTransceiver.receive(); verifyNoInteractions(clock, histogram); } @Test void receiveIsANoOpAfterAllMessagesWereConsumed() { when(clock.nanoTime()).thenReturn(1500L);
messageTransceiver.send(5, 128, 1111, CHECKSUM);
real-logic/benchmarks
benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/AeronUtil.java
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/ArchivingMediaDriver.java // static ArchivingMediaDriver launchArchiveWithEmbeddedDriver() // { // MediaDriver driver = null; // Archive archive = null; // try // { // final MediaDriver.Context driverCtx = new MediaDriver.Context() // .dirDeleteOnStart(true) // .dirDeleteOnShutdown(true) // .spiesSimulateConnection(true); // // driver = MediaDriver.launch(driverCtx); // // final Archive.Context archiveCtx = new Archive.Context() // .aeronDirectoryName(driverCtx.aeronDirectoryName()) // .deleteArchiveOnStart(true); // // final int errorCounterId = SystemCounterDescriptor.ERRORS.id(); // final AtomicCounter errorCounter = null != archiveCtx.errorCounter() ? // archiveCtx.errorCounter() : new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId); // // final ErrorHandler errorHandler = null != archiveCtx.errorHandler() ? // archiveCtx.errorHandler() : driverCtx.errorHandler(); // // archive = Archive.launch(archiveCtx // .mediaDriverAgentInvoker(driver.sharedAgentInvoker()) // .aeronDirectoryName(driverCtx.aeronDirectoryName()) // .errorHandler(errorHandler) // .errorCounter(errorCounter)); // // return new ArchivingMediaDriver(driver, archive); // } // catch (final Exception ex) // { // CloseHelper.quietCloseAll(archive, driver); // throw ex; // } // } // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/ArchivingMediaDriver.java // static ArchivingMediaDriver launchArchiveWithStandaloneDriver() // { // return new ArchivingMediaDriver(null, Archive.launch(new Archive.Context().deleteArchiveOnStart(true))); // }
import io.aeron.Aeron; import io.aeron.ExclusivePublication; import io.aeron.Image; import io.aeron.Subscription; import io.aeron.archive.client.AeronArchive; import io.aeron.archive.client.ArchiveException; import io.aeron.archive.client.RecordingDescriptorConsumer; import io.aeron.driver.MediaDriver; import io.aeron.exceptions.AeronException; import io.aeron.logbuffer.BufferClaim; import io.aeron.logbuffer.FragmentHandler; import org.agrona.ErrorHandler; import org.agrona.LangUtil; import org.agrona.MutableDirectBuffer; import org.agrona.collections.MutableLong; import org.agrona.concurrent.IdleStrategy; import org.agrona.concurrent.NanoClock; import org.agrona.concurrent.NoOpIdleStrategy; import org.agrona.concurrent.ShutdownSignalBarrier; import org.agrona.concurrent.status.CountersReader; import sun.misc.Signal; import sun.misc.SignalHandler; import java.util.Arrays; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.BooleanSupplier; import static io.aeron.CommonContext.IPC_CHANNEL; import static io.aeron.Publication.*; import static io.aeron.archive.status.RecordingPos.findCounterIdBySession; import static io.aeron.archive.status.RecordingPos.getRecordingId; import static java.lang.Boolean.getBoolean; import static java.lang.Class.forName; import static java.lang.Integer.getInteger; import static java.lang.Long.MAX_VALUE; import static java.lang.System.getProperty; import static java.nio.ByteOrder.LITTLE_ENDIAN; import static org.agrona.BitUtil.SIZE_OF_LONG; import static org.agrona.Strings.isEmpty; import static org.agrona.SystemUtil.parseDuration; import static org.agrona.concurrent.status.CountersReader.NULL_COUNTER_ID; import static uk.co.real_logic.benchmarks.aeron.remote.ArchivingMediaDriver.launchArchiveWithEmbeddedDriver; import static uk.co.real_logic.benchmarks.aeron.remote.ArchivingMediaDriver.launchArchiveWithStandaloneDriver;
final String idleStrategy = getProperty(IDLE_STRATEGY_PROP_NAME); if (isEmpty(idleStrategy)) { return NoOpIdleStrategy.INSTANCE; } try { return (IdleStrategy)forName(idleStrategy).getConstructor().newInstance(); } catch (final ReflectiveOperationException | ClassCastException ex) { throw new IllegalArgumentException("Invalid IdleStrategy: " + idleStrategy, ex); } } static MediaDriver launchEmbeddedMediaDriverIfConfigured() { if (embeddedMediaDriver()) { return MediaDriver.launch(new MediaDriver.Context() .dirDeleteOnStart(true) .spiesSimulateConnection(true)); } return null; } static ArchivingMediaDriver launchArchivingMediaDriver() {
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/ArchivingMediaDriver.java // static ArchivingMediaDriver launchArchiveWithEmbeddedDriver() // { // MediaDriver driver = null; // Archive archive = null; // try // { // final MediaDriver.Context driverCtx = new MediaDriver.Context() // .dirDeleteOnStart(true) // .dirDeleteOnShutdown(true) // .spiesSimulateConnection(true); // // driver = MediaDriver.launch(driverCtx); // // final Archive.Context archiveCtx = new Archive.Context() // .aeronDirectoryName(driverCtx.aeronDirectoryName()) // .deleteArchiveOnStart(true); // // final int errorCounterId = SystemCounterDescriptor.ERRORS.id(); // final AtomicCounter errorCounter = null != archiveCtx.errorCounter() ? // archiveCtx.errorCounter() : new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId); // // final ErrorHandler errorHandler = null != archiveCtx.errorHandler() ? // archiveCtx.errorHandler() : driverCtx.errorHandler(); // // archive = Archive.launch(archiveCtx // .mediaDriverAgentInvoker(driver.sharedAgentInvoker()) // .aeronDirectoryName(driverCtx.aeronDirectoryName()) // .errorHandler(errorHandler) // .errorCounter(errorCounter)); // // return new ArchivingMediaDriver(driver, archive); // } // catch (final Exception ex) // { // CloseHelper.quietCloseAll(archive, driver); // throw ex; // } // } // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/ArchivingMediaDriver.java // static ArchivingMediaDriver launchArchiveWithStandaloneDriver() // { // return new ArchivingMediaDriver(null, Archive.launch(new Archive.Context().deleteArchiveOnStart(true))); // } // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/AeronUtil.java import io.aeron.Aeron; import io.aeron.ExclusivePublication; import io.aeron.Image; import io.aeron.Subscription; import io.aeron.archive.client.AeronArchive; import io.aeron.archive.client.ArchiveException; import io.aeron.archive.client.RecordingDescriptorConsumer; import io.aeron.driver.MediaDriver; import io.aeron.exceptions.AeronException; import io.aeron.logbuffer.BufferClaim; import io.aeron.logbuffer.FragmentHandler; import org.agrona.ErrorHandler; import org.agrona.LangUtil; import org.agrona.MutableDirectBuffer; import org.agrona.collections.MutableLong; import org.agrona.concurrent.IdleStrategy; import org.agrona.concurrent.NanoClock; import org.agrona.concurrent.NoOpIdleStrategy; import org.agrona.concurrent.ShutdownSignalBarrier; import org.agrona.concurrent.status.CountersReader; import sun.misc.Signal; import sun.misc.SignalHandler; import java.util.Arrays; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.BooleanSupplier; import static io.aeron.CommonContext.IPC_CHANNEL; import static io.aeron.Publication.*; import static io.aeron.archive.status.RecordingPos.findCounterIdBySession; import static io.aeron.archive.status.RecordingPos.getRecordingId; import static java.lang.Boolean.getBoolean; import static java.lang.Class.forName; import static java.lang.Integer.getInteger; import static java.lang.Long.MAX_VALUE; import static java.lang.System.getProperty; import static java.nio.ByteOrder.LITTLE_ENDIAN; import static org.agrona.BitUtil.SIZE_OF_LONG; import static org.agrona.Strings.isEmpty; import static org.agrona.SystemUtil.parseDuration; import static org.agrona.concurrent.status.CountersReader.NULL_COUNTER_ID; import static uk.co.real_logic.benchmarks.aeron.remote.ArchivingMediaDriver.launchArchiveWithEmbeddedDriver; import static uk.co.real_logic.benchmarks.aeron.remote.ArchivingMediaDriver.launchArchiveWithStandaloneDriver; final String idleStrategy = getProperty(IDLE_STRATEGY_PROP_NAME); if (isEmpty(idleStrategy)) { return NoOpIdleStrategy.INSTANCE; } try { return (IdleStrategy)forName(idleStrategy).getConstructor().newInstance(); } catch (final ReflectiveOperationException | ClassCastException ex) { throw new IllegalArgumentException("Invalid IdleStrategy: " + idleStrategy, ex); } } static MediaDriver launchEmbeddedMediaDriverIfConfigured() { if (embeddedMediaDriver()) { return MediaDriver.launch(new MediaDriver.Context() .dirDeleteOnStart(true) .spiesSimulateConnection(true)); } return null; } static ArchivingMediaDriver launchArchivingMediaDriver() {
return embeddedMediaDriver() ? launchArchiveWithEmbeddedDriver() : launchArchiveWithStandaloneDriver();
real-logic/benchmarks
benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/AeronUtil.java
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/ArchivingMediaDriver.java // static ArchivingMediaDriver launchArchiveWithEmbeddedDriver() // { // MediaDriver driver = null; // Archive archive = null; // try // { // final MediaDriver.Context driverCtx = new MediaDriver.Context() // .dirDeleteOnStart(true) // .dirDeleteOnShutdown(true) // .spiesSimulateConnection(true); // // driver = MediaDriver.launch(driverCtx); // // final Archive.Context archiveCtx = new Archive.Context() // .aeronDirectoryName(driverCtx.aeronDirectoryName()) // .deleteArchiveOnStart(true); // // final int errorCounterId = SystemCounterDescriptor.ERRORS.id(); // final AtomicCounter errorCounter = null != archiveCtx.errorCounter() ? // archiveCtx.errorCounter() : new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId); // // final ErrorHandler errorHandler = null != archiveCtx.errorHandler() ? // archiveCtx.errorHandler() : driverCtx.errorHandler(); // // archive = Archive.launch(archiveCtx // .mediaDriverAgentInvoker(driver.sharedAgentInvoker()) // .aeronDirectoryName(driverCtx.aeronDirectoryName()) // .errorHandler(errorHandler) // .errorCounter(errorCounter)); // // return new ArchivingMediaDriver(driver, archive); // } // catch (final Exception ex) // { // CloseHelper.quietCloseAll(archive, driver); // throw ex; // } // } // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/ArchivingMediaDriver.java // static ArchivingMediaDriver launchArchiveWithStandaloneDriver() // { // return new ArchivingMediaDriver(null, Archive.launch(new Archive.Context().deleteArchiveOnStart(true))); // }
import io.aeron.Aeron; import io.aeron.ExclusivePublication; import io.aeron.Image; import io.aeron.Subscription; import io.aeron.archive.client.AeronArchive; import io.aeron.archive.client.ArchiveException; import io.aeron.archive.client.RecordingDescriptorConsumer; import io.aeron.driver.MediaDriver; import io.aeron.exceptions.AeronException; import io.aeron.logbuffer.BufferClaim; import io.aeron.logbuffer.FragmentHandler; import org.agrona.ErrorHandler; import org.agrona.LangUtil; import org.agrona.MutableDirectBuffer; import org.agrona.collections.MutableLong; import org.agrona.concurrent.IdleStrategy; import org.agrona.concurrent.NanoClock; import org.agrona.concurrent.NoOpIdleStrategy; import org.agrona.concurrent.ShutdownSignalBarrier; import org.agrona.concurrent.status.CountersReader; import sun.misc.Signal; import sun.misc.SignalHandler; import java.util.Arrays; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.BooleanSupplier; import static io.aeron.CommonContext.IPC_CHANNEL; import static io.aeron.Publication.*; import static io.aeron.archive.status.RecordingPos.findCounterIdBySession; import static io.aeron.archive.status.RecordingPos.getRecordingId; import static java.lang.Boolean.getBoolean; import static java.lang.Class.forName; import static java.lang.Integer.getInteger; import static java.lang.Long.MAX_VALUE; import static java.lang.System.getProperty; import static java.nio.ByteOrder.LITTLE_ENDIAN; import static org.agrona.BitUtil.SIZE_OF_LONG; import static org.agrona.Strings.isEmpty; import static org.agrona.SystemUtil.parseDuration; import static org.agrona.concurrent.status.CountersReader.NULL_COUNTER_ID; import static uk.co.real_logic.benchmarks.aeron.remote.ArchivingMediaDriver.launchArchiveWithEmbeddedDriver; import static uk.co.real_logic.benchmarks.aeron.remote.ArchivingMediaDriver.launchArchiveWithStandaloneDriver;
final String idleStrategy = getProperty(IDLE_STRATEGY_PROP_NAME); if (isEmpty(idleStrategy)) { return NoOpIdleStrategy.INSTANCE; } try { return (IdleStrategy)forName(idleStrategy).getConstructor().newInstance(); } catch (final ReflectiveOperationException | ClassCastException ex) { throw new IllegalArgumentException("Invalid IdleStrategy: " + idleStrategy, ex); } } static MediaDriver launchEmbeddedMediaDriverIfConfigured() { if (embeddedMediaDriver()) { return MediaDriver.launch(new MediaDriver.Context() .dirDeleteOnStart(true) .spiesSimulateConnection(true)); } return null; } static ArchivingMediaDriver launchArchivingMediaDriver() {
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/ArchivingMediaDriver.java // static ArchivingMediaDriver launchArchiveWithEmbeddedDriver() // { // MediaDriver driver = null; // Archive archive = null; // try // { // final MediaDriver.Context driverCtx = new MediaDriver.Context() // .dirDeleteOnStart(true) // .dirDeleteOnShutdown(true) // .spiesSimulateConnection(true); // // driver = MediaDriver.launch(driverCtx); // // final Archive.Context archiveCtx = new Archive.Context() // .aeronDirectoryName(driverCtx.aeronDirectoryName()) // .deleteArchiveOnStart(true); // // final int errorCounterId = SystemCounterDescriptor.ERRORS.id(); // final AtomicCounter errorCounter = null != archiveCtx.errorCounter() ? // archiveCtx.errorCounter() : new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId); // // final ErrorHandler errorHandler = null != archiveCtx.errorHandler() ? // archiveCtx.errorHandler() : driverCtx.errorHandler(); // // archive = Archive.launch(archiveCtx // .mediaDriverAgentInvoker(driver.sharedAgentInvoker()) // .aeronDirectoryName(driverCtx.aeronDirectoryName()) // .errorHandler(errorHandler) // .errorCounter(errorCounter)); // // return new ArchivingMediaDriver(driver, archive); // } // catch (final Exception ex) // { // CloseHelper.quietCloseAll(archive, driver); // throw ex; // } // } // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/ArchivingMediaDriver.java // static ArchivingMediaDriver launchArchiveWithStandaloneDriver() // { // return new ArchivingMediaDriver(null, Archive.launch(new Archive.Context().deleteArchiveOnStart(true))); // } // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/AeronUtil.java import io.aeron.Aeron; import io.aeron.ExclusivePublication; import io.aeron.Image; import io.aeron.Subscription; import io.aeron.archive.client.AeronArchive; import io.aeron.archive.client.ArchiveException; import io.aeron.archive.client.RecordingDescriptorConsumer; import io.aeron.driver.MediaDriver; import io.aeron.exceptions.AeronException; import io.aeron.logbuffer.BufferClaim; import io.aeron.logbuffer.FragmentHandler; import org.agrona.ErrorHandler; import org.agrona.LangUtil; import org.agrona.MutableDirectBuffer; import org.agrona.collections.MutableLong; import org.agrona.concurrent.IdleStrategy; import org.agrona.concurrent.NanoClock; import org.agrona.concurrent.NoOpIdleStrategy; import org.agrona.concurrent.ShutdownSignalBarrier; import org.agrona.concurrent.status.CountersReader; import sun.misc.Signal; import sun.misc.SignalHandler; import java.util.Arrays; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.BooleanSupplier; import static io.aeron.CommonContext.IPC_CHANNEL; import static io.aeron.Publication.*; import static io.aeron.archive.status.RecordingPos.findCounterIdBySession; import static io.aeron.archive.status.RecordingPos.getRecordingId; import static java.lang.Boolean.getBoolean; import static java.lang.Class.forName; import static java.lang.Integer.getInteger; import static java.lang.Long.MAX_VALUE; import static java.lang.System.getProperty; import static java.nio.ByteOrder.LITTLE_ENDIAN; import static org.agrona.BitUtil.SIZE_OF_LONG; import static org.agrona.Strings.isEmpty; import static org.agrona.SystemUtil.parseDuration; import static org.agrona.concurrent.status.CountersReader.NULL_COUNTER_ID; import static uk.co.real_logic.benchmarks.aeron.remote.ArchivingMediaDriver.launchArchiveWithEmbeddedDriver; import static uk.co.real_logic.benchmarks.aeron.remote.ArchivingMediaDriver.launchArchiveWithStandaloneDriver; final String idleStrategy = getProperty(IDLE_STRATEGY_PROP_NAME); if (isEmpty(idleStrategy)) { return NoOpIdleStrategy.INSTANCE; } try { return (IdleStrategy)forName(idleStrategy).getConstructor().newInstance(); } catch (final ReflectiveOperationException | ClassCastException ex) { throw new IllegalArgumentException("Invalid IdleStrategy: " + idleStrategy, ex); } } static MediaDriver launchEmbeddedMediaDriverIfConfigured() { if (embeddedMediaDriver()) { return MediaDriver.launch(new MediaDriver.Context() .dirDeleteOnStart(true) .spiesSimulateConnection(true)); } return null; } static ArchivingMediaDriver launchArchivingMediaDriver() {
return embeddedMediaDriver() ? launchArchiveWithEmbeddedDriver() : launchArchiveWithStandaloneDriver();
real-logic/benchmarks
benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/ManyToOneConcurrentLinkedQueueBenchmark.java
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128;
import org.agrona.concurrent.ManyToOneConcurrentLinkedQueue; import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY;
/* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class ManyToOneConcurrentLinkedQueueBenchmark { @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; Integer[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); final Queue<Integer> sendQueue = new ManyToOneConcurrentLinkedQueue<>(); @SuppressWarnings("unchecked")
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128; // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/ManyToOneConcurrentLinkedQueueBenchmark.java import org.agrona.concurrent.ManyToOneConcurrentLinkedQueue; import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY; /* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class ManyToOneConcurrentLinkedQueueBenchmark { @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; Integer[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); final Queue<Integer> sendQueue = new ManyToOneConcurrentLinkedQueue<>(); @SuppressWarnings("unchecked")
final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT];
real-logic/benchmarks
benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/ManyToOneConcurrentLinkedQueueBenchmark.java
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128;
import org.agrona.concurrent.ManyToOneConcurrentLinkedQueue; import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY;
/* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class ManyToOneConcurrentLinkedQueueBenchmark { @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; Integer[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); final Queue<Integer> sendQueue = new ManyToOneConcurrentLinkedQueue<>(); @SuppressWarnings("unchecked") final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT]; Thread consumerThread; @Setup public synchronized void setup() { for (int i = 0; i < MAX_THREAD_COUNT; i++) {
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128; // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/ManyToOneConcurrentLinkedQueueBenchmark.java import org.agrona.concurrent.ManyToOneConcurrentLinkedQueue; import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY; /* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class ManyToOneConcurrentLinkedQueueBenchmark { @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; Integer[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); final Queue<Integer> sendQueue = new ManyToOneConcurrentLinkedQueue<>(); @SuppressWarnings("unchecked") final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT]; Thread consumerThread; @Setup public synchronized void setup() { for (int i = 0; i < MAX_THREAD_COUNT; i++) {
responseQueues[i] = new OneToOneConcurrentArrayQueue<>(RESPONSE_QUEUE_CAPACITY);
real-logic/benchmarks
benchmarks-grpc/src/test/java/uk/co/real_logic/benchmarks/grpc/remote/StreamingMessageTransceiverTest.java
// Path: benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/MessageTransceiver.java // public abstract class MessageTransceiver extends MessageTransceiverBase // { // // Padding // boolean p000, p001, p002, p003, p004, p005, p006, p007, p008, p009, p010, p011, p012, p013, p014, p015; // boolean p016, p017, p018, p019, p020, p021, p022, p023, p024, p025, p026, p027, p028, p029, p030, p031; // boolean p032, p033, p034, p035, p036, p037, p038, p039, p040, p041, p042, p043, p044, p045, p046, p047; // boolean p048, p049, p050, p051, p052, p053, p054, p055, p056, p057, p058, p059, p060, p061, p062, p063; // boolean p064, p065, p066, p067, p068, p069, p070, p071, p072, p073, p074, p075, p076, p077, p078, p079; // boolean p080, p081, p082, p083, p084, p085, p086, p087, p088, p089, p090, p091, p092, p093, p094, p095; // boolean p096, p097, p098, p099, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111; // boolean p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127; // // public MessageTransceiver() // { // super(SystemNanoClock.INSTANCE, new Histogram(HOURS.toNanos(1), 3)); // } // // MessageTransceiver(final NanoClock clock, final Histogram histogram) // { // super(clock, histogram); // } // // /** // * Initialize state and establish all necessary connections. // * // * @param configuration configuration options // * @throws Exception in case of an error // * @implNote The method should block until it is safe to call {@link #send(int, int, long, long)} // * and {@link #receive()} methods. // */ // public abstract void init(Configuration configuration) throws Exception; // // /** // * Cleanup resources and tear down the connections with remote side. // * // * @throws Exception in case of an error // */ // public abstract void destroy() throws Exception; // // /** // * Sends specified number of {@code numberOfMessages} with the given {@code messageLength} and a {@code timestamp} // * as a payload. // * // * @param numberOfMessages to be sent. // * @param messageLength in bytes (of a single message). // * @param timestamp to be included at the beginning of the message payload. // * @param checksum to be included at the end of the message payload. // * @return actual number of messages sent. // * @implSpec {@code Sender} must send a message with the payload that is at least {@code messageLength} bytes long // * and <strong>must</strong> include given {@code timestamp} value at the beginning of the message payload and // * {@code checksum} at the end of it. Any header added by the sender <strong>may not</strong> be counted towards // * the {@code messageLength} bytes. // * <p> // * If send is <em>synchronous and blocking</em>, i.e. for every message sent there will be an immediate response // * message, then for every received message method {@link #onMessageReceived(long, long)} <strong>must</strong> be // * called. // * </p> // * @implNote The implementation can re-try actual send operation multiple times if needed but it // * <strong>should not</strong> block forever since test rig will re-try sending the batch, e.g. if a first call // * sends only {code 3} out of {code 5} messages then there will be a second call with the batch size of {code 2}. // */ // public abstract int send(int numberOfMessages, int messageLength, long timestamp, long checksum); // // /** // * Receive one or more messages. // * // * @implSpec For every received message method {@link #onMessageReceived(long, long)} <strong>must be</strong> // * called. // * @implNote Can be a no op if the send is <em>synchronous and blocking</em>. // * @see #send(int, int, long, long) // */ // public abstract void receive(); // // /** // * Callback method to be invoked for every message received. // * // * @param timestamp from the received message. // * @param checksum from the received message. // */ // protected final void onMessageReceived(final long timestamp, final long checksum) // { // if (CHECKSUM != checksum) // { // throw new IllegalStateException("Invalid checksum: expected=" + CHECKSUM + ", actual=" + checksum); // } // // histogram.recordValue(clock.nanoTime() - timestamp); // receivedMessages.getAndIncrement(); // } // // final void reset() // { // histogram.reset(); // receivedMessages.set(0); // } // }
import uk.co.real_logic.benchmarks.remote.MessageTransceiver;
/* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.grpc.remote; class StreamingMessageTransceiverTest extends AbstractGrpcTest {
// Path: benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/MessageTransceiver.java // public abstract class MessageTransceiver extends MessageTransceiverBase // { // // Padding // boolean p000, p001, p002, p003, p004, p005, p006, p007, p008, p009, p010, p011, p012, p013, p014, p015; // boolean p016, p017, p018, p019, p020, p021, p022, p023, p024, p025, p026, p027, p028, p029, p030, p031; // boolean p032, p033, p034, p035, p036, p037, p038, p039, p040, p041, p042, p043, p044, p045, p046, p047; // boolean p048, p049, p050, p051, p052, p053, p054, p055, p056, p057, p058, p059, p060, p061, p062, p063; // boolean p064, p065, p066, p067, p068, p069, p070, p071, p072, p073, p074, p075, p076, p077, p078, p079; // boolean p080, p081, p082, p083, p084, p085, p086, p087, p088, p089, p090, p091, p092, p093, p094, p095; // boolean p096, p097, p098, p099, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111; // boolean p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127; // // public MessageTransceiver() // { // super(SystemNanoClock.INSTANCE, new Histogram(HOURS.toNanos(1), 3)); // } // // MessageTransceiver(final NanoClock clock, final Histogram histogram) // { // super(clock, histogram); // } // // /** // * Initialize state and establish all necessary connections. // * // * @param configuration configuration options // * @throws Exception in case of an error // * @implNote The method should block until it is safe to call {@link #send(int, int, long, long)} // * and {@link #receive()} methods. // */ // public abstract void init(Configuration configuration) throws Exception; // // /** // * Cleanup resources and tear down the connections with remote side. // * // * @throws Exception in case of an error // */ // public abstract void destroy() throws Exception; // // /** // * Sends specified number of {@code numberOfMessages} with the given {@code messageLength} and a {@code timestamp} // * as a payload. // * // * @param numberOfMessages to be sent. // * @param messageLength in bytes (of a single message). // * @param timestamp to be included at the beginning of the message payload. // * @param checksum to be included at the end of the message payload. // * @return actual number of messages sent. // * @implSpec {@code Sender} must send a message with the payload that is at least {@code messageLength} bytes long // * and <strong>must</strong> include given {@code timestamp} value at the beginning of the message payload and // * {@code checksum} at the end of it. Any header added by the sender <strong>may not</strong> be counted towards // * the {@code messageLength} bytes. // * <p> // * If send is <em>synchronous and blocking</em>, i.e. for every message sent there will be an immediate response // * message, then for every received message method {@link #onMessageReceived(long, long)} <strong>must</strong> be // * called. // * </p> // * @implNote The implementation can re-try actual send operation multiple times if needed but it // * <strong>should not</strong> block forever since test rig will re-try sending the batch, e.g. if a first call // * sends only {code 3} out of {code 5} messages then there will be a second call with the batch size of {code 2}. // */ // public abstract int send(int numberOfMessages, int messageLength, long timestamp, long checksum); // // /** // * Receive one or more messages. // * // * @implSpec For every received message method {@link #onMessageReceived(long, long)} <strong>must be</strong> // * called. // * @implNote Can be a no op if the send is <em>synchronous and blocking</em>. // * @see #send(int, int, long, long) // */ // public abstract void receive(); // // /** // * Callback method to be invoked for every message received. // * // * @param timestamp from the received message. // * @param checksum from the received message. // */ // protected final void onMessageReceived(final long timestamp, final long checksum) // { // if (CHECKSUM != checksum) // { // throw new IllegalStateException("Invalid checksum: expected=" + CHECKSUM + ", actual=" + checksum); // } // // histogram.recordValue(clock.nanoTime() - timestamp); // receivedMessages.getAndIncrement(); // } // // final void reset() // { // histogram.reset(); // receivedMessages.set(0); // } // } // Path: benchmarks-grpc/src/test/java/uk/co/real_logic/benchmarks/grpc/remote/StreamingMessageTransceiverTest.java import uk.co.real_logic.benchmarks.remote.MessageTransceiver; /* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.grpc.remote; class StreamingMessageTransceiverTest extends AbstractGrpcTest {
protected MessageTransceiver createMessageTransceiver()
real-logic/benchmarks
benchmarks-api/src/test/java/uk/co/real_logic/benchmarks/remote/ResultsAggregatorTest.java
// Path: benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/PersistedHistogram.java // static final String AGGREGATE_FILE_SUFFIX = "-combined" + FILE_EXTENSION; // // Path: benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/PersistedHistogram.java // static final String REPORT_FILE_SUFFIX = "-report.hgrm";
import static uk.co.real_logic.benchmarks.remote.PersistedHistogram.AGGREGATE_FILE_SUFFIX; import static uk.co.real_logic.benchmarks.remote.PersistedHistogram.REPORT_FILE_SUFFIX; import org.HdrHistogram.Histogram; import org.HdrHistogram.HistogramLogReader; import org.HdrHistogram.HistogramLogWriter; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import java.io.*; import java.nio.file.Path; import static java.nio.file.Files.*; import static java.nio.file.StandardOpenOption.CREATE_NEW; import static java.util.Arrays.sort; import static org.junit.jupiter.api.Assertions.*;
} @Test void directoryContainsNonHdrFiles() throws IOException { final Path otherFile = createFile(tempDir.resolve("other.txt")); final ResultsAggregator aggregator = new ResultsAggregator(tempDir, 1); aggregator.run(); assertArrayEquals(new File[]{ otherFile.toFile() }, tempDir.toFile().listFiles()); } @Test void multipleHistogramFiles() throws IOException { saveToDisc("my-5.hdr", createHistogram(10, 25, 100, 555, 777, 999)); saveToDisc("my-0.hdr", createHistogram(2, 4, 555555, 1232343)); saveToDisc("my-combined.hdr", createHistogram(3, 4, 11, 1, 1, 22)); saveToDisc("other-78.hdr", createHistogram(1, 45, 200)); write(tempDir.resolve("other-report.hgrm"), new byte[]{ 0, -128, 127 }, CREATE_NEW); saveToDisc("hidden-4.ccc", createHistogram(0, 0, 1, 2, 3, 4, 5, 6)); saveToDisc("hidden-6.ccc", createHistogram(0, 0, 6, 6, 0)); final double reportOutputScalingRatio = 250.0; final ResultsAggregator aggregator = new ResultsAggregator(tempDir, reportOutputScalingRatio); aggregator.run();
// Path: benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/PersistedHistogram.java // static final String AGGREGATE_FILE_SUFFIX = "-combined" + FILE_EXTENSION; // // Path: benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/PersistedHistogram.java // static final String REPORT_FILE_SUFFIX = "-report.hgrm"; // Path: benchmarks-api/src/test/java/uk/co/real_logic/benchmarks/remote/ResultsAggregatorTest.java import static uk.co.real_logic.benchmarks.remote.PersistedHistogram.AGGREGATE_FILE_SUFFIX; import static uk.co.real_logic.benchmarks.remote.PersistedHistogram.REPORT_FILE_SUFFIX; import org.HdrHistogram.Histogram; import org.HdrHistogram.HistogramLogReader; import org.HdrHistogram.HistogramLogWriter; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import java.io.*; import java.nio.file.Path; import static java.nio.file.Files.*; import static java.nio.file.StandardOpenOption.CREATE_NEW; import static java.util.Arrays.sort; import static org.junit.jupiter.api.Assertions.*; } @Test void directoryContainsNonHdrFiles() throws IOException { final Path otherFile = createFile(tempDir.resolve("other.txt")); final ResultsAggregator aggregator = new ResultsAggregator(tempDir, 1); aggregator.run(); assertArrayEquals(new File[]{ otherFile.toFile() }, tempDir.toFile().listFiles()); } @Test void multipleHistogramFiles() throws IOException { saveToDisc("my-5.hdr", createHistogram(10, 25, 100, 555, 777, 999)); saveToDisc("my-0.hdr", createHistogram(2, 4, 555555, 1232343)); saveToDisc("my-combined.hdr", createHistogram(3, 4, 11, 1, 1, 22)); saveToDisc("other-78.hdr", createHistogram(1, 45, 200)); write(tempDir.resolve("other-report.hgrm"), new byte[]{ 0, -128, 127 }, CREATE_NEW); saveToDisc("hidden-4.ccc", createHistogram(0, 0, 1, 2, 3, 4, 5, 6)); saveToDisc("hidden-6.ccc", createHistogram(0, 0, 6, 6, 0)); final double reportOutputScalingRatio = 250.0; final ResultsAggregator aggregator = new ResultsAggregator(tempDir, reportOutputScalingRatio); aggregator.run();
final String[] aggregateFiles = tempDir.toFile().list((dir, name) -> name.endsWith(AGGREGATE_FILE_SUFFIX));
real-logic/benchmarks
benchmarks-api/src/test/java/uk/co/real_logic/benchmarks/remote/ResultsAggregatorTest.java
// Path: benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/PersistedHistogram.java // static final String AGGREGATE_FILE_SUFFIX = "-combined" + FILE_EXTENSION; // // Path: benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/PersistedHistogram.java // static final String REPORT_FILE_SUFFIX = "-report.hgrm";
import static uk.co.real_logic.benchmarks.remote.PersistedHistogram.AGGREGATE_FILE_SUFFIX; import static uk.co.real_logic.benchmarks.remote.PersistedHistogram.REPORT_FILE_SUFFIX; import org.HdrHistogram.Histogram; import org.HdrHistogram.HistogramLogReader; import org.HdrHistogram.HistogramLogWriter; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import java.io.*; import java.nio.file.Path; import static java.nio.file.Files.*; import static java.nio.file.StandardOpenOption.CREATE_NEW; import static java.util.Arrays.sort; import static org.junit.jupiter.api.Assertions.*;
aggregator.run(); assertArrayEquals(new File[]{ otherFile.toFile() }, tempDir.toFile().listFiles()); } @Test void multipleHistogramFiles() throws IOException { saveToDisc("my-5.hdr", createHistogram(10, 25, 100, 555, 777, 999)); saveToDisc("my-0.hdr", createHistogram(2, 4, 555555, 1232343)); saveToDisc("my-combined.hdr", createHistogram(3, 4, 11, 1, 1, 22)); saveToDisc("other-78.hdr", createHistogram(1, 45, 200)); write(tempDir.resolve("other-report.hgrm"), new byte[]{ 0, -128, 127 }, CREATE_NEW); saveToDisc("hidden-4.ccc", createHistogram(0, 0, 1, 2, 3, 4, 5, 6)); saveToDisc("hidden-6.ccc", createHistogram(0, 0, 6, 6, 0)); final double reportOutputScalingRatio = 250.0; final ResultsAggregator aggregator = new ResultsAggregator(tempDir, reportOutputScalingRatio); aggregator.run(); final String[] aggregateFiles = tempDir.toFile().list((dir, name) -> name.endsWith(AGGREGATE_FILE_SUFFIX)); assertNotNull(aggregateFiles); sort(aggregateFiles); assertArrayEquals(new String[]{ "my-combined.hdr", "other-combined.hdr" }, aggregateFiles); final Histogram myAggregate = createHistogram(2, 25, 100, 555, 777, 999, 555555, 1232343); assertEquals(myAggregate, loadFromDisc("my-combined.hdr")); final Histogram otherAggregate = createHistogram(1, 45, 200); assertEquals(otherAggregate, loadFromDisc("other-combined.hdr"));
// Path: benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/PersistedHistogram.java // static final String AGGREGATE_FILE_SUFFIX = "-combined" + FILE_EXTENSION; // // Path: benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/PersistedHistogram.java // static final String REPORT_FILE_SUFFIX = "-report.hgrm"; // Path: benchmarks-api/src/test/java/uk/co/real_logic/benchmarks/remote/ResultsAggregatorTest.java import static uk.co.real_logic.benchmarks.remote.PersistedHistogram.AGGREGATE_FILE_SUFFIX; import static uk.co.real_logic.benchmarks.remote.PersistedHistogram.REPORT_FILE_SUFFIX; import org.HdrHistogram.Histogram; import org.HdrHistogram.HistogramLogReader; import org.HdrHistogram.HistogramLogWriter; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import java.io.*; import java.nio.file.Path; import static java.nio.file.Files.*; import static java.nio.file.StandardOpenOption.CREATE_NEW; import static java.util.Arrays.sort; import static org.junit.jupiter.api.Assertions.*; aggregator.run(); assertArrayEquals(new File[]{ otherFile.toFile() }, tempDir.toFile().listFiles()); } @Test void multipleHistogramFiles() throws IOException { saveToDisc("my-5.hdr", createHistogram(10, 25, 100, 555, 777, 999)); saveToDisc("my-0.hdr", createHistogram(2, 4, 555555, 1232343)); saveToDisc("my-combined.hdr", createHistogram(3, 4, 11, 1, 1, 22)); saveToDisc("other-78.hdr", createHistogram(1, 45, 200)); write(tempDir.resolve("other-report.hgrm"), new byte[]{ 0, -128, 127 }, CREATE_NEW); saveToDisc("hidden-4.ccc", createHistogram(0, 0, 1, 2, 3, 4, 5, 6)); saveToDisc("hidden-6.ccc", createHistogram(0, 0, 6, 6, 0)); final double reportOutputScalingRatio = 250.0; final ResultsAggregator aggregator = new ResultsAggregator(tempDir, reportOutputScalingRatio); aggregator.run(); final String[] aggregateFiles = tempDir.toFile().list((dir, name) -> name.endsWith(AGGREGATE_FILE_SUFFIX)); assertNotNull(aggregateFiles); sort(aggregateFiles); assertArrayEquals(new String[]{ "my-combined.hdr", "other-combined.hdr" }, aggregateFiles); final Histogram myAggregate = createHistogram(2, 25, 100, 555, 777, 999, 555555, 1232343); assertEquals(myAggregate, loadFromDisc("my-combined.hdr")); final Histogram otherAggregate = createHistogram(1, 45, 200); assertEquals(otherAggregate, loadFromDisc("other-combined.hdr"));
final String[] reportFiles = tempDir.toFile().list((dir, name) -> name.endsWith(REPORT_FILE_SUFFIX));
real-logic/benchmarks
benchmarks-api/src/test/java/uk/co/real_logic/benchmarks/remote/PersistedHistogramTest.java
// Path: benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/PersistedHistogram.java // static final String AGGREGATE_FILE_SUFFIX = "-combined" + FILE_EXTENSION;
import static org.mockito.Mockito.*; import static uk.co.real_logic.benchmarks.remote.PersistedHistogram.AGGREGATE_FILE_SUFFIX; import org.HdrHistogram.EncodableHistogram; import org.HdrHistogram.Histogram; import org.HdrHistogram.HistogramLogReader; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import static org.junit.jupiter.api.Assertions.*;
@Test void saveToFileCreatesNewFileWithIndexZero(final @TempDir Path tempDir) throws IOException { Files.createFile(tempDir.resolve("another-one-13.hdr")); final Histogram histogram = new Histogram(3); histogram.setStartTimeStamp(123456789); histogram.setEndTimeStamp(987654321); histogram.recordValue(100); histogram.recordValue(1000); histogram.recordValue(250); final PersistedHistogram persistedHistogram = new PersistedHistogram(histogram.copy()); final Path file = persistedHistogram.saveToFile(tempDir, "test-histogram"); assertNotNull(file); assertTrue(Files.exists(file)); assertEquals("test-histogram-0.hdr", file.getFileName().toString()); final Histogram savedHistogram = readHistogram(file); assertEquals(histogram, savedHistogram); assertEquals(histogram.getStartTimeStamp(), savedHistogram.getStartTimeStamp()); assertEquals(histogram.getEndTimeStamp(), savedHistogram.getEndTimeStamp()); } @Test void saveToFileCreatesNewFileByIncrementExistingMaxIndex(final @TempDir Path tempDir) throws IOException { Files.createFile(tempDir.resolve("another_one-13.hdr"));
// Path: benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/PersistedHistogram.java // static final String AGGREGATE_FILE_SUFFIX = "-combined" + FILE_EXTENSION; // Path: benchmarks-api/src/test/java/uk/co/real_logic/benchmarks/remote/PersistedHistogramTest.java import static org.mockito.Mockito.*; import static uk.co.real_logic.benchmarks.remote.PersistedHistogram.AGGREGATE_FILE_SUFFIX; import org.HdrHistogram.EncodableHistogram; import org.HdrHistogram.Histogram; import org.HdrHistogram.HistogramLogReader; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import static org.junit.jupiter.api.Assertions.*; @Test void saveToFileCreatesNewFileWithIndexZero(final @TempDir Path tempDir) throws IOException { Files.createFile(tempDir.resolve("another-one-13.hdr")); final Histogram histogram = new Histogram(3); histogram.setStartTimeStamp(123456789); histogram.setEndTimeStamp(987654321); histogram.recordValue(100); histogram.recordValue(1000); histogram.recordValue(250); final PersistedHistogram persistedHistogram = new PersistedHistogram(histogram.copy()); final Path file = persistedHistogram.saveToFile(tempDir, "test-histogram"); assertNotNull(file); assertTrue(Files.exists(file)); assertEquals("test-histogram-0.hdr", file.getFileName().toString()); final Histogram savedHistogram = readHistogram(file); assertEquals(histogram, savedHistogram); assertEquals(histogram.getStartTimeStamp(), savedHistogram.getStartTimeStamp()); assertEquals(histogram.getEndTimeStamp(), savedHistogram.getEndTimeStamp()); } @Test void saveToFileCreatesNewFileByIncrementExistingMaxIndex(final @TempDir Path tempDir) throws IOException { Files.createFile(tempDir.resolve("another_one-13.hdr"));
Files.createFile(tempDir.resolve("another_one" + AGGREGATE_FILE_SUFFIX));
real-logic/benchmarks
benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/ManyToOneRingBufferBenchmark.java
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128;
import java.util.concurrent.atomic.AtomicInteger; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY; import org.agrona.BitUtil; import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.MessageHandler; import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.concurrent.UnsafeBuffer; import org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer; import org.agrona.concurrent.ringbuffer.RingBuffer; import org.agrona.concurrent.ringbuffer.RingBufferDescriptor; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.atomic.AtomicBoolean;
/* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class ManyToOneRingBufferBenchmark { static final int MESSAGE_COUNT_LIMIT = 16; static final Integer SENTINEL = 0; static final int BUFFER_LENGTH = (64 * 1024) + RingBufferDescriptor.TRAILER_LENGTH; @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; int[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); RingBuffer ringBuffer; @SuppressWarnings("unchecked")
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128; // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/ManyToOneRingBufferBenchmark.java import java.util.concurrent.atomic.AtomicInteger; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY; import org.agrona.BitUtil; import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.MessageHandler; import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.concurrent.UnsafeBuffer; import org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer; import org.agrona.concurrent.ringbuffer.RingBuffer; import org.agrona.concurrent.ringbuffer.RingBufferDescriptor; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.atomic.AtomicBoolean; /* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class ManyToOneRingBufferBenchmark { static final int MESSAGE_COUNT_LIMIT = 16; static final Integer SENTINEL = 0; static final int BUFFER_LENGTH = (64 * 1024) + RingBufferDescriptor.TRAILER_LENGTH; @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; int[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); RingBuffer ringBuffer; @SuppressWarnings("unchecked")
final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT];
real-logic/benchmarks
benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/ManyToOneRingBufferBenchmark.java
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128;
import java.util.concurrent.atomic.AtomicInteger; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY; import org.agrona.BitUtil; import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.MessageHandler; import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.concurrent.UnsafeBuffer; import org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer; import org.agrona.concurrent.ringbuffer.RingBuffer; import org.agrona.concurrent.ringbuffer.RingBufferDescriptor; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.atomic.AtomicBoolean;
/* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class ManyToOneRingBufferBenchmark { static final int MESSAGE_COUNT_LIMIT = 16; static final Integer SENTINEL = 0; static final int BUFFER_LENGTH = (64 * 1024) + RingBufferDescriptor.TRAILER_LENGTH; @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; int[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); RingBuffer ringBuffer; @SuppressWarnings("unchecked") final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT]; Thread consumerThread; @Setup public synchronized void setup() { for (int i = 0; i < MAX_THREAD_COUNT; i++) {
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128; // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/ManyToOneRingBufferBenchmark.java import java.util.concurrent.atomic.AtomicInteger; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY; import org.agrona.BitUtil; import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.MessageHandler; import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.concurrent.UnsafeBuffer; import org.agrona.concurrent.ringbuffer.ManyToOneRingBuffer; import org.agrona.concurrent.ringbuffer.RingBuffer; import org.agrona.concurrent.ringbuffer.RingBufferDescriptor; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.atomic.AtomicBoolean; /* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class ManyToOneRingBufferBenchmark { static final int MESSAGE_COUNT_LIMIT = 16; static final Integer SENTINEL = 0; static final int BUFFER_LENGTH = (64 * 1024) + RingBufferDescriptor.TRAILER_LENGTH; @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; int[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); RingBuffer ringBuffer; @SuppressWarnings("unchecked") final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT]; Thread consumerThread; @Setup public synchronized void setup() { for (int i = 0; i < MAX_THREAD_COUNT; i++) {
responseQueues[i] = new OneToOneConcurrentArrayQueue<>(RESPONSE_QUEUE_CAPACITY);
real-logic/benchmarks
benchmarks-aeron/src/test/java/uk/co/real_logic/benchmarks/aeron/remote/LiveReplayTest.java
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/ArchivingMediaDriver.java // static ArchivingMediaDriver launchArchiveWithEmbeddedDriver() // { // MediaDriver driver = null; // Archive archive = null; // try // { // final MediaDriver.Context driverCtx = new MediaDriver.Context() // .dirDeleteOnStart(true) // .dirDeleteOnShutdown(true) // .spiesSimulateConnection(true); // // driver = MediaDriver.launch(driverCtx); // // final Archive.Context archiveCtx = new Archive.Context() // .aeronDirectoryName(driverCtx.aeronDirectoryName()) // .deleteArchiveOnStart(true); // // final int errorCounterId = SystemCounterDescriptor.ERRORS.id(); // final AtomicCounter errorCounter = null != archiveCtx.errorCounter() ? // archiveCtx.errorCounter() : new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId); // // final ErrorHandler errorHandler = null != archiveCtx.errorHandler() ? // archiveCtx.errorHandler() : driverCtx.errorHandler(); // // archive = Archive.launch(archiveCtx // .mediaDriverAgentInvoker(driver.sharedAgentInvoker()) // .aeronDirectoryName(driverCtx.aeronDirectoryName()) // .errorHandler(errorHandler) // .errorCounter(errorCounter)); // // return new ArchivingMediaDriver(driver, archive); // } // catch (final Exception ex) // { // CloseHelper.quietCloseAll(archive, driver); // throw ex; // } // }
import io.aeron.archive.client.AeronArchive; import org.agrona.IoUtil; import org.junit.jupiter.api.AfterEach; import java.io.File; import java.util.concurrent.atomic.AtomicBoolean; import static io.aeron.archive.client.AeronArchive.connect; import static uk.co.real_logic.benchmarks.aeron.remote.ArchivingMediaDriver.launchArchiveWithEmbeddedDriver;
/* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.remote; class LiveReplayTest extends AbstractTest<ArchivingMediaDriver, AeronArchive, LiveReplayMessageTransceiver, ArchiveNode> { private File archiveDir; @AfterEach void afterEach() { IoUtil.delete(archiveDir, true); } protected ArchiveNode createNode( final AtomicBoolean running, final ArchivingMediaDriver archivingMediaDriver, final AeronArchive aeronArchive) { return new ArchiveNode(running, archivingMediaDriver, aeronArchive, false); } protected ArchivingMediaDriver createDriver() {
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/ArchivingMediaDriver.java // static ArchivingMediaDriver launchArchiveWithEmbeddedDriver() // { // MediaDriver driver = null; // Archive archive = null; // try // { // final MediaDriver.Context driverCtx = new MediaDriver.Context() // .dirDeleteOnStart(true) // .dirDeleteOnShutdown(true) // .spiesSimulateConnection(true); // // driver = MediaDriver.launch(driverCtx); // // final Archive.Context archiveCtx = new Archive.Context() // .aeronDirectoryName(driverCtx.aeronDirectoryName()) // .deleteArchiveOnStart(true); // // final int errorCounterId = SystemCounterDescriptor.ERRORS.id(); // final AtomicCounter errorCounter = null != archiveCtx.errorCounter() ? // archiveCtx.errorCounter() : new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId); // // final ErrorHandler errorHandler = null != archiveCtx.errorHandler() ? // archiveCtx.errorHandler() : driverCtx.errorHandler(); // // archive = Archive.launch(archiveCtx // .mediaDriverAgentInvoker(driver.sharedAgentInvoker()) // .aeronDirectoryName(driverCtx.aeronDirectoryName()) // .errorHandler(errorHandler) // .errorCounter(errorCounter)); // // return new ArchivingMediaDriver(driver, archive); // } // catch (final Exception ex) // { // CloseHelper.quietCloseAll(archive, driver); // throw ex; // } // } // Path: benchmarks-aeron/src/test/java/uk/co/real_logic/benchmarks/aeron/remote/LiveReplayTest.java import io.aeron.archive.client.AeronArchive; import org.agrona.IoUtil; import org.junit.jupiter.api.AfterEach; import java.io.File; import java.util.concurrent.atomic.AtomicBoolean; import static io.aeron.archive.client.AeronArchive.connect; import static uk.co.real_logic.benchmarks.aeron.remote.ArchivingMediaDriver.launchArchiveWithEmbeddedDriver; /* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.remote; class LiveReplayTest extends AbstractTest<ArchivingMediaDriver, AeronArchive, LiveReplayMessageTransceiver, ArchiveNode> { private File archiveDir; @AfterEach void afterEach() { IoUtil.delete(archiveDir, true); } protected ArchiveNode createNode( final AtomicBoolean running, final ArchivingMediaDriver archivingMediaDriver, final AeronArchive aeronArchive) { return new ArchiveNode(running, archivingMediaDriver, aeronArchive, false); } protected ArchivingMediaDriver createDriver() {
final ArchivingMediaDriver driver = launchArchiveWithEmbeddedDriver();
real-logic/benchmarks
benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/EchoClusteredService.java
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/AeronUtil.java // static void checkPublicationResult(final long result) // { // if (result == CLOSED || // result == NOT_CONNECTED || // result == MAX_POSITION_EXCEEDED) // { // throw new AeronException("Publication error: " + result); // } // }
import io.aeron.ExclusivePublication; import io.aeron.Image; import io.aeron.cluster.client.AeronCluster; import io.aeron.cluster.codecs.CloseReason; import io.aeron.cluster.service.ClientSession; import io.aeron.cluster.service.Cluster; import io.aeron.cluster.service.ClusteredService; import io.aeron.logbuffer.BufferClaim; import io.aeron.logbuffer.Header; import org.agrona.DirectBuffer; import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.IdleStrategy; import static uk.co.real_logic.benchmarks.aeron.remote.AeronUtil.checkPublicationResult;
} public void onSessionOpen(final ClientSession session, final long timestamp) { } public void onSessionClose(final ClientSession session, final long timestamp, final CloseReason closeReason) { } public void onSessionMessage( final ClientSession session, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) { if (null == session) { return; // skip non-client calls } final IdleStrategy idleStrategy = this.idleStrategy; final BufferClaim bufferClaim = this.bufferClaim; idleStrategy.reset(); long result; while ((result = session.tryClaim(length, bufferClaim)) <= 0) {
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/AeronUtil.java // static void checkPublicationResult(final long result) // { // if (result == CLOSED || // result == NOT_CONNECTED || // result == MAX_POSITION_EXCEEDED) // { // throw new AeronException("Publication error: " + result); // } // } // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/EchoClusteredService.java import io.aeron.ExclusivePublication; import io.aeron.Image; import io.aeron.cluster.client.AeronCluster; import io.aeron.cluster.codecs.CloseReason; import io.aeron.cluster.service.ClientSession; import io.aeron.cluster.service.Cluster; import io.aeron.cluster.service.ClusteredService; import io.aeron.logbuffer.BufferClaim; import io.aeron.logbuffer.Header; import org.agrona.DirectBuffer; import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.IdleStrategy; import static uk.co.real_logic.benchmarks.aeron.remote.AeronUtil.checkPublicationResult; } public void onSessionOpen(final ClientSession session, final long timestamp) { } public void onSessionClose(final ClientSession session, final long timestamp, final CloseReason closeReason) { } public void onSessionMessage( final ClientSession session, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) { if (null == session) { return; // skip non-client calls } final IdleStrategy idleStrategy = this.idleStrategy; final BufferClaim bufferClaim = this.bufferClaim; idleStrategy.reset(); long result; while ((result = session.tryClaim(length, bufferClaim)) <= 0) {
checkPublicationResult(result);
real-logic/benchmarks
benchmarks-api/src/test/java/uk/co/real_logic/benchmarks/remote/LoadTestRigTest.java
// Path: benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/LoadTestRig.java // static final int MINIMUM_NUMBER_OF_CPU_CORES = 6;
import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; import static uk.co.real_logic.benchmarks.remote.LoadTestRig.MINIMUM_NUMBER_OF_CPU_CORES; import static uk.co.real_logic.benchmarks.remote.MessageTransceiver.CHECKSUM; import org.HdrHistogram.Histogram; import org.agrona.concurrent.IdleStrategy; import org.agrona.concurrent.NanoClock; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import org.junit.jupiter.api.io.TempDir; import org.mockito.InOrder; import java.io.File; import java.io.PrintStream; import java.nio.file.Path; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.SECONDS;
@Test void constructorThrowsNullPointerExceptionIfConfigurationIsNull() { assertThrows(NullPointerException.class, () -> new LoadTestRig(null)); } @Test void runPerformsWarmupBeforeMeasurement() throws Exception { final long nanoTime = SECONDS.toNanos(123); final NanoClock clock = () -> nanoTime; configuration = new Configuration.Builder() .warmupIterations(1) .warmupMessageRate(1) .iterations(1) .messageRate(1) .messageTransceiverClass(configuration.messageTransceiverClass()) .idleStrategy(idleStrategy) .outputDirectory(configuration.outputDirectory()) .outputFileNamePrefix("test") .build(); final LoadTestRig loadTestRig = new LoadTestRig( configuration, messageTransceiver, out, clock, persistedHistogram,
// Path: benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/LoadTestRig.java // static final int MINIMUM_NUMBER_OF_CPU_CORES = 6; // Path: benchmarks-api/src/test/java/uk/co/real_logic/benchmarks/remote/LoadTestRigTest.java import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; import static uk.co.real_logic.benchmarks.remote.LoadTestRig.MINIMUM_NUMBER_OF_CPU_CORES; import static uk.co.real_logic.benchmarks.remote.MessageTransceiver.CHECKSUM; import org.HdrHistogram.Histogram; import org.agrona.concurrent.IdleStrategy; import org.agrona.concurrent.NanoClock; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import org.junit.jupiter.api.io.TempDir; import org.mockito.InOrder; import java.io.File; import java.io.PrintStream; import java.nio.file.Path; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.SECONDS; @Test void constructorThrowsNullPointerExceptionIfConfigurationIsNull() { assertThrows(NullPointerException.class, () -> new LoadTestRig(null)); } @Test void runPerformsWarmupBeforeMeasurement() throws Exception { final long nanoTime = SECONDS.toNanos(123); final NanoClock clock = () -> nanoTime; configuration = new Configuration.Builder() .warmupIterations(1) .warmupMessageRate(1) .iterations(1) .messageRate(1) .messageTransceiverClass(configuration.messageTransceiverClass()) .idleStrategy(idleStrategy) .outputDirectory(configuration.outputDirectory()) .outputFileNamePrefix("test") .build(); final LoadTestRig loadTestRig = new LoadTestRig( configuration, messageTransceiver, out, clock, persistedHistogram,
MINIMUM_NUMBER_OF_CPU_CORES * 2);
real-logic/benchmarks
benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/ConcurrentLinkedQueueBenchmark.java
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128;
import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY;
/* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class ConcurrentLinkedQueueBenchmark { @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; Integer[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); final Queue<Integer> sendQueue = new ConcurrentLinkedQueue<>(); @SuppressWarnings("unchecked")
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128; // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/ConcurrentLinkedQueueBenchmark.java import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY; /* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class ConcurrentLinkedQueueBenchmark { @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; Integer[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); final Queue<Integer> sendQueue = new ConcurrentLinkedQueue<>(); @SuppressWarnings("unchecked")
final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT];
real-logic/benchmarks
benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/ConcurrentLinkedQueueBenchmark.java
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128;
import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY;
/* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class ConcurrentLinkedQueueBenchmark { @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; Integer[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); final Queue<Integer> sendQueue = new ConcurrentLinkedQueue<>(); @SuppressWarnings("unchecked") final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT]; Thread consumerThread; @Setup public synchronized void setup() { for (int i = 0; i < MAX_THREAD_COUNT; i++) {
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128; // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/ConcurrentLinkedQueueBenchmark.java import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY; /* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class ConcurrentLinkedQueueBenchmark { @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; Integer[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); final Queue<Integer> sendQueue = new ConcurrentLinkedQueue<>(); @SuppressWarnings("unchecked") final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT]; Thread consumerThread; @Setup public synchronized void setup() { for (int i = 0; i < MAX_THREAD_COUNT; i++) {
responseQueues[i] = new OneToOneConcurrentArrayQueue<>(RESPONSE_QUEUE_CAPACITY);
real-logic/benchmarks
benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/AeronIpcBenchmark.java
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128;
import io.aeron.Aeron; import io.aeron.CommonContext; import io.aeron.Publication; import io.aeron.Subscription; import io.aeron.driver.MediaDriver; import io.aeron.driver.ThreadingMode; import io.aeron.logbuffer.FragmentHandler; import io.aeron.logbuffer.Header; import org.agrona.BufferUtil; import org.agrona.DirectBuffer; import org.agrona.concurrent.BusySpinIdleStrategy; import org.agrona.concurrent.IdleStrategy; import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.concurrent.UnsafeBuffer; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import static org.agrona.BitUtil.SIZE_OF_INT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY;
/* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class AeronIpcBenchmark { static final int STREAM_ID = 1; static final int FRAGMENT_LIMIT = 128; static final Integer SENTINEL = 0; @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; int[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); MediaDriver.Context ctx; MediaDriver mediaDriver; Aeron aeron; Publication publication; Subscription subscription; @SuppressWarnings("unchecked")
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128; // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/AeronIpcBenchmark.java import io.aeron.Aeron; import io.aeron.CommonContext; import io.aeron.Publication; import io.aeron.Subscription; import io.aeron.driver.MediaDriver; import io.aeron.driver.ThreadingMode; import io.aeron.logbuffer.FragmentHandler; import io.aeron.logbuffer.Header; import org.agrona.BufferUtil; import org.agrona.DirectBuffer; import org.agrona.concurrent.BusySpinIdleStrategy; import org.agrona.concurrent.IdleStrategy; import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.concurrent.UnsafeBuffer; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import static org.agrona.BitUtil.SIZE_OF_INT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY; /* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class AeronIpcBenchmark { static final int STREAM_ID = 1; static final int FRAGMENT_LIMIT = 128; static final Integer SENTINEL = 0; @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; int[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); MediaDriver.Context ctx; MediaDriver mediaDriver; Aeron aeron; Publication publication; Subscription subscription; @SuppressWarnings("unchecked")
final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT];
real-logic/benchmarks
benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/AeronIpcBenchmark.java
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128;
import io.aeron.Aeron; import io.aeron.CommonContext; import io.aeron.Publication; import io.aeron.Subscription; import io.aeron.driver.MediaDriver; import io.aeron.driver.ThreadingMode; import io.aeron.logbuffer.FragmentHandler; import io.aeron.logbuffer.Header; import org.agrona.BufferUtil; import org.agrona.DirectBuffer; import org.agrona.concurrent.BusySpinIdleStrategy; import org.agrona.concurrent.IdleStrategy; import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.concurrent.UnsafeBuffer; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import static org.agrona.BitUtil.SIZE_OF_INT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY;
/* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class AeronIpcBenchmark { static final int STREAM_ID = 1; static final int FRAGMENT_LIMIT = 128; static final Integer SENTINEL = 0; @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; int[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); MediaDriver.Context ctx; MediaDriver mediaDriver; Aeron aeron; Publication publication; Subscription subscription; @SuppressWarnings("unchecked") final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT]; Thread consumerThread; @Setup public synchronized void setup() { for (int i = 0; i < MAX_THREAD_COUNT; i++) {
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128; // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/AeronIpcBenchmark.java import io.aeron.Aeron; import io.aeron.CommonContext; import io.aeron.Publication; import io.aeron.Subscription; import io.aeron.driver.MediaDriver; import io.aeron.driver.ThreadingMode; import io.aeron.logbuffer.FragmentHandler; import io.aeron.logbuffer.Header; import org.agrona.BufferUtil; import org.agrona.DirectBuffer; import org.agrona.concurrent.BusySpinIdleStrategy; import org.agrona.concurrent.IdleStrategy; import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.concurrent.UnsafeBuffer; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import static org.agrona.BitUtil.SIZE_OF_INT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY; /* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class AeronIpcBenchmark { static final int STREAM_ID = 1; static final int FRAGMENT_LIMIT = 128; static final Integer SENTINEL = 0; @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; int[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); MediaDriver.Context ctx; MediaDriver mediaDriver; Aeron aeron; Publication publication; Subscription subscription; @SuppressWarnings("unchecked") final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT]; Thread consumerThread; @Setup public synchronized void setup() { for (int i = 0; i < MAX_THREAD_COUNT; i++) {
responseQueues[i] = new OneToOneConcurrentArrayQueue<>(RESPONSE_QUEUE_CAPACITY);
real-logic/benchmarks
benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/DisruptorBenchmark.java
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128;
import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY; import com.lmax.disruptor.BusySpinWaitStrategy; import com.lmax.disruptor.EventHandler; import com.lmax.disruptor.LifecycleAware; import com.lmax.disruptor.RingBuffer; import com.lmax.disruptor.dsl.Disruptor; import com.lmax.disruptor.dsl.ProducerType; import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger;
/* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class DisruptorBenchmark { static final Integer SENTINEL = 0; @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; int[] values; final AtomicInteger threadId = new AtomicInteger(); Disruptor<Message> disruptor; Handler handler; @SuppressWarnings("unchecked")
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128; // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/DisruptorBenchmark.java import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY; import com.lmax.disruptor.BusySpinWaitStrategy; import com.lmax.disruptor.EventHandler; import com.lmax.disruptor.LifecycleAware; import com.lmax.disruptor.RingBuffer; import com.lmax.disruptor.dsl.Disruptor; import com.lmax.disruptor.dsl.ProducerType; import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger; /* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class DisruptorBenchmark { static final Integer SENTINEL = 0; @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; int[] values; final AtomicInteger threadId = new AtomicInteger(); Disruptor<Message> disruptor; Handler handler; @SuppressWarnings("unchecked")
final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT];
real-logic/benchmarks
benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/DisruptorBenchmark.java
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128;
import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY; import com.lmax.disruptor.BusySpinWaitStrategy; import com.lmax.disruptor.EventHandler; import com.lmax.disruptor.LifecycleAware; import com.lmax.disruptor.RingBuffer; import com.lmax.disruptor.dsl.Disruptor; import com.lmax.disruptor.dsl.ProducerType; import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger;
/* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class DisruptorBenchmark { static final Integer SENTINEL = 0; @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; int[] values; final AtomicInteger threadId = new AtomicInteger(); Disruptor<Message> disruptor; Handler handler; @SuppressWarnings("unchecked") final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT]; @Setup public synchronized void setup() throws InterruptedException { for (int i = 0; i < MAX_THREAD_COUNT; i++) {
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128; // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/DisruptorBenchmark.java import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY; import com.lmax.disruptor.BusySpinWaitStrategy; import com.lmax.disruptor.EventHandler; import com.lmax.disruptor.LifecycleAware; import com.lmax.disruptor.RingBuffer; import com.lmax.disruptor.dsl.Disruptor; import com.lmax.disruptor.dsl.ProducerType; import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger; /* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class DisruptorBenchmark { static final Integer SENTINEL = 0; @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; int[] values; final AtomicInteger threadId = new AtomicInteger(); Disruptor<Message> disruptor; Handler handler; @SuppressWarnings("unchecked") final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT]; @Setup public synchronized void setup() throws InterruptedException { for (int i = 0; i < MAX_THREAD_COUNT; i++) {
responseQueues[i] = new OneToOneConcurrentArrayQueue<>(RESPONSE_QUEUE_CAPACITY);
real-logic/benchmarks
benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/ClusterNode.java
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/AeronUtil.java // static ErrorHandler rethrowingErrorHandler(final String context) // { // return (Throwable throwable) -> // { // System.err.println(context); // throwable.printStackTrace(System.err); // LangUtil.rethrowUnchecked(throwable); // }; // }
import io.aeron.CommonContext; import io.aeron.archive.Archive; import io.aeron.archive.client.AeronArchive; import io.aeron.cluster.ConsensusModule; import io.aeron.cluster.service.ClusteredServiceContainer; import org.agrona.IoUtil; import org.agrona.PropertyAction; import org.agrona.SystemUtil; import org.agrona.concurrent.NoOpLock; import org.agrona.concurrent.ShutdownSignalBarrier; import java.nio.file.Paths; import static uk.co.real_logic.benchmarks.aeron.remote.AeronUtil.rethrowingErrorHandler;
/* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.remote; public final class ClusterNode { public static void main(final String[] args) { SystemUtil.loadPropertiesFiles(PropertyAction.PRESERVE, args); final Archive.Context archiveContext = new Archive.Context() .deleteArchiveOnStart(true) .recordingEventsEnabled(false); archiveContext.localControlStreamId(archiveContext.controlStreamId()); final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context() .lock(NoOpLock.INSTANCE) .controlRequestChannel(CommonContext.IPC_CHANNEL) .controlResponseChannel(CommonContext.IPC_CHANNEL) .aeronDirectoryName(archiveContext.aeronDirectoryName()); final ConsensusModule.Context consensusModuleContext = new ConsensusModule.Context()
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/AeronUtil.java // static ErrorHandler rethrowingErrorHandler(final String context) // { // return (Throwable throwable) -> // { // System.err.println(context); // throwable.printStackTrace(System.err); // LangUtil.rethrowUnchecked(throwable); // }; // } // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/remote/ClusterNode.java import io.aeron.CommonContext; import io.aeron.archive.Archive; import io.aeron.archive.client.AeronArchive; import io.aeron.cluster.ConsensusModule; import io.aeron.cluster.service.ClusteredServiceContainer; import org.agrona.IoUtil; import org.agrona.PropertyAction; import org.agrona.SystemUtil; import org.agrona.concurrent.NoOpLock; import org.agrona.concurrent.ShutdownSignalBarrier; import java.nio.file.Paths; import static uk.co.real_logic.benchmarks.aeron.remote.AeronUtil.rethrowingErrorHandler; /* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.remote; public final class ClusterNode { public static void main(final String[] args) { SystemUtil.loadPropertiesFiles(PropertyAction.PRESERVE, args); final Archive.Context archiveContext = new Archive.Context() .deleteArchiveOnStart(true) .recordingEventsEnabled(false); archiveContext.localControlStreamId(archiveContext.controlStreamId()); final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context() .lock(NoOpLock.INSTANCE) .controlRequestChannel(CommonContext.IPC_CHANNEL) .controlResponseChannel(CommonContext.IPC_CHANNEL) .aeronDirectoryName(archiveContext.aeronDirectoryName()); final ConsensusModule.Context consensusModuleContext = new ConsensusModule.Context()
.errorHandler(rethrowingErrorHandler("consensus-module"))
real-logic/benchmarks
benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/LinkedBlockingQueueBenchmark.java
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128;
import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY;
/* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class LinkedBlockingQueueBenchmark { @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; Integer[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); final Queue<Integer> sendQueue = new LinkedBlockingQueue<>(); @SuppressWarnings("unchecked")
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128; // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/LinkedBlockingQueueBenchmark.java import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY; /* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class LinkedBlockingQueueBenchmark { @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; Integer[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); final Queue<Integer> sendQueue = new LinkedBlockingQueue<>(); @SuppressWarnings("unchecked")
final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT];
real-logic/benchmarks
benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/LinkedBlockingQueueBenchmark.java
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128;
import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY;
/* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class LinkedBlockingQueueBenchmark { @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; Integer[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); final Queue<Integer> sendQueue = new LinkedBlockingQueue<>(); @SuppressWarnings("unchecked") final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT]; Thread consumerThread; @Setup public synchronized void setup() { for (int i = 0; i < MAX_THREAD_COUNT; i++) {
// Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int MAX_THREAD_COUNT = 4; // // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/Configuration.java // public static final int RESPONSE_QUEUE_CAPACITY = 128; // Path: benchmarks-aeron/src/main/java/uk/co/real_logic/benchmarks/aeron/ipc/LinkedBlockingQueueBenchmark.java import org.agrona.concurrent.OneToOneConcurrentArrayQueue; import org.agrona.hints.ThreadHints; import org.openjdk.jmh.annotations.*; import java.util.Arrays; import java.util.Queue; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.MAX_THREAD_COUNT; import static uk.co.real_logic.benchmarks.aeron.ipc.Configuration.RESPONSE_QUEUE_CAPACITY; /* * Copyright 2015-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.real_logic.benchmarks.aeron.ipc; public class LinkedBlockingQueueBenchmark { @State(Scope.Benchmark) public static class SharedState { @Param({ "1", "100" }) int burstLength; Integer[] values; final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger threadId = new AtomicInteger(); final Queue<Integer> sendQueue = new LinkedBlockingQueue<>(); @SuppressWarnings("unchecked") final Queue<Integer>[] responseQueues = new OneToOneConcurrentArrayQueue[MAX_THREAD_COUNT]; Thread consumerThread; @Setup public synchronized void setup() { for (int i = 0; i < MAX_THREAD_COUNT; i++) {
responseQueues[i] = new OneToOneConcurrentArrayQueue<>(RESPONSE_QUEUE_CAPACITY);
real-logic/benchmarks
benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/LoadTestRig.java
// Path: benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/MessageTransceiver.java // static final long CHECKSUM = ThreadLocalRandom.current().nextLong();
import org.agrona.LangUtil; import org.agrona.PropertyAction; import org.agrona.SystemUtil; import org.agrona.concurrent.IdleStrategy; import org.agrona.concurrent.NanoClock; import java.io.PrintStream; import java.util.concurrent.atomic.AtomicLong; import static java.lang.Math.min; import static java.lang.Math.round; import static java.util.Objects.requireNonNull; import static java.util.concurrent.TimeUnit.NANOSECONDS; import static java.util.concurrent.TimeUnit.SECONDS; import static uk.co.real_logic.benchmarks.remote.MessageTransceiverBase.CHECKSUM;
histogram.saveToFile(configuration.outputDirectory(), configuration.outputFileNamePrefix()); } finally { messageTransceiver.destroy(); } } @SuppressWarnings("MethodLength") long send(final int iterations, final int numberOfMessages) { final MessageTransceiver messageTransceiver = this.messageTransceiver; final NanoClock clock = this.clock; final AtomicLong receivedMessages = messageTransceiver.receivedMessages; final int burstSize = configuration.batchSize(); final int messageSize = configuration.messageLength(); final IdleStrategy idleStrategy = configuration.idleStrategy(); final long sendIntervalNs = NANOS_PER_SECOND * burstSize / numberOfMessages; final long totalNumberOfMessages = (long)iterations * numberOfMessages; final long startTimeNs = clock.nanoTime(); final long endTimeNs = startTimeNs + iterations * NANOS_PER_SECOND; long sentMessages = 0; long timestampNs = startTimeNs; long nowNs = startTimeNs; long nextReportTimeNs = startTimeNs + NANOS_PER_SECOND; int batchSize = (int)min(totalNumberOfMessages, burstSize); while (true) {
// Path: benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/MessageTransceiver.java // static final long CHECKSUM = ThreadLocalRandom.current().nextLong(); // Path: benchmarks-api/src/main/java/uk/co/real_logic/benchmarks/remote/LoadTestRig.java import org.agrona.LangUtil; import org.agrona.PropertyAction; import org.agrona.SystemUtil; import org.agrona.concurrent.IdleStrategy; import org.agrona.concurrent.NanoClock; import java.io.PrintStream; import java.util.concurrent.atomic.AtomicLong; import static java.lang.Math.min; import static java.lang.Math.round; import static java.util.Objects.requireNonNull; import static java.util.concurrent.TimeUnit.NANOSECONDS; import static java.util.concurrent.TimeUnit.SECONDS; import static uk.co.real_logic.benchmarks.remote.MessageTransceiverBase.CHECKSUM; histogram.saveToFile(configuration.outputDirectory(), configuration.outputFileNamePrefix()); } finally { messageTransceiver.destroy(); } } @SuppressWarnings("MethodLength") long send(final int iterations, final int numberOfMessages) { final MessageTransceiver messageTransceiver = this.messageTransceiver; final NanoClock clock = this.clock; final AtomicLong receivedMessages = messageTransceiver.receivedMessages; final int burstSize = configuration.batchSize(); final int messageSize = configuration.messageLength(); final IdleStrategy idleStrategy = configuration.idleStrategy(); final long sendIntervalNs = NANOS_PER_SECOND * burstSize / numberOfMessages; final long totalNumberOfMessages = (long)iterations * numberOfMessages; final long startTimeNs = clock.nanoTime(); final long endTimeNs = startTimeNs + iterations * NANOS_PER_SECOND; long sentMessages = 0; long timestampNs = startTimeNs; long nowNs = startTimeNs; long nextReportTimeNs = startTimeNs + NANOS_PER_SECOND; int batchSize = (int)min(totalNumberOfMessages, burstSize); while (true) {
final int sent = messageTransceiver.send(batchSize, messageSize, timestampNs, CHECKSUM);
shapesecurity/shape-functional-java
src/main/java/com/shapesecurity/functional/data/Semigroup.java
// Path: src/main/java/com/shapesecurity/functional/Unit.java // public final class Unit { // public final static Unit unit = new Unit(); // // private Unit() { // } // }
import com.shapesecurity.functional.Unit; import javax.annotation.CheckReturnValue; import javax.annotation.Nonnull;
/* * Copyright 2014 Shape Security, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.shapesecurity.functional.data; @CheckReturnValue public interface Semigroup<T> { UnitIdentity UNIT_IDENTITY = new UnitIdentity(); IntegerAdditive INTEGER_ADDITIVE = new IntegerAdditive(); IntegerMultiplicative INTEGER_MULTIPLICATIVE = new IntegerMultiplicative(); StringConcat STRING_CONCAT = new StringConcat(); BooleanOr BOOLEAN_OR = new BooleanOr(); BooleanAnd BOOLEAN_AND = new BooleanAnd(); @Nonnull T append(T a, T b);
// Path: src/main/java/com/shapesecurity/functional/Unit.java // public final class Unit { // public final static Unit unit = new Unit(); // // private Unit() { // } // } // Path: src/main/java/com/shapesecurity/functional/data/Semigroup.java import com.shapesecurity.functional.Unit; import javax.annotation.CheckReturnValue; import javax.annotation.Nonnull; /* * Copyright 2014 Shape Security, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.shapesecurity.functional.data; @CheckReturnValue public interface Semigroup<T> { UnitIdentity UNIT_IDENTITY = new UnitIdentity(); IntegerAdditive INTEGER_ADDITIVE = new IntegerAdditive(); IntegerMultiplicative INTEGER_MULTIPLICATIVE = new IntegerMultiplicative(); StringConcat STRING_CONCAT = new StringConcat(); BooleanOr BOOLEAN_OR = new BooleanOr(); BooleanAnd BOOLEAN_AND = new BooleanAnd(); @Nonnull T append(T a, T b);
class UnitIdentity implements Semigroup<Unit> {
shapesecurity/shape-functional-java
src/main/java/com/shapesecurity/functional/data/Either.java
// Path: src/main/java/com/shapesecurity/functional/Effect.java // @FunctionalInterface // public interface Effect<A> extends F<A, Unit> { // void e(@Nonnull A a); // // @Nonnull // default Unit apply(@Nonnull A a) { // this.e(a); // return Unit.unit; // } // } // // Path: src/main/java/com/shapesecurity/functional/F.java // @CheckReturnValue // @FunctionalInterface // public interface F<A, R> { // @Nonnull // static <A extends B, B> F<A, B> id() { // return o -> o; // } // // @Nonnull // static <A, B> F<A, B> constant(@Nonnull final B b) { // return a -> b; // } // // @Nonnull // static <A, B, C> F2<A, B, C> uncurry(@Nonnull final F<A, F<B, C>> f) { // return (a, b) -> f.apply(a).apply(b); // } // // @Nonnull // static <A, B, C> F<B, F<A, C>> flip(@Nonnull final F<A, F<B, C>> f) { // return b -> a -> f.apply(a).apply(b); // } // // @Nonnull // R apply(@Nonnull A a); // // @Nonnull // default <C> F<C, R> compose(@Nonnull final F<C, A> f) { // return c -> this.apply(f.apply(c)); // } // // // @Nonnull // default <B> F<A, B> then(@Nonnull final F<R, B> f) { // return c -> f.apply(this.apply(c)); // } // } // // Path: src/main/java/com/shapesecurity/functional/ThrowingSupplier.java // @FunctionalInterface // public interface ThrowingSupplier<A> { // A get() throws Exception; // }
import com.shapesecurity.functional.Effect; import com.shapesecurity.functional.F; import com.shapesecurity.functional.ThrowingSupplier; import javax.annotation.CheckReturnValue; import javax.annotation.Nonnull;
/* * Copyright 2014 Shape Security, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.shapesecurity.functional.data; @CheckReturnValue public final class Either<A, B> { private final Object data; private enum Tag { LEFT, RIGHT } private final Tag tag; // class local private Either(Object data, Tag tag) { super(); this.data = data; this.tag = tag; } @Nonnull public static <A, B> Either<A, B> left(@Nonnull A a) { return new Either<>(a, Tag.LEFT); } @Nonnull public static <A, B> Either<A, B> right(@Nonnull B b) { return new Either<>(b, Tag.RIGHT); } @Nonnull public static <A, B extends A, C extends A> A extract(Either<B, C> e) { return e.either(x -> x, x -> x); } @Nonnull
// Path: src/main/java/com/shapesecurity/functional/Effect.java // @FunctionalInterface // public interface Effect<A> extends F<A, Unit> { // void e(@Nonnull A a); // // @Nonnull // default Unit apply(@Nonnull A a) { // this.e(a); // return Unit.unit; // } // } // // Path: src/main/java/com/shapesecurity/functional/F.java // @CheckReturnValue // @FunctionalInterface // public interface F<A, R> { // @Nonnull // static <A extends B, B> F<A, B> id() { // return o -> o; // } // // @Nonnull // static <A, B> F<A, B> constant(@Nonnull final B b) { // return a -> b; // } // // @Nonnull // static <A, B, C> F2<A, B, C> uncurry(@Nonnull final F<A, F<B, C>> f) { // return (a, b) -> f.apply(a).apply(b); // } // // @Nonnull // static <A, B, C> F<B, F<A, C>> flip(@Nonnull final F<A, F<B, C>> f) { // return b -> a -> f.apply(a).apply(b); // } // // @Nonnull // R apply(@Nonnull A a); // // @Nonnull // default <C> F<C, R> compose(@Nonnull final F<C, A> f) { // return c -> this.apply(f.apply(c)); // } // // // @Nonnull // default <B> F<A, B> then(@Nonnull final F<R, B> f) { // return c -> f.apply(this.apply(c)); // } // } // // Path: src/main/java/com/shapesecurity/functional/ThrowingSupplier.java // @FunctionalInterface // public interface ThrowingSupplier<A> { // A get() throws Exception; // } // Path: src/main/java/com/shapesecurity/functional/data/Either.java import com.shapesecurity.functional.Effect; import com.shapesecurity.functional.F; import com.shapesecurity.functional.ThrowingSupplier; import javax.annotation.CheckReturnValue; import javax.annotation.Nonnull; /* * Copyright 2014 Shape Security, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.shapesecurity.functional.data; @CheckReturnValue public final class Either<A, B> { private final Object data; private enum Tag { LEFT, RIGHT } private final Tag tag; // class local private Either(Object data, Tag tag) { super(); this.data = data; this.tag = tag; } @Nonnull public static <A, B> Either<A, B> left(@Nonnull A a) { return new Either<>(a, Tag.LEFT); } @Nonnull public static <A, B> Either<A, B> right(@Nonnull B b) { return new Either<>(b, Tag.RIGHT); } @Nonnull public static <A, B extends A, C extends A> A extract(Either<B, C> e) { return e.either(x -> x, x -> x); } @Nonnull
public static <A> Either<Exception, A> _try(@Nonnull ThrowingSupplier<A> s) {
shapesecurity/shape-functional-java
src/main/java/com/shapesecurity/functional/data/Either.java
// Path: src/main/java/com/shapesecurity/functional/Effect.java // @FunctionalInterface // public interface Effect<A> extends F<A, Unit> { // void e(@Nonnull A a); // // @Nonnull // default Unit apply(@Nonnull A a) { // this.e(a); // return Unit.unit; // } // } // // Path: src/main/java/com/shapesecurity/functional/F.java // @CheckReturnValue // @FunctionalInterface // public interface F<A, R> { // @Nonnull // static <A extends B, B> F<A, B> id() { // return o -> o; // } // // @Nonnull // static <A, B> F<A, B> constant(@Nonnull final B b) { // return a -> b; // } // // @Nonnull // static <A, B, C> F2<A, B, C> uncurry(@Nonnull final F<A, F<B, C>> f) { // return (a, b) -> f.apply(a).apply(b); // } // // @Nonnull // static <A, B, C> F<B, F<A, C>> flip(@Nonnull final F<A, F<B, C>> f) { // return b -> a -> f.apply(a).apply(b); // } // // @Nonnull // R apply(@Nonnull A a); // // @Nonnull // default <C> F<C, R> compose(@Nonnull final F<C, A> f) { // return c -> this.apply(f.apply(c)); // } // // // @Nonnull // default <B> F<A, B> then(@Nonnull final F<R, B> f) { // return c -> f.apply(this.apply(c)); // } // } // // Path: src/main/java/com/shapesecurity/functional/ThrowingSupplier.java // @FunctionalInterface // public interface ThrowingSupplier<A> { // A get() throws Exception; // }
import com.shapesecurity.functional.Effect; import com.shapesecurity.functional.F; import com.shapesecurity.functional.ThrowingSupplier; import javax.annotation.CheckReturnValue; import javax.annotation.Nonnull;
} @Nonnull public static <A, B> Either<A, B> right(@Nonnull B b) { return new Either<>(b, Tag.RIGHT); } @Nonnull public static <A, B extends A, C extends A> A extract(Either<B, C> e) { return e.either(x -> x, x -> x); } @Nonnull public static <A> Either<Exception, A> _try(@Nonnull ThrowingSupplier<A> s) { try { return Either.right(s.get()); } catch (Exception e) { return Either.left(e); } } public final boolean isLeft() { return this.tag == Tag.LEFT; } public final boolean isRight() { return this.tag == Tag.RIGHT; } @SuppressWarnings("unchecked")
// Path: src/main/java/com/shapesecurity/functional/Effect.java // @FunctionalInterface // public interface Effect<A> extends F<A, Unit> { // void e(@Nonnull A a); // // @Nonnull // default Unit apply(@Nonnull A a) { // this.e(a); // return Unit.unit; // } // } // // Path: src/main/java/com/shapesecurity/functional/F.java // @CheckReturnValue // @FunctionalInterface // public interface F<A, R> { // @Nonnull // static <A extends B, B> F<A, B> id() { // return o -> o; // } // // @Nonnull // static <A, B> F<A, B> constant(@Nonnull final B b) { // return a -> b; // } // // @Nonnull // static <A, B, C> F2<A, B, C> uncurry(@Nonnull final F<A, F<B, C>> f) { // return (a, b) -> f.apply(a).apply(b); // } // // @Nonnull // static <A, B, C> F<B, F<A, C>> flip(@Nonnull final F<A, F<B, C>> f) { // return b -> a -> f.apply(a).apply(b); // } // // @Nonnull // R apply(@Nonnull A a); // // @Nonnull // default <C> F<C, R> compose(@Nonnull final F<C, A> f) { // return c -> this.apply(f.apply(c)); // } // // // @Nonnull // default <B> F<A, B> then(@Nonnull final F<R, B> f) { // return c -> f.apply(this.apply(c)); // } // } // // Path: src/main/java/com/shapesecurity/functional/ThrowingSupplier.java // @FunctionalInterface // public interface ThrowingSupplier<A> { // A get() throws Exception; // } // Path: src/main/java/com/shapesecurity/functional/data/Either.java import com.shapesecurity.functional.Effect; import com.shapesecurity.functional.F; import com.shapesecurity.functional.ThrowingSupplier; import javax.annotation.CheckReturnValue; import javax.annotation.Nonnull; } @Nonnull public static <A, B> Either<A, B> right(@Nonnull B b) { return new Either<>(b, Tag.RIGHT); } @Nonnull public static <A, B extends A, C extends A> A extract(Either<B, C> e) { return e.either(x -> x, x -> x); } @Nonnull public static <A> Either<Exception, A> _try(@Nonnull ThrowingSupplier<A> s) { try { return Either.right(s.get()); } catch (Exception e) { return Either.left(e); } } public final boolean isLeft() { return this.tag == Tag.LEFT; } public final boolean isRight() { return this.tag == Tag.RIGHT; } @SuppressWarnings("unchecked")
public <X> X either(F<A, X> f1, F<B, X> f2) {
shapesecurity/shape-functional-java
src/main/java/com/shapesecurity/functional/data/Either.java
// Path: src/main/java/com/shapesecurity/functional/Effect.java // @FunctionalInterface // public interface Effect<A> extends F<A, Unit> { // void e(@Nonnull A a); // // @Nonnull // default Unit apply(@Nonnull A a) { // this.e(a); // return Unit.unit; // } // } // // Path: src/main/java/com/shapesecurity/functional/F.java // @CheckReturnValue // @FunctionalInterface // public interface F<A, R> { // @Nonnull // static <A extends B, B> F<A, B> id() { // return o -> o; // } // // @Nonnull // static <A, B> F<A, B> constant(@Nonnull final B b) { // return a -> b; // } // // @Nonnull // static <A, B, C> F2<A, B, C> uncurry(@Nonnull final F<A, F<B, C>> f) { // return (a, b) -> f.apply(a).apply(b); // } // // @Nonnull // static <A, B, C> F<B, F<A, C>> flip(@Nonnull final F<A, F<B, C>> f) { // return b -> a -> f.apply(a).apply(b); // } // // @Nonnull // R apply(@Nonnull A a); // // @Nonnull // default <C> F<C, R> compose(@Nonnull final F<C, A> f) { // return c -> this.apply(f.apply(c)); // } // // // @Nonnull // default <B> F<A, B> then(@Nonnull final F<R, B> f) { // return c -> f.apply(this.apply(c)); // } // } // // Path: src/main/java/com/shapesecurity/functional/ThrowingSupplier.java // @FunctionalInterface // public interface ThrowingSupplier<A> { // A get() throws Exception; // }
import com.shapesecurity.functional.Effect; import com.shapesecurity.functional.F; import com.shapesecurity.functional.ThrowingSupplier; import javax.annotation.CheckReturnValue; import javax.annotation.Nonnull;
return e.either(x -> x, x -> x); } @Nonnull public static <A> Either<Exception, A> _try(@Nonnull ThrowingSupplier<A> s) { try { return Either.right(s.get()); } catch (Exception e) { return Either.left(e); } } public final boolean isLeft() { return this.tag == Tag.LEFT; } public final boolean isRight() { return this.tag == Tag.RIGHT; } @SuppressWarnings("unchecked") public <X> X either(F<A, X> f1, F<B, X> f2) { if (this.tag == Tag.LEFT) { return f1.apply((A) this.data); } else { return f2.apply((B) this.data); } } @SuppressWarnings("unchecked")
// Path: src/main/java/com/shapesecurity/functional/Effect.java // @FunctionalInterface // public interface Effect<A> extends F<A, Unit> { // void e(@Nonnull A a); // // @Nonnull // default Unit apply(@Nonnull A a) { // this.e(a); // return Unit.unit; // } // } // // Path: src/main/java/com/shapesecurity/functional/F.java // @CheckReturnValue // @FunctionalInterface // public interface F<A, R> { // @Nonnull // static <A extends B, B> F<A, B> id() { // return o -> o; // } // // @Nonnull // static <A, B> F<A, B> constant(@Nonnull final B b) { // return a -> b; // } // // @Nonnull // static <A, B, C> F2<A, B, C> uncurry(@Nonnull final F<A, F<B, C>> f) { // return (a, b) -> f.apply(a).apply(b); // } // // @Nonnull // static <A, B, C> F<B, F<A, C>> flip(@Nonnull final F<A, F<B, C>> f) { // return b -> a -> f.apply(a).apply(b); // } // // @Nonnull // R apply(@Nonnull A a); // // @Nonnull // default <C> F<C, R> compose(@Nonnull final F<C, A> f) { // return c -> this.apply(f.apply(c)); // } // // // @Nonnull // default <B> F<A, B> then(@Nonnull final F<R, B> f) { // return c -> f.apply(this.apply(c)); // } // } // // Path: src/main/java/com/shapesecurity/functional/ThrowingSupplier.java // @FunctionalInterface // public interface ThrowingSupplier<A> { // A get() throws Exception; // } // Path: src/main/java/com/shapesecurity/functional/data/Either.java import com.shapesecurity.functional.Effect; import com.shapesecurity.functional.F; import com.shapesecurity.functional.ThrowingSupplier; import javax.annotation.CheckReturnValue; import javax.annotation.Nonnull; return e.either(x -> x, x -> x); } @Nonnull public static <A> Either<Exception, A> _try(@Nonnull ThrowingSupplier<A> s) { try { return Either.right(s.get()); } catch (Exception e) { return Either.left(e); } } public final boolean isLeft() { return this.tag == Tag.LEFT; } public final boolean isRight() { return this.tag == Tag.RIGHT; } @SuppressWarnings("unchecked") public <X> X either(F<A, X> f1, F<B, X> f2) { if (this.tag == Tag.LEFT) { return f1.apply((A) this.data); } else { return f2.apply((B) this.data); } } @SuppressWarnings("unchecked")
public void foreach(@Nonnull Effect<A> f1, @Nonnull Effect<B> f2) {
shapesecurity/shape-functional-java
src/test/java/com/shapesecurity/functional/data/MaybeTest.java
// Path: src/test/java/com/shapesecurity/functional/TestBase.java // public abstract class TestBase { // private static final String BASE_PATH = System.getenv("CONFIG_DIR") == null ? "src/test/resources" : System.getenv( // "CONFIG_DIR"); // // private static Random rand = new Random(); // // protected static int rand(int low, int high) { // return rand.nextInt(Math.max(high - low, 1)) + low; // } // // protected static int rand() { // return rand(-100, 101); // } // // protected static Path getPath(String path) { // Path pathObj = Paths.get(BASE_PATH + '/' + path); // if (Files.exists(pathObj)) { // return pathObj; // } else { // try { // return Paths.get(TestBase.class.getResource("/" + path).toURI()); // } catch (URISyntaxException e) { // throw new RuntimeException(e); // } // } // } // // @Nonnull // protected static String readFile(@Nonnull String path) throws IOException { // byte[] encoded = Files.readAllBytes(getPath(path)); // return StandardCharsets.UTF_8.decode(ByteBuffer.wrap(encoded)).toString(); // } // // // Tests // // // static // // static protected NonEmptyImmutableList<Integer> LONG_LIST = ImmutableList.of(rand()); // static protected NonEmptyImmutableList<Integer> LONG_INT_LIST = ImmutableList.of(0); // static { // for (int i = 0; i < 1000; i++) { // LONG_LIST = LONG_LIST.cons(rand()); // } // for (int i = 0; i < 1 << 14; i++) { // LONG_INT_LIST = LONG_INT_LIST.cons(i); // } // } // // @Before // public void setUp() { // rand = new Random(12345L); // } // // @Nonnull // public ImmutableList<Integer> range(final int upper) { // return range(0, upper); // } // // @Nonnull // public ImmutableList<Integer> range(final int lower, final int upper) { // return range(lower, upper, 1); // } // // @Nonnull // public ImmutableList<Integer> range(final int lower, final int upper, final int step) { // ImmutableList<Integer> result = ImmutableList.empty(); // for (int i = upper - ((upper - lower + step - 1) % step + 1); i >= lower; i -= step) { // result = result.cons(i); // } // return result; // } // } // // Path: src/main/java/com/shapesecurity/functional/Thunk.java // public final class Thunk<A> { // @Nonnull // private final Supplier<A> supplier; // // Exception on style: private nullable. // @Nullable // private volatile A value = null; // // private Thunk(@Nonnull Supplier<A> supplier) { // this.supplier = supplier; // } // // @Nonnull // public static <A> Thunk<A> constant(@Nonnull final A value) { // Thunk<A> t = new Thunk<>(() -> value); // t.value = value; // return t; // } // // @Nonnull // public static <A> Thunk<A> from(@Nonnull Supplier<A> supplier) { // return new Thunk<>(supplier); // } // // @Nonnull // public final A get() { // // Double locked. // A value = this.value; // if (value == null) { // synchronized (this) { // value = this.value; // if (value == null) { // value = this.supplier.get(); // this.value = value; // } // } // } // return value; // } // }
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.shapesecurity.functional.TestBase; import com.shapesecurity.functional.Thunk; import javax.annotation.Nullable; import org.junit.Test;
assertEquals(1, effect[0]); effect[0] = 0; Maybe.of(notNull).foreach(() -> { fail("Maybe.forEach(r, f) should not execute r on Just"); }, x -> { effect[0] += 1; }); assertEquals(1, effect[0]); } @Test public void testToList() { assertEquals(ImmutableList.<Integer>empty(), Maybe.<Integer>empty().toList()); assertEquals(ImmutableList.of(notNull), Maybe.of(notNull).toList()); } @Test public void testEq() { assertTrue(Maybe.fromNullable(notNull).eq(Maybe.of(notNull))); assertFalse(Maybe.fromNullable(notNull).eq(Maybe.of(notNull + 1))); assertFalse(Maybe.fromNullable(notNull).eq(Maybe.<Integer>empty())); assertTrue(Maybe.fromNullable(nulled).eq(Maybe.<Integer>empty())); assertFalse(Maybe.fromNullable(nulled).eq(Maybe.fromNullable(notNull))); } @Test public void testOrJusts() { assertEquals(notNull, Maybe.fromNullable(notNull).orJust(notNull)); assertEquals(notNull, Maybe.fromNullable(nulled).orJust(notNull));
// Path: src/test/java/com/shapesecurity/functional/TestBase.java // public abstract class TestBase { // private static final String BASE_PATH = System.getenv("CONFIG_DIR") == null ? "src/test/resources" : System.getenv( // "CONFIG_DIR"); // // private static Random rand = new Random(); // // protected static int rand(int low, int high) { // return rand.nextInt(Math.max(high - low, 1)) + low; // } // // protected static int rand() { // return rand(-100, 101); // } // // protected static Path getPath(String path) { // Path pathObj = Paths.get(BASE_PATH + '/' + path); // if (Files.exists(pathObj)) { // return pathObj; // } else { // try { // return Paths.get(TestBase.class.getResource("/" + path).toURI()); // } catch (URISyntaxException e) { // throw new RuntimeException(e); // } // } // } // // @Nonnull // protected static String readFile(@Nonnull String path) throws IOException { // byte[] encoded = Files.readAllBytes(getPath(path)); // return StandardCharsets.UTF_8.decode(ByteBuffer.wrap(encoded)).toString(); // } // // // Tests // // // static // // static protected NonEmptyImmutableList<Integer> LONG_LIST = ImmutableList.of(rand()); // static protected NonEmptyImmutableList<Integer> LONG_INT_LIST = ImmutableList.of(0); // static { // for (int i = 0; i < 1000; i++) { // LONG_LIST = LONG_LIST.cons(rand()); // } // for (int i = 0; i < 1 << 14; i++) { // LONG_INT_LIST = LONG_INT_LIST.cons(i); // } // } // // @Before // public void setUp() { // rand = new Random(12345L); // } // // @Nonnull // public ImmutableList<Integer> range(final int upper) { // return range(0, upper); // } // // @Nonnull // public ImmutableList<Integer> range(final int lower, final int upper) { // return range(lower, upper, 1); // } // // @Nonnull // public ImmutableList<Integer> range(final int lower, final int upper, final int step) { // ImmutableList<Integer> result = ImmutableList.empty(); // for (int i = upper - ((upper - lower + step - 1) % step + 1); i >= lower; i -= step) { // result = result.cons(i); // } // return result; // } // } // // Path: src/main/java/com/shapesecurity/functional/Thunk.java // public final class Thunk<A> { // @Nonnull // private final Supplier<A> supplier; // // Exception on style: private nullable. // @Nullable // private volatile A value = null; // // private Thunk(@Nonnull Supplier<A> supplier) { // this.supplier = supplier; // } // // @Nonnull // public static <A> Thunk<A> constant(@Nonnull final A value) { // Thunk<A> t = new Thunk<>(() -> value); // t.value = value; // return t; // } // // @Nonnull // public static <A> Thunk<A> from(@Nonnull Supplier<A> supplier) { // return new Thunk<>(supplier); // } // // @Nonnull // public final A get() { // // Double locked. // A value = this.value; // if (value == null) { // synchronized (this) { // value = this.value; // if (value == null) { // value = this.supplier.get(); // this.value = value; // } // } // } // return value; // } // } // Path: src/test/java/com/shapesecurity/functional/data/MaybeTest.java import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.shapesecurity.functional.TestBase; import com.shapesecurity.functional.Thunk; import javax.annotation.Nullable; import org.junit.Test; assertEquals(1, effect[0]); effect[0] = 0; Maybe.of(notNull).foreach(() -> { fail("Maybe.forEach(r, f) should not execute r on Just"); }, x -> { effect[0] += 1; }); assertEquals(1, effect[0]); } @Test public void testToList() { assertEquals(ImmutableList.<Integer>empty(), Maybe.<Integer>empty().toList()); assertEquals(ImmutableList.of(notNull), Maybe.of(notNull).toList()); } @Test public void testEq() { assertTrue(Maybe.fromNullable(notNull).eq(Maybe.of(notNull))); assertFalse(Maybe.fromNullable(notNull).eq(Maybe.of(notNull + 1))); assertFalse(Maybe.fromNullable(notNull).eq(Maybe.<Integer>empty())); assertTrue(Maybe.fromNullable(nulled).eq(Maybe.<Integer>empty())); assertFalse(Maybe.fromNullable(nulled).eq(Maybe.fromNullable(notNull))); } @Test public void testOrJusts() { assertEquals(notNull, Maybe.fromNullable(notNull).orJust(notNull)); assertEquals(notNull, Maybe.fromNullable(nulled).orJust(notNull));
assertEquals(notNull, Maybe.fromNullable(notNull).orJustLazy(Thunk.from(() -> notNull)));