private static void validateNetworkMask(IPv6Address addressToValidate) { final BitSet addressAsBitSet = bitSetOf(addressToValidate.getLowBits(), addressToValidate.getHighBits()); boolean firstZeroFound = false; for (int i = 127; i >= 0 && !firstZeroFound; i--) { if (!addressAsBitSet.get(i)) { firstZeroFound = true; // a zero -> all the others should also be zero for (int j = i - 1; j >= 0; j--) { if (addressAsBitSet.get(j)) { throw new IllegalArgumentException(addressToValidate + " is not a valid network mask"); } } } } }
public int numberOfTrailingOnes() { // count trailing ones in "value" by counting the trailing zeroes in "value + 1" final IPv6Address plusOne = this.add(1); return plusOne.getLowBits() == 0 ? Long.numberOfTrailingZeros(plusOne.getHighBits()) + 64 : Long.numberOfTrailingZeros(plusOne.getLowBits()); }
private static void validateNetworkMask(IPv6Address addressToValidate) { final BitSet addressAsBitSet = bitSetOf(addressToValidate.getLowBits(), addressToValidate.getHighBits()); boolean firstZeroFound = false; for (int i = 127; i >= 0 && !firstZeroFound; i--) { if (!addressAsBitSet.get(i)) { firstZeroFound = true; // a zero -> all the others should also be zero for (int j = i - 1; j >= 0; j--) { if (addressAsBitSet.get(j)) { throw new IllegalArgumentException(addressToValidate + " is not a valid network mask"); } } } } }
public int numberOfTrailingOnes() { // count trailing ones in "value" by counting the trailing zeroes in "value + 1" final IPv6Address plusOne = this.add(1); return plusOne.getLowBits() == 0 ? Long.numberOfTrailingZeros(plusOne.getHighBits()) + 64 : Long.numberOfTrailingZeros(plusOne.getLowBits()); }
static int longestPrefixLength(IPv6Address first, IPv6Address last) { final BitSet firstBits = bitSetOf(first.getLowBits(), first.getHighBits()); final BitSet lastBits = bitSetOf(last.getLowBits(), last.getHighBits()); return countLeadingSimilarBits(firstBits, lastBits); }
static int longestPrefixLength(IPv6Address first, IPv6Address last) { final BitSet firstBits = bitSetOf(first.getLowBits(), first.getHighBits()); final BitSet lastBits = bitSetOf(last.getLowBits(), last.getHighBits()); return countLeadingSimilarBits(firstBits, lastBits); }