/** * Creates an instance of {@link CountPair}. This is a helper method that is useful for following methods:<br> * {@link #exactly(CountPair...)}<br> * {@link #exactly(List)}<br> * * @param value The value. * @param count Represents how many times value can be used. * @param <T> Type of value count pair contains. * @return An instance of {@link CountPair}. */ public static <T> CountPair<T> countPair(T value, int count) { return new CountPair<>(value(value), count); }
/** * Creates an instance of {@link WeightPair}. This is a helper method that is useful for following methods:<br> * {@link #weighted(WeightPair...)}<br> * {@link #weighted(List)}<br> * * @param value The value. * @param weight Represents distribution weight of this value. * @param <T> Type of value weight pair contains. * @return An instance of {@link CountPair}. */ public static <T> WeightPair<T> weightPair(T value, double weight) { return new WeightPair<>(value(value), weight); }
@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 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 specified values distributed by their weights. * * @param pairs List of values with corresponding weights. * @param <T> Type instance of {@link ObjectGenerator} will generate. * @return An instance of {@link ObjectGenerator} which generates specified values distributed by their weights. */ public static <T> ObjectGenerator<T> weighted(List<WeightPair<T>> pairs) { return wrap(new WeightedValue<>(unwrapWeightPairs(pairs))); }
/** * Creates an instance of {@link ObjectGenerator} which generates current date-time as {@link Date} object. * * @return An instance of {@link ObjectGenerator} which generates current date-time as {@link Date} object. */ public static ObjectGenerator<Date> nowDate() { return wrap(new NowDateValue()); }
/** * Creates an instance of {@link ObjectGenerator} which generates current date-time as {@link LocalDateTime} object. * * @return An instance of {@link ObjectGenerator} which generates current date-time as {@link LocalDateTime} object. */ public static ObjectGenerator<LocalDateTime> nowLocalDateTime() { return wrap(new NowLocalDateTimeValue()); }
/** * Creates an instance of {@link ObjectGenerator} which converts specified instance of {@link ObjectGenerator} to * JSON. Uses default instance of {@link ObjectMapper} to converted to JSON. * * @param generator Instance of {@link ObjectGenerator} which value will be converted to JSON. * @return An instance of {@link ObjectGenerator} which converts specified instance of {@link ObjectGenerator} to * JSON. */ public static ObjectGenerator<String> json(ObjectGenerator<?> generator) { return wrap(new JsonTransformer(generator.value)); }
/** * Generates next object. * * @return An instance of {@code <T>}. */ public T next() { return buildOne(); }
private static <T> ObjectGenerator<T> wrap(Value<T> value) { return new ObjectGenerator<>(value); }
/** * Creates an instance of {@link Range}. This is a helper method that is useful for following methods:<br> * {@link #random(Range)}<br> * {@link #random(Range, boolean)}<br> * {@link #random(Range, boolean, Distribution)}<br> * {@link #circular(Range, Object)}<br> * {@link #randomContentString(ObjectGenerator, Range...)}<br> * {@link #randomContentString(ObjectGenerator, List)}<br> * * @param beginning Beginning of the range. * @param end End of the range. * @param <T> Type of the range. * @return An instance of {@link Range}. */ public static <T> Range<T> range(T beginning, T end) { return new Range<>(beginning, end); }
@Override public Map<String, Object> getNext(long time) { return (Map<String, Object>) objectGenerator.next(); } }
/** * Creates an instance of {@link CountPair}. This is a helper method that is useful for following methods:<br> * {@link #exactly(CountPair...)}<br> * {@link #exactly(List)}<br> * * @param value The value. * @param count Represents how many times value can be used. * @param <T> Type of value count pair contains. * @return An instance of {@link CountPair}. */ public static <T> CountPair<T> countPair(T value, int count) { return new CountPair<>(value(value), count); }
/** * Creates an instance of {@link WeightPair}. This is a helper method that is useful for following methods:<br> * {@link #weighted(WeightPair...)}<br> * {@link #weighted(List)}<br> * * @param value The value. * @param weight Represents distribution weight of this value. * @param <T> Type of value weight pair contains. * @return An instance of {@link CountPair}. */ public static <T> WeightPair<T> weightPair(T value, double weight) { return new WeightPair<>(value(value), weight); }
@SuppressWarnings({ "unchecked", "rawtypes" }) private static List<Value<?>> unwrapRaw(List<Object> objects) { List result = unwrap(objects); return result; }
/** * Generates next object. * * @return An instance of {@code <T>}. */ public T next() { return buildOne(); }
private static <T> ObjectGenerator<T> wrap(Value<T> value) { return new ObjectGenerator<>(value); }
/** * Creates an instance of {@link Range}. This is a helper method that is useful for following methods:<br> * {@link #random(Range)}<br> * {@link #random(Range, boolean)}<br> * {@link #random(Range, boolean, Distribution)}<br> * {@link #circular(Range, Object)}<br> * {@link #randomContentString(ObjectGenerator, Range...)}<br> * {@link #randomContentString(ObjectGenerator, List)}<br> * * @param beginning Beginning of the range. * @param end End of the range. * @param <T> Type of the range. * @return An instance of {@link Range}. */ public static <T> Range<T> range(T beginning, T end) { return new Range<>(beginning, end); }
@Override public Map<String, Object> getNext(long time) { return (Map<String, Object>) objectGenerator.next(); } }