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

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

Introduction

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

Prototype

public int getMaximumInteger() 

Source Link

Document

Gets the maximum number in this range as a int.

Usage

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

/**
 * Helper method to convert a list of {@link IntRange} to a delimited string.
 * The delimiter used is {@link #PARTITION_VALUE_DELIMITER}
 * @param ranges List of ranges to be converted to String.
 * @return String representation of the lis tof ranges.
 *///from   ww  w.ja va 2s . c  om
public static String rangesToString(List<IntRange> ranges) {
    StringBuilder builder = new StringBuilder();

    for (int i = 0; i < ranges.size(); i++) {
        builder.append("[");
        IntRange range = ranges.get(i);

        builder.append(range.getMinimumInteger());
        builder.append(" ");
        builder.append(range.getMaximumInteger());
        builder.append("]");

        if (i < ranges.size() - 1) {
            builder.append(PARTITION_VALUE_DELIMITER);
        }
    }
    return builder.toString();
}

From source file:edu.harvard.med.screensaver.util.CollectionUtils.java

public static List<IntRange> splitIntoSequentialRanges(SortedSet<Integer> integers) {
    List<IntRange> ranges = Lists.newArrayList();
    Iterator<Integer> iter = integers.iterator();
    if (iter.hasNext()) {
        IntRange range = new IntRange(iter.next());
        while (iter.hasNext()) {
            int next = iter.next();
            if (next - 1 == range.getMaximumInteger()) {
                range = new IntRange(range.getMinimumInteger(), next);
            } else {
                ranges.add(range);/* w  ww .  ja v  a  2s.c  o  m*/
                range = new IntRange(next);
            }
        }
        ranges.add(range);
    }
    return ranges;
}

From source file:au.org.ala.delta.rtf.RTFUtils.java

/**
 * Returns the index of the first non-RTF keyword character after the
 * specified index./*from   w  w w . j a va  2s  . c  o  m*/
 * 
 * @param text
 *            the text to check.
 * @param startPos
 *            the position in the text to start checking.
 */
public static int skipKeyword(String text, int startPos) {
    FirstRTFKeywordMarker handler = new FirstRTFKeywordMarker();
    RTFReader reader = new RTFReader(text.substring(startPos), handler);
    handler.setReader(reader);
    try {
        reader.parse();
    } catch (Exception ex) {
        // Ignore, and return the original text
        return -1;
    }
    IntRange firstKeyWordPos = handler.getFirstKeywordPosition();
    return firstKeyWordPos.getMaximumInteger() - 1;
}

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

@Override
public void parse(C context, String data) throws ParseException {
    args = new DirectiveArguments();
    String[] typeDescriptors = data.trim().split(" |\\n");
    for (String typeDescriptor : typeDescriptors) {
        typeDescriptor = typeDescriptor.trim();
        if (CHAR_LIST_ITEM_PATTERN.matcher(typeDescriptor).matches()) {
            String[] bits = typeDescriptor.trim().split(",");
            IntRange r = parseRange(bits[0]);

            for (int charNumber = r.getMinimumInteger(); charNumber <= r.getMaximumInteger(); ++charNumber) {
                addArgument(args, charNumber, bits[1]);
            }//w  w  w. j a v a2  s . c  o m
        }
    }
}

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

protected void forEach(IntRange range, C context, IntegerFunctor<C> func) {
    for (int i = range.getMinimumInteger(); i <= range.getMaximumInteger(); ++i) {
        if (func != null) {
            func.invoke(context, i);/*from  w  w  w  .j  av a2 s  .  co  m*/
        }
    }
}

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

private void parseOrderedMultistateChar(DirectiveArgument<Integer> arg) throws ParseException {
    IntRange states = readIds(null);
    arg.add(states.getMinimumInteger());
    arg.add(states.getMaximumInteger());
}

From source file:au.org.ala.delta.rtf.RTFUtilsTest.java

@Test
public void testMarkKeyword() {
    IntRange range = RTFUtils.markKeyword("\\i{}Ornithospermum\\i0{} Dumoulin, \\i{}Tema\\i0{} Adans.");
    assertEquals(0, range.getMinimumInteger());
    assertEquals(5, range.getMaximumInteger());

    range = RTFUtils.markKeyword("No keywords here");
    assertEquals(-1, range.getMinimumInteger());
    assertEquals(-1, range.getMaximumInteger());

    range = RTFUtils.markKeyword("Hi\\i there.");
    assertEquals(2, range.getMinimumInteger());
    assertEquals(6, range.getMaximumInteger());

    range = RTFUtils.markKeyword("Hi\\i ");
    assertEquals(2, range.getMinimumInteger());
    assertEquals(6, range.getMaximumInteger());
}

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

private CharacterType getType(IntRange charNums) throws ParseException {
    CharacterType type = _dataSet.getCharacter(charNums.getMinimumInteger()).getCharacterType();
    for (int i = charNums.getMaximumInteger() + 1; i < charNums.getMaximumInteger(); i++) {
        if (type != _dataSet.getCharacter(i).getCharacterType()) {
            throw DirectiveError.asException(DirectiveError.Error.CHARACTERS_MUST_BE_SAME_TYPE, _position);
        }//  w w  w .  ja v a  2s. c  o m
    }
    return type;
}

From source file:com.linkedin.pinot.tools.data.generator.DataGenerator.java

public void init(DataGeneratorSpec spec) throws IOException {
    genSpec = spec;// w  w w  .ja v  a2s .  c  o  m
    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();
    }
}

From source file:au.org.ala.delta.model.format.AttributeFormatter.java

private String formatIntegerAttribute(IntegerAttribute attribute) {
    StringBuilder builder = new StringBuilder();

    int minValue = attribute.getCharacter().getMinimumValue();
    int maxValue = attribute.getCharacter().getMaximumValue();

    // Need to determine if values below the minimum and or above the maximum are present - these are handled by outputting "or less" and "or more"
    boolean belowMinimumPresent = false;
    boolean aboveMaximumPresent = false;

    List<Integer> valuesCopy = new ArrayList<Integer>(attribute.getPresentValues());
    Collections.sort(valuesCopy);

    Set<Integer> belowMinAboveMaxValues = new HashSet<Integer>();
    for (int value : valuesCopy) {
        if (value < minValue) {
            belowMinimumPresent = true;/*from w ww .j  a  v a 2 s  .  co  m*/
            belowMinAboveMaxValues.add(value);
        } else if (value > maxValue) {
            aboveMaximumPresent = true;
            belowMinAboveMaxValues.add(value);
        }
    }

    // Remove any values above the maximum or below the minimum from the list as they will be handled specially.
    valuesCopy.removeAll(belowMinAboveMaxValues);

    List<IntRange> intRanges = new ArrayList<IntRange>();

    if (valuesCopy.size() == 1) {
        intRanges.add(new IntRange(valuesCopy.get(0), valuesCopy.get(0)));
    } else {
        int startCurrentRange = 0;
        for (int i = 0; i < valuesCopy.size(); i++) {
            int num = valuesCopy.get(i);
            if (i > 0) {
                int prevNum = valuesCopy.get(i - 1);

                if (num != prevNum + 1) {
                    intRanges.add(new IntRange(startCurrentRange, prevNum));
                    startCurrentRange = num;
                }

                if (i == valuesCopy.size() - 1) {
                    intRanges.add(new IntRange(startCurrentRange, num));
                }
            } else {
                startCurrentRange = num;
            }
        }
    }

    String orSeparator = getOrSeparator(attribute);

    if (belowMinimumPresent) {
        builder.append(String.format(_orLessCaption, Integer.toString(minValue - 1)));
        if (intRanges.size() > 0 || aboveMaximumPresent) {
            builder.append(orSeparator);
        }
    }

    for (int i = 0; i < intRanges.size(); i++) {
        IntRange range = intRanges.get(i);

        if (range.getMinimumInteger() == range.getMaximumInteger()) {
            builder.append(Integer.toString(range.getMinimumInteger()));
        } else {
            builder.append(Integer.toString(range.getMinimumInteger()) + "-"
                    + Integer.toString(range.getMaximumInteger()));
        }

        if (i != intRanges.size() - 1 || aboveMaximumPresent) {
            builder.append(orSeparator);
        }
    }

    if (aboveMaximumPresent) {
        builder.append(String.format(_orMoreCaption, Integer.toString(maxValue + 1)));
    }

    String units = attribute.getCharacter().getUnits();
    if (!StringUtils.isBlank(units)) {
        builder.append(" ");
        builder.append(units);
    }

    return defaultFormat(builder.toString());
}