Search in sources :

Example 71 with Iterator

use of java.util.Iterator in project groovy-core by groovy.

the class Sequence method checkCollectionType.

// Implementation methods
//-------------------------------------------------------------------------
/**
     * Checks that each member of the given collection are of the correct
     * type
     */
protected void checkCollectionType(Collection c) {
    if (type != null) {
        for (Iterator iter = c.iterator(); iter.hasNext(); ) {
            Object element = iter.next();
            checkType(element);
        }
    }
}
Also used : Iterator(java.util.Iterator)

Example 72 with Iterator

use of java.util.Iterator in project groovy-core by groovy.

the class IOGroovyMethods method iterator.

/**
     * Creates an iterator which will traverse through the reader a line at a time.
     *
     * @param self a Reader object
     * @return an Iterator for the Reader
     * @see java.io.BufferedReader#readLine()
     * @since 1.5.0
     */
public static Iterator<String> iterator(Reader self) {
    final BufferedReader bufferedReader;
    if (self instanceof BufferedReader)
        bufferedReader = (BufferedReader) self;
    else
        bufferedReader = new BufferedReader(self);
    return new Iterator<String>() {

        String nextVal;

        boolean nextMustRead = true;

        boolean hasNext = true;

        public boolean hasNext() {
            if (nextMustRead && hasNext) {
                try {
                    nextVal = readNext();
                    nextMustRead = false;
                } catch (IOException e) {
                    hasNext = false;
                }
            }
            return hasNext;
        }

        public String next() {
            String retval = null;
            if (nextMustRead) {
                try {
                    retval = readNext();
                } catch (IOException e) {
                    hasNext = false;
                }
            } else
                retval = nextVal;
            nextMustRead = true;
            return retval;
        }

        private String readNext() throws IOException {
            String nv = bufferedReader.readLine();
            if (nv == null)
                hasNext = false;
            return nv;
        }

        public void remove() {
            throw new UnsupportedOperationException("Cannot remove() from a Reader Iterator");
        }
    };
}
Also used : BufferedReader(java.io.BufferedReader) Iterator(java.util.Iterator) FromString(groovy.transform.stc.FromString) StringWriterIOException(groovy.lang.StringWriterIOException) IOException(java.io.IOException)

Example 73 with Iterator

use of java.util.Iterator in project groovy-core by groovy.

the class InvokerHelper method createMap.

public static Map createMap(Object[] values) {
    Map answer = new LinkedHashMap(values.length / 2);
    int i = 0;
    while (i < values.length - 1) {
        if ((values[i] instanceof SpreadMap) && (values[i + 1] instanceof Map)) {
            Map smap = (Map) values[i + 1];
            Iterator iter = smap.keySet().iterator();
            for (; iter.hasNext(); ) {
                Object key = iter.next();
                answer.put(key, smap.get(key));
            }
            i += 2;
        } else {
            answer.put(values[i++], values[i++]);
        }
    }
    return answer;
}
Also used : Iterator(java.util.Iterator) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 74 with Iterator

use of java.util.Iterator in project groovy-core by groovy.

the class InvokerHelper method spreadMap.

public static SpreadMap spreadMap(Object value) {
    if (value instanceof Map) {
        Object[] values = new Object[((Map) value).keySet().size() * 2];
        int index = 0;
        Iterator it = ((Map) value).keySet().iterator();
        for (; it.hasNext(); ) {
            Object key = it.next();
            values[index++] = key;
            values[index++] = ((Map) value).get(key);
        }
        return new SpreadMap(values);
    }
    throw new SpreadMapEvaluatingException("Cannot spread the map " + value.getClass().getName() + ", value " + value);
}
Also used : Iterator(java.util.Iterator) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 75 with Iterator

use of java.util.Iterator in project groovy-core by groovy.

the class FlatNodeListTraversal method process.

public AST process(AST t) {
    GroovySourceAST node = (GroovySourceAST) t;
    // fetch all the nodes in this AST into a List
    NodeCollector collector = new NodeCollector();
    AntlrASTProcessor internalTraversal = new PreOrderTraversal(collector);
    internalTraversal.process(t);
    List listOfAllNodesInThisAST = collector.getNodes();
    // process each node in turn
    setUp(node);
    Iterator itr = listOfAllNodesInThisAST.iterator();
    while (itr.hasNext()) {
        GroovySourceAST currentNode = (GroovySourceAST) itr.next();
        accept(currentNode);
    }
    tearDown(node);
    return null;
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST) Iterator(java.util.Iterator) List(java.util.List) AntlrASTProcessor(org.codehaus.groovy.antlr.AntlrASTProcessor)

Aggregations

Iterator (java.util.Iterator)8930 ArrayList (java.util.ArrayList)2267 Set (java.util.Set)1895 HashMap (java.util.HashMap)1828 Map (java.util.Map)1714 List (java.util.List)1622 HashSet (java.util.HashSet)1602 Test (org.junit.Test)624 IOException (java.io.IOException)524 Collection (java.util.Collection)377 Region (org.apache.geode.cache.Region)240 SSOException (com.iplanet.sso.SSOException)227 File (java.io.File)216 LinkedList (java.util.LinkedList)213 TreeSet (java.util.TreeSet)191 LinkedHashMap (java.util.LinkedHashMap)181 Entry (java.util.Map.Entry)174 SMSException (com.sun.identity.sm.SMSException)169 ListIterator (java.util.ListIterator)146 TreeMap (java.util.TreeMap)145