net.sf.webmancer.util.integerset
Class IntervalIntegerSetParser

java.lang.Object
  extended by net.sf.webmancer.util.integerset.IntervalIntegerSetParser
All Implemented Interfaces:
IIntegerSetParser

public class IntervalIntegerSetParser
extends java.lang.Object
implements IIntegerSetParser

This class parses string of a list of non-negative integers and creates a IIntegerSet from it. The recognized format is a list of non-negative integers delimited by colon (","), also intervals could be used. The delimiter of interval values is minus sign ("-"). Whitespaces are skipped.

Example: "-2,3,6-10,13,20-" results in a IIntegerSet that contains all numbers from minimum to 2 (inclusive), then also values 3, 6, 7, 8, 9, 10, 13 and all numbers from 20 (inclusive) to maximum.

Author:
Michal Burda

Constructor Summary
IntervalIntegerSetParser()
          Create new parser using boundaries from 0 to Integer.MAX_VALUE.
IntervalIntegerSetParser(int minimum, int maximum)
          Create new parser using given boundaries.
 
Method Summary
 IIntegerSet parse(java.lang.String str)
          Parse the given string to integer set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IntervalIntegerSetParser

public IntervalIntegerSetParser(int minimum,
                                int maximum)
Create new parser using given boundaries. Note that minimum must be lower or equal to maximum.

Parameters:
minimum - The minimum value (lower boundary for open intervals). The value must be non-negative since this parser does not support negative integers.
maximum - The maximum value (upper boundary for open intervals). A value of Integer.MAX_VALUE means "infinity".

IntervalIntegerSetParser

public IntervalIntegerSetParser()
Create new parser using boundaries from 0 to Integer.MAX_VALUE.

See Also:
IntervalIntegerSetParser(int, int)
Method Detail

parse

public IIntegerSet parse(java.lang.String str)
                  throws java.lang.NumberFormatException
Parse the given string to integer set.

Specified by:
parse in interface IIntegerSetParser
Parameters:
str - A string to be parsed
Returns:
An integer set corresponding to given list of integers in str
Throws:
java.lang.NumberFormatException - if any non-integer number is found
See Also:
cz.vsb.cs.ruleminer.util.integerset.IIntegerSetParser#parse(java.lang.String)


Copyright © 2006-2007. All Rights Reserved.