use of org.apache.commons.lang.math.IntRange in project incubator-systemml by apache.
the class DMLDebuggerFunctions method getRange.
/**
* Parse command line arguments and return valid IntRange variable
* @param args CLI arguments for range of debugger display functionality
* @param length Size (number of lines of code) of DML script
* @return Validated range of lines within DML script to be displayed
* @throws DMLDebuggerException Invalid range
*/
protected IntRange getRange(String[] args, int length) throws DMLDebuggerException {
IntRange range = new IntRange(1, length);
if (args == null)
return range;
if (args.length == 2) {
try {
range = new IntRange(Integer.parseInt(args[0]), Integer.parseInt(args[1]));
if (range.getMinimumInteger() <= 0 || range.getMaximumInteger() > length) {
System.err.println("Invalid range values. Parameters <start end> must be two positive integers.");
range = new IntRange(0, 0);
}
} catch (NumberFormatException e) {
System.err.println("Invalid integer range format. Parameter must be a positive integer <= " + length);
range = new IntRange(0, 0);
}
} else {
System.err.println("Invalid range values. Parameters <start end> must be two positive integers.");
range = new IntRange(0, 0);
}
return range;
}
use of org.apache.commons.lang.math.IntRange in project gatk-protected by broadinstitute.
the class ParamUtilsUnitTest method testInRangeSuccess.
@Test
public void testInRangeSuccess() {
Assert.assertTrue(4 == ParamUtils.inRange(4L, 3, 6, "Range calculation did not work properly"), "Did not return proper value");
Assert.assertTrue(4 == ParamUtils.inRange(4, 3, 6, "Range calculation did not work properly"), "Did not return proper value");
Assert.assertTrue(4 == ParamUtils.inRange(new IntRange(3, 6), 4, "error"));
Assert.assertTrue(4.1 == ParamUtils.inRange(4.1, 3, 6, "Range calculation did not work properly"), "Did not return proper value");
Assert.assertTrue(4.1 == ParamUtils.inRange(4.1, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
Assert.assertTrue(4.1 == ParamUtils.inRange(new DoubleRange(-3, 6), 4.1, "error"));
Assert.assertTrue(0 == ParamUtils.inRange(0L, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
Assert.assertTrue(0 == ParamUtils.inRange(0, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
Assert.assertTrue(0 == ParamUtils.inRange(new IntRange(-3, 6), 0, "error"));
Assert.assertTrue(0.0 == ParamUtils.inRange(0.0, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
Assert.assertTrue(0.0 == ParamUtils.inRange(new DoubleRange(-3, 6), 0.0, "error"));
Assert.assertTrue(0 == ParamUtils.inRange(0L, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
Assert.assertTrue(0 == ParamUtils.inRange(0, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
Assert.assertTrue(0 == ParamUtils.inRange(new IntRange(-3, 6), 0, "error"));
Assert.assertTrue(-1 == ParamUtils.inRange(-1L, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
Assert.assertTrue(-1 == ParamUtils.inRange(-1, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
Assert.assertTrue(-1 == ParamUtils.inRange(new IntRange(-3, 6), -1, "error"));
Assert.assertTrue(-1.5 == ParamUtils.inRange(-1.5, -3, 6, "Range calculation did not work properly"), "Did not return proper value");
Assert.assertTrue(-1.5 == ParamUtils.inRange(new DoubleRange(-3, 6), -1.5, "error"));
}
use of org.apache.commons.lang.math.IntRange in project pinot by linkedin.
the class GenerateDataCommand method execute.
@Override
public boolean execute() throws Exception {
LOGGER.info("Executing command: " + toString());
if ((_numRecords < 0) || (_numFiles < 0)) {
throw new RuntimeException("Cannot generate negative number of records/files.");
}
Schema schema = Schema.fromFile(new File(_schemaFile));
List<String> columns = new LinkedList<String>();
final HashMap<String, DataType> dataTypes = new HashMap<String, DataType>();
final HashMap<String, FieldType> fieldTypes = new HashMap<String, FieldType>();
final HashMap<String, TimeUnit> timeUnits = new HashMap<String, TimeUnit>();
final HashMap<String, Integer> cardinality = new HashMap<String, Integer>();
final HashMap<String, IntRange> range = new HashMap<String, IntRange>();
buildCardinalityRangeMaps(_schemaAnnFile, cardinality, range);
final DataGeneratorSpec spec = buildDataGeneratorSpec(schema, columns, dataTypes, fieldTypes, timeUnits, cardinality, range);
final DataGenerator gen = new DataGenerator();
gen.init(spec);
gen.generate(_numRecords, _numFiles);
return true;
}
use of org.apache.commons.lang.math.IntRange in project pinot by linkedin.
the class DataGenerator method init.
public void init(DataGeneratorSpec spec) throws IOException {
genSpec = spec;
outDir = new File(genSpec.getOutputDir());
if (outDir.exists() && !genSpec.isOverrideOutDir()) {
LOGGER.error("output directory already exists, and override is set to false");
throw new RuntimeException("output directory exists");
}
if (outDir.exists()) {
FileUtils.deleteDirectory(outDir);
}
outDir.mkdir();
for (final String column : genSpec.getColumns()) {
DataType dataType = genSpec.getDataTypesMap().get(column);
if (genSpec.getCardinalityMap().containsKey(column)) {
generators.put(column, GeneratorFactory.getGeneratorFor(dataType, genSpec.getCardinalityMap().get(column)));
} else if (genSpec.getRangeMap().containsKey(column)) {
IntRange range = genSpec.getRangeMap().get(column);
generators.put(column, GeneratorFactory.getGeneratorFor(dataType, range.getMinimumInteger(), range.getMaximumInteger()));
} else {
LOGGER.error("cardinality for this column does not exist : " + column);
throw new RuntimeException("cardinality for this column does not exist");
}
generators.get(column).init();
}
}
use of org.apache.commons.lang.math.IntRange in project intellij-elixir by KronicDeth.
the class Import method onlyCallDefinitionClauseCallFilter.
@NotNull
private static Function<Call, Boolean> onlyCallDefinitionClauseCallFilter(PsiElement element) {
final Map<String, List<Integer>> aritiesByName = aritiesByNameFromNameByArityKeywordList(element);
return new Function<Call, Boolean>() {
@Override
public Boolean fun(Call call) {
Pair<String, IntRange> callNameArityRange = nameArityRange(call);
boolean include = false;
if (callNameArityRange != null) {
String callName = callNameArityRange.first;
if (callName != null) {
List<Integer> arities = aritiesByName.get(callName);
if (arities != null) {
IntRange callArityRange = callNameArityRange.second;
for (int arity : arities) {
if (callArityRange.containsInteger(arity)) {
include = true;
break;
}
}
}
}
}
return include;
}
};
}
Aggregations