Search in sources :

Example 86 with List

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

the class DefaultTableModel method getValueAt.

public Object getValueAt(int rowIndex, int columnIndex) {
    List rows = getRows();
    Object answer = null;
    if (rowIndex < 0 || rowIndex >= rows.size()) {
        return answer;
    }
    if (columnIndex < 0 || columnIndex >= columnModel.getColumnCount()) {
        return answer;
    }
    Object row = getRows().get(rowIndex);
    rowModel.setValue(row);
    DefaultTableColumn column = (DefaultTableColumn) columnModel.getColumn(columnIndex);
    if (row == null || column == null) {
        return answer;
    }
    return column.getValue(row, rowIndex, columnIndex);
}
Also used : List(java.util.List)

Example 87 with List

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

the class GPathResult method getBody.

/**
     * Creates a Closure representing the body of this GPathResult.
     *
     * @return the body of this GPathResult, converted to a <code>Closure</code>
     */
public Closure getBody() {
    return new Closure(this.parent, this) {

        public void doCall(Object[] args) {
            final GroovyObject delegate = (GroovyObject) getDelegate();
            final GPathResult thisObject = (GPathResult) getThisObject();
            Node node = (Node) thisObject.getAt(0);
            List children = node.children();
            for (Object child : children) {
                delegate.getProperty("mkp");
                if (child instanceof Node) {
                    delegate.invokeMethod("yield", new Object[] { new NodeChild((Node) child, thisObject, "*", null) });
                } else {
                    delegate.invokeMethod("yield", new Object[] { child });
                }
            }
        }
    };
}
Also used : Closure(groovy.lang.Closure) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) GroovyObject(groovy.lang.GroovyObject) GroovyObject(groovy.lang.GroovyObject)

Example 88 with List

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

the class GPathResult method breadthFirst.

/**
     * Provides an Iterator over all the nodes of this GPathResult using a breadth-first traversal.
     *
     * @return the <code>Iterator</code> of (breadth-first) ordered GPathResults
     */
public Iterator breadthFirst() {
    return new Iterator() {

        private final List list = new LinkedList();

        private Iterator iter = iterator();

        private GPathResult next = getNextByBreadth();

        public boolean hasNext() {
            return this.next != null;
        }

        public Object next() {
            try {
                return this.next;
            } finally {
                this.next = getNextByBreadth();
            }
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }

        private GPathResult getNextByBreadth() {
            List children = new ArrayList();
            while (this.iter.hasNext() || !children.isEmpty()) {
                if (this.iter.hasNext()) {
                    final GPathResult node = (GPathResult) this.iter.next();
                    this.list.add(node);
                    this.list.add(this.iter);
                    children.add(node.children());
                } else {
                    List nextLevel = new ArrayList();
                    for (Object child : children) {
                        GPathResult next = (GPathResult) child;
                        Iterator iterator = next.iterator();
                        while (iterator.hasNext()) {
                            nextLevel.add(iterator.next());
                        }
                    }
                    this.iter = nextLevel.iterator();
                    children = new ArrayList();
                }
            }
            if (this.list.isEmpty()) {
                return null;
            } else {
                GPathResult result = (GPathResult) this.list.get(0);
                this.list.remove(0);
                this.iter = (Iterator) this.list.get(0);
                this.list.remove(0);
                return result;
            }
        }
    };
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) GroovyObject(groovy.lang.GroovyObject) LinkedList(java.util.LinkedList)

Example 89 with List

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

the class GPathResult method depthFirst.

/**
     * Provides an Iterator over all the nodes of this GPathResult using a depth-first traversal.
     *
     * @return the <code>Iterator</code> of (depth-first) ordered GPathResults
     */
public Iterator depthFirst() {
    return new Iterator() {

        private final List list = new LinkedList();

        private final Stack stack = new Stack();

        private Iterator iter = iterator();

        private GPathResult next = getNextByDepth();

        public boolean hasNext() {
            return this.next != null;
        }

        public Object next() {
            try {
                return this.next;
            } finally {
                this.next = getNextByDepth();
            }
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }

        private GPathResult getNextByDepth() {
            while (this.iter.hasNext()) {
                final GPathResult node = (GPathResult) this.iter.next();
                this.list.add(node);
                this.stack.push(this.iter);
                this.iter = node.children().iterator();
            }
            if (this.list.isEmpty()) {
                return null;
            } else {
                GPathResult result = (GPathResult) this.list.get(0);
                this.list.remove(0);
                this.iter = (Iterator) this.stack.pop();
                return result;
            }
        }
    };
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) LinkedList(java.util.LinkedList) Stack(java.util.Stack)

Example 90 with List

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

the class GPathResult method getAt.

/**
     * Supports the subscript operator for a GPathResult.
     * <pre class="groovyTestCase">
     * import groovy.util.slurpersupport.*
     * def text = """
     * &lt;characterList&gt;
     *   &lt;character/&gt;
     *   &lt;character&gt;
     *     &lt;name>Gromit&lt;/name&gt;
     *   &lt;/character&gt;
     * &lt;/characterList&gt;"""
     *
     * GPathResult characterList = new XmlSlurper().parseText(text)
     *
     * assert characterList.character[1].name == 'Gromit'
     * </pre>
     * @param index an index
     * @return the value at the given index
     */
public Object getAt(final int index) {
    if (index < 0) {
        // calculate whole list in this case
        // recommend avoiding -ve's as this is obviously not as efficient
        List list = list();
        int adjustedIndex = index + list.size();
        if (adjustedIndex >= 0 && adjustedIndex < list.size())
            return list.get(adjustedIndex);
    } else {
        final Iterator iter = iterator();
        int count = 0;
        while (iter.hasNext()) {
            if (count++ == index) {
                return iter.next();
            } else {
                iter.next();
            }
        }
    }
    return new NoChildren(this, this.name, this.namespaceTagHints);
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

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