RedisServiceImpl extends AbstractConsoleService<RedisTblDao> implements RedisService { protected List<RedisTbl> inter(List<Pair<String, Integer>> userGiven, List<RedisTbl> redisTbls) { List<RedisTbl> result = new LinkedList<>(); redisTbls.forEach(new Consumer<RedisTbl>() { @Override public void accept(RedisTbl redisTbl) { boolean exist = false; for (Pair<String, Integer> addr : userGiven) { if (addr.getKey().equalsIgnoreCase(redisTbl.getRedisIp()) && addr.getValue().equals(redisTbl.getRedisPort())) { exist = true; break; } } if (exist) { result.add(redisTbl); } } }); return result; }  @Override RedisTbl find(final long id); @Override List<RedisTbl> findAllRedisWithSameIP(String ip); @Override List<RedisTbl> findAllByDcClusterShard(final long dcClusterShardId); @Override List<RedisTbl> findAllRedisesByDcClusterName(String dcId, String clusterId); @Override List<RedisTbl> findAllByDcClusterShard(String dcId, String clusterId, String shardId); @Override List<RedisTbl> findRedisesByDcClusterShard(String dcId, String clusterId, String shardId); @Override List<RedisTbl> findKeepersByDcClusterShard(String dcId, String clusterId, String shardId); @Override synchronized void insertRedises(String dcId, String clusterId, String shardId,
                                           List<Pair<String, Integer>> redisAddresses); @Override synchronized int insertKeepers(String dcId, String clusterId, String shardId,
                                          List<KeeperBasicInfo> keepers); @Override List<RedisTbl> deleteKeepers(String dcId, String clusterId, String shardId); @Override void deleteRedises(String dcId, String clusterId, String shardId, List<Pair<String, Integer>> redisAddresses); @Override void updateByPK(final RedisTbl redis); @Override void updateBatchMaster(List<RedisTbl> redises); @Override void updateBatchKeeperActive(List<RedisTbl> redises); @Override void updateRedises(String dcName, String clusterName, String shardName, ShardModel shardModel); @Override List<RedisTbl> findAllKeeperContainerCountInfo(); @Override List<Long> findClusterIdsByKeeperContainer(long keeperContainerId); void insertInstancesToDb(long dcClusterShardId, String role, Pair<String, Integer>... addrs);  }
@Test public void testInter() { List<Pair<String, Integer>> first = Lists.newArrayList( Pair.from("127.0.0.1", 1111), Pair.from("127.0.0.1", 1112), Pair.from("127.0.0.1", 1113) ); List<RedisTbl> second = Lists.newArrayList( new RedisTbl().setRedisIp("127.0.0.1").setRedisPort(1111), new RedisTbl().setRedisIp("127.0.0.1").setRedisPort(1112), new RedisTbl().setRedisIp("127.0.0.1").setRedisPort(9999) ); List<RedisTbl> inter = redisService.inter(first, second); Assert.assertEquals(2, inter.size()); }