Search in sources :

Example 16 with Iterator

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

the class Node method build.

public void build(final GroovyObject builder, final Map namespaceMap, final Map<String, String> namespaceTagHints) {
    if (this.replacementNodeStack.empty()) {
        final Closure rest = new Closure(null) {

            public Object doCall(final Object o) {
                buildChildren(builder, namespaceMap, namespaceTagHints);
                return null;
            }
        };
        if (this.namespaceURI.length() == 0 && this.attributeNamespaces.isEmpty()) {
            builder.invokeMethod(this.name, new Object[] { this.attributes, rest });
        } else {
            final List newTags = new LinkedList();
            builder.getProperty("mkp");
            final List namespaces = (List) builder.invokeMethod("getNamespaces", new Object[] {});
            final Map current = (Map) namespaces.get(0);
            final Map pending = (Map) namespaces.get(1);
            if (this.attributeNamespaces.isEmpty()) {
                builder.getProperty(getTagFor(this.namespaceURI, current, pending, namespaceMap, namespaceTagHints, newTags, builder));
                builder.invokeMethod(this.name, new Object[] { this.attributes, rest });
            } else {
                final Map attributesWithNamespaces = new HashMap(this.attributes);
                for (Object key : this.attributes.keySet()) {
                    final Object attributeNamespaceURI = this.attributeNamespaces.get(key);
                    if (attributeNamespaceURI != null) {
                        attributesWithNamespaces.put(getTagFor(attributeNamespaceURI, current, pending, namespaceMap, namespaceTagHints, newTags, builder) + "$" + key, attributesWithNamespaces.remove(key));
                    }
                }
                builder.getProperty(getTagFor(this.namespaceURI, current, pending, namespaceMap, namespaceTagHints, newTags, builder));
                builder.invokeMethod(this.name, new Object[] { attributesWithNamespaces, rest });
            }
            // remove the new tags we had to define for this element
            if (!newTags.isEmpty()) {
                final Iterator iter = newTags.iterator();
                do {
                    pending.remove(iter.next());
                } while (iter.hasNext());
            }
        }
    } else {
        ((ReplacementNode) this.replacementNodeStack.peek()).build(builder, namespaceMap, namespaceTagHints);
    }
}
Also used : Closure(groovy.lang.Closure) HashMap(java.util.HashMap) Iterator(java.util.Iterator) GroovyObject(groovy.lang.GroovyObject) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map) LinkedList(java.util.LinkedList)

Example 17 with Iterator

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

the class NodeChildren method appendNode.

protected void appendNode(final Object newValue) {
    final Iterator iter = iterator();
    while (iter.hasNext()) {
        final NodeChild result = (NodeChild) iter.next();
        result.appendNode(newValue);
    }
}
Also used : Iterator(java.util.Iterator)

Example 18 with Iterator

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

the class SAXBuilder method createNode.

protected Object createNode(Object name, Map attributeMap, Object text) {
    AttributesImpl attributes = new AttributesImpl();
    for (Iterator iter = attributeMap.entrySet().iterator(); iter.hasNext(); ) {
        Map.Entry entry = (Map.Entry) iter.next();
        Object key = entry.getKey();
        Object value = entry.getValue();
        String uri = "";
        String localName = null;
        String qualifiedName = "";
        String valueText = (value != null) ? value.toString() : "";
        if (key instanceof QName) {
            QName qname = (QName) key;
            uri = qname.getNamespaceURI();
            localName = qname.getLocalPart();
            qualifiedName = qname.getQualifiedName();
        } else {
            localName = key.toString();
            qualifiedName = localName;
        }
        attributes.addAttribute(uri, localName, qualifiedName, "CDATA", valueText);
    }
    doStartElement(name, attributes);
    if (text != null) {
        doText(text);
    }
    return name;
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Iterator(java.util.Iterator) Map(java.util.Map)

Example 19 with Iterator

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

the class SSLFactory method disableExcludedCiphers.

private void disableExcludedCiphers(SSLEngine sslEngine) {
    String[] cipherSuites = sslEngine.getEnabledCipherSuites();
    ArrayList<String> defaultEnabledCipherSuites = new ArrayList<String>(Arrays.asList(cipherSuites));
    Iterator iterator = excludeCiphers.iterator();
    while (iterator.hasNext()) {
        String cipherName = (String) iterator.next();
        if (defaultEnabledCipherSuites.contains(cipherName)) {
            defaultEnabledCipherSuites.remove(cipherName);
            LOG.debug("Disabling cipher suite {}.", cipherName);
        }
    }
    cipherSuites = defaultEnabledCipherSuites.toArray(new String[defaultEnabledCipherSuites.size()]);
    sslEngine.setEnabledCipherSuites(cipherSuites);
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 20 with Iterator

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

the class DeltaIterationTranslationTest method testCorrectTranslation.

@Test
public void testCorrectTranslation() {
    try {
        final String JOB_NAME = "Test JobName";
        final String ITERATION_NAME = "Test Name";
        final String BEFORE_NEXT_WORKSET_MAP = "Some Mapper";
        final String AGGREGATOR_NAME = "AggregatorName";
        final int[] ITERATION_KEYS = new int[] { 2 };
        final int NUM_ITERATIONS = 13;
        final int DEFAULT_parallelism = 133;
        final int ITERATION_parallelism = 77;
        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
        // ------------ construct the test program ------------------
        {
            env.setParallelism(DEFAULT_parallelism);
            @SuppressWarnings("unchecked") DataSet<Tuple3<Double, Long, String>> initialSolutionSet = env.fromElements(new Tuple3<Double, Long, String>(3.44, 5L, "abc"));
            @SuppressWarnings("unchecked") DataSet<Tuple2<Double, String>> initialWorkSet = env.fromElements(new Tuple2<Double, String>(1.23, "abc"));
            DeltaIteration<Tuple3<Double, Long, String>, Tuple2<Double, String>> iteration = initialSolutionSet.iterateDelta(initialWorkSet, NUM_ITERATIONS, ITERATION_KEYS);
            iteration.name(ITERATION_NAME).parallelism(ITERATION_parallelism);
            iteration.registerAggregator(AGGREGATOR_NAME, new LongSumAggregator());
            // test that multiple workset consumers are supported
            DataSet<Tuple2<Double, String>> worksetSelfJoin = iteration.getWorkset().map(new IdentityMapper<Tuple2<Double, String>>()).join(iteration.getWorkset()).where(1).equalTo(1).projectFirst(0, 1);
            DataSet<Tuple3<Double, Long, String>> joined = worksetSelfJoin.join(iteration.getSolutionSet()).where(1).equalTo(2).with(new SolutionWorksetJoin());
            DataSet<Tuple3<Double, Long, String>> result = iteration.closeWith(joined, joined.map(new NextWorksetMapper()).name(BEFORE_NEXT_WORKSET_MAP));
            result.output(new DiscardingOutputFormat<Tuple3<Double, Long, String>>());
            result.writeAsText("/dev/null");
        }
        Plan p = env.createProgramPlan(JOB_NAME);
        // ------------- validate the plan ----------------
        assertEquals(JOB_NAME, p.getJobName());
        assertEquals(DEFAULT_parallelism, p.getDefaultParallelism());
        // validate the iteration
        GenericDataSinkBase<?> sink1, sink2;
        {
            Iterator<? extends GenericDataSinkBase<?>> sinks = p.getDataSinks().iterator();
            sink1 = sinks.next();
            sink2 = sinks.next();
        }
        DeltaIterationBase<?, ?> iteration = (DeltaIterationBase<?, ?>) sink1.getInput();
        // check that multi consumer translation works for iterations
        assertEquals(iteration, sink2.getInput());
        // check the basic iteration properties
        assertEquals(NUM_ITERATIONS, iteration.getMaximumNumberOfIterations());
        assertArrayEquals(ITERATION_KEYS, iteration.getSolutionSetKeyFields());
        assertEquals(ITERATION_parallelism, iteration.getParallelism());
        assertEquals(ITERATION_NAME, iteration.getName());
        MapOperatorBase<?, ?, ?> nextWorksetMapper = (MapOperatorBase<?, ?, ?>) iteration.getNextWorkset();
        InnerJoinOperatorBase<?, ?, ?, ?> solutionSetJoin = (InnerJoinOperatorBase<?, ?, ?, ?>) iteration.getSolutionSetDelta();
        InnerJoinOperatorBase<?, ?, ?, ?> worksetSelfJoin = (InnerJoinOperatorBase<?, ?, ?, ?>) solutionSetJoin.getFirstInput();
        MapOperatorBase<?, ?, ?> worksetMapper = (MapOperatorBase<?, ?, ?>) worksetSelfJoin.getFirstInput();
        assertEquals(IdentityMapper.class, worksetMapper.getUserCodeWrapper().getUserCodeClass());
        assertEquals(NextWorksetMapper.class, nextWorksetMapper.getUserCodeWrapper().getUserCodeClass());
        if (solutionSetJoin.getUserCodeWrapper().getUserCodeObject() instanceof WrappingFunction) {
            WrappingFunction<?> wf = (WrappingFunction<?>) solutionSetJoin.getUserCodeWrapper().getUserCodeObject();
            assertEquals(SolutionWorksetJoin.class, wf.getWrappedFunction().getClass());
        } else {
            assertEquals(SolutionWorksetJoin.class, solutionSetJoin.getUserCodeWrapper().getUserCodeClass());
        }
        assertEquals(BEFORE_NEXT_WORKSET_MAP, nextWorksetMapper.getName());
        assertEquals(AGGREGATOR_NAME, iteration.getAggregators().getAllRegisteredAggregators().iterator().next().getName());
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) GenericDataSinkBase(org.apache.flink.api.common.operators.GenericDataSinkBase) DataSet(org.apache.flink.api.java.DataSet) LongSumAggregator(org.apache.flink.api.common.aggregators.LongSumAggregator) DiscardingOutputFormat(org.apache.flink.api.java.io.DiscardingOutputFormat) MapOperatorBase(org.apache.flink.api.common.operators.base.MapOperatorBase) Iterator(java.util.Iterator) DeltaIterationBase(org.apache.flink.api.common.operators.base.DeltaIterationBase) DeltaIteration(org.apache.flink.api.java.operators.DeltaIteration) InnerJoinOperatorBase(org.apache.flink.api.common.operators.base.InnerJoinOperatorBase) Plan(org.apache.flink.api.common.Plan) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Tuple3(org.apache.flink.api.java.tuple.Tuple3) Test(org.junit.Test)

Aggregations

Iterator (java.util.Iterator)7939 ArrayList (java.util.ArrayList)2053 Set (java.util.Set)1744 HashMap (java.util.HashMap)1678 HashSet (java.util.HashSet)1526 Map (java.util.Map)1486 List (java.util.List)1463 Test (org.junit.Test)576 IOException (java.io.IOException)465 Collection (java.util.Collection)320 Region (org.apache.geode.cache.Region)240 SSOException (com.iplanet.sso.SSOException)227 LinkedList (java.util.LinkedList)196 File (java.io.File)187 TreeSet (java.util.TreeSet)187 SMSException (com.sun.identity.sm.SMSException)169 LinkedHashMap (java.util.LinkedHashMap)146 IdRepoException (com.sun.identity.idm.IdRepoException)133 NoSuchElementException (java.util.NoSuchElementException)130 Session (org.hibernate.Session)126