/** * Creates an instance of {@link ObjectGenerator} which generates values in order they are specified. When values * are depleted, it starts again from the beginning of the list. * * @param values List of values. * @param <T> Type instance of {@link ObjectGenerator} will generate. * @return An instance of {@link ObjectGenerator} which generates values in order they are specified. */ @SafeVarargs public static <T> ObjectGenerator<T> circular(T... values) { return circular(Arrays.asList(values)); }
/** * Creates an instance of {@link ObjectGenerator} which generates list containing all values specified. * * @param values List of values. * @param <T> Type instance of {@link ObjectGenerator} will generate. * @return An instance of {@link ObjectGenerator} which generates list containing all values specified. */ @SafeVarargs public static <T> ObjectGenerator<List<T>> list(T... values) { return list(Arrays.asList(values)); }
/** * Creates an instance of {@link ObjectGenerator} which generates uniformly distributed values from specified list. * * @param values List of values. * @param <T> Type instance of {@link ObjectGenerator} will generate. * @return An instance of {@link ObjectGenerator} which generates uniformly distributed values from specified list. */ @SafeVarargs public static <T> ObjectGenerator<T> random(T... values) { return random(Arrays.asList(values)); }
/** * Creates an instance of {@link ObjectGenerator} which generates uniformly distributed values from specified list. * * @param values List of values. * @param <T> Type instance of {@link ObjectGenerator} will generate. * @return An instance of {@link ObjectGenerator} which generates uniformly distributed values from specified list. */ public static <T> ObjectGenerator<T> random(List<T> values) { return wrap(new DiscreteValue<>(unwrap(values))); }
/** * Creates an instance of {@link ObjectGenerator} which generates a formatted string using the specified format * string and objects. Placeholder for value is defined as '{}', first placeholder uses first value, second, second * value, and so on. * * @param format Format string, * @param values List of values. * @return An instance of {@link ObjectGenerator} which generates formated strings. */ public static ObjectGenerator<String> string(String format, List<Object> values) { return wrap(new StringTransformer(format, unwrapRaw(values))); }
/** * Creates an instance of {@link ObjectGenerator} which generates each value exactly specified number of times. * Values are generated using weighted distribution until depleted. When all values are generated specified number * of times and {@link ObjectGenerator#next()} is invoked, * {@link io.smartcat.ranger.core.ExactWeightedValue.ExactWeightedValueDepletedException * ExactWeightedValueDepletedException} is thrown. * * @param pairs List of values with corresponding counts. * @param <T> Type instance of {@link ObjectGenerator} will generate. * @return An instance of {@link ObjectGenerator} which generates each value exactly specified number of times. */ public static <T> ObjectGenerator<T> exactly(List<CountPair<T>> pairs) { return wrap(new ExactWeightedValue<>(unwrapCountPairs(pairs))); }
/** * Creates an instance of {@link ObjectGenerator} which generates random string values of length to which * <code>lengthGenerator</code> evaluates to. Each generation can evaluate to different string length, based on * value generated by <code>lengthGenerator</code>. String will contain specified character ranges. Uniform * distribution is used to select characters from character ranges. * * @param lengthValue Value that returns integer which represents length of generated string. It should never * generate length that is less than 1. * @param ranges List of ranges from which characters are taken with uniform distribution. * @return An instance of {@link ObjectGenerator} which generates random string values of specified length. */ public static ObjectGenerator<String> randomContentString(ObjectGenerator<Integer> lengthValue, List<Range<Character>> ranges) { List<io.smartcat.ranger.core.Range<Character>> convertedRanges = new ArrayList<>(); for (Range<Character> range : ranges) { convertedRanges.add(toRange(range)); } return wrap(new RandomContentStringValue(lengthValue.value, convertedRanges)); }
@SuppressWarnings({ "unchecked", "rawtypes" }) private static List<Value<?>> unwrapRaw(List<Object> objects) { List result = unwrap(objects); return result; }
/** * Creates an instance of {@link ObjectGenerator} which generates a formatted string using the specified format * string and objects. Placeholder for value is defined as '{}', first placeholder uses first value, second, second * value, and so on. * * @param format Format string, * @param values List of values. * @return An instance of {@link ObjectGenerator} which generates formated strings. */ public static ObjectGenerator<String> string(String format, Object... values) { return string(format, Arrays.asList(values)); }
/** * Creates an instance of {@link ObjectGenerator} which generates each value exactly specified number of times. * Values are generated using weighted distribution until depleted. When all values are generated specified number * of times and {@link ObjectGenerator#next()} is invoked, * {@link io.smartcat.ranger.core.ExactWeightedValue.ExactWeightedValueDepletedException * ExactWeightedValueDepletedException} is thrown. * * @param pairs List of values with corresponding count. * @param <T> Type instance of {@link ObjectGenerator} will generate. * @return An instance of {@link ObjectGenerator} which generates each value exactly specified number of times. */ @SafeVarargs public static <T> ObjectGenerator<T> exactly(CountPair<T>... pairs) { return exactly(Arrays.asList(pairs)); }
/** * Creates an instance of {@link ObjectGenerator} which generates random string values of length to which * <code>lengthGenerator</code> evaluates to. Each generation can evaluate to different string length, based on * value generated by <code>lengthGenerator</code>. String will contain specified character ranges. Uniform * distribution is used to select characters from character ranges. * * @param lengthValue Value that returns integer which represents length of generated string. It should never * generate length that is less than 1. * @param ranges List of ranges from which characters are taken with uniform distribution. * @return An instance of {@link ObjectGenerator} which generates random string values of specified length. */ @SafeVarargs public static ObjectGenerator<String> randomContentString(ObjectGenerator<Integer> lengthValue, Range<Character>... ranges) { return randomContentString(lengthValue, Arrays.asList(ranges)); }
/** * Creates an instance of {@link ObjectGenerator} which generates list containing all values specified. * * @param values List of values. * @param <T> Type instance of {@link ObjectGenerator} will generate. * @return An instance of {@link ObjectGenerator} which generates list containing all values specified. */ public static <T> ObjectGenerator<List<T>> list(List<T> values) { return wrap(new ListValue<>(unwrap(values))); }
/** * Creates an instance of {@link ObjectGenerator} which generates random string values of length to which * <code>lengthGenerator</code> evaluates to. Each generation can evaluate to different string length, based on * value generated by <code>lengthGenerator</code>. String will contain specified character ranges. Uniform * distribution is used to select characters from character ranges. * * @param lengthValue Value that returns integer which represents length of generated string. It should never * generate length that is less than 1. * @param ranges List of ranges from which characters are taken with uniform distribution. * @return An instance of {@link ObjectGenerator} which generates random string values of specified length. */ public static ObjectGenerator<String> randomContentString(ObjectGenerator<Integer> lengthValue, List<Range<Character>> ranges) { List<io.smartcat.ranger.core.Range<Character>> convertedRanges = new ArrayList<>(); for (Range<Character> range : ranges) { convertedRanges.add(toRange(range)); } return wrap(new RandomContentStringValue(lengthValue.value, convertedRanges)); }
/** * Creates an instance of {@link ObjectGenerator} which generates a formatted string using the specified format * string and objects. Placeholder for value is defined as '{}', first placeholder uses first value, second, second * value, and so on. * * @param format Format string, * @param values List of values. * @return An instance of {@link ObjectGenerator} which generates formated strings. */ public static ObjectGenerator<String> string(String format, List<Object> values) { return wrap(new StringTransformer(format, unwrapRaw(values))); }
/** * Creates an instance of {@link ObjectGenerator} which generates each value exactly specified number of times. * Values are generated using weighted distribution until depleted. When all values are generated specified number * of times and {@link ObjectGenerator#next()} is invoked, * {@link io.smartcat.ranger.core.ExactWeightedValue.ExactWeightedValueDepletedException * ExactWeightedValueDepletedException} is thrown. * * @param pairs List of values with corresponding counts. * @param <T> Type instance of {@link ObjectGenerator} will generate. * @return An instance of {@link ObjectGenerator} which generates each value exactly specified number of times. */ public static <T> ObjectGenerator<T> exactly(List<CountPair<T>> pairs) { return wrap(new ExactWeightedValue<>(unwrapCountPairs(pairs))); }
@SuppressWarnings({ "unchecked", "rawtypes" }) private static List<Value<?>> unwrapRaw(List<Object> objects) { List result = unwrap(objects); return result; }
/** * Creates an instance of {@link ObjectGenerator} which generates a formatted string using the specified format * string and objects. Placeholder for value is defined as '{}', first placeholder uses first value, second, second * value, and so on. * * @param format Format string, * @param values List of values. * @return An instance of {@link ObjectGenerator} which generates formated strings. */ public static ObjectGenerator<String> string(String format, Object... values) { return string(format, Arrays.asList(values)); }
/** * Creates an instance of {@link ObjectGenerator} which generates each value exactly specified number of times. * Values are generated using weighted distribution until depleted. When all values are generated specified number * of times and {@link ObjectGenerator#next()} is invoked, * {@link io.smartcat.ranger.core.ExactWeightedValue.ExactWeightedValueDepletedException * ExactWeightedValueDepletedException} is thrown. * * @param pairs List of values with corresponding count. * @param <T> Type instance of {@link ObjectGenerator} will generate. * @return An instance of {@link ObjectGenerator} which generates each value exactly specified number of times. */ @SafeVarargs public static <T> ObjectGenerator<T> exactly(CountPair<T>... pairs) { return exactly(Arrays.asList(pairs)); }
/** * Creates an instance of {@link ObjectGenerator} which generates random string values of length to which * <code>lengthGenerator</code> evaluates to. Each generation can evaluate to different string length, based on * value generated by <code>lengthGenerator</code>. String will contain specified character ranges. Uniform * distribution is used to select characters from character ranges. * * @param lengthValue Value that returns integer which represents length of generated string. It should never * generate length that is less than 1. * @param ranges List of ranges from which characters are taken with uniform distribution. * @return An instance of {@link ObjectGenerator} which generates random string values of specified length. */ @SafeVarargs public static ObjectGenerator<String> randomContentString(ObjectGenerator<Integer> lengthValue, Range<Character>... ranges) { return randomContentString(lengthValue, Arrays.asList(ranges)); }
/** * Creates an instance of {@link ObjectGenerator} which generates list containing all values specified. * * @param values List of values. * @param <T> Type instance of {@link ObjectGenerator} will generate. * @return An instance of {@link ObjectGenerator} which generates list containing all values specified. */ public static <T> ObjectGenerator<List<T>> list(List<T> values) { return wrap(new ListValue<>(unwrap(values))); }