Example usage for java.util Set containsAll

List of usage examples for java.util Set containsAll

Introduction

In this page you can find the example usage for java.util Set containsAll.

Prototype

boolean containsAll(Collection<?> c);

Source Link

Document

Returns true if this set contains all of the elements of the specified collection.

Usage

From source file:org.apache.flink.streaming.connectors.kinesis.internals.KinesisDataFetcherTest.java

@Test
public void testStreamToLastSeenShardStateIsCorrectlySetWhenNewShardsFoundSinceRestoredCheckpointAndSomeStreamsDoNotExist()
        throws Exception {
    List<String> fakeStreams = new LinkedList<>();
    fakeStreams.add("fakeStream1");
    fakeStreams.add("fakeStream2");
    fakeStreams.add("fakeStream3"); // fakeStream3 will not have any shards
    fakeStreams.add("fakeStream4"); // fakeStream4 will not have any shards

    Map<StreamShardHandle, String> restoredStateUnderTest = new HashMap<>();

    // fakeStream1 has 3 shards before restore
    restoredStateUnderTest.put(//from ww  w .  jav  a2s.c  om
            new StreamShardHandle("fakeStream1",
                    new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(0))),
            UUID.randomUUID().toString());
    restoredStateUnderTest.put(
            new StreamShardHandle("fakeStream1",
                    new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(1))),
            UUID.randomUUID().toString());
    restoredStateUnderTest.put(
            new StreamShardHandle("fakeStream1",
                    new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(2))),
            UUID.randomUUID().toString());

    // fakeStream2 has 2 shards before restore
    restoredStateUnderTest.put(
            new StreamShardHandle("fakeStream2",
                    new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(0))),
            UUID.randomUUID().toString());
    restoredStateUnderTest.put(
            new StreamShardHandle("fakeStream2",
                    new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(1))),
            UUID.randomUUID().toString());

    Map<String, Integer> streamToShardCount = new HashMap<>();
    streamToShardCount.put("fakeStream1", 3 + 1); // fakeStream1 had 3 shards before & 1 new shard after restore
    streamToShardCount.put("fakeStream2", 2 + 3); // fakeStream2 had 2 shards before & 2 new shard after restore
    streamToShardCount.put("fakeStream3", 0); // no shards can be found for fakeStream3
    streamToShardCount.put("fakeStream4", 0); // no shards can be found for fakeStream4

    HashMap<String, String> subscribedStreamsToLastSeenShardIdsUnderTest = KinesisDataFetcher
            .createInitialSubscribedStreamsToLastDiscoveredShardsState(fakeStreams);

    // using a non-resharded streams kinesis behaviour to represent that Kinesis is not resharded AFTER the restore
    final TestableKinesisDataFetcher<String> fetcher = new TestableKinesisDataFetcher<>(fakeStreams,
            new TestSourceContext<>(), TestUtils.getStandardProperties(),
            new KinesisDeserializationSchemaWrapper<>(new SimpleStringSchema()), 10, 2, new AtomicReference<>(),
            new LinkedList<>(), subscribedStreamsToLastSeenShardIdsUnderTest,
            FakeKinesisBehavioursFactory.nonReshardedStreamsBehaviour(streamToShardCount));

    for (Map.Entry<StreamShardHandle, String> restoredState : restoredStateUnderTest.entrySet()) {
        fetcher.advanceLastDiscoveredShardOfStream(restoredState.getKey().getStreamName(),
                restoredState.getKey().getShard().getShardId());
        fetcher.registerNewSubscribedShardState(new KinesisStreamShardState(
                KinesisDataFetcher.convertToStreamShardMetadata(restoredState.getKey()), restoredState.getKey(),
                new SequenceNumber(restoredState.getValue())));
    }

    CheckedThread runFetcherThread = new CheckedThread() {
        @Override
        public void go() throws Exception {
            fetcher.runFetcher();
        }
    };
    runFetcherThread.start();

    fetcher.waitUntilInitialDiscovery();
    fetcher.shutdownFetcher();
    runFetcherThread.sync();

    // assert that the streams tracked in the state are identical to the subscribed streams
    Set<String> streamsInState = subscribedStreamsToLastSeenShardIdsUnderTest.keySet();
    assertEquals(fakeStreams.size(), streamsInState.size());
    assertTrue(streamsInState.containsAll(fakeStreams));

    // assert that the last seen shards in state is correctly set
    assertEquals(KinesisShardIdGenerator.generateFromShardOrder(3),
            subscribedStreamsToLastSeenShardIdsUnderTest.get("fakeStream1"));
    assertEquals(KinesisShardIdGenerator.generateFromShardOrder(4),
            subscribedStreamsToLastSeenShardIdsUnderTest.get("fakeStream2"));
    assertNull(subscribedStreamsToLastSeenShardIdsUnderTest.get("fakeStream3"));
    assertNull(subscribedStreamsToLastSeenShardIdsUnderTest.get("fakeStream4"));
}

From source file:com.aurel.track.admin.user.person.PersonBL.java

public static boolean remianAdminUserAfterDelete(String selectedPersonIDs) {
    List<String> personsToDeleteList = Arrays.asList(selectedPersonIDs.split(","));
    Set<Integer> personsToDeleteSet = new HashSet<Integer>();
    for (String idItem : personsToDeleteList) {
        personsToDeleteSet.add(Integer.parseInt(idItem));
    }//from  ww  w  . j  a  va2 s. co  m

    List<TPersonBean> personBeanList = PersonBL.loadSystemAdmins();
    Set<Integer> allSysAdminSet = new HashSet<Integer>();
    for (TPersonBean aPerson : personBeanList) {
        allSysAdminSet.add(aPerson.getObjectID());
    }

    if (personsToDeleteSet.containsAll(allSysAdminSet)) {
        return false;
    } else {
        return true;
    }
}

From source file:com.taobao.android.differ.dex.DexDiffer.java

private boolean equalsImpl(Set<?> s, @Nullable Object object) {
    if (s == object) {
        return true;
    } else if (object instanceof Set) {
        Set o = (Set) object;

        try {//from   www.ja v a 2s .co m
            return s.size() == o.size() && s.containsAll(o);
        } catch (NullPointerException var4) {
            return false;
        } catch (ClassCastException var5) {
            return false;
        }
    } else {
        return false;
    }
}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.algorithm.VehicleStatusTestCase.java

@Test
public void testCase01() throws ParseException {
    String status = "{\"vehicle.id\":\"b2345527-2796-4ea9-b500-d842d6f2b638\",\"state\":\"active\",\"latitude\":47.82211311,\"longitude\":13.04076076,\"altitude\":30.0,"
            + "\"tolerance\":1.2,\"actions\":[\"photo\"]}";
    @SuppressWarnings("serial")
    Set<String> expectedSensors = new HashSet<String>() {
        {// w  ww  . ja v a  2 s.c o m
            add("photo");
        }
    };

    JSONParser parser = new JSONParser();
    VehicleStatus s = new VehicleStatus((JSONObject) parser.parse(status));
    Assert.assertEquals("b2345527-2796-4ea9-b500-d842d6f2b638", s.getId());
    Assert.assertEquals("active", s.getState().toString().toLowerCase());
    Assert.assertEquals(47.82211311, s.getPosition().getLatitude(), 1E-9);
    Assert.assertEquals(13.04076076, s.getPosition().getLongitude(), 1E-9);
    Assert.assertEquals(30.0, s.getPosition().getAltitude(), 1E-9);
    Assert.assertEquals(1.2, s.getTolerance(), 1E-9);
    Assert.assertTrue(s.getActions().containsAll(expectedSensors));
    Assert.assertTrue(expectedSensors.containsAll(s.getActions()));
    System.out.println("testCase01-1: " + s.toJSONString());

    s = new VehicleStatus((JSONObject) parser.parse(s.toJSONString()));
    Assert.assertEquals("b2345527-2796-4ea9-b500-d842d6f2b638", s.getId());
    Assert.assertEquals("active", s.getState().toString().toLowerCase());
    Assert.assertEquals(47.82211311, s.getPosition().getLatitude(), 1E-9);
    Assert.assertEquals(13.04076076, s.getPosition().getLongitude(), 1E-9);
    Assert.assertEquals(30.0, s.getPosition().getAltitude(), 1E-9);
    Assert.assertEquals(1.2, s.getTolerance(), 1E-9);
    Assert.assertTrue(s.getActions().containsAll(expectedSensors));
    Assert.assertTrue(expectedSensors.containsAll(s.getActions()));
}

From source file:org.apache.hadoop.hbase.coprocessor.TestClassLoading.java

@Test
// HBASE-3516: Test CP Class loading from HDFS
public void testClassLoadingFromHDFS() throws Exception {
    FileSystem fs = cluster.getFileSystem();

    File jarFile1 = buildCoprocessorJar(cpName1);
    File jarFile2 = buildCoprocessorJar(cpName2);

    // copy the jars into dfs
    fs.copyFromLocalFile(new Path(jarFile1.getPath()), new Path(fs.getUri().toString() + Path.SEPARATOR));
    String jarFileOnHDFS1 = fs.getUri().toString() + Path.SEPARATOR + jarFile1.getName();
    Path pathOnHDFS1 = new Path(jarFileOnHDFS1);
    assertTrue("Copy jar file to HDFS failed.", fs.exists(pathOnHDFS1));
    LOG.info("Copied jar file to HDFS: " + jarFileOnHDFS1);

    fs.copyFromLocalFile(new Path(jarFile2.getPath()), new Path(fs.getUri().toString() + Path.SEPARATOR));
    String jarFileOnHDFS2 = fs.getUri().toString() + Path.SEPARATOR + jarFile2.getName();
    Path pathOnHDFS2 = new Path(jarFileOnHDFS2);
    assertTrue("Copy jar file to HDFS failed.", fs.exists(pathOnHDFS2));
    LOG.info("Copied jar file to HDFS: " + jarFileOnHDFS2);

    // create a table that references the coprocessors
    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
    htd.addFamily(new HColumnDescriptor("test"));
    // without configuration values
    htd.setValue("COPROCESSOR$1", jarFileOnHDFS1.toString() + "|" + cpName1 + "|" + Coprocessor.PRIORITY_USER);
    // with configuration values
    htd.setValue("COPROCESSOR$2",
            jarFileOnHDFS2.toString() + "|" + cpName2 + "|" + Coprocessor.PRIORITY_USER + "|k1=v1,k2=v2,k3=v3");
    HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
    if (admin.tableExists(tableName)) {
        if (admin.isTableEnabled(tableName)) {
            admin.disableTable(tableName);
        }/*ww w.j  a  v  a2s.  co  m*/
        admin.deleteTable(tableName);
    }
    CoprocessorClassLoader.clearCache();
    byte[] startKey = { 10, 63 };
    byte[] endKey = { 12, 43 };
    admin.createTable(htd, startKey, endKey, 4);
    waitForTable(htd.getTableName());

    // verify that the coprocessors were loaded
    boolean foundTableRegion = false;
    boolean found1 = true, found2 = true, found2_k1 = true, found2_k2 = true, found2_k3 = true;
    Map<HRegion, Set<ClassLoader>> regionsActiveClassLoaders = new HashMap<HRegion, Set<ClassLoader>>();
    MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster();
    for (HRegion region : hbase.getRegionServer(0).getOnlineRegionsLocalContext()) {
        if (region.getRegionNameAsString().startsWith(tableName)) {
            foundTableRegion = true;
            CoprocessorEnvironment env;
            env = region.getCoprocessorHost().findCoprocessorEnvironment(cpName1);
            found1 = found1 && (env != null);
            env = region.getCoprocessorHost().findCoprocessorEnvironment(cpName2);
            found2 = found2 && (env != null);
            if (env != null) {
                Configuration conf = env.getConfiguration();
                found2_k1 = found2_k1 && (conf.get("k1") != null);
                found2_k2 = found2_k2 && (conf.get("k2") != null);
                found2_k3 = found2_k3 && (conf.get("k3") != null);
            } else {
                found2_k1 = found2_k2 = found2_k3 = false;
            }
            regionsActiveClassLoaders.put(region,
                    ((CoprocessorHost) region.getCoprocessorHost()).getExternalClassLoaders());
        }
    }

    assertTrue("No region was found for table " + tableName, foundTableRegion);
    assertTrue("Class " + cpName1 + " was missing on a region", found1);
    assertTrue("Class " + cpName2 + " was missing on a region", found2);
    assertTrue("Configuration key 'k1' was missing on a region", found2_k1);
    assertTrue("Configuration key 'k2' was missing on a region", found2_k2);
    assertTrue("Configuration key 'k3' was missing on a region", found2_k3);
    // check if CP classloaders are cached
    assertNotNull(jarFileOnHDFS1 + " was not cached", CoprocessorClassLoader.getIfCached(pathOnHDFS1));
    assertNotNull(jarFileOnHDFS2 + " was not cached", CoprocessorClassLoader.getIfCached(pathOnHDFS2));
    //two external jar used, should be one classloader per jar
    assertEquals("The number of cached classloaders should be equal to the number" + " of external jar files",
            2, CoprocessorClassLoader.getAllCached().size());
    //check if region active classloaders are shared across all RS regions
    Set<ClassLoader> externalClassLoaders = new HashSet<ClassLoader>(CoprocessorClassLoader.getAllCached());
    for (Map.Entry<HRegion, Set<ClassLoader>> regionCP : regionsActiveClassLoaders.entrySet()) {
        assertTrue("Some CP classloaders for region " + regionCP.getKey() + " are not cached."
                + " ClassLoader Cache:" + externalClassLoaders + " Region ClassLoaders:" + regionCP.getValue(),
                externalClassLoaders.containsAll(regionCP.getValue()));
    }
}

From source file:org.javassonne.ui.controllers.GameController.java

public void scoreTurn(Notification n) {
    HashMap<String, Object> data = (HashMap<String, Object>) n.argument();
    Point p = (Point) data.get("location");

    TileBoardIterator iter = new TileBoardGenIterator(GameState.getInstance().getBoard(), p);

    Set<Meeple> meeple = new HashSet<Meeple>();

    // Score completed features on this tile
    RegionsCalc c = new RegionsCalc();
    for (Tile.Region r : Tile.Region.values()) {
        c.traverseRegion(iter, r);/*from  w ww . j  a  va2 s.  c  o  m*/
    }
    for (Tile.Region r : Tile.Region.values()) {
        if (c.getRegionCompletion(iter.getLocation(), r)) {
            if (!meeple.containsAll(c.getMeepleList(p, r))) {
                scoreFeature(c.getScoreOfRegion(p, r), c.getMeepleList(p, r));
                meeple.addAll(c.getMeepleList(p, r));
            }
        }
    }

    // Score cloisters - go right then move clockwise
    // Note: do not need to recheck iter because it was checked above
    TileBoardGenIterator temp = new TileBoardGenIterator(iter);
    c.traverseRegion(temp.right(), Tile.Region.Center);
    // TODO: Change these to get the correct score (algorithm should do it)
    if (c.getRegionCompletion(temp.getLocation(), Tile.Region.Center)) {
        scoreFeature(c.getScoreOfRegion(temp.getLocation(), Tile.Region.Center),
                c.getMeepleList(temp.getLocation(), Tile.Region.Center));
    }
    c.traverseRegion(temp.down(), Tile.Region.Center);
    if (c.getRegionCompletion(temp.getLocation(), Tile.Region.Center)) {
        scoreFeature(c.getScoreOfRegion(temp.getLocation(), Tile.Region.Center),
                c.getMeepleList(temp.getLocation(), Tile.Region.Center));
    }
    c.traverseRegion(temp.left(), Tile.Region.Center);
    if (c.getRegionCompletion(temp.getLocation(), Tile.Region.Center)) {
        scoreFeature(c.getScoreOfRegion(temp.getLocation(), Tile.Region.Center),
                c.getMeepleList(temp.getLocation(), Tile.Region.Center));
    }
    c.traverseRegion(temp.left(), Tile.Region.Center);
    if (c.getRegionCompletion(temp.getLocation(), Tile.Region.Center)) {
        scoreFeature(c.getScoreOfRegion(temp.getLocation(), Tile.Region.Center),
                c.getMeepleList(temp.getLocation(), Tile.Region.Center));
    }
    c.traverseRegion(temp.up(), Tile.Region.Center);
    if (c.getRegionCompletion(temp.getLocation(), Tile.Region.Center)) {
        scoreFeature(c.getScoreOfRegion(temp.getLocation(), Tile.Region.Center),
                c.getMeepleList(temp.getLocation(), Tile.Region.Center));
    }
    c.traverseRegion(temp.up(), Tile.Region.Center);
    if (c.getRegionCompletion(temp.getLocation(), Tile.Region.Center)) {
        scoreFeature(c.getScoreOfRegion(temp.getLocation(), Tile.Region.Center),
                c.getMeepleList(temp.getLocation(), Tile.Region.Center));
    }
    c.traverseRegion(temp.right(), Tile.Region.Center);
    if (c.getRegionCompletion(temp.getLocation(), Tile.Region.Center)) {
        scoreFeature(c.getScoreOfRegion(temp.getLocation(), Tile.Region.Center),
                c.getMeepleList(temp.getLocation(), Tile.Region.Center));
    }
    c.traverseRegion(temp.right(), Tile.Region.Center);
    if (c.getRegionCompletion(temp.getLocation(), Tile.Region.Center)) {
        scoreFeature(c.getScoreOfRegion(temp.getLocation(), Tile.Region.Center),
                c.getMeepleList(temp.getLocation(), Tile.Region.Center));
    }

    if (GameState.getInstance().getDeck().tilesRemaining() == 0)
        NotificationManager.getInstance().sendNotification(Notification.GAME_OVER);
    else {
        GameState.getInstance().advanceCurrentPlayer();
        beginTurn();
    }
}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.algorithm.VehicleStatusTestCase.java

@Test
public void testCase03() throws ParseException {
    String status = "{\"vehicle.id\":\"c2345527-2796-4ea9-b500-d842d6f2b638\",\"state\":\"suspended\",\"latitude\":48.82211311,\"longitude\":18.04076076,\"altitude\":38.0,"
            + "\"tolerance\":8.2,\"actions\":[\"temperature\"]}";
    @SuppressWarnings("serial")
    Set<String> expectedSensors = new HashSet<String>() {
        {/* ww  w .  j  a  v  a2s .  c o m*/
            add("temperature");
        }
    };

    JSONParser parser = new JSONParser();
    VehicleStatus s = new VehicleStatus((JSONObject) parser.parse(status));
    Assert.assertEquals("c2345527-2796-4ea9-b500-d842d6f2b638", s.getId());
    Assert.assertEquals("suspended", s.getState().toString().toLowerCase());
    Assert.assertEquals(48.82211311, s.getPosition().getLatitude(), 1E-9);
    Assert.assertEquals(18.04076076, s.getPosition().getLongitude(), 1E-9);
    Assert.assertEquals(38.0, s.getPosition().getAltitude(), 1E-9);
    Assert.assertEquals(8.2, s.getTolerance(), 1E-9);
    Assert.assertTrue(s.getActions().containsAll(expectedSensors));
    Assert.assertTrue(expectedSensors.containsAll(s.getActions()));

    s = new VehicleStatus((JSONObject) parser.parse(s.toJSONString()));
    Assert.assertEquals("c2345527-2796-4ea9-b500-d842d6f2b638", s.getId());
    Assert.assertEquals("suspended", s.getState().toString().toLowerCase());
    Assert.assertEquals(48.82211311, s.getPosition().getLatitude(), 1E-9);
    Assert.assertEquals(18.04076076, s.getPosition().getLongitude(), 1E-9);
    Assert.assertEquals(38.0, s.getPosition().getAltitude(), 1E-9);
    Assert.assertEquals(8.2, s.getTolerance(), 1E-9);
    Assert.assertTrue(s.getActions().containsAll(expectedSensors));
    Assert.assertTrue(expectedSensors.containsAll(s.getActions()));
}

From source file:gov.nih.nci.sdk.example.generator.WebServiceGenerator.java

private void compileWebServiceInterface() {
    java.util.Set<String> processedFocusDomainSet = (java.util.Set<String>) getScriptContext().getMemory()
            .get("processedFocusDomainSet");

    if (processedFocusDomainSet == null) {
        processedFocusDomainSet = new java.util.HashSet<String>();
        getScriptContext().getMemory().put("processedFocusDomainSet", processedFocusDomainSet);
    }//from w  w w. j a  v  a  2  s .c o m

    processedFocusDomainSet.add(getScriptContext().getFocusDomain());

    if (processedFocusDomainSet.containsAll(getScriptContext().retrieveDomainSet()) == true) { //All domains have been processed so now we can compile and generate WSDL

        StandardJavaFileManager fileManager = null;

        try {
            String jaxbPojoPath = GeneratorUtil.getJaxbPojoPath(getScriptContext());
            String servicePath = GeneratorUtil.getServicePath(getScriptContext());
            String serviceImplPath = GeneratorUtil.getServiceImplPath(getScriptContext());
            String projectRoot = getScriptContext().getProperties().getProperty("PROJECT_ROOT");

            List<String> compilerFiles = GeneratorUtil.getFiles(jaxbPojoPath, new String[] { "java" });
            compilerFiles.addAll(GeneratorUtil.getFiles(servicePath, new String[] { "java" }));
            compilerFiles.addAll(GeneratorUtil.getFiles(serviceImplPath, new String[] { "java" }));

            getScriptContext().logInfo("Compiling files: " + compilerFiles);
            // Check if output directory exist, create it
            GeneratorUtil.createOutputDir(projectRoot + File.separator + "classes");

            List<String> options = new ArrayList<String>();
            options.add("-classpath");
            String classPathStr = GeneratorUtil
                    .getFiles(new java.io.File(getScriptContext().getGeneratorBase()).getAbsolutePath()
                            + File.separator + "lib", new String[] { "jar" }, File.pathSeparator)
                    + File.pathSeparator
                    + new java.io.File(projectRoot + File.separatorChar + "classes").getAbsolutePath();

            getScriptContext().logInfo("compiler classpath is: " + classPathStr);

            options.add(classPathStr);

            options.add("-d");
            options.add(projectRoot + File.separator + "classes");

            options.add("-s");
            options.add(projectRoot + File.separator + "src/generated");

            JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
            DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
            fileManager = compiler.getStandardFileManager(diagnostics, null, null);
            Iterable<? extends JavaFileObject> compilationUnits = fileManager
                    .getJavaFileObjectsFromStrings(compilerFiles);
            JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, options, null,
                    compilationUnits);
            boolean success = task.call();

            for (Diagnostic diagnostic : diagnostics.getDiagnostics()) {
                getScriptContext().logInfo(diagnostic.getCode());
                getScriptContext().logInfo(diagnostic.getKind().toString());
                getScriptContext().logInfo(diagnostic.getPosition() + "");
                getScriptContext().logInfo(diagnostic.getStartPosition() + "");
                getScriptContext().logInfo(diagnostic.getEndPosition() + "");
                getScriptContext().logInfo(diagnostic.getSource().toString());
                getScriptContext().logInfo(diagnostic.getMessage(null));
            }
        } catch (Throwable t) {
            getScriptContext().logError(t);
        } finally {
            try {
                fileManager.close();
            } catch (Throwable t) {
            }
        }

        for (String focusDomain : getScriptContext().retrieveDomainSet()) {
            generateWebServiceArtifacts(focusDomain);
        }
    }
}

From source file:org.splevo.vpm.analyzer.semantic.SemanticVPMAnalyzer.java

/**
 * Build filter for variation points not sharing the same set of terms with all of it's
 * connected vps./*ww  w . j  av a 2  s. co m*/
 *
 * If configured, also variation points sharing more than one term are included in the filter.
 *
 * @param sharedTermTable
 *            The table of variation points, there referenced other VPs and the terms they
 *            share.
 * @return The set of VP ids to not register any relationships for.
 */
private Set<String> buildImpreciseVPFilter(Table<String, String, Set<String>> sharedTermTable) {
    Set<String> vpFilter = Sets.newLinkedHashSet();
    if (similarTermSetOnlyConfig.getCurrentValue()) {

        // CHECK VPs in both directions as shared term is a bi-derectional relationship
        // and some VPs might be contained in only one direction.

        // CHECK ROWS
        for (String referenceVP : sharedTermTable.rowKeySet()) {
            Map<String, Set<String>> row = sharedTermTable.row(referenceVP);
            Set<String> referenceTerms = null;
            for (Set<String> currentTerms : row.values()) {
                if (referenceTerms == null) {
                    if (oneSharedTermOnlyConfig.getCurrentValue() && currentTerms.size() > 1) {
                        vpFilter.add(referenceVP);
                        break;
                    }
                    referenceTerms = currentTerms;
                } else {
                    if (!referenceTerms.containsAll(currentTerms)
                            || !currentTerms.containsAll(referenceTerms)) {
                        vpFilter.add(referenceVP);
                        break;
                    }
                }
            }
        }

        // CHECK COLUMNS
        for (String referenceVP : sharedTermTable.columnKeySet()) {
            Map<String, Set<String>> column = sharedTermTable.column(referenceVP);
            Set<String> referenceTerms = null;
            for (Set<String> currentTerms : column.values()) {
                if (referenceTerms == null) {
                    if (oneSharedTermOnlyConfig.getCurrentValue() && currentTerms.size() > 1) {
                        vpFilter.add(referenceVP);
                        break;
                    }
                    referenceTerms = currentTerms;
                } else {
                    if (!referenceTerms.containsAll(currentTerms)
                            || !currentTerms.containsAll(referenceTerms)) {
                        vpFilter.add(referenceVP);
                        break;
                    }
                }
            }
        }
    }
    return vpFilter;
}

From source file:uk.gov.gchq.gaffer.sketches.datasketches.sampling.function.aggregate.ReservoirLongUnionAggregatorTest.java

@Test
public void testAggregate() {
    final ReservoirLongsUnionAggregator unionAggregator = new ReservoirLongsUnionAggregator();
    unionAggregator.init();// w  w  w .  j a va  2 s.com

    unionAggregator._aggregate(union1);
    ReservoirLongsSketch currentState = unionAggregator._state().getResult();
    assertEquals(3L, currentState.getN());
    assertEquals(3, currentState.getNumSamples());
    // As less items have been added than the capacity, the sample should exactly match what was added.
    Set<Long> samples = new HashSet<>(Arrays.asList(ArrayUtils.toObject(currentState.getSamples())));
    Set<Long> expectedSamples = new HashSet<>();
    expectedSamples.add(1L);
    expectedSamples.add(2L);
    expectedSamples.add(3L);
    assertEquals(expectedSamples, samples);

    unionAggregator._aggregate(union2);
    currentState = unionAggregator._state().getResult();
    assertEquals(99L, currentState.getN());
    assertEquals(20L, currentState.getNumSamples());
    // As more items have been added than the capacity, we can't know exactly what items will be present
    // in the sample but we can check that they are all from the set of things we added.
    samples = new HashSet<>(Arrays.asList(ArrayUtils.toObject(currentState.getSamples())));
    for (long l = 4L; l < 100; l++) {
        expectedSamples.add(l);
    }
    assertTrue(expectedSamples.containsAll(samples));
}