public Pair < List < Node > , List < Node > > splitIntervalPattern ( String raw ) { List < Node > pattern = parse ( raw ) ; Set < Character > seen = new HashSet <> ( ) ; List < Node > fst = new ArrayList <> ( ) ; List < Node > snd = new ArrayList <> ( ) ; // Indicates we've seen a repeated field. boolean boundary = false ; for ( Node node : pattern ) { if ( node instanceof Field ) { char ch = ( ( Field ) node ) . ch ( ) ; if ( seen . contains ( ch ) ) { boundary = true ; } else { seen . add ( ch ) ; } } if ( boundary ) { snd . add ( node ) ; } else { fst . add ( node ) ; } } return Pair . pair ( fst , snd ) ; }
Looks for the first repeated field in the pattern splitting it into two parts on that boundary .