List of usage examples for java.util ListIterator previous
E previous();
From source file:org.synku4j.wbxml.util.WbxmlUtil.java
/** * Get the fields from the source object which are annotated with the * <code>WbxmlField</code> class. * //from w ww . j ava2 s . c o m * Note, this search from the bottom up, which means fields in the base class * are found before those in the derived class. * * NOTE: We should do some name clashing checks here, duplicate fields in classes * will more than likely screw up the marshaling. * * @param source the source object. * @return the annotated fields. */ public static Field[] getFields(final Object source) { if (source == null) { throw new NullPointerException("source object cannot be null"); } final ArrayList<Class<?>> heirachy = new ArrayList<Class<?>>(); Class<? extends Object> clazz = (source instanceof Class<?>) ? (Class<?>) source : source.getClass(); do { heirachy.add(clazz); clazz = clazz.getSuperclass(); } while (!Object.class.equals(clazz)); final List<Field> fields = new LinkedList<Field>(); // from the bottom up scan. final ListIterator<Class<?>> liter = heirachy.listIterator(heirachy.size()); while (liter.hasPrevious()) { clazz = liter.previous(); for (Field field : clazz.getDeclaredFields()) { final WbxmlField wbxmlField = field.getAnnotation(WbxmlField.class); if (wbxmlField != null) { fields.add(field); } } } if (log.isDebugEnabled()) { log.debug("Object class :" + source + " has (" + fields.size() + ") annotated fields"); } return fields.toArray(new Field[0]); }
From source file:Main.java
public static <E> Iterable<E> reverse(final List<E> list) { return new Iterable<E>() { @Override//w w w .j a v a2 s . c o m public Iterator<E> iterator() { final ListIterator<E> it = list.listIterator(list.size()); return new Iterator<E>() { @Override public boolean hasNext() { return it.hasPrevious(); } @Override public E next() { return it.previous(); } @Override public void remove() { it.remove(); } }; } }; }
From source file:com.redhat.lightblue.eval.Projector.java
private static ArrayProjector findArrayProjectorForField(Projector p, Path field) { if (p instanceof ListProjector) { List<Projector> items = ((ListProjector) p).getItems(); ListIterator<Projector> itemsItr = items.listIterator(items.size()); while (itemsItr.hasPrevious()) { Projector projector = itemsItr.previous(); ArrayProjector x = findArrayProjectorForField(projector, field); if (x != null) return x; }// w w w.j a va 2 s. c om } else if (p instanceof ArrayProjector) { if (field.matches(((ArrayProjector) p).getArrayFieldPattern())) { return (ArrayProjector) p; } return findArrayProjectorForField(p.getNestedProjector(), field); } return null; }
From source file:exm.stc.ic.ICUtil.java
public static void rewindIterator(@SuppressWarnings("rawtypes") ListIterator it, int n) { for (int i = 0; i < n; i++) { it.previous(); }//from w ww . ja v a2s .c o m }
From source file:org.apache.cocoon.forms.util.DomHelper.java
public static Map getInheritedNSDeclarations(Element elm) { List ancestorsAndSelf = new LinkedList(); Element current = elm;/*from w w w .java 2 s . c om*/ while (current != null) { ancestorsAndSelf.add(current); Node parent = current.getParentNode(); if (parent.getNodeType() == Node.ELEMENT_NODE) current = (Element) parent; else current = null; } Map nsDeclarations = null; ListIterator iter = ancestorsAndSelf.listIterator(ancestorsAndSelf.size()); while (iter.hasPrevious()) { Element element = (Element) iter.previous(); nsDeclarations = addLocalNSDeclarations(element, nsDeclarations); } return nsDeclarations; }
From source file:org.apache.xml.security.keys.keyresolver.implementations.RetrievalMethodResolver.java
private static Element getDocumentElement(Set<Node> set) { Iterator<Node> it = set.iterator(); Element e = null;//from w w w . j a v a 2s .c om while (it.hasNext()) { Node currentNode = it.next(); if (currentNode != null && Node.ELEMENT_NODE == currentNode.getNodeType()) { e = (Element) currentNode; break; } } List<Node> parents = new ArrayList<Node>(); // Obtain all the parents of the elemnt while (e != null) { parents.add(e); Node n = e.getParentNode(); if (n == null || Node.ELEMENT_NODE != n.getNodeType()) { break; } e = (Element) n; } // Visit them in reverse order. ListIterator<Node> it2 = parents.listIterator(parents.size() - 1); Element ele = null; while (it2.hasPrevious()) { ele = (Element) it2.previous(); if (set.contains(ele)) { return ele; } } return null; }
From source file:com.offbynull.coroutines.instrumenter.asm.SearchUtils.java
/** * Find line number associated with an instruction. * @param insnList instruction list for method * @param insnNode instruction within method being searched against * @throws NullPointerException if any argument is {@code null} or contains {@code null} * @throws IllegalArgumentException if arguments aren't all from the same method * @return line number node associated with the instruction, or {@code null} if no line number exists */// ww w. j av a 2 s . co m public static LineNumberNode findLineNumberForInstruction(InsnList insnList, AbstractInsnNode insnNode) { Validate.notNull(insnList); Validate.notNull(insnNode); int idx = insnList.indexOf(insnNode); Validate.isTrue(idx != -1); // Get index of labels and insnNode within method ListIterator<AbstractInsnNode> insnIt = insnList.iterator(idx); while (insnIt.hasPrevious()) { AbstractInsnNode node = insnIt.previous(); if (node instanceof LineNumberNode) { return (LineNumberNode) node; } } return null; }
From source file:Main.java
/** * Wraps an <code>ListIterator</code> and returns a <code>ListIterator</code> * that cannot modify the underlying list. * All methods that could be used to modify the list throw * <code>UnsupportedOperationException</code> * @param underlying original list iterator * @param <T> element type//from w w w . java 2s. c o m * @return unmodifiable list iterator */ @Nonnull public static <T> ListIterator<T> unmodifiableListIterator(final @Nonnull ListIterator<T> underlying) { return new ListIterator<T>() { public boolean hasNext() { return underlying.hasNext(); } public T next() { return underlying.next(); } public boolean hasPrevious() { return underlying.hasPrevious(); } public T previous() { return underlying.previous(); } public int nextIndex() { return underlying.nextIndex(); } public int previousIndex() { return underlying.previousIndex(); } public void remove() { throw new UnsupportedOperationException(); } public void set(T t) { throw new UnsupportedOperationException(); } public void add(T t) { throw new UnsupportedOperationException(); } }; }
From source file:Alias2.java
public static void verifyAtLeast(List output, List expected) { verifyLength(output.size(), expected.size(), Test.AT_LEAST); if (!output.containsAll(expected)) { ListIterator it = expected.listIterator(); while (output.contains(it.next())) { }/*from www. j a v a 2 s . c om*/ throw new SimpleTestException("expected: <" + it.previous().toString() + ">"); } }
From source file:com.nettyhttpserver.server.util.HttpRequestHandler.java
private static String generateStatus() { List<ServerRequestDTO> serverRequestList = serverRequestService.getServerRequest(); List<RedirectRequestDTO> redirectRequestList = redirectRequestService.getRedirectRequest(); StringBuilder sb = new StringBuilder(); sb.append(//from w w w . jav a 2 s. com "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><head>") .append( /* * Table style */ "<head>") .append("<style>") .append("table, td {border: solid 1px grey;background-color: rgb(233, 233, 233); margin: 0 auto;") .append("}table {width:90%;text-align: left; font-size: 16pt; bont-weight: bolder;}td{padding: 10px;}") .append("</style>").append("</head>") /* * Requests count */ .append("<h3>Server request count: ").append(serverRequestService.getRequestCount()) .append("<br>Server unique requests count: ").append(serverRequestService.getUniqueRequestCount()) .append("</h3>").append("<br><h3>Open connections: ").append(allChannels.size()).append("</h3>") /* * Table of server requests */ .append("<br><table id=\"table\"><caption>Server requests(last 100 )</caption> ") .append("<thead><tr> <th>IP</th><th>Count</th>") .append("<th>Last Request</th> </tr></thead><tbody> "); for (ServerRequestDTO record : serverRequestList) { sb.append("<tr><td>").append(record.getIP()).append("</td><td>").append(record.getRequestCount()) .append("</td><td>").append(record.getLastTimestamp()).append("</td></tr>"); } sb.append("</tbody></table>"); /* * Table of redirect requests */ sb.append("<table id=\"table\"><caption>Redirect requests(last 100 )</caption> ") .append("<thead><tr><th>URL</th>").append("<th>Count</th> </tr></thead><tbody> "); for (RedirectRequestDTO record : redirectRequestList) { sb.append("<tr><td>").append(record.getUrl()).append("</td><td>").append(record.getCount()) .append("</td>"); } sb.append("</tbody></table>"); /* * Table of server connections columns src_ip, URI, timestamp, * sent_bytes, received_bytes, speed (bytes/sec) */ sb.append("<table id=\"table\"><caption>Last 16 connections").append("</caption>") .append("<tr> <th>IP</th><th>URI</th>") .append("<th>TimeStamp</th><th>Sent</th><th>Recieved</th><th>Speed</th> </tr> "); ListIterator<ConnectionInfoDTO> iterator = NettyChannelTrafficShapingHandler .getServerConnectionListIterator(); synchronized (iterator) { while (iterator.hasPrevious()) { ConnectionInfoDTO item = iterator.previous(); sb.append("<tr><td>").append(item.getIp()).append("</td><td>").append(item.getUri()) .append("</td><td>").append(item.getTimestamp().toLocalDateTime()).append("</td><td>") .append(item.getSentBytes()).append("</td><td>").append(item.getRecivedBytes()) .append("</td><td>").append(item.getSpeed()).append("</td></tr>"); } } sb.append("</table>"); return sb.toString(); }