/** * Private helper method to find the free range just after the given address. */ private IPv6AddressRange findFreeRangeAfter(IPv6Network network) { for (IPv6AddressRange freeRange : freeRanges) { if (freeRange.getFirst().subtract(1).equals(network.getLast())) { return freeRange; } } // not found return null; }
/** * Private helper method to find the free range just after the given address. */ private IPv6AddressRange findFreeRangeAfter(IPv6Network network) { for (IPv6AddressRange freeRange : freeRanges) { if (freeRange.getFirst().subtract(1).equals(network.getLast())) { return freeRange; } } // not found return null; }
/** * Remove an address from the range, resulting in one, none or two new ranges. If an address outside the range is removed, this has no * effect. If the first or last address is removed, a single new range is returned (potentially empty if the range only contained a * single address). If an address somewhere else in the range is removed, two new ranges are returned. * * @param address adddress to remove from the range * @return list of resulting ranges */ public List<IPv6AddressRange> remove(IPv6Address address) { if (address == null) throw new IllegalArgumentException("invalid address [null]"); if (!contains(address)) return Collections.singletonList(this); else if (address.equals(first) && address.equals(last)) return Collections.emptyList(); else if (address.equals(first)) return Collections.singletonList(fromFirstAndLast(first.add(1), last)); else if (address.equals(last)) return Collections.singletonList(fromFirstAndLast(first, last.subtract(1))); else return Arrays.asList(fromFirstAndLast(first, address.subtract(1)), fromFirstAndLast(address.add(1), last)); }
/** * Remove an address from the range, resulting in one, none or two new ranges. If an address outside the range is removed, this has no * effect. If the first or last address is removed, a single new range is returned (potentially empty if the range only contained a * single address). If an address somewhere else in the range is removed, two new ranges are returned. * * @param address adddress to remove from the range * @return list of resulting ranges */ public List<IPv6AddressRange> remove(IPv6Address address) { if (address == null) throw new IllegalArgumentException("invalid address [null]"); if (!contains(address)) return Collections.singletonList(this); else if (address.equals(first) && address.equals(last)) return Collections.emptyList(); else if (address.equals(first)) return Collections.singletonList(fromFirstAndLast(first.add(1), last)); else if (address.equals(last)) return Collections.singletonList(fromFirstAndLast(first, last.subtract(1))); else return Arrays.asList(fromFirstAndLast(first, address.subtract(1)), fromFirstAndLast(address.add(1), last)); }
/** * Remove a network from the range, resulting in one, none or two new ranges. If a network outside (or partially outside) the range is * removed, this has no effect. If the network which is removed is aligned with the beginning or end of the range, a single new ranges * is returned (potentially empty if the range was equal to the network which is removed from it). If a network somewhere else in the * range is removed, two new ranges are returned. * * @param network network to remove from the range * @return list of resulting ranges */ public List<IPv6AddressRange> remove(IPv6Network network) { if (network == null) throw new IllegalArgumentException("invalid network [null]"); if (!contains(network)) return Collections.singletonList(this); else if (this.equals(network)) return Collections.emptyList(); else if (first.equals(network.getFirst())) return Collections.singletonList(fromFirstAndLast(network.getLast().add(1), last)); else if (last.equals(network.getLast())) return Collections.singletonList(fromFirstAndLast(first, network.getFirst().subtract(1))); else return Arrays.asList(fromFirstAndLast(first, network.getFirst().subtract(1)), fromFirstAndLast(network.getLast().add(1), last)); }
/** * Remove a network from the range, resulting in one, none or two new ranges. If a network outside (or partially outside) the range is * removed, this has no effect. If the network which is removed is aligned with the beginning or end of the range, a single new ranges * is returned (potentially empty if the range was equal to the network which is removed from it). If a network somewhere else in the * range is removed, two new ranges are returned. * * @param network network to remove from the range * @return list of resulting ranges */ public List<IPv6AddressRange> remove(IPv6Network network) { if (network == null) throw new IllegalArgumentException("invalid network [null]"); if (!contains(network)) return Collections.singletonList(this); else if (this.equals(network)) return Collections.emptyList(); else if (first.equals(network.getFirst())) return Collections.singletonList(fromFirstAndLast(network.getLast().add(1), last)); else if (last.equals(network.getLast())) return Collections.singletonList(fromFirstAndLast(first, network.getFirst().subtract(1))); else return Arrays.asList(fromFirstAndLast(first, network.getFirst().subtract(1)), fromFirstAndLast(network.getLast().add(1), last)); }