public static String getNextIp6InRange(final String currentIp, final String ipRange) { final String[] ips = ipRange.split("-"); final String startIp = ips[0]; String endIp = null; if (ips.length > 1) { endIp = ips[1]; } final IPv6Address start = IPv6Address.fromString(startIp); final IPv6Address end = IPv6Address.fromString(endIp); final IPv6Address current = IPv6Address.fromString(currentIp); IPv6Address result = null; if (current.equals(end)) { result = start; } else { result = current.add(1); } String resultIp = null; if (result != null) { resultIp = result.toString(); } return resultIp; }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof IPv6AddressRange)) return false; IPv6AddressRange that = (IPv6AddressRange) o; if (first != null ? !first.equals(that.first) : that.first != null) return false; if (last != null ? !last.equals(that.last) : that.last != null) return false; return true; }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof IPv6AddressRange)) return false; IPv6AddressRange that = (IPv6AddressRange) o; if (first != null ? !first.equals(that.first) : that.first != null) return false; if (last != null ? !last.equals(that.last) : that.last != null) return false; return true; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; IPv6Network that = (IPv6Network) o; if (address != null ? !address.equals(that.address) : that.address != null) return false; if (networkMask != null ? !networkMask.equals(that.networkMask) : that.networkMask != null) return false; return true; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; IPv6Network that = (IPv6Network) o; if (address != null ? !address.equals(that.address) : that.address != null) return false; if (networkMask != null ? !networkMask.equals(that.networkMask) : that.networkMask != null) return false; return true; }
/** * The natural order of {@link com.googlecode.ipv6.IPv6AddressRange}s orders them on increasing first addresses, and on increasing last * address if the first address would be equal. * <p> * Note that the natural order does thus not compare sizes of ranges. * * @param that range to compare with * @return negative, zero or positive depending on whether this is smaller, equal or greater than that */ @Override public int compareTo(IPv6AddressRange that) { if (!this.first.equals(that.first)) return this.first.compareTo(that.first); else return this.last.compareTo(that.last); }
/** * The natural order of {@link com.googlecode.ipv6.IPv6AddressRange}s orders them on increasing first addresses, and on increasing last * address if the first address would be equal. * <p> * Note that the natural order does thus not compare sizes of ranges. * * @param that range to compare with * @return negative, zero or positive depending on whether this is smaller, equal or greater than that */ @Override public int compareTo(IPv6AddressRange that) { if (!this.first.equals(that.first)) return this.first.compareTo(that.first); else return this.last.compareTo(that.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 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)); }
/** * Private helper method to find the free range just before the given network. */ private IPv6AddressRange findFreeRangeBefore(IPv6Network network) { for (IPv6AddressRange freeRange : freeRanges) { if (freeRange.getLast().add(1).equals(network.getFirst())) { 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; }
/** * Private helper method to find the free range just before the given network. */ private IPv6AddressRange findFreeRangeBefore(IPv6Network network) { for (IPv6AddressRange freeRange : freeRanges) { if (freeRange.getLast().add(1).equals(network.getFirst())) { 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; }
public static String getNextIp6InRange(final String currentIp, final String ipRange) { final String[] ips = ipRange.split("-"); final String startIp = ips[0]; String endIp = null; if (ips.length > 1) { endIp = ips[1]; } final IPv6Address start = IPv6Address.fromString(startIp); final IPv6Address end = IPv6Address.fromString(endIp); final IPv6Address current = IPv6Address.fromString(currentIp); IPv6Address result = null; if (current.equals(end)) { result = start; } else { result = current.add(1); } String resultIp = null; if (result != null) { resultIp = result.toString(); } return resultIp; }
/** * 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)); }
while (step < 128 && !(base.setBit(step)).equals(base))
while (step < 128 && !(base.setBit(step)).equals(base))