private Range getRange ( final URI uri ) { int start = 0 ; int end = Integer . MAX_VALUE ; String startId = null ; String endId = null ; final String fragment = uri . getFragment ( ) ; if ( fragment != null ) { // RFC 5147 final Matcher m = Pattern . compile ( "^line=(?:(\\d+)|(\\d+)?,(\\d+)?)$" ) . matcher ( fragment ) ; if ( m . matches ( ) ) { if ( m . group ( 1 ) != null ) { start = Integer . parseInt ( m . group ( 1 ) ) ; end = start ; } else { if ( m . group ( 2 ) != null ) { start = Integer . parseInt ( m . group ( 2 ) ) ; } if ( m . group ( 3 ) != null ) { end = Integer . parseInt ( m . group ( 3 ) ) - 1 ; } } return new LineNumberRange ( start , end ) . handler ( this ) ; } else { final Matcher mc = Pattern . compile ( "^line-range\\((\\d+)(?:,\\s*(\\d+))?\\)$" ) . matcher ( fragment ) ; if ( mc . matches ( ) ) { start = Integer . parseInt ( mc . group ( 1 ) ) - 1 ; if ( mc . group ( 2 ) != null ) { end = Integer . parseInt ( mc . group ( 2 ) ) - 1 ; } return new LineNumberRange ( start , end ) . handler ( this ) ; } else { final Matcher mi = Pattern . compile ( "^token=([^,\\s)]*)(?:,\\s*([^,\\s)]+))?$" ) . matcher ( fragment ) ; if ( mi . matches ( ) ) { if ( mi . group ( 1 ) != null && mi . group ( 1 ) . length ( ) != 0 ) { startId = mi . group ( 1 ) ; } if ( mi . group ( 2 ) != null ) { endId = mi . group ( 2 ) ; } return new AnchorRange ( startId , endId ) . handler ( this ) ; } } } } return new AllRange ( ) . handler ( this ) ; }
Factory method for Range implementation