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);
}
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 });
}
}
}
};
}
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;
}
}
};
}
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;
}
}
};
}
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 = """
* <characterList>
* <character/>
* <character>
* <name>Gromit</name>
* </character>
* </characterList>"""
*
* 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);
}
Aggregations