public IPAddressSeqRange [ ] subtract ( IPAddressSeqRange other ) { IPAddress otherLower = other . getLower ( ) ; IPAddress otherUpper = other . getUpper ( ) ; IPAddress lower = this . getLower ( ) ; IPAddress upper = this . getUpper ( ) ; if ( compareLowValues ( lower , otherLower ) < 0 ) { if ( compareLowValues ( upper , otherUpper ) > 0 ) { // l ol ou u return createPair ( lower , otherLower . increment ( - 1 ) , otherUpper . increment ( 1 ) , upper ) ; } else { int comp = compareLowValues ( upper , otherLower ) ; if ( comp < 0 ) { // l u ol ou return createSingle ( ) ; } else if ( comp == 0 ) { // l u == ol ou return createSingle ( lower , upper . increment ( - 1 ) ) ; } return createSingle ( lower , otherLower . increment ( - 1 ) ) ; // l ol u ou } } else if ( compareLowValues ( otherUpper , upper ) >= 0 ) { // ol l u ou return createEmpty ( ) ; } else { int comp = compareLowValues ( otherUpper , lower ) ; if ( comp < 0 ) { return createSingle ( ) ; // ol ou l u } else if ( comp == 0 ) { return createSingle ( lower . increment ( 1 ) , upper ) ; //ol ou == l u } return createSingle ( otherUpper . increment ( 1 ) , upper ) ; // ol l ou u } }
Subtracts the given range from this range to produce either zero one or two address ranges that contain the addresses in this range and not in the given range . If the result has length 2 the two ranges are in increasing order .