Search in sources :

Example 11 with IntRange

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;
}
Also used : IntRange(org.apache.commons.lang.math.IntRange)

Example 12 with IntRange

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"));
}
Also used : DoubleRange(org.apache.commons.lang.math.DoubleRange) IntRange(org.apache.commons.lang.math.IntRange) Test(org.testng.annotations.Test)

Example 13 with IntRange

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;
}
Also used : HashMap(java.util.HashMap) Schema(com.linkedin.pinot.common.data.Schema) IntRange(org.apache.commons.lang.math.IntRange) LinkedList(java.util.LinkedList) FieldType(com.linkedin.pinot.common.data.FieldSpec.FieldType) DataGenerator(com.linkedin.pinot.tools.data.generator.DataGenerator) DataType(com.linkedin.pinot.common.data.FieldSpec.DataType) TimeUnit(java.util.concurrent.TimeUnit) File(java.io.File) DataGeneratorSpec(com.linkedin.pinot.tools.data.generator.DataGeneratorSpec)

Example 14 with IntRange

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();
    }
}
Also used : IntRange(org.apache.commons.lang.math.IntRange) DataType(com.linkedin.pinot.common.data.FieldSpec.DataType) File(java.io.File)

Example 15 with IntRange

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;
        }
    };
}
Also used : Function(com.intellij.util.Function) Call(org.elixir_lang.psi.call.Call) IntRange(org.apache.commons.lang.math.IntRange) ArrayList(java.util.ArrayList) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

IntRange (org.apache.commons.lang.math.IntRange)31 Call (org.elixir_lang.psi.call.Call)10 PsiElement (com.intellij.psi.PsiElement)6 File (java.io.File)6 Nullable (org.jetbrains.annotations.Nullable)6 ArrayList (java.util.ArrayList)5 NotNull (org.jetbrains.annotations.NotNull)4 Test (org.testng.annotations.Test)4 Pair (com.intellij.openapi.util.Pair)3 DataType (com.linkedin.pinot.common.data.FieldSpec.DataType)3 DataGeneratorSpec (com.linkedin.pinot.tools.data.generator.DataGeneratorSpec)3 List (java.util.List)3 AtUnqualifiedNoParenthesesCall (org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall)3 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)2 PsiReference (com.intellij.psi.PsiReference)2 FieldSpec (com.linkedin.pinot.common.data.FieldSpec)2 FieldType (com.linkedin.pinot.common.data.FieldSpec.FieldType)2 DataGenerator (com.linkedin.pinot.tools.data.generator.DataGenerator)2 HashMap (java.util.HashMap)2 TimeUnit (java.util.concurrent.TimeUnit)2