Example usage for org.apache.commons.lang.math IntRange IntRange

List of usage examples for org.apache.commons.lang.math IntRange IntRange

Introduction

In this page you can find the example usage for org.apache.commons.lang.math IntRange IntRange.

Prototype

public IntRange(Number number1, Number number2) 

Source Link

Document

Constructs a new IntRange with the specified minimum and maximum numbers (both inclusive).

The arguments may be passed in the order (min,max) or (max,min).

Usage

From source file:au.org.ala.delta.key.AllowImproperSubgroupsTest.java

public void testAllowImproperSubgroups() throws Exception {
    URL directivesFileURL = getClass().getResource("/sample/mykey");
    File directivesFile = new File(directivesFileURL.toURI());

    URL charFileURL = getClass().getResource("/sample/kchars");
    File charFile = new File(charFileURL.toURI());

    URL itemsFileURL = getClass().getResource("/sample/kitems");
    File itemsFile = new File(itemsFileURL.toURI());

    // Use dummy temp file for data directory seeing as we don't have a use
    // for it here
    KeyContext context = new KeyContext(directivesFile);
    context.setABase(1.0);/*from   ww w. ja v a 2s. c  om*/
    context.setVaryWt(1.0);
    context.setRBase(1.0);
    context.setReuse(1.0);
    context.setCharactersFile(charFile);
    context.setItemsFile(itemsFile);

    context.setAllowImproperSubgroups(false);

    KeyUtils.loadDataset(context);

    List<Integer> availableCharacterNumbers = Arrays
            .asList(ArrayUtils.toObject(new IntRange(1, context.getNumberOfCharacters()).toArray()));
    List<Integer> availableTaxaNumbers = Arrays
            .asList(ArrayUtils.toObject(new IntRange(1, context.getMaximumNumberOfItems()).toArray()));

    Map<Character, Double> bestMap = KeyBest.orderBest(context.getDataSet(), context.getCharacterCostsAsArray(),
            context.getCalculatedItemAbundanceValuesAsArray(), availableCharacterNumbers, availableTaxaNumbers,
            context.getRBase(), context.getABase(), context.getReuse(), context.getVaryWt(),
            context.getAllowImproperSubgroups());

    assertFalse(bestMap.containsKey(context.getCharacter(10)));

    context.setAllowImproperSubgroups(true);

    Map<Character, Double> bestMap2 = KeyBest.orderBest(context.getDataSet(),
            context.getCharacterCostsAsArray(), context.getCalculatedItemAbundanceValuesAsArray(),
            availableCharacterNumbers, availableTaxaNumbers, context.getRBase(), context.getABase(),
            context.getReuse(), context.getVaryWt(), context.getAllowImproperSubgroups());

    assertTrue(bestMap2.containsKey(context.getCharacter(10)));
}

From source file:com.linkedin.pinot.common.config.ColumnPartitionConfig.java

/**
 * Helper method to convert an array of ranges in string form (eg [2 3]) into a list
 * of {@link IntRange}. Expects each string range to be formatted correctly.
 *
 * @param inputs Array of ranges in string form.
 * @return List of IntRange's for the given input.
 *///w ww.  ja  v  a  2s .  c  o m
public static List<IntRange> rangesFromString(String[] inputs) {
    List<IntRange> ranges = new ArrayList<>(inputs.length);
    for (String input : inputs) {

        String trimmed = input.trim();
        String[] split = trimmed.split("\\s+");
        String startString = split[0].substring(1, split[0].length());
        String endString = split[1].substring(0, split[1].length() - 1);
        ranges.add(new IntRange(Integer.parseInt(startString), Integer.parseInt(endString)));
    }
    return ranges;
}

From source file:com.mobiquitynetworks.statsutilspig.CreateCombinations.java

public Map<Integer, Object> getVectors(Integer fieldsCardinality) {
    Map<Integer, Object> vectors = new HashMap<>();
    for (int i = 0; i < fieldsCardinality; i++) {
        int[] intArray = new IntRange(0, i).toArray();
        vectors.put(i + 1, intArray);/*www  . j  av a  2  s  . c om*/
    }
    return vectors;
}

From source file:edu.cornell.med.icb.goby.reads.TestQualityEncoding.java

/**
 * Validate score conversion for {@link edu.cornell.med.icb.goby.reads.QualityEncoding#SANGER}.
 *//*w ww  .jav a2  s.c om*/
@Test
public void sanger() {
    final Range qualityRange = new IntRange(0, 40);
    final String qualityChars = encodedQualityCharacters.substring(0, 40);
    final QualityEncoding encoding = QualityEncoding.SANGER;
    for (int i = 0; i < 40; i++) {
        final byte score = (byte) (qualityRange.getMinimumInteger() + i);
        assertEquals("wrong character for score " + score, qualityChars.charAt(i),
                encoding.phredQualityScoreToAsciiEncoding(score));
        assertEquals("wrong score for character " + qualityChars.charAt(i), score,
                encoding.asciiEncodingToPhredQualityScore(qualityChars.charAt(i)));
    }

    final QualityEncoding solexaEncoding = QualityEncoding.ILLUMINA;
    for (byte qPhred = 0; qPhred < 93; qPhred++) {
        final char sanger = solexaEncoding.phredQualityScoreToAsciiEncoding(qPhred);
        final byte roundTrip = solexaEncoding.asciiEncodingToPhredQualityScore(sanger);
        assertEquals(qPhred, roundTrip);

    }
}

From source file:au.org.ala.delta.directives.AbstractDirective.java

protected IntRange parseRange(String str) {
    Matcher m = RANGE_PATTERN.matcher(str);
    if (m.matches()) {
        int lhs = Integer.parseInt(m.group(1));
        int rhs = Integer.parseInt(m.group(2));
        return new IntRange(lhs, rhs);
    } else {/*  w  ww  .ja  va2 s  .co  m*/
        return new IntRange(Integer.parseInt(str));
    }
}

From source file:edu.harvard.med.screensaver.io.libraries.rnai.WorkbookLibraryContentsParser.java

public void convert() throws IOException {
    Workbook _workbook = new Workbook("Library Contents Input Stream", getStream());
    File tmpFile = File.createTempFile("workbook", ".csv");
    tmpFile.deleteOnExit();//from  www .ja v  a2s  . c  o m
    log.debug("converting workbook into csv file: " + tmpFile.getAbsolutePath());
    CSVPrintWriter writer = new CSVPrintWriter(new BufferedWriter(new FileWriter(tmpFile)), "\n",
            FIELD_DELIMITER);
    Iterator<Worksheet> worksheetsIterator = _workbook.iterator();
    int prevSheetLastRecord = 0;
    int record = 0;
    _worksheetRecordRanges = Maps.newHashMap();
    while (worksheetsIterator.hasNext()) {
        Worksheet worksheet = worksheetsIterator.next().forOrigin(0, FIRST_DATA_ROW);
        Iterator<Row> rowsIterator = worksheet.iterator();
        while (rowsIterator.hasNext()) {
            for (Cell cell : rowsIterator.next()) {
                writer.print(cell.getAsString());
            }
            writer.println();
            ++record;
        }
        IntRange worksheetRecordRange = new IntRange(prevSheetLastRecord, record);
        _worksheetRecordRanges.put(worksheetRecordRange, worksheet.getName());
        prevSheetLastRecord = record;
    }
    writer.close();
    _reader = new BufferedReader(new FileReader(tmpFile));
    log.debug("done converting workbook into csv file");
}

From source file:edu.cornell.med.icb.goby.reads.TestQualityEncoding.java

/**
 * Validate score conversion for//ww w. j a  va2  s  . c om
 * {@link edu.cornell.med.icb.goby.reads.QualityEncoding#ILLUMINA}.
 */
@Test
public void illumina() {
    final Range qualityRange = new IntRange(0, 40);
    final String qualityChars = encodedQualityCharacters.substring(31, 71);
    final QualityEncoding encoding = QualityEncoding.ILLUMINA;
    for (int i = 0; i < 40; i++) {
        final byte score = (byte) (qualityRange.getMinimumInteger() + i);
        assertEquals("wrong character for score " + score, qualityChars.charAt(i),
                encoding.phredQualityScoreToAsciiEncoding(score));
        assertEquals("wrong score for character " + qualityChars.charAt(i), score,
                encoding.asciiEncodingToPhredQualityScore(qualityChars.charAt(i)));
    }

    final QualityEncoding solexaEncoding = QualityEncoding.ILLUMINA;
    for (byte qPhred = 0; qPhred < 62; qPhred++) {
        final char illumina13 = solexaEncoding.phredQualityScoreToAsciiEncoding(qPhred);
        final byte roundTrip = solexaEncoding.asciiEncodingToPhredQualityScore(illumina13);
        assertEquals(qPhred, roundTrip);

    }
}

From source file:au.org.ala.delta.directives.args.DirectiveArgsParser.java

protected IntRange readIds(IntegerValidator validator) throws ParseException {
    int startPos = _position;
    int first = readInteger();
    validateId(first, validator, startPos);
    if (_currentChar == '-') {
        readNext();//from   w  w w  .ja v  a 2s. c o  m
        startPos = _position;
        int last = readInteger();
        validateId(last, validator, startPos);

        if (_validateRangeOrder && first > last) {
            throw DirectiveError.asException(DirectiveError.Error.RANGE_SEQUENCE_ERROR, startPos);
        }

        return new IntRange(first, last);
    }
    return new IntRange(first);
}

From source file:au.org.ala.delta.intkey.directives.ParsingUtils.java

public static IntRange parseIntRange(String text) {
    try {/*from   w  ww .  ja  va  2s.c o  m*/
        Matcher m = INT_RANGE_PATTERN.matcher(text);
        if (m.matches()) {
            int lhs = Integer.parseInt(m.group(1));
            int rhs = Integer.parseInt(m.group(2));
            return new IntRange(lhs, rhs);
        } else {
            return new IntRange(Integer.parseInt(text));
        }
    } catch (NumberFormatException ex) {
        return null;
    }
}

From source file:com.linkedin.pinot.core.segment.creator.impl.stats.AbstractColumnStatisticsCollector.java

/**
 * Returns the partition range within which the column values exist.
 *
 * @return List of ranges for the column values.
 *//*from  w  w  w .  j a v  a 2  s . c  o m*/
@Nullable
public List<IntRange> getPartitionRanges() {
    if (partitionRangeStart <= partitionRangeEnd) {
        return Arrays.asList(new IntRange(partitionRangeStart, partitionRangeEnd));
    } else {
        return null;
    }
}