org.scalameter.japi.JGen Maven / Gradle / Ivy
package org.scalameter.japi;
import java.io.Serializable;
import org.scalameter.Gen;
import org.scalameter.picklers.*;
import scala.Tuple2;
import scala.Tuple3;
import scala.Tuple4;
import scala.collection.immutable.List;
import scala.runtime.BoxedUnit;
/** Java version of the [[org.scalameter.Gen]].
* After combining and changing your generators
* you should finally call the `asScala()` method.
*
* Note that it's immutable, so every method return new JGen.
*/
@SuppressWarnings({"unchecked"})
public class JGen implements Serializable {
private final Gen gen;
public JGen(Gen gen) {
this.gen = gen;
}
public Gen asScala() {
return this.gen;
}
public JGen cached() {
return new JGen(gen.cached());
}
public JGen> zip(JGen that) {
return new JGen>(this.gen.cross(that.gen));
}
public JGen map(final Fun1 f) {
return new JGen(this.gen.map(new SerializableAbstractFunction1() {
public S apply(T v) {
return f.apply(v);
}
}));
}
/* Standard factory methods. */
public static JGen exponential(
String axisName, int from, int until, int factor
) {
return new JGen(
(Gen)(Object) Gen.exponential(axisName, from, until, factor)
);
}
public static JGen range(
String axisName, int from, int upto, int hop
) {
return new JGen(
(Gen)(Object) Gen.range(axisName, from, upto, hop)
);
}
public static JGen none(String axisName) {
return new JGen(Gen.unit(axisName));
}
/* Factory methods that produce cross product of multiple JGen instances. */
public static JGen> crossProduct(
JGen p, JGen q
) {
return new JGen>(
Gen.crossProduct(p.gen, q.gen)
);
}
public static JGen> crossProduct(
JGen p, JGen q, JGen r
) {
return new JGen>(
Gen.crossProduct(p.gen, q.gen, r.gen)
);
}
public static JGen> crossProduct(
JGen p, JGen q, JGen r, JGen s
) {
return new JGen>(
Gen.crossProduct(p.gen, q.gen, r.gen, s.gen)
);
}
/* Factory methods that return enumerations. */
private static List toList(T[] array) {
return ArrayToList.apply(array);
}
public static JGen booleanValues(
String axisName, Boolean... values
) {
return new JGen(Gen.enumeration(
axisName, toList(values), (Pickler)(Object) Implicits.booleanPickler()
));
}
public static JGen charValues(
String axisName, Character... values
) {
return new JGen(Gen.enumeration(
axisName, toList(values), (Pickler)(Object) Implicits.charPickler()
));
}
public static JGen byteValues(
String axisName, Byte... values
) {
return new JGen(Gen.enumeration(
axisName, toList(values), (Pickler)(Object) Implicits.bytePickler()
));
}
public static JGen shortValues(
String axisName, Short... values
) {
return new JGen(Gen.enumeration(
axisName, toList(values), (Pickler)(Object) Implicits.shortPickler()
));
}
public static JGen intValues(
String axisName, Integer... values
) {
return new JGen(Gen.enumeration(
axisName, toList(values), (Pickler)(Object) Implicits.intPickler()
));
}
public static JGen longValues(
String axisName, Long... values
) {
return new JGen(Gen.enumeration(
axisName, toList(values), (Pickler)(Object) Implicits.longPickler()
));
}
public static JGen floatValues(
String axisName, Float... values
) {
return new JGen(Gen.enumeration(
axisName, toList(values), (Pickler)(Object) Implicits.floatPickler()
));
}
public static JGen doubleValues(
String axisName, Double... values
) {
return new JGen(Gen.enumeration(
axisName, toList(values), (Pickler)(Object) Implicits.doublePickler()
));
}
public static > JGen enumValues(
String axisName, T... values
) {
return new JGen(Gen.enumeration(
axisName, toList(values), (Pickler) Implicits.enumPickler()
));
}
public static JGen values(
String axisName, Pickler pickler, T... values
) {
return new JGen(Gen.enumeration(
axisName, toList(values), pickler
));
}
}