/** * Helper method to construct {@link ConstantValue}. * * @param value Value to be returned by created constant value. * @param <T> Type this value would evaluate to. * * @return An instance of {@link ConstantValue}. */ public static <T> ConstantValue<T> of(T value) { return new ConstantValue<T>(value); } }
@SuppressWarnings({ "unchecked" }) private static <T> Value<T> value(T object) { return object instanceof ObjectGenerator ? ((ObjectGenerator<T>) object).value : ConstantValue.of(object); }
@SuppressWarnings({ "unchecked" }) private static <T> Value<T> value(T object) { return object instanceof ObjectGenerator ? ((ObjectGenerator<T>) object).value : ConstantValue.of(object); }
/** * Helper method to construct {@link ConstantValue}. * * @param value Value to be returned by created constant value. * @param <T> Type this value would evaluate to. * * @return An instance of {@link ConstantValue}. */ public static <T> ConstantValue<T> of(T value) { return new ConstantValue<T>(value); } }
/** * Sets the value to be used for generating values for property. * * @param property Name of the property. * @param value Value to be used for generating values. * @param <V> Type of object which value will be generate. * @return This builder. */ @SuppressWarnings({ "rawtypes" }) public <V> ObjectGeneratorBuilder prop(String property, V value) { propertyValues.put(property, value instanceof ObjectGenerator ? ((ObjectGenerator) value).value : ConstantValue.of(value)); return this; }
/** * Sets the value to be used for generating values for property. * * @param property Name of the property. * @param value Value to be used for generating values. * @param <V> Type of object which value will be generate. * @return This builder. */ @SuppressWarnings({ "rawtypes" }) public <V> ObjectGeneratorBuilder prop(String property, V value) { propertyValues.put(property, value instanceof ObjectGenerator ? ((ObjectGenerator) value).value : ConstantValue.of(value)); return this; }
@SuppressWarnings({ "unchecked", "rawtypes" }) private static <T> List<Value<T>> unwrap(List<T> objects) { List<Value<T>> result = new ArrayList<>(); for (T object : objects) { if (object instanceof ObjectGenerator) { result.add(((ObjectGenerator) object).value); } else { result.add(ConstantValue.of(object)); } } return result; }
@SuppressWarnings({ "unchecked", "rawtypes" }) private static <T> List<Value<T>> unwrap(List<T> objects) { List<Value<T>> result = new ArrayList<>(); for (T object : objects) { if (object instanceof ObjectGenerator) { result.add(((ObjectGenerator) object).value); } else { result.add(ConstantValue.of(object)); } } return result; }
/** * Creates an instance of {@link ObjectGenerator} which always returns specified value. * * @param value Value to be returned by created constant object generator. * @param <T> Type this value would evaluate to. * * @return An instance of {@link ObjectGenerator}. */ public static <T> ObjectGenerator<T> constant(T value) { return wrap(ConstantValue.of(value)); }
/** * Creates an instance of {@link ObjectGenerator} which always returns specified value. * * @param value Value to be returned by created constant object generator. * @param <T> Type this value would evaluate to. * * @return An instance of {@link ObjectGenerator}. */ public static <T> ObjectGenerator<T> constant(T value) { return wrap(ConstantValue.of(value)); }
/** * Number value definition. * * @return Number value definition rule. */ public Rule numberLiteralValue() { return Sequence(numberLiteral(), push(ConstantValue.of(pop()))); }
private Value<?> parseSimpleValue(String parentName, Object def) { // handle String as expression and all other types as primitives if (def instanceof String) { parser.setParentName(stripOffLastReference(parentName)); ParsingResult<Value<?>> result = parseRunner.run((String) def); return result.valueStack.pop(); } else { return ConstantValue.of(def); } }
/** * Boolean value definition. * * @return Boolean value definition rule. */ public Rule booleanLiteralValue() { return Sequence(booleanLiteral(), push(ConstantValue.of(pop()))); }
/** * Number value definition. * * @return Number value definition rule. */ public Rule numberLiteralValue() { return Sequence(numberLiteral(), push(ConstantValue.of(pop()))); }
/** * Boolean value definition. * * @return Boolean value definition rule. */ public Rule booleanLiteralValue() { return Sequence(booleanLiteral(), push(ConstantValue.of(pop()))); }
private Value<?> parseSimpleValue(String parentName, Object def) { // handle String as expression and all other types as primitives if (def instanceof String) { parser.setParentName(stripOffLastReference(parentName)); ParsingResult<Value<?>> result = parseRunner.run((String) def); return result.valueStack.pop(); } else { return ConstantValue.of(def); } }
/** * String value definition. * * @return String value definition rule. */ public Rule stringLiteralValue() { return Sequence(FirstOf(stringLiteral(), nakedStringLiteral()), push(ConstantValue.of(pop()))); }
/** * String value definition. * * @return String value definition rule. */ public Rule stringLiteralValue() { return Sequence(FirstOf(stringLiteral(), nakedStringLiteral()), push(ConstantValue.of(pop()))); }