public static List expand ( String ranges , int maxNumber ) { SequenceList parse = new SequenceList ( ranges ) ; LinkedList list = new LinkedList ( ) ; boolean sair = false ; while ( ! sair ) { sair = parse . getAttributes ( ) ; if ( parse . low == - 1 && parse . high == - 1 && ! parse . even && ! parse . odd ) continue ; if ( parse . low < 1 ) parse . low = 1 ; if ( parse . high < 1 || parse . high > maxNumber ) parse . high = maxNumber ; if ( parse . low > maxNumber ) parse . low = maxNumber ; //System.out.println("low="+parse.low+",high="+parse.high+",odd="+parse.odd+",even="+parse.even+",inverse="+parse.inverse); int inc = 1 ; if ( parse . inverse ) { if ( parse . low > parse . high ) { int t = parse . low ; parse . low = parse . high ; parse . high = t ; } for ( ListIterator it = list . listIterator ( ) ; it . hasNext ( ) ; ) { int n = ( ( Integer ) it . next ( ) ) . intValue ( ) ; if ( parse . even && ( n & 1 ) == 1 ) continue ; if ( parse . odd && ( n & 1 ) == 0 ) continue ; if ( n >= parse . low && n <= parse . high ) it . remove ( ) ; } } else { if ( parse . low > parse . high ) { inc = - 1 ; if ( parse . odd || parse . even ) { -- inc ; if ( parse . even ) parse . low &= ~ 1 ; else parse . low -= ( ( parse . low & 1 ) == 1 ? 0 : 1 ) ; } for ( int k = parse . low ; k >= parse . high ; k += inc ) list . ( Integer . valueOf ( k ) ) ; } else { if ( parse . odd || parse . even ) { ++ inc ; if ( parse . odd ) parse . low |= 1 ; else parse . low += ( ( parse . low & 1 ) == 1 ? 1 : 0 ) ; } for ( int k = parse . low ; k <= parse . high ; k += inc ) { list . add ( Integer . valueOf ( k ) ) ; } } } } return list ; }
Generates a list of numbers from a string .