Java Code Examples for inet.ipaddr.IPAddress#equals()
The following examples show how to use
inet.ipaddr.IPAddress#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IPAddressProvider.java From IPAddress with Apache License 2.0 | 6 votes |
/** * When a value provider produces no value, equality and comparison are based on the enum IPType, * which can by null. * @param o * @return */ default boolean providerEquals(IPAddressProvider other) throws IncompatibleAddressException { if(this == other) { return true; } IPAddress value = getProviderAddress(); if(value != null) { IPAddress otherValue = other.getProviderAddress(); if(otherValue != null) { return value.equals(otherValue); } else { return false; } } //this works with both null and also non-null since the type is an enum return getType() == other.getType(); }
Example 2
Source File: HostTest.java From IPAddress with Apache License 2.0 | 6 votes |
void testMasked(String masked, String mask, Integer prefixLength, String result) { HostName maskedHostStr = createHost(masked); IPAddress maskAddr = mask != null ? createAddress(mask).getAddress() : null; if(result != null) { IPAddress resultAddr = createAddress(result).getAddress(); IPAddress maskedAddr = maskedHostStr.getAddress(); if(!maskedAddr.equals(resultAddr)) { addFailure(new Failure("masked " + maskedAddr + " instead of expected " + resultAddr, maskedAddr)); } } if(!Objects.equals(maskAddr, maskedHostStr.getMask())) { addFailure(new Failure("masked " + maskAddr + " instead of expected " + maskedHostStr.getMask(), maskedHostStr)); } if(!Objects.equals(maskedHostStr.getNetworkPrefixLength(), prefixLength)) { addFailure(new Failure("masked prefix length was " + maskedHostStr.getNetworkPrefixLength() + " instead of expected " + prefixLength, maskedHostStr)); } incrementTestCount(); }
Example 3
Source File: TestBase.java From IPAddress with Apache License 2.0 | 6 votes |
boolean confirmAddrStrings(IPAddress ipAddr, String ...strs) { for(String str : strs) { if(str == null) { continue; } IPAddressString addrString = createAddress(str, DEFAULT_BASIC_VALIDATION_OPTIONS); IPAddress addr = addrString.getAddress(); if(!ipAddr.equals(addr)) { addFailure(new Failure("failed produced string: " + str, ipAddr)); addrString = createAddress(str, DEFAULT_BASIC_VALIDATION_OPTIONS); addrString.getAddress(); return false; } } incrementTestCount(); return true; }
Example 4
Source File: TestBase.java From IPAddress with Apache License 2.0 | 6 votes |
boolean confirmHostStrings(IPAddress ipAddr, boolean omitZone, String ...strs) { for(String str : strs) { HostName hostName = new HostName(str); IPAddress a = hostName.getAddress(); if(omitZone) { IPv6Address ipv6Addr = ipAddr.toIPv6(); ipAddr = new IPv6Address(ipv6Addr.getSection()); } if(!ipAddr.equals(a)) { addFailure(new Failure("failed produced string: " + str, ipAddr)); return false; } String again = hostName.toNormalizedString(); hostName = new HostName(again); a = hostName.getAddress(); if(!ipAddr.equals(a)) { addFailure(new Failure("failed produced string: " + str, ipAddr)); return false; } } incrementTestCount(); return true; }
Example 5
Source File: TestBase.java From IPAddress with Apache License 2.0 | 6 votes |
boolean confirmHostStrings(IPAddress ipAddr, HostName ...strs) { for(HostName str : strs) { IPAddress a = str.getAddress(); if(!ipAddr.equals(a)) { addFailure(new Failure("failed produced string: " + str, ipAddr)); return false; } String again = str.toNormalizedString(); str = new HostName(again); a = str.getAddress(); if(!ipAddr.equals(a)) { addFailure(new Failure("failed produced string: " + str, ipAddr)); return false; } } incrementTestCount(); return true; }
Example 6
Source File: TestBase.java From IPAddress with Apache License 2.0 | 6 votes |
void testHostAddress(String addressStr) { IPAddressString str = createAddress(addressStr); IPAddress address = str.getAddress(); if(address != null) { IPAddress hostAddress = str.getHostAddress(); int prefixIndex = addressStr.indexOf(IPAddress.PREFIX_LEN_SEPARATOR); if(prefixIndex < 0) { if(!address.equals(hostAddress) || !address.contains(hostAddress)) { addFailure(new Failure("failed host address with no prefix: " + hostAddress + " expected: " + address, str)); } } else { String substr = addressStr.substring(0, prefixIndex); IPAddressString str2 = createAddress(substr); IPAddress address2 = str2.getAddress(); if(!address2.equals(hostAddress)) { addFailure(new Failure("failed host address: " + hostAddress + " expected: " + address2, str)); } } } }
Example 7
Source File: SpecialTypesTest.java From IPAddress with Apache License 2.0 | 6 votes |
void testAllValues(IPVersion version, BigInteger count) { HostName hostAll = createHost("*", HOST_OPTIONS); IPAddressString addressAllStr = createAddress("*", ADDRESS_OPTIONS); IPAddress addressAll = addressAllStr.getAddress(version); String address2Str = version.isIPv4() ? "*.*.*.*" : "*:*:*:*:*:*:*:*"; IPAddress address = createAddress(address2Str, ADDRESS_OPTIONS).getAddress(); if(!addressAll.equals(address)) { addFailure(new Failure("no match " + address, addressAll)); } else if(addressAll.compareTo(address) != 0) { addFailure(new Failure("no match " + address, addressAll)); } else if(!addressAll.getCount().equals(count)) { addFailure(new Failure("no count match ", addressAll)); } else { addressAll = hostAll.asAddress(version); if(!addressAll.equals(address)) { addFailure(new Failure("no match " + address, addressAll)); } else if(addressAll.compareTo(address) != 0) { addFailure(new Failure("no match " + address, addressAll)); } else if(!addressAll.getCount().equals(count)) { addFailure(new Failure("no count match ", addressAll)); } } incrementTestCount(); }
Example 8
Source File: TestBase.java From IPAddress with Apache License 2.0 | 5 votes |
boolean confirmAddrStrings(IPAddress ipAddr, IPAddressString ...strs) { for(IPAddressString str : strs) { IPAddress addr = str.getAddress(); if(!ipAddr.equals(addr)) { addFailure(new Failure("failed produced string: " + str, ipAddr)); return false; } } incrementTestCount(); return true; }
Example 9
Source File: SpecialTypesTest.java From IPAddress with Apache License 2.0 | 4 votes |
void testEmptyValues() { HostName hostEmpty = createHost("", HOST_OPTIONS); IPAddressString addressEmpty = createAddress("", ADDRESS_OPTIONS); try { InetAddress addr = InetAddress.getByName(""); InetAddress addr2 = InetAddress.getByName(null); IPAddressStringFormatParameters params = addr instanceof Inet6Address ? ADDRESS_OPTIONS.getIPv6Parameters() : ADDRESS_OPTIONS.getIPv4Parameters(); IPAddressNetwork<?, ?, ?, ?, ?> network = params.getNetwork(); IPAddress address = network.getAddressCreator().createAddress(addr.getAddress()); IPAddressStringFormatParameters params2 = addr2 instanceof Inet6Address ? ADDRESS_OPTIONS.getIPv6Parameters() : ADDRESS_OPTIONS.getIPv4Parameters(); IPAddressNetwork<?, ?, ?, ?, ?> network2 = params2.getNetwork(); IPAddress address2 = network2.getAddressCreator().createAddress(addr2.getAddress()); if(!addressEmpty.getAddress().equals(address)) { addFailure(new Failure("no match " + addr, addressEmpty)); } else if(!addressEmpty.getAddress().equals(address2)) { addFailure(new Failure("no match " + addr2, addressEmpty)); } else if(addressEmpty.getAddress().compareTo(address) != 0) { addFailure(new Failure("no match " + addr, addressEmpty)); } else if(addressEmpty.getAddress().compareTo(address2) != 0) { addFailure(new Failure("no match " + addr2, addressEmpty)); } else if(!addressEmpty.getAddress().getCount().equals(BigInteger.ONE)) { addFailure(new Failure("no count match " + addr2, addressEmpty)); } else { addressEmpty = hostEmpty.asAddressString();//note that hostEmpty allows empty strings and they resolve to loopbacks, but they are not treated as addresses if(addressEmpty != null) { addFailure(new Failure("host treated as address " + addr, addressEmpty)); } else { addressEmpty = createHost("", EMPTY_ADDRESS_OPTIONS).asAddressString(); if(addressEmpty == null || !addressEmpty.getAddress().equals(address)) { addFailure(new Failure("no match " + addr, addressEmpty)); } else if(!addressEmpty.getAddress().equals(address2)) { addFailure(new Failure("no match " + addr2, addressEmpty)); } else if(addressEmpty.getAddress().compareTo(address) != 0) { addFailure(new Failure("no match " + addr, addressEmpty)); } else if(addressEmpty.getAddress().compareTo(address2) != 0) { addFailure(new Failure("no match " + addr2, addressEmpty)); } else if(!addressEmpty.getAddress().getCount().equals(BigInteger.ONE)) { addFailure(new Failure("no count match " + addr2, addressEmpty)); } else { IPAddress addressEmptyValue = hostEmpty.getAddress(); if(!addressEmptyValue.equals(address)) { addFailure(new Failure("no match " + addr, addressEmpty)); } else if(!addressEmptyValue.equals(address2)) { addFailure(new Failure("no match " + addr2, addressEmpty)); } else if(addressEmptyValue.compareTo(address) != 0) { addFailure(new Failure("no match " + addr, addressEmpty)); } else if(addressEmptyValue.compareTo(address2) != 0) { addFailure(new Failure("no match " + addr2, addressEmpty)); } else if(!addressEmptyValue.getCount().equals(BigInteger.ONE)) { addFailure(new Failure("no count match " + addr2, addressEmpty)); } } } } } catch(UnknownHostException e) { addFailure(new Failure("unexpected unknown host", addressEmpty)); } incrementTestCount(); }