public IPv6Address maskWithNetworkMask ( final IPv6NetworkMask networkMask ) { if ( networkMask . asPrefixLength ( ) == 128 ) { return this ; } else if ( networkMask . asPrefixLength ( ) == 64 ) { return new IPv6Address ( this . highBits , 0 ) ; } else if ( networkMask . asPrefixLength ( ) == 0 ) { return new IPv6Address ( 0 , 0 ) ; } else if ( networkMask . asPrefixLength ( ) > 64 ) { // apply mask on low bits only final int remainingPrefixLength = networkMask . asPrefixLength ( ) - 64 ; return new IPv6Address ( this . highBits , this . lowBits & ( 0xFFFFFFFFFFFFFFFF L << ( 64 - remainingPrefixLength ) ) ) ; } else { // apply mask on high bits, low bits completely 0 return new IPv6Address ( this . highBits & ( 0xFFFFFFFFFFFFFFFF L << ( 64 - networkMask . asPrefixLength ( ) ) ) , 0 ) ; } }
Mask the address with the given network mask .