List of usage examples for java.util ListIterator next
E next();
From source file:Main.java
/** * Introduces overlap into a series of lists. * @param before # of elements from the end of the previous list to prepend * @param after # of elements from the beginning of the next list to append *//* www . j a va 2 s. c o m*/ public static <T> List<List<T>> overlap(List<List<T>> lists, int before, int after) { if (before < 0) { throw new IllegalArgumentException("Value of before cannot be negative"); } if (after < 0) { throw new IllegalArgumentException("Value of after cannot be negative"); } ListIterator<List<T>> iter = lists.listIterator(); List<List<T>> result = new ArrayList<List<T>>(); for (; iter.hasNext();) { List<T> current = new ArrayList<T>(iter.next()); List<T> prev = before > 0 ? findPrevious(iter) : null; List<T> next = after > 0 ? findNext(iter) : null; if (prev != null) { List<T> overlap = prev.subList(prev.size() - before, prev.size()); current.addAll(0, overlap); } if (next != null) { List<T> overlap = next.subList(0, after); current.addAll(overlap); } result.add(current); } return result; }
From source file:com.aliyun.openservices.odps.console.resource.CreateResourceCommand.java
public static AddResourceCommand parse(String commandString, ExecutionContext sessionContext) throws ODPSConsoleException { String[] tokens = new AntlrObject(commandString).getTokenStringArray(); if (tokens != null && tokens.length >= 2 && tokens[0].toUpperCase().equals("CREATE") && tokens[1].toUpperCase().equals("RESOURCE")) { GnuParser parser = new GnuParser(); Options options = new Options(); options.addOption("p", "project", true, null); options.addOption("c", "comment", true, null); options.addOption("f", "force", false, null); try {/*from www . j a va 2 s . c o m*/ CommandLine cl = parser.parse(options, tokens); String refName = null; String alias = ""; String comment = null; String type = null; String partitionSpec = ""; boolean isUpdate = false; List<String> argList = cl.getArgList(); int size = argList.size(); if (size < 4) { throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "Missing parameters"); } ListIterator<String> iter = argList.listIterator(); iter.next(); iter.next(); type = iter.next(); refName = iter.next(); if (iter.hasNext()) { String item = iter.next(); if (item.equals("(")) { boolean isParenPaired = false; while (iter.hasNext()) { String s = iter.next(); if (s.equals(")")) { isParenPaired = true; break; } partitionSpec += s; } if (!isParenPaired) { throw new ODPSConsoleException( ODPSConsoleConstants.BAD_COMMAND + "Unpaired parenthesis"); } if (!iter.hasNext()) { throw new ODPSConsoleException( ODPSConsoleConstants.BAD_COMMAND + "Missing parameter: alias"); } item = iter.next(); } alias = item; } if (iter.hasNext()) { throw new ODPSConsoleException( ODPSConsoleConstants.BAD_COMMAND + "Illegal parameter: " + iter.next()); } String projectName = null; Option[] opts = cl.getOptions(); for (Option opt : opts) { if ("f".equals(opt.getOpt())) { isUpdate = true; } else if ("c".equals(opt.getOpt())) { comment = opt.getValue(); } else if ("p".equals(opt.getOpt())) { projectName = opt.getValue(); } else { throw new ODPSConsoleException( ODPSConsoleConstants.BAD_COMMAND + "Illegal option: " + opt.getOpt()); } } return new AddResourceCommand(commandString, sessionContext, refName, alias, comment, type, partitionSpec, isUpdate, projectName); } catch (ParseException e) { throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "Invalid parameters"); } } else { return null; } }
From source file:Main.java
public static <E> void swapAll(final List<E> list, final int off, final int len) { if (list instanceof RandomAccess) { final int last = off + len - 1; for (int i = off, j = last; i < j; i++, j--) { list.set(i, list.set(j, list.get(i))); }/* w w w . j av a 2 s. c om*/ } else { final int end = off + len; final ListIterator<E> iteratorI = list.listIterator(off); final ListIterator<E> iteratorJ = list.listIterator(end); E tmp; while (iteratorI.nextIndex() < iteratorJ.nextIndex()) { tmp = iteratorI.next(); iteratorI.set(iteratorJ.previous()); iteratorJ.set(tmp); } } }
From source file:Main.java
public static <E> void swapAll(final List<E> list) { if (list instanceof RandomAccess) { for (int i = 0, j = list.size() - 1; i < j; i++, j--) { list.set(i, list.set(j, list.get(i))); }/* w w w . j a v a 2 s.com*/ } else { final ListIterator<E> iteratorI = list.listIterator(); final ListIterator<E> iteratorJ = list.listIterator(list.size()); E tmp; while (iteratorI.nextIndex() < iteratorJ.nextIndex()) { tmp = iteratorI.next(); iteratorI.set(iteratorJ.previous()); iteratorJ.set(tmp); } } }
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.j av a 2 s . co 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:gov.nih.nci.protexpress.util.ManageProtAppInputOutputHelper.java
/** * Removes the invalid items (inputs/outputs with blank name, filename and notes) from the list. * * @param lst the list of inputs/outputs. *///from www. ja va2s .c om public static void removeInvalidItems(List<InputOutputObject> lst) { ListIterator<InputOutputObject> listIter = lst.listIterator(); while (listIter.hasNext()) { InputOutputObject ioObject = listIter.next(); if (StringUtils.isBlank(ioObject.getName()) && StringUtils.isBlank(ioObject.getDataFileURL()) && StringUtils.isBlank(ioObject.getNotes())) { listIter.remove(); } } }
From source file:cascading.ComparePlatformsTest.java
private static void createComparisons(String comparison, File lhsRoot, File rhsRoot, TestSuite suite) { LOG.info("comparing directory: {}, with: {}", lhsRoot, rhsRoot); LinkedList<File> lhsFiles = new LinkedList<File>( FileUtils.listFiles(lhsRoot, new RegexFileFilter("^[\\w-]+"), TrueFileFilter.INSTANCE)); LinkedList<File> rhsFiles = new LinkedList<File>(); LOG.info("found lhs files: {}", lhsFiles.size()); int rootLength = lhsRoot.toString().length() + 1; ListIterator<File> iterator = lhsFiles.listIterator(); while (iterator.hasNext()) { File localFile = iterator.next(); File file = new File(rhsRoot, localFile.toString().substring(rootLength)); if (localFile.toString().endsWith(NONDETERMINISTIC)) iterator.remove();//from w w w . j a v a 2s .c om else if (file.exists()) rhsFiles.add(file); else iterator.remove(); } LOG.info("running {} comparisons", lhsFiles.size()); for (int i = 0; i < lhsFiles.size(); i++) { File localFile = lhsFiles.get(i); File hadoopFile = rhsFiles.get(i); suite.addTest(new CompareTestCase(comparison, localFile, hadoopFile)); } }
From source file:de.codesourcery.asm.util.Disassembler.java
/** * Disassemble a method.//from w w w. j av a 2s.c om * * @param method method to disassemble * @param includeVirtual whether to 'disassemble' virtual (ASM-generated) nodes that * have no equivalent in .class files * @param printInsnIndices * @param printInsnIndices whether to output the instruction index in front of the mnemonic * @return disassembled method */ public static String disassemble(MethodNode method, boolean includeVirtual, boolean printInsnIndices) { final StringBuilder result = new StringBuilder(); @SuppressWarnings("unchecked") final ListIterator<AbstractInsnNode> it = method.instructions.iterator(); while (it.hasNext()) { AbstractInsnNode node = it.next(); String line = disassemble(node, method, includeVirtual, printInsnIndices); if (line == null) { continue; } if (result.length() > 0) { result.append("\n"); } result.append(line); } return result.toString(); }
From source file:org.mule.providers.soap.axis.wsdl.wsrf.util.AdviceAdderHelper.java
/** * addAdvisors to ProxyfactoryBean given using reflection to find Advices class * end with "Advice" suffix. All advisors are mapped on "extend*" pattern string * method refer to Target bean./* w ww . j a va 2 s . c o m*/ * * @param targetImpl Target Object * @return new Proxy */ public static IExtendCall addAdvisorsTo(IExtendCall targetImpl) { ProxyFactory factory = new ProxyFactory(targetImpl); List l = getListAdvisorClass(); ListIterator li = l.listIterator(); Advisor advisor = null; if (order.size() == 0) { while (li.hasNext()) { advisor = (Advisor) li.next(); order.add(advisor); } } Iterator it = order.iterator(); while (it.hasNext()) { advisor = (Advisor) it.next(); factory.addAdvisor(countAdvice, advisor); Logger.getLogger(factory.getClass()).log(Level.DEBUG, factory.getClass().getName() + " : added " + advisor.getAdvice().getClass().getName() + " at index position " + countAdvice); countAdvice++; } countAdvice = 0; return (IExtendCall) factory.getProxy(); }
From source file:gov.nih.nci.protexpress.util.ManageProtAppInputOutputHelper.java
/** * Removes potential duplicate inputs from the list. * * @param lstInputs the protocol application inputs. * @param lstPotentialInputs the list of potential inputs. *//*from www . j a v a2 s. co m*/ private static void removeDuplicateInputs(List<InputOutputObject> lstInputs, List<InputOutputObject> lstPotentialInputs) { ListIterator<InputOutputObject> iterPAInputs = lstInputs.listIterator(); while (iterPAInputs.hasNext()) { InputOutputObject currentInput = iterPAInputs.next(); if ((currentInput.getId() != null) && !StringUtils.isBlank(currentInput.getId().toString()) && lstPotentialInputs.contains(currentInput)) { lstPotentialInputs.remove(currentInput); } } }