Search in sources :

Example 96 with List

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

the class OutputSplitterITCase method testOnSingleDataStream.

@Test
public void testOnSingleDataStream() throws Exception {
    TestListResultSink<Integer> splitterResultSink1 = new TestListResultSink<Integer>();
    TestListResultSink<Integer> splitterResultSink2 = new TestListResultSink<Integer>();
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(1);
    env.setBufferTimeout(1);
    DataStream<Integer> ds = env.fromElements(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    ds.split(new OutputSelector<Integer>() {

        private static final long serialVersionUID = 2524335410904414121L;

        @Override
        public Iterable<String> select(Integer value) {
            List<String> s = new ArrayList<String>();
            if (value % 2 == 0) {
                s.add("even");
            } else {
                s.add("odd");
            }
            return s;
        }
    }).select("even").addSink(splitterResultSink1);
    ds.split(new OutputSelector<Integer>() {

        private static final long serialVersionUID = -511693919586034092L;

        @Override
        public Iterable<String> select(Integer value) {
            List<String> s = new ArrayList<String>();
            if (value % 4 == 0) {
                s.add("yes");
            } else {
                s.add("no");
            }
            return s;
        }
    }).select("yes").addSink(splitterResultSink2);
    env.execute();
    expectedSplitterResult.clear();
    expectedSplitterResult.addAll(Arrays.asList(0, 2, 4, 6, 8));
    assertEquals(expectedSplitterResult, splitterResultSink1.getSortedResult());
    expectedSplitterResult.clear();
    expectedSplitterResult.addAll(Arrays.asList(0, 4, 8));
    assertEquals(expectedSplitterResult, splitterResultSink2.getSortedResult());
}
Also used : TestListResultSink(org.apache.flink.test.streaming.runtime.util.TestListResultSink) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 97 with List

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

the class VerifyClass method readClass.

private boolean readClass(String clazz) throws IOException {
    ClassReader cr = new ClassReader(new FileInputStream(clazz));
    ClassNode ca = new ClassNode() {

        public void visitEnd() {
        //accept(cv);
        }
    };
    cr.accept(new CheckClassAdapter(ca), ClassWriter.COMPUTE_MAXS);
    boolean failed = false;
    List methods = ca.methods;
    for (int i = 0; i < methods.size(); ++i) {
        MethodNode method = (MethodNode) methods.get(i);
        if (method.instructions.size() > 0) {
            Analyzer a = new Analyzer(new SimpleVerifier());
            try {
                a.analyze(ca.name, method);
                continue;
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (!failed) {
                failed = true;
                log("verifying of class " + clazz + " failed");
            }
            if (verbose)
                log(method.name + method.desc);
            TraceMethodVisitor mv = new TraceMethodVisitor(null);
            /*= new TraceMethodVisitor(null) {
                    public void visitMaxs(int maxStack, int maxLocals) {
                        StringBuffer buffer = new StringBuffer();
                        for (int i = 0; i < text.size(); ++i) {
                            String s = frames[i] == null ? "null" : frames[i].toString();
                            while (s.length() < maxStack + maxLocals + 1) {
                                s += " ";
                            }
                            buffer.append(Integer.toString(i + 100000).substring(1));
                            buffer.append(" ");
                            buffer.append(s);
                            buffer.append(" : ");
                            buffer.append(text.get(i));
                        }
                        if (verbose) log(buffer.toString());
                    }
                };*/
            for (int j = 0; j < method.instructions.size(); ++j) {
                Object insn = method.instructions.get(j);
                if (insn instanceof AbstractInsnNode) {
                    ((AbstractInsnNode) insn).accept(mv);
                } else {
                    mv.visitLabel((Label) insn);
                }
            }
            mv.visitMaxs(method.maxStack, method.maxLocals);
        }
    }
    return !failed;
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) SimpleVerifier(org.objectweb.asm.tree.analysis.SimpleVerifier) Analyzer(org.objectweb.asm.tree.analysis.Analyzer) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) TraceMethodVisitor(org.objectweb.asm.util.TraceMethodVisitor) FileInputStream(java.io.FileInputStream) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) MethodNode(org.objectweb.asm.tree.MethodNode) CheckClassAdapter(org.objectweb.asm.util.CheckClassAdapter) ClassReader(org.objectweb.asm.ClassReader) List(java.util.List)

Example 98 with List

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

the class BSFSpecTest method testSimpleIntegration.

@Test
public void testSimpleIntegration() throws BSFException {
    // tag::bsf_simple[]
    String myScript = "println('Hello World')\n  return [1, 2, 3]";
    BSFManager manager = new BSFManager();
    List answer = (List) manager.eval("groovy", "myScript.groovy", 0, 0, myScript);
    assertEquals(3, answer.size());
// end::bsf_simple[]
}
Also used : List(java.util.List) BSFManager(org.apache.bsf.BSFManager) Test(org.junit.Test)

Example 99 with List

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

the class CacheBSFTest method testEval.

public void testEval() throws Exception {
    Object dontcare = manager.eval("groovy", "Test1.groovy", 0, 0, "return [1, 2, 3]");
    // nothing to really test here...just looking for debug that says it
    // used cache version
    Object answer = manager.eval("groovy", "Test.groovy", 0, 0, "return [1, 2, 3]");
    assertTrue("Should return a list: " + answer, answer instanceof List);
    List list = (List) answer;
    assertEquals("List should be of right size", 3, list.size());
}
Also used : List(java.util.List)

Example 100 with List

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

the class DecayRpcScheduler method getDecayedCallCounts.

private Map<Object, Long> getDecayedCallCounts() {
    Map<Object, Long> decayedCallCounts = new HashMap<>(callCounts.size());
    Iterator<Map.Entry<Object, List<AtomicLong>>> it = callCounts.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<Object, List<AtomicLong>> entry = it.next();
        Object user = entry.getKey();
        Long decayedCount = entry.getValue().get(0).get();
        if (decayedCount > 0) {
            decayedCallCounts.put(user, decayedCount);
        }
    }
    return decayedCallCounts;
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AtomicLong(java.util.concurrent.atomic.AtomicLong) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

List (java.util.List)19204 ArrayList (java.util.ArrayList)12470 Test (org.junit.Test)4025 HashMap (java.util.HashMap)3622 Map (java.util.Map)3242 IOException (java.io.IOException)1670 Iterator (java.util.Iterator)1563 LinkedList (java.util.LinkedList)1336 HashSet (java.util.HashSet)1189 Set (java.util.Set)1151 File (java.io.File)921 ImmutableList (com.google.common.collect.ImmutableList)826 Collectors (java.util.stream.Collectors)784 LinkedHashMap (java.util.LinkedHashMap)540 Test (org.testng.annotations.Test)527 Session (org.hibernate.Session)521 Collection (java.util.Collection)496 Collections (java.util.Collections)474 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)471 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)453