Java Code Examples for java.util.List.listIterator()

The following are Jave code examples for showing how to use listIterator() of the java.util.List class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: VirtualHook   File: SpecialComponentList.java   View Source Code Vote up 6 votes
public static void protectIntentFilter(IntentFilter filter) {
    if (filter != null) {
        List<String> actions = mirror.android.content.IntentFilter.mActions.get(filter);
        ListIterator<String> iterator = actions.listIterator();
        while (iterator.hasNext()) {
            String action = iterator.next();
            if (SpecialComponentList.isActionInBlackList(action)) {
                iterator.remove();
                continue;
            }
            if (SYSTEM_BROADCAST_ACTION.contains(action)) {
                continue;
            }
            String newAction = SpecialComponentList.protectAction(action);
            if (newAction != null) {
                iterator.set(newAction);
            }
        }
    }
}
 
Example 2
Project: iTAP-controller   File: VectorClockInconsistencyResolver.java   View Source Code Vote up 6 votes
public List<Versioned<T>> resolveConflicts(List<Versioned<T>> items) {
    int size = items.size();
    if(size <= 1)
        return items;

    List<Versioned<T>> newItems = Lists.newArrayList();
    for(Versioned<T> v1: items) {
        boolean found = false;
        for(ListIterator<Versioned<T>> it2 =
                newItems.listIterator(); it2.hasNext();) {
            Versioned<T> v2 = it2.next();
            Occurred compare = v1.getVersion().compare(v2.getVersion());
            if(compare == Occurred.AFTER) {
                if(found)
                    it2.remove();
                else
                    it2.set(v1);
            }
            if(compare != Occurred.CONCURRENTLY)
                found = true;
        }
        if(!found)
            newItems.add(v1);
    }
    return newItems;
}
 
Example 3
Project: JRediClients   File: RedissonListTest.java   View Source Code Vote up 6 votes
@Test
public void testListIteratorGetSet() {
    List<Integer> list = redisson.getList("list");
    list.add(1);
    list.add(2);
    list.add(3);
    list.add(4);

    ListIterator<Integer> iterator = list.listIterator();

    Assert.assertFalse(iterator.hasPrevious());
    Assert.assertTrue(1 == iterator.next());
    iterator.set(3);
    assertThat(list).containsExactly(3, 2, 3, 4);
    Assert.assertTrue(2 == iterator.next());
    iterator.add(31);
    assertThat(list).containsExactly(3, 2, 31, 3, 4);
    Assert.assertTrue(3 == iterator.next());
    Assert.assertTrue(4 == iterator.next());
    Assert.assertFalse(iterator.hasNext());
    iterator.add(71);
    assertThat(list).containsExactly(3, 2, 31, 3, 4, 71);
    iterator.add(8);
    assertThat(list).containsExactly(3, 2, 31, 3, 4, 71, 8);
}
 
Example 4
Project: n4js   File: N4HeadlessCompiler.java   View Source Code Vote up 6 votes
/**
 * Remove the given marked project from every loaded project that it depends on and unload those projects which have
 * no marks anymore, since those are no longer required to process other projects.
 *
 * @param loadedProjects
 *            the currently loaded projects
 * @param markedProject
 *            the project that was just processed
 * @param resourceSet
 *            the resource set
 * @param recorder
 *            the progress recorder
 */
private void unmarkAndUnloadProjects(List<MarkedProject> loadedProjects, MarkedProject markedProject,
		ResourceSet resourceSet, N4ProgressStateRecorder recorder) {
	ListIterator<MarkedProject> loadedIter = loadedProjects.listIterator();
	while (loadedIter.hasNext()) {
		MarkedProject loaded = loadedIter.next();
		loaded.remove(markedProject.project);

		if (!loaded.hasMarkers()) {
			if (logger.isCreateDebugOutput()) {
				logger.debug("Unloading project " + loaded.project);
			}

			loaded.unload(resourceSet, recorder);
			loadedIter.remove();
		}
	}
}
 
Example 5
Project: LaunchTime   File: MainActivity.java   View Source Code Vote up 6 votes
private String getNextCategory(String category, int dir) {
    if (dir>0) dir = 1;
    if (dir<0) dir = -1;

    List<String> categories = db().getCategories();
    for (ListIterator<String> it = categories.listIterator(); it.hasNext();) {
        String cat = it.next();
        if (Categories.isHiddenCategory(cat)) it.remove();
    }
    int last = categories.size() -1;
    for (int i=0; i<categories.size(); i++) {
        if (categories.get(i).equals(category)) {
            if (i==0 && dir==-1) return categories.get(last);
            if (i==last && dir==1) return categories.get(0);
            return categories.get(i+dir);
        }
    }
    return null;
}
 
Example 6
Project: hanlpStudy   File: NotionalTokenizer.java   View Source Code Vote up 6 votes
/**
 * 切分为句子形式
 *
 * @param text
 * @param filterArrayChain 自定义过滤器链
 * @return
 */
public static List<List<Term>> seg2sentence(String text, Filter... filterArrayChain)
{
    List<List<Term>> sentenceList = SEGMENT.seg2sentence(text);
    for (List<Term> sentence : sentenceList)
    {
        ListIterator<Term> listIterator = sentence.listIterator();
        while (listIterator.hasNext())
        {
            if (filterArrayChain != null)
            {
                Term term = listIterator.next();
                for (Filter filter : filterArrayChain)
                {
                    if (!filter.shouldInclude(term))
                    {
                        listIterator.remove();
                        break;
                    }
                }
            }
        }
    }

    return sentenceList;
}
 
Example 7
Project: HCFCore   File: AbstractLinkedList.java   View Source Code Vote up 6 votes
@Override
public boolean equals(final Object obj) {
    if (obj == this) {
        return true;
    }
    if (obj instanceof List == false) {
        return false;
    }
    final List<?> other = (List<?>) obj;
    if (other.size() != size()) {
        return false;
    }
    final ListIterator<?> it1 = listIterator();
    final ListIterator<?> it2 = other.listIterator();
    while (it1.hasNext() && it2.hasNext()) {
        final Object o1 = it1.next();
        final Object o2 = it2.next();
        if (!(o1 == null ? o2 == null : o1.equals(o2))) {
            return false;
        }
    }
    return !(it1.hasNext() || it2.hasNext());
}
 
Example 8
Project: openjdk-jdk10   File: XPreferTest.java   View Source Code Vote up 5 votes
public PermutationIterator(List<T> toPermute) {
    ListIterator<T> iter = toPermute.listIterator();
    if (iter.hasNext())
        head = new DirInt(iter.nextIndex(), iter.next());
    DirInt prev = head;
    while (iter.hasNext()) {
        DirInt di = new DirInt(iter.nextIndex(), iter.next());
        di.left = prev;
        prev.right = di;
        prev = di;
    }
}
 
Example 9
Project: hanlpStudy   File: CoreStopWordDictionary.java   View Source Code Vote up 5 votes
/**
 * 对分词结果应用过滤
 * @param termList
 */
public static void apply(List<Term> termList)
{
    ListIterator<Term> listIterator = termList.listIterator();
    while (listIterator.hasNext())
    {
        if (shouldRemove(listIterator.next())) listIterator.remove();
    }
}
 
Example 10
Project: RNLearn_Project1   File: FallbackJSBundleLoader.java   View Source Code Vote up 5 votes
/**
 * @param loaders Loaders for the sources to try, in descending order of
 *                preference.
 */
public FallbackJSBundleLoader(List<JSBundleLoader> loaders) {
  mLoaders = new Stack();
  ListIterator<JSBundleLoader> it = loaders.listIterator(loaders.size());
  while (it.hasPrevious()) {
    mLoaders.push(it.previous());
  }
}
 
Example 11
Project: sstore-soft   File: Lists.java   View Source Code Vote up 5 votes
/**
 * An implementation of {@link List#indexOf(Object)}.
 */
static int indexOfImpl(List<?> list, @Nullable Object element) {
  ListIterator<?> listIterator = list.listIterator();
  while (listIterator.hasNext()) {
    if (Objects.equal(element, listIterator.next())) {
      return listIterator.previousIndex();
    }
  }
  return -1;
}
 
Example 12
Project: openjdk-jdk10   File: SubList.java   View Source Code Vote up 5 votes
@Test(dataProvider = "unsettable",
      expectedExceptions = UnsupportedOperationException.class)
public void testUnmodListIteratorSet(List<Integer> list, int from, int to) {
    List<Integer> subList = list.subList(from, to);
    ListIterator<Integer> it = subList.listIterator();
    it.next();
    it.set(42);
}
 
Example 13
Project: cf-mta-deploy-service   File: RetryActivitiAction.java   View Source Code Vote up 5 votes
@Override
public void executeAction(String superProcessInstanceId) {
    List<String> subProcessIds = getActiveExecutionIds(superProcessInstanceId);
    ListIterator<String> subProcessesIdsIterator = subProcessIds.listIterator(subProcessIds.size());
    while (subProcessesIdsIterator.hasPrevious()) {
        String subProcessId = subProcessesIdsIterator.previous();
        retryProcess(subProcessId);
    }
}
 
Example 14
Project: Visitor   File: MultipleMapIterateState.java   View Source Code Vote up 5 votes
@Override
protected KeyValuePair<K, V> visitImpl(Map<K, V> map, boolean hasExtra, MapOperateInterceptor<K, V> moip,
		IterationInfo info, Object param, MapPredicateVisitor<K, V> predicate, List<KeyValuePair<K, V>> out) {

	final List<KeyValuePair<K, V>> keyValues = map.getKeyValues();
	final ListIterator<KeyValuePair<K, V>> it = keyValues.listIterator();

	KeyValuePair<K, V> pair;
	if (hasExtra) {
		for (; it.hasNext();) {
			pair = it.next();
			if (moip.intercept(map, pair, param, info)) {
				continue;
			}
			if (isTrue(predicate.visit(pair, param))) {
				out.add(pair);
			}
		}
	} else {
		// no extra ops
		for (; it.hasNext();) {
			pair = it.next();
			if (isTrue(predicate.visit(pair, param))) {
				out.add(pair);
			}
		}
	}
	return null;
}
 
Example 15
Project: JRediClients   File: RedissonListTest.java   View Source Code Vote up 5 votes
@Test
public void testListIteratorOK() {
    List<Integer> list = redisson.getList("simpleList");
    list.add(1);

    ListIterator<Integer> iterator = list.listIterator();

    iterator.next();
    iterator.set(3);
    iterator.set(4);
}
 
Example 16
Project: s-store   File: Lists.java   View Source Code Vote up 5 votes
/**
 * An implementation of {@link List#indexOf(Object)}.
 */
static int indexOfImpl(List<?> list, @Nullable Object element) {
  ListIterator<?> listIterator = list.listIterator();
  while (listIterator.hasNext()) {
    if (Objects.equal(element, listIterator.next())) {
      return listIterator.previousIndex();
    }
  }
  return -1;
}
 
Example 17
Project: rapidminer   File: ProcessRendererMouseHandler.java   View Source Code Vote up 4 votes
/**
 * Updates the currently hovered element
 *
 * @param e
 */
private void updateHoveringState(final MouseEvent e) {
	int hoveringProcessIndex = model.getHoveringProcessIndex();
	if (model.getHoveringProcessIndex() != -1) {
		int relativeX = (int) model.getMousePositionRelativeToProcess().getX();
		int relativeY = (int) model.getMousePositionRelativeToProcess().getY();

		OutputPort connectionSourceUnderMouse = controller.getPortForConnectorNear(
				model.getMousePositionRelativeToProcess(), model.getProcess(hoveringProcessIndex));
		if (connectionSourceUnderMouse != model.getHoveringConnectionSource()) {
			model.setHoveringConnectionSource(connectionSourceUnderMouse);
			model.fireMiscChanged();
			e.consume();
		}

		// find inner sinks/sources under mouse
		if (controller.checkPortUnder(model.getProcess(hoveringProcessIndex).getInnerSinks(), relativeX, relativeY)
				|| controller.checkPortUnder(model.getProcess(hoveringProcessIndex).getInnerSources(), relativeX,
						relativeY)) {
			e.consume();
			return;
		}

		// find operator under mouse
		List<Operator> operators = model.getProcess(hoveringProcessIndex).getOperators();
		ListIterator<Operator> iterator = operators.listIterator(operators.size());
		while (iterator.hasPrevious()) {
			Operator op = iterator.previous();
			// first, check whether we are over a port
			if (controller.checkPortUnder(op.getInputPorts(), relativeX, relativeY)
					|| controller.checkPortUnder(op.getOutputPorts(), relativeX, relativeY)) {
				e.consume();
				return;
			}
			// If not, check operator.
			Rectangle2D rect = model.getOperatorRect(op);
			if (rect == null) {
				continue;
			}
			if (rect.contains(new Point2D.Double(relativeX, relativeY))) {
				if (model.getHoveringOperator() != op) {
					model.setHoveringPort(null);
					view.setHoveringOperator(op);
					if (model.getHoveringOperator() instanceof OperatorChain) {
						controller.showStatus(I18N.getGUILabel("processRenderer.displayChain.hover"));
					} else {
						controller.showStatus(I18N.getGUILabel("processRenderer.operator.hover"));
					}
				}
				e.consume();
				return;
			}
		}
	}
	if (model.getHoveringOperator() != null) {
		view.setHoveringOperator(null);
	}
	if (model.getHoveringPort() != null) {
		model.setHoveringPort(null);
		view.updateCursor();
		model.fireMiscChanged();
	}
	if (model.getHoveringConnectionSource() != null) {
		controller.showStatus(I18N.getGUILabel("processRenderer.connection.hover"));
		e.consume();
	} else {
		controller.clearStatus();
	}
}
 
Example 18
Project: HCFCore   File: CollectionUtils.java   View Source Code Vote up 4 votes
/**
 * Transform the collection by applying a Transformer to each element.
 * <p>
 * If the input collection or transformer is null, there is no change made.
 * <p>
 * This routine is best for Lists, for which set() is used to do the
 * transformations "in place." For other Collections, clear() and addAll()
 * are used to replace elements.
 * <p>
 * If the input collection controls its input, such as a Set, and the
 * Transformer creates duplicates (or are otherwise invalid), the collection
 * may reduce in size due to calling this method.
 *
 * @param <C>  the type of object the {@link Collection} contains
 * @param collection  the {@link Collection} to get the input from, may be null
 * @param transformer  the transformer to perform, may be null
 */
public static <C> void transform(final Collection<C> collection,
                                 final Transformer<? super C, ? extends C> transformer) {

    if (collection != null && transformer != null) {
        if (collection instanceof List<?>) {
            final List<C> list = (List<C>) collection;
            for (final ListIterator<C> it = list.listIterator(); it.hasNext();) {
                it.set(transformer.transform(it.next()));
            }
        } else {
            final Collection<C> resultCollection = collect(collection, transformer);
            collection.clear();
            collection.addAll(resultCollection);
        }
    }
}
 
Example 19
Project: alvisnlp   File: ShellEnvironment.java   View Source Code Vote up 4 votes
private ElementPosition(List<Element> list) throws Exception {
	iterator = list.listIterator();
	if (!iterator.hasNext())
		throw new Exception("no solution");
	element = iterator.next();
}
 
Example 20
Project: oma-riista-android   File: HarvestFragment.java   View Source Code Vote up 4 votes
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == MapViewerActivity.LOCATION_REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            Location location = data.getParcelableExtra(MapViewerActivity.RESULT_LOCATION);

            if (mEvent != null) {
                mEvent.mLocation = location;
                mEvent.mAccuracy = location.getAccuracy();
                mEvent.mHasAltitude = location.hasAltitude();
                mEvent.mAltitude = location.getAltitude();
                mEvent.mCoordinates = MapUtils.WGS84toETRSTM35FIN(location.getLatitude(), location.getLongitude());
                mEvent.mLocationSource = data.getStringExtra(MapViewerActivity.RESULT_LOCATION_SOURCE);
            }
        }
    } else if (requestCode == ChooseSpeciesActivity.SPECIES_REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            mSelectedSpecies = (Species) data.getSerializableExtra(ChooseSpeciesActivity.RESULT_SPECIES);
            mEvent.mSpeciesID = mSelectedSpecies.mId;
        }
    } else if (requestCode == SPECIMENS_REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            List<Specimen> specimens = (List<Specimen>) data.getSerializableExtra(HarvestSpecimensActivity.RESULT_SPECIMENS);

            for (Iterator<Specimen> iter = specimens.listIterator(); iter.hasNext(); ) {
                Specimen specimen = iter.next();
                if (specimen.isEmpty()) {
                    iter.remove();
                }
            }

            mEvent.mSpecimen.clear();
            mEvent.mSpecimen.addAll(specimens);
        }
    } else if (requestCode == HarvestPermitActivity.PERMIT_REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            String permitNumber = data.getStringExtra(HarvestPermitActivity.RESULT_PERMIT_NUMBER);
            String permitType = data.getStringExtra(HarvestPermitActivity.RESULT_PERMIT_TYPE);
            int species = data.getIntExtra(HarvestPermitActivity.RESULT_PERMIT_SPECIES, -1);

            mEvent.mPermitNumber = permitNumber;
            mEvent.mPermitType = permitType;
            mEvent.mSpeciesID = species;

            mSelectedSpecies = SpeciesInformation.getSpecies(species);
            mPermitNumber.setText(permitNumber);
        }
    } else {
        mDiaryImageManager.handleImageResult(requestCode, resultCode, data);
    }
}