private int [ ] getCompressIndexAndCount ( CompressOptions options , boolean createMixed ) { if ( options != null ) { CompressionChoiceOptions rangeSelection = options . rangeSelection ; RangeList compressibleSegs = rangeSelection . compressHost ( ) ? getZeroRangeSegments ( ) : getZeroSegments ( ) ; int maxIndex = - 1 , maxCount = 0 ; int segmentCount = getSegmentCount ( ) ; boolean compressMixed = createMixed && options . compressMixedOptions . compressMixed ( this ) ; boolean preferHost = ( rangeSelection == CompressOptions . CompressionChoiceOptions . HOST_PREFERRED ) ; boolean preferMixed = createMixed && ( rangeSelection == CompressOptions . CompressionChoiceOptions . MIXED_PREFERRED ) ; for ( int i = compressibleSegs . size ( ) - 1 ; i >= 0 ; i -- ) { Range range = compressibleSegs . getRange ( i ) ; int index = range . index ; int count = range . length ; if ( createMixed ) { //so here we shorten the range to exclude the mixed part if necessary int mixedIndex = IPv6Address . MIXED_ORIGINAL_SEGMENT_COUNT - addressSegmentIndex ; if ( ! compressMixed || index > mixedIndex || index + count < segmentCount ) { //range does not include entire mixed part. We never compress only part of a mixed part. //the compressible range must stop at the mixed part count = Math . min ( count , mixedIndex - index ) ; } } //select this range if is the longest if ( count > 0 && count >= maxCount && ( options . compressSingle || count > 1 ) ) { maxIndex = index ; maxCount = count ; } if ( preferHost && isPrefixed ( ) && ( ( index + count ) * IPv6Address . BITS_PER_SEGMENT ) > getNetworkPrefixLength ( ) ) { //this range contains the host //Since we are going backwards, this means we select as the maximum any zero segment that includes the host break ; } if ( preferMixed && index + count >= segmentCount ) { //this range contains the mixed section //Since we are going backwards, this means we select to compress the mixed segment break ; } } if ( maxIndex >= 0 ) { return new int [ ] { maxIndex , maxCount } ; } } return null ; }
Chooses a single segment to be compressed or null if no segment could be chosen .