### Question:
AnyGroupFilter implements Filter<ServerInfo> { @Override public Set<ServerInfo> apply( Set<ServerInfo> data ) { return data.stream().filter( matchesAnyGroup ).collect( Collectors.toSet() ); } AnyGroupFilter( String... groups );   AnyGroupFilter( Set<String> groups ); @Override Set<ServerInfo> apply( Set<ServerInfo> data ); @Override boolean equals( Object o ); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void shouldReturnServersMatchingAnyGroup() { AnyGroupFilter groupFilter = new AnyGroupFilter( asSet( "china-west", "europe" ) ); ServerInfo serverA = new ServerInfo( new AdvertisedSocketAddress( "bolt", 1 ), new MemberId( UUID.randomUUID() ), asSet( "china-west" ) ); ServerInfo serverB = new ServerInfo( new AdvertisedSocketAddress( "bolt", 2 ), new MemberId( UUID.randomUUID() ), asSet( "europe" ) ); ServerInfo serverC = new ServerInfo( new AdvertisedSocketAddress( "bolt", 3 ), new MemberId( UUID.randomUUID() ), asSet( "china", "china-west" ) ); ServerInfo serverD = new ServerInfo( new AdvertisedSocketAddress( "bolt", 4 ), new MemberId( UUID.randomUUID() ), asSet( "china-west", "china" ) ); ServerInfo serverE = new ServerInfo( new AdvertisedSocketAddress( "bolt", 5 ), new MemberId( UUID.randomUUID() ), asSet( "china-east", "asia" ) ); ServerInfo serverF = new ServerInfo( new AdvertisedSocketAddress( "bolt", 6 ), new MemberId( UUID.randomUUID() ), asSet( "europe-west" ) ); ServerInfo serverG = new ServerInfo( new AdvertisedSocketAddress( "bolt", 7 ), new MemberId( UUID.randomUUID() ), asSet( "china-west", "europe" ) ); ServerInfo serverH = new ServerInfo( new AdvertisedSocketAddress( "bolt", 8 ), new MemberId( UUID.randomUUID() ), asSet( "africa" ) ); Set<ServerInfo> data = asSet( serverA, serverB, serverC, serverD, serverE, serverF, serverG, serverH ); Set<ServerInfo> output = groupFilter.apply( data ); Set<Integer> ports = new HashSet<>(); for ( ServerInfo info : output ) { ports.add( info.boltAddress().getPort() ); } assertEquals( asSet( 1, 2, 3, 4, 7 ), ports ); }