CapabilitiesDecorator implements Capabilities { @Override public int hashCode() { HashCodeBuilder hcb = new HashCodeBuilder(); for(Capability cap : getRequiredCapabilities()) hcb.append(cap).append(false); for(Capability cap : getOptionalCapabilities()) hcb.append(cap).append(true); return hcb.toHashCode(); } CapabilitiesDecorator(Capabilities decorated); @Override Set<Capability> getRequiredCapabilities(); @Override Set<Capability> getOptionalCapabilities(); @Override boolean equals(Object obj); @Override int hashCode();  }
@Test public void testRequiredCapabilitiesSameSizeSameArgsSameOrder() { CapabilitiesImpl cd1 = new CapabilitiesImpl(new Capability[] { new AutonomousSystem4Capability(16), new MultiProtocolCapability(AddressFamily.IPv4, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new MultiProtocolCapability(AddressFamily.IPv6, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new RouteRefreshCapability() }); CapabilitiesImpl cd2 = new CapabilitiesImpl(new Capability[] { new AutonomousSystem4Capability(16), new MultiProtocolCapability(AddressFamily.IPv4, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new MultiProtocolCapability(AddressFamily.IPv6, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new RouteRefreshCapability() }); CapabilitiesDecorator cp1 = new CapabilitiesDecorator(cd1); CapabilitiesDecorator cp2 = new CapabilitiesDecorator(cd2); Assert.assertEquals(cd1, cd2); Assert.assertEquals(cd1.hashCode(), cd2.hashCode()); Assert.assertEquals(cp1, cp2); Assert.assertEquals(cp1.hashCode(), cp2.hashCode()); Assert.assertEquals(cd1, cp1); Assert.assertEquals(cd1.hashCode(), cp1.hashCode()); Assert.assertEquals(cd2, cp2); Assert.assertEquals(cd2.hashCode(), cp2.hashCode()); }
@Test public void testRequiredCapabilitiesSameSizeSameArgsDifferentOrder() { CapabilitiesImpl cd1 = new CapabilitiesImpl(new Capability[] { new AutonomousSystem4Capability(16), new MultiProtocolCapability(AddressFamily.IPv4, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new MultiProtocolCapability(AddressFamily.IPv6, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new RouteRefreshCapability() }); CapabilitiesImpl cd2 = new CapabilitiesImpl(new Capability[] { new RouteRefreshCapability(), new MultiProtocolCapability(AddressFamily.IPv6, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new MultiProtocolCapability(AddressFamily.IPv4, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new AutonomousSystem4Capability(16) }); CapabilitiesDecorator cp1 = new CapabilitiesDecorator(cd1); CapabilitiesDecorator cp2 = new CapabilitiesDecorator(cd2); Assert.assertEquals(cd1, cd2); Assert.assertEquals(cd1.hashCode(), cd2.hashCode()); Assert.assertEquals(cp1, cp2); Assert.assertEquals(cp1.hashCode(), cp2.hashCode()); Assert.assertEquals(cd1, cp1); Assert.assertEquals(cd1.hashCode(), cp1.hashCode()); Assert.assertEquals(cd2, cp2); Assert.assertEquals(cd2.hashCode(), cp2.hashCode()); }
@Test public void testRequiredCapabilitiesRepeatedArgs() { CapabilitiesImpl cd1 = new CapabilitiesImpl(new Capability[] { new AutonomousSystem4Capability(16), new MultiProtocolCapability(AddressFamily.IPv4, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new MultiProtocolCapability(AddressFamily.IPv6, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new RouteRefreshCapability() }); CapabilitiesImpl cd2 = new CapabilitiesImpl(new Capability[] { new AutonomousSystem4Capability(16), new AutonomousSystem4Capability(16), new MultiProtocolCapability(AddressFamily.IPv4, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new MultiProtocolCapability(AddressFamily.IPv4, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new MultiProtocolCapability(AddressFamily.IPv6, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new MultiProtocolCapability(AddressFamily.IPv6, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new RouteRefreshCapability(), new RouteRefreshCapability() }); CapabilitiesDecorator cp1 = new CapabilitiesDecorator(cd1); CapabilitiesDecorator cp2 = new CapabilitiesDecorator(cd2); Assert.assertEquals(cd1, cd2); Assert.assertEquals(cd1.hashCode(), cd2.hashCode()); Assert.assertEquals(cp1, cp2); Assert.assertEquals(cp1.hashCode(), cp2.hashCode()); Assert.assertEquals(cd1, cp1); Assert.assertEquals(cd1.hashCode(), cp1.hashCode()); Assert.assertEquals(cd2, cp2); Assert.assertEquals(cd2.hashCode(), cp2.hashCode()); }
@Test public void testOptionalCapabilitiesSameSizeSameArgsSameOrder() { CapabilitiesImpl cd1 = new CapabilitiesImpl(null, new Capability[] { new AutonomousSystem4Capability(16), new MultiProtocolCapability(AddressFamily.IPv4, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new MultiProtocolCapability(AddressFamily.IPv6, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new RouteRefreshCapability() }); CapabilitiesImpl cd2 = new CapabilitiesImpl(null, new Capability[] { new AutonomousSystem4Capability(16), new MultiProtocolCapability(AddressFamily.IPv4, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new MultiProtocolCapability(AddressFamily.IPv6, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new RouteRefreshCapability() }); CapabilitiesDecorator cp1 = new CapabilitiesDecorator(cd1); CapabilitiesDecorator cp2 = new CapabilitiesDecorator(cd2); Assert.assertEquals(cd1, cd2); Assert.assertEquals(cd1.hashCode(), cd2.hashCode()); Assert.assertEquals(cp1, cp2); Assert.assertEquals(cp1.hashCode(), cp2.hashCode()); Assert.assertEquals(cd1, cp1); Assert.assertEquals(cd1.hashCode(), cp1.hashCode()); Assert.assertEquals(cd2, cp2); Assert.assertEquals(cd2.hashCode(), cp2.hashCode()); }
@Test public void testOptionalCapabilitiesSameSizeSameArgsDifferentOrder() { CapabilitiesImpl cd1 = new CapabilitiesImpl(null, new Capability[] { new AutonomousSystem4Capability(16), new MultiProtocolCapability(AddressFamily.IPv4, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new MultiProtocolCapability(AddressFamily.IPv6, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new RouteRefreshCapability() }); CapabilitiesImpl cd2 = new CapabilitiesImpl(null, new Capability[] { new RouteRefreshCapability(), new MultiProtocolCapability(AddressFamily.IPv6, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new MultiProtocolCapability(AddressFamily.IPv4, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new AutonomousSystem4Capability(16) }); CapabilitiesDecorator cp1 = new CapabilitiesDecorator(cd1); CapabilitiesDecorator cp2 = new CapabilitiesDecorator(cd2); Assert.assertEquals(cd1, cd2); Assert.assertEquals(cd1.hashCode(), cd2.hashCode()); Assert.assertEquals(cp1, cp2); Assert.assertEquals(cp1.hashCode(), cp2.hashCode()); Assert.assertEquals(cd1, cp1); Assert.assertEquals(cd1.hashCode(), cp1.hashCode()); Assert.assertEquals(cd2, cp2); Assert.assertEquals(cd2.hashCode(), cp2.hashCode()); }
@Test public void testOptionalCapabilitiesRepeatedArgs() { CapabilitiesImpl cd1 = new CapabilitiesImpl(null, new Capability[] { new AutonomousSystem4Capability(16), new MultiProtocolCapability(AddressFamily.IPv4, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new MultiProtocolCapability(AddressFamily.IPv6, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new RouteRefreshCapability() }); CapabilitiesImpl cd2 = new CapabilitiesImpl(null, new Capability[] { new AutonomousSystem4Capability(16), new AutonomousSystem4Capability(16), new MultiProtocolCapability(AddressFamily.IPv4, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new MultiProtocolCapability(AddressFamily.IPv4, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new MultiProtocolCapability(AddressFamily.IPv6, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new MultiProtocolCapability(AddressFamily.IPv6, SubsequentAddressFamily.NLRI_UNICAST_FORWARDING), new RouteRefreshCapability(), new RouteRefreshCapability() }); CapabilitiesDecorator cp1 = new CapabilitiesDecorator(cd1); CapabilitiesDecorator cp2 = new CapabilitiesDecorator(cd2); Assert.assertEquals(cd1, cd2); Assert.assertEquals(cd1.hashCode(), cd2.hashCode()); Assert.assertEquals(cp1, cp2); Assert.assertEquals(cp1.hashCode(), cp2.hashCode()); Assert.assertEquals(cd1, cp1); Assert.assertEquals(cd1.hashCode(), cp1.hashCode()); Assert.assertEquals(cd2, cp2); Assert.assertEquals(cd2.hashCode(), cp2.hashCode()); }