@Test public void testAdd() throws Exception { assertAdd("192.168.1.43", "-24", "192.168.1.19"); assertAdd("fe80::20e:c00:fe33:d204", "1095216660480", "fe80::20e:cff:fe33:d204"); assertAdd("fe80::20e:cff:fe33:d204", "-4261412864", "fe80::20e:cff:0033:d204"); assertAdd("fe00::20e:cff:fe33:d204", "664613997892457936451903530140172288", "fe80::20e:cff:fe33:d204"); assertAdd("fe80::20e:cff:fe33:d204", null, null); assertAddNegative("192.168.1.43", "-664613997892457936451903530140172288"); assertAddNegative("192.168.1.43", "664613997892457936451903530140172288"); }
public IPTarget add(BigInteger offset) { if(offset == null) { return null; } if(offset.compareTo(BigInteger.ZERO) == 0) { return new IPTarget(this); } BigInteger a = new BigInteger(1, this.addr); byte[] ip = new byte[addr.length]; BigInteger bi = a.add(offset); if(bi.compareTo(BigInteger.ZERO) < 0 || !v6 && bi.compareTo(MAX_V4_VALUE) > 0 || v6 && bi.compareTo(MAX_V6_VALUE) > 0) { throw new IllegalArgumentException("Cannot add value " + offset + " from " + this + " - result is out of range"); } byte[] b = bi.toByteArray(); System.arraycopy(b, (b.length == ip.length + 1) ? 1 : 0, ip, 0, ip.length); return new IPTarget(ip); }
IPTarget extends PGinet implements Serializable, Cloneable, Comparable<IPTarget> { public IPTarget add(BigInteger offset) { if(offset == null) { return null; } if(offset.compareTo(BigInteger.ZERO) == 0) { return new IPTarget(this); } BigInteger a = new BigInteger(1, this.addr); byte[] ip = new byte[addr.length]; BigInteger bi = a.add(offset); if(bi.compareTo(BigInteger.ZERO) < 0 || !v6 && bi.compareTo(MAX_V4_VALUE) > 0 || v6 && bi.compareTo(MAX_V6_VALUE) > 0) { throw new IllegalArgumentException("Cannot add value " + offset + " from " + this + " - result is out of range"); } byte[] b = bi.toByteArray(); System.arraycopy(b, (b.length == ip.length + 1) ? 1 : 0, ip, 0, ip.length); return new IPTarget(ip); } }
IPTarget extends PGinet implements Serializable, Cloneable, Comparable<IPTarget> { public IPTarget add(BigInteger offset) { if(offset == null) { return null; } if(offset.compareTo(BigInteger.ZERO) == 0) { return new IPTarget(this); } BigInteger a = new BigInteger(1, this.addr); byte[] ip = new byte[addr.length]; BigInteger bi = a.add(offset); if(bi.compareTo(BigInteger.ZERO) < 0 || !v6 && bi.compareTo(MAX_V4_VALUE) > 0 || v6 && bi.compareTo(MAX_V6_VALUE) > 0) { throw new IllegalArgumentException("Cannot add value " + offset + " from " + this + " - result is out of range"); } byte[] b = bi.toByteArray(); System.arraycopy(b, (b.length == ip.length + 1) ? 1 : 0, ip, 0, ip.length); return new IPTarget(ip); } IPTarget();  IPTarget(PGinet ip);  IPTarget(byte[] address);  IPTarget(String ip); }
IPTarget extends PGinet implements Serializable, Cloneable, Comparable<IPTarget> { public IPTarget add(BigInteger offset) { if(offset == null) { return null; } if(offset.compareTo(BigInteger.ZERO) == 0) { return new IPTarget(this); } BigInteger a = new BigInteger(1, this.addr); byte[] ip = new byte[addr.length]; BigInteger bi = a.add(offset); if(bi.compareTo(BigInteger.ZERO) < 0 || !v6 && bi.compareTo(MAX_V4_VALUE) > 0 || v6 && bi.compareTo(MAX_V6_VALUE) > 0) { throw new IllegalArgumentException("Cannot add value " + offset + " from " + this + " - result is out of range"); } byte[] b = bi.toByteArray(); System.arraycopy(b, (b.length == ip.length + 1) ? 1 : 0, ip, 0, ip.length); return new IPTarget(ip); } IPTarget();  IPTarget(PGinet ip);  IPTarget(byte[] address);  IPTarget(String ip); final void init(); @Override void setValue(String v); InetAddress getHost(); byte[] getAddr(); void setHost(InetAddress host); boolean isV6(); void setV6(boolean v6); @Override boolean equals(Object obj); @Override int hashCode(); @Override int compareTo(IPTarget o); byte[] getMAC(); InetAddress getUnicastPrefixMCAddress(); IPTarget getPrevious(); IPTarget getNext(); IPTarget getEmbeddedIPv4(); BigInteger subtract(IPTarget ip); IPTarget subtract(BigInteger offset); IPTarget subtract(long offset); IPTarget add(BigInteger offset); IPTarget add(long offset); boolean isMulticast(); boolean isMulticastGlobal(); boolean isMulticastLinkLocal(); boolean isMulticastNodeLocal(); boolean isMulticastOrgLocal(); boolean isMulticastSiteLocal(); boolean isLinkLocal(); boolean isAnyLocal(); boolean isLoopback(); @Override String toString(); }
IPTarget extends PGinet implements Serializable, Cloneable, Comparable<IPTarget> { public IPTarget add(BigInteger offset) { if(offset == null) { return null; } if(offset.compareTo(BigInteger.ZERO) == 0) { return new IPTarget(this); } BigInteger a = new BigInteger(1, this.addr); byte[] ip = new byte[addr.length]; BigInteger bi = a.add(offset); if(bi.compareTo(BigInteger.ZERO) < 0 || !v6 && bi.compareTo(MAX_V4_VALUE) > 0 || v6 && bi.compareTo(MAX_V6_VALUE) > 0) { throw new IllegalArgumentException("Cannot add value " + offset + " from " + this + " - result is out of range"); } byte[] b = bi.toByteArray(); System.arraycopy(b, (b.length == ip.length + 1) ? 1 : 0, ip, 0, ip.length); return new IPTarget(ip); } IPTarget();  IPTarget(PGinet ip);  IPTarget(byte[] address);  IPTarget(String ip); final void init(); @Override void setValue(String v); InetAddress getHost(); byte[] getAddr(); void setHost(InetAddress host); boolean isV6(); void setV6(boolean v6); @Override boolean equals(Object obj); @Override int hashCode(); @Override int compareTo(IPTarget o); byte[] getMAC(); InetAddress getUnicastPrefixMCAddress(); IPTarget getPrevious(); IPTarget getNext(); IPTarget getEmbeddedIPv4(); BigInteger subtract(IPTarget ip); IPTarget subtract(BigInteger offset); IPTarget subtract(long offset); IPTarget add(BigInteger offset); IPTarget add(long offset); boolean isMulticast(); boolean isMulticastGlobal(); boolean isMulticastLinkLocal(); boolean isMulticastNodeLocal(); boolean isMulticastOrgLocal(); boolean isMulticastSiteLocal(); boolean isLinkLocal(); boolean isAnyLocal(); boolean isLoopback(); @Override String toString(); static final InetAddress MAX_V4_ADDRESS; static final BigInteger MAX_V4_VALUE; static final InetAddress MAX_V6_ADDRESS; static final BigInteger MAX_V6_VALUE; }