private IPv6AddressPool doAllocate(final IPv6Network toAllocate, final IPv6AddressRange rangeToAllocateFrom)
    {
        assert freeRanges.contains(rangeToAllocateFrom);
        assert rangeToAllocateFrom.contains(toAllocate);

        final TreeSet<IPv6AddressRange> newFreeRanges = new TreeSet<IPv6AddressRange>(this.freeRanges);

        // remove range from free ranges
        newFreeRanges.remove(rangeToAllocateFrom);

        // from the range, remove the allocated subnet
        final List<IPv6AddressRange> newRanges = rangeToAllocateFrom.remove(toAllocate);

        // and add the resulting ranges as new free ranges
        newFreeRanges.addAll(newRanges);

        return new IPv6AddressPool(underlyingRange, allocationSubnetSize, newFreeRanges, toAllocate);
    }
private IPv6AddressPool doAllocate ( final IPv6Network toAllocate , final IPv6AddressRange rangeToAllocateFrom ) { assert freeRanges . contains ( rangeToAllocateFrom ) ; assert rangeToAllocateFrom . contains ( toAllocate ) ; final TreeSet < IPv6AddressRange > newFreeRanges = new TreeSet < IPv6AddressRange > ( this . freeRanges ) ; newFreeRanges . remove ( rangeToAllocateFrom ) ; final List < IPv6AddressRange > newRanges = rangeToAllocateFrom . remove ( toAllocate ) ; newFreeRanges . addAll ( newRanges ) ; return new IPv6AddressPool ( underlyingRange , allocationSubnetSize , newFreeRanges , toAllocate ) ; }
Private helper method to perform the allocation of a subnet within one of the free ranges.

@param toAllocate          subnet to allocate
@param rangeToAllocateFrom free range to allocate from
@return resulting pool