Search in sources :

Example 31 with HashSet

use of java.util.HashSet in project flink by apache.

the class DataSetUtilsITCase method testZipWithUniqueId.

@Test
public void testZipWithUniqueId() throws Exception {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    long expectedSize = 100L;
    DataSet<Long> numbers = env.generateSequence(1L, expectedSize);
    DataSet<Long> ids = DataSetUtils.zipWithUniqueId(numbers).map(new MapFunction<Tuple2<Long, Long>, Long>() {

        @Override
        public Long map(Tuple2<Long, Long> value) throws Exception {
            return value.f0;
        }
    });
    Set<Long> result = new HashSet<>(ids.collect());
    Assert.assertEquals(expectedSize, result.size());
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Tuple2(org.apache.flink.api.java.tuple.Tuple2) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 32 with HashSet

use of java.util.HashSet in project groovy by apache.

the class MopWriter method buildCurrentClassSignatureSet.

private static Set<MopKey> buildCurrentClassSignatureSet(List<MethodNode> methods) {
    if (methods.isEmpty())
        return Collections.EMPTY_SET;
    Set<MopKey> result = new HashSet<MopKey>(methods.size());
    for (MethodNode mn : methods) {
        MopKey key = new MopKey(mn.getName(), mn.getParameters());
        result.add(key);
    }
    return result;
}
Also used : MethodNode(org.codehaus.groovy.ast.MethodNode) HashSet(java.util.HashSet)

Example 33 with HashSet

use of java.util.HashSet in project hadoop by apache.

the class TestHarFileSystemBasics method testListLocatedStatus.

@Test
public void testListLocatedStatus() throws Exception {
    String testHarPath = this.getClass().getResource("/test.har").getPath();
    URI uri = new URI("har://" + testHarPath);
    HarFileSystem hfs = new HarFileSystem(localFileSystem);
    hfs.initialize(uri, new Configuration());
    // test.har has the following contents:
    //   dir1/1.txt
    //   dir1/2.txt
    Set<String> expectedFileNames = new HashSet<String>();
    expectedFileNames.add("1.txt");
    expectedFileNames.add("2.txt");
    // List contents of dir, and ensure we find all expected files
    Path path = new Path("dir1");
    RemoteIterator<LocatedFileStatus> fileList = hfs.listLocatedStatus(path);
    while (fileList.hasNext()) {
        String fileName = fileList.next().getPath().getName();
        assertTrue(fileName + " not in expected files list", expectedFileNames.contains(fileName));
        expectedFileNames.remove(fileName);
    }
    assertEquals("Didn't find all of the expected file names: " + expectedFileNames, 0, expectedFileNames.size());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) URI(java.net.URI) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 34 with HashSet

use of java.util.HashSet in project flink by apache.

the class StreamGraphHasherV1 method traverseStreamGraphAndGenerateHashes.

@Override
public Map<Integer, byte[]> traverseStreamGraphAndGenerateHashes(StreamGraph streamGraph) {
    // The hash function used to generate the hash
    final HashFunction hashFunction = Hashing.murmur3_128(0);
    final Map<Integer, byte[]> hashes = new HashMap<>();
    Set<Integer> visited = new HashSet<>();
    Queue<StreamNode> remaining = new ArrayDeque<>();
    // We need to make the source order deterministic. The source IDs are
    // not returned in the same order, which means that submitting the same
    // program twice might result in different traversal, which breaks the
    // deterministic hash assignment.
    List<Integer> sources = new ArrayList<>();
    for (Integer sourceNodeId : streamGraph.getSourceIDs()) {
        sources.add(sourceNodeId);
    }
    Collections.sort(sources);
    // Start with source nodes
    for (Integer sourceNodeId : sources) {
        remaining.add(streamGraph.getStreamNode(sourceNodeId));
        visited.add(sourceNodeId);
    }
    StreamNode currentNode;
    while ((currentNode = remaining.poll()) != null) {
        // generate the hash code.
        if (generateNodeHash(currentNode, hashFunction, hashes, streamGraph.isChainingEnabled())) {
            // Add the child nodes
            for (StreamEdge outEdge : currentNode.getOutEdges()) {
                StreamNode child = outEdge.getTargetVertex();
                if (!visited.contains(child.getId())) {
                    remaining.add(child);
                    visited.add(child.getId());
                }
            }
        } else {
            // We will revisit this later.
            visited.remove(currentNode.getId());
        }
    }
    return hashes;
}
Also used : HashFunction(com.google.common.hash.HashFunction) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StreamEdge(org.apache.flink.streaming.api.graph.StreamEdge) StreamNode(org.apache.flink.streaming.api.graph.StreamNode) ArrayDeque(java.util.ArrayDeque) HashSet(java.util.HashSet)

Example 35 with HashSet

use of java.util.HashSet in project flink by apache.

the class JarFileCreatorTest method TestAnonymousInnerClassTrick4.

//anonymous inner class in an anonymous inner class accessing a field of the outermost enclosing class.
@Test
public void TestAnonymousInnerClassTrick4() throws Exception {
    File out = new File(System.getProperty("java.io.tmpdir"), "jarcreatortest.jar");
    JarFileCreator jfc = new JarFileCreator(out);
    jfc.addClass(NestedAnonymousInnerClass.class).createJarFile();
    Set<String> ans = new HashSet<String>();
    ans.add("org/apache/flink/runtime/util/jartestprogram/NestedAnonymousInnerClass.class");
    ans.add("org/apache/flink/runtime/util/jartestprogram/NestedAnonymousInnerClass$1$1.class");
    ans.add("org/apache/flink/runtime/util/jartestprogram/NestedAnonymousInnerClass$1.class");
    ans.add("org/apache/flink/runtime/util/jartestprogram/NestedAnonymousInnerClass$A.class");
    Assert.assertTrue("Jar file for Anonymous Inner Class is not correct", validate(ans, out));
    out.delete();
}
Also used : File(java.io.File) NestedAnonymousInnerClass(org.apache.flink.runtime.util.jartestprogram.NestedAnonymousInnerClass) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

HashSet (java.util.HashSet)12137 Set (java.util.Set)2609 ArrayList (java.util.ArrayList)2318 HashMap (java.util.HashMap)2096 Test (org.junit.Test)2060 Map (java.util.Map)1198 Iterator (java.util.Iterator)979 IOException (java.io.IOException)934 List (java.util.List)911 File (java.io.File)607 LinkedHashSet (java.util.LinkedHashSet)460 Test (org.testng.annotations.Test)460 TreeSet (java.util.TreeSet)271 Collection (java.util.Collection)233 LinkedList (java.util.LinkedList)224 Region (org.apache.geode.cache.Region)202 SSOException (com.iplanet.sso.SSOException)188 Date (java.util.Date)180 LinkedHashMap (java.util.LinkedHashMap)169 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)166