final private void addPositionFromToken ( MtasToken token , Long ref ) throws IOException { int prefixId = storePrefixAndTermRef ? token . getPrefixId ( ) : 0 ; if ( ! closed && ( token != null ) ) { if ( token . checkPositionType ( MtasPosition . POSITION_SINGLE ) ) { addSinglePoint ( token . getPositionStart ( ) , prefixId , token . getTermRef ( ) , token . getId ( ) , ref ) ; } else if ( token . checkPositionType ( MtasPosition . POSITION_RANGE ) ) { addRange ( token . getPositionStart ( ) , token . getPositionEnd ( ) , prefixId , token . getTermRef ( ) , token . getId ( ) , ref ) ; } else if ( token . checkPositionType ( MtasPosition . POSITION_SET ) ) { // split set into minimum number of single points and ranges SortedMap < Integer , Integer > list = new TreeMap <> ( ) ; int [ ] positions = token . getPositions ( ) ; Integer lastPoint = null ; Integer startPoint = null ; for ( int position : positions ) { if ( lastPoint == null ) { startPoint = position ; lastPoint = position ; } else if ( ( position - lastPoint ) != 1 ) { list . put ( startPoint , lastPoint ) ; startPoint = position ; } lastPoint = position ; } if ( lastPoint != null ) { list . put ( startPoint , lastPoint ) ; } for ( Entry < Integer , Integer > entry : list . entrySet ( ) ) { if ( entry . getKey ( ) . equals ( entry . getValue ( ) ) ) { addSinglePoint ( entry . getKey ( ) , prefixId , token . getTermRef ( ) , token . getId ( ) , ref ) ; } else { addRange ( entry . getKey ( ) , entry . getValue ( ) , prefixId , token . getTermRef ( ) , token . getId ( ) , ref ) ; } } } } }
Adds the position from token .