List of usage examples for java.util ListIterator hasNext
boolean hasNext();
From source file:Main.java
public static <T> boolean listEquals(List<T> left, List<T> right) { if (left == right) return true; ListIterator<T> leftIterator = left.listIterator(); ListIterator<T> rightIterator = right.listIterator(); while (leftIterator.hasNext() && rightIterator.hasNext()) { T leftElement = leftIterator.next(); T rightElement = rightIterator.next(); if (!(leftElement == null ? rightElement == null : leftElement.equals(rightElement))) return false; }//from w w w . j a va 2s . c om return !(leftIterator.hasNext() || rightIterator.hasNext()); }
From source file:Main.java
/** * Finds an item by iterating through the specified iterator. * //from w w w .j a va2 s .c om * @param item the object to find * @param iter the iterator to examine * @return list index of the item or -1 if the item was not found */ public static int findObject(Object item, ListIterator<?> iter) { while (iter.hasNext()) { Object o = iter.next(); if (item == null ? o == null : item.equals(o)) { return iter.previousIndex(); } } return -1; }
From source file:Main.java
private static <E> void updateList(List<E> origList, Collection<? extends E> updateList, boolean add, boolean replace, boolean remove, BiPredicate<? super E, ? super E> equalTester, BiConsumer<List<E>, Collection<? extends E>> adder) { List<E> itemsToRemove = null; List<E> itemsToAdd = null; for (E update : updateList) { boolean origListContainsUpdate = false; ListIterator<E> origIter = origList.listIterator(); while (origIter.hasNext()) { E orig = origIter.next();/* ww w . java 2s . c o m*/ if (equalTester.test(orig, update)) { origListContainsUpdate = true; if (remove) { if (itemsToRemove == null) { itemsToRemove = new ArrayList<>(origList); } itemsToRemove.remove(orig); } if (replace) { origIter.set(update); } break; } } if (!origListContainsUpdate && add) { if (itemsToAdd == null) { itemsToAdd = new ArrayList<>(); } itemsToAdd.add(update); } } if (remove) { if (itemsToRemove != null) { origList.removeAll(itemsToRemove); } else { origList.clear(); } } if (itemsToAdd != null) { adder.accept(origList, itemsToAdd); } }
From source file:edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList.java
/** * Replace the first instance of this class of policy in the list. If no * instance is found, add the policy to the end of the list. *//*from w w w .j a va 2s. c o m*/ public static void replacePolicy(ServletContext sc, PolicyIface policy) { if (policy == null) { return; } Class<?> clzz = policy.getClass(); PolicyList policies = getPolicyList(sc); ListIterator<PolicyIface> it = policies.listIterator(); while (it.hasNext()) { if (clzz.isAssignableFrom(it.next().getClass())) { it.set(policy); return; } } addPolicy(sc, policy); }
From source file:mitm.common.util.StringReplaceUtils.java
/** * For each String in the list the non-XML characters are replaced. The returned list is the same instance as input * (it's an in place replacement)//from w w w . ja v a 2s.co m */ public static List<String> replaceNonXML(List<String> input, String replaceWith) { Check.notNull(replaceWith, "replaceWith"); if (input == null) { return null; } ListIterator<String> listIterator = input.listIterator(); while (listIterator.hasNext()) { String line = listIterator.next(); listIterator.set(StringReplaceUtils.replaceNonXML(line, "#")); } return input; }
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 *//*ww w . j a v a 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: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 2s . com * @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. */// w ww . ja v a 2 s. c o m 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: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. *//* ww w. j av a 2 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); } } }
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();//w w w . j a va2s. c o m 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)); } }