本文整理了Java中java.util.ListIterator.remove()
方法的一些代码示例,展示了ListIterator.remove()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ListIterator.remove()
方法的具体详情如下:
包路径:java.util.ListIterator
类名称:ListIterator
方法名:remove
[英]Removes from the list the last element that was returned by #next or #previous (optional operation). This call can only be made once per call to next or previous. It can be made only if #add has not been called after the last call to next or previous.
[中]从列表中删除#next或#previous返回的最后一个元素(可选操作)。每次呼叫下一个或上一个时,只能进行一次此呼叫。只有在上次调用“下一个”或“上一个”后未调用“添加”时,才能执行此操作。
代码示例来源:origin: hankcs/HanLP
/**
* Delete removed documents from the internal container.
*/
void refresh()
{
ListIterator<Document<K>> listIterator = documents_.listIterator();
while (listIterator.hasNext())
{
if (listIterator.next() == null)
listIterator.remove();
}
}
代码示例来源:origin: airbnb/lottie-android
@Override public void absorbContent(ListIterator<Content> contents) {
// Fast forward the iterator until after this content.
//noinspection StatementWithEmptyBody
while (contents.hasPrevious() && contents.previous() != this) {}
while (contents.hasPrevious()) {
Content content = contents.previous();
if (content instanceof PathContent) {
pathContents.add((PathContent) content);
contents.remove();
}
}
}
代码示例来源:origin: hankcs/HanLP
private static void mergeDate(ListIterator<Vertex> listIterator, Vertex next, Vertex current)
{
current = Vertex.newTimeInstance(current.realWord + next.realWord);
listIterator.previous();
listIterator.previous();
listIterator.set(current);
listIterator.next();
listIterator.next();
listIterator.remove();
}
代码示例来源:origin: stackoverflow.com
public class Reversed<T> implements Iterable<T> {
private final List<T> original;
public Reversed(List<T> original) {
this.original = original;
}
public Iterator<T> iterator() {
final ListIterator<T> i = original.listIterator(original.size());
return new Iterator<T>() {
public boolean hasNext() { return i.hasPrevious(); }
public T next() { return i.previous(); }
public void remove() { i.remove(); }
};
}
public static <T> Reversed<T> reversed(List<T> original) {
return new Reversed<T>(original);
}
}
代码示例来源:origin: google/guava
private static void assertTransformListIterator(List<String> list) {
ListIterator<String> iterator = list.listIterator(1);
assertEquals(1, iterator.nextIndex());
assertEquals("2", iterator.next());
assertEquals("3", iterator.next());
assertEquals("4", iterator.next());
assertEquals(4, iterator.nextIndex());
try {
assertEquals("4", iterator.previous());
assertEquals("3", iterator.previous());
assertEquals("2", iterator.previous());
assertTrue(iterator.hasPrevious());
assertEquals("1", iterator.previous());
assertFalse(iterator.hasPrevious());
assertEquals(-1, iterator.previousIndex());
try {
} catch (NoSuchElementException expected) {
iterator.remove();
assertEquals(asList("2", "3", "4"), list);
assertFalse(list.isEmpty());
iterator.add("1");
fail("transformed list iterator is addable");
} catch (UnsupportedOperationException expected) {
代码示例来源:origin: google/guava
public void testEmptyListIterator() {
ListIterator<String> iterator = Iterators.emptyListIterator();
assertFalse(iterator.hasNext());
assertFalse(iterator.hasPrevious());
assertEquals(0, iterator.nextIndex());
assertEquals(-1, iterator.previousIndex());
try {
iterator.next();
fail("no exception thrown");
} catch (NoSuchElementException expected) {
iterator.previous();
fail("no exception thrown");
} catch (NoSuchElementException expected) {
iterator.remove();
fail("no exception thrown");
} catch (UnsupportedOperationException expected) {
iterator.add("a");
fail("no exception thrown");
} catch (UnsupportedOperationException expected) {
代码示例来源:origin: apache/hbase
/**
* Try to remove extraneous items from the set of sampled items. This checks
* if an item is unnecessary based on the desired error bounds, and merges it
* with the adjacent item if it is.
*/
private void compress() {
if (samples.size() < 2) {
return;
}
ListIterator<SampleItem> it = samples.listIterator();
SampleItem prev = null;
SampleItem next = it.next();
while (it.hasNext()) {
prev = next;
next = it.next();
if (prev.g + next.g + next.delta <= allowableError(it.previousIndex())) {
next.g += prev.g;
// Remove prev. it.remove() kills the last thing returned.
it.previous();
it.previous();
it.remove();
// it.next() is now equal to next, skip it back forward again
it.next();
}
}
}
代码示例来源:origin: commons-collections/commons-collections
public void testBugCollections447() {
final List treeList = new TreeList();
treeList.add("A");
treeList.add("B");
treeList.add("C");
treeList.add("D");
final ListIterator li = treeList.listIterator();
assertEquals("A", li.next());
assertEquals("B", li.next());
assertEquals("B", li.previous());
li.remove(); // Deletes "B"
// previous() after remove() should move to
// the element before the one just removed
assertEquals("A", li.previous());
}
}
代码示例来源:origin: redisson/redisson
static synchronized AttributeInfo remove(ArrayList list, String name) {
if (list == null)
return null;
AttributeInfo removed = null;
ListIterator iterator = list.listIterator();
while (iterator.hasNext()) {
AttributeInfo ai = (AttributeInfo)iterator.next();
if (ai.getName().equals(name)) {
iterator.remove();
removed = ai;
}
}
return removed;
}
代码示例来源:origin: commons-collections/commons-collections
/**
* Test remove after add behaviour.
*/
public void testAddThenRemove() {
ListIterator it = makeFullListIterator();
// add then remove
if (supportsAdd() && supportsRemove()) {
it.next();
it.add(addSetValue());
try {
it.remove();
fail("IllegalStateException must be thrown from remove after add");
} catch (IllegalStateException e) {
}
}
}
代码示例来源:origin: robovm/robovm
/**
* Obtains a free entry from this pool, if one is available.
*
* @return an available pool entry, or <code>null</code> if there is none
*/
public BasicPoolEntry allocEntry(final Object state) {
if (!freeEntries.isEmpty()) {
ListIterator<BasicPoolEntry> it = freeEntries.listIterator(freeEntries.size());
while (it.hasPrevious()) {
BasicPoolEntry entry = it.previous();
if (LangUtils.equals(state, entry.getState())) {
it.remove();
return entry;
}
}
}
if (!freeEntries.isEmpty()) {
BasicPoolEntry entry = freeEntries.remove();
entry.setState(null);
OperatedClientConnection conn = entry.getConnection();
try {
conn.close();
} catch (IOException ex) {
log.debug("I/O error closing connection", ex);
}
return entry;
}
return null;
}
代码示例来源:origin: commons-collections/commons-collections
public void testRemoveThenSet() {
ListIterator it = makeFullListIterator();
if (supportsRemove() && supportsSet()) {
it.next();
it.remove();
try {
it.set(addSetValue());
fail("IllegalStateException must be thrown from set after remove");
} catch (IllegalStateException e) {
}
}
}
代码示例来源:origin: hankcs/HanLP
public static List<IWord> spilt(List<IWord> wordList)
{
ListIterator<IWord> listIterator = wordList.listIterator();
while (listIterator.hasNext())
{
IWord word = listIterator.next();
if (word instanceof CompoundWord)
{
listIterator.remove();
for (Word inner : ((CompoundWord) word).innerList)
{
listIterator.add(inner);
}
}
}
return wordList;
}
}
代码示例来源:origin: SpongePowered/SpongeAPI
/**
* Removes all empty texts from the beginning and end of this
* builder.
*
* @return This builder
*/
public Builder trim() {
Iterator<Text> front = this.children.iterator();
while (front.hasNext()) {
if (front.next().isEmpty()) {
front.remove();
} else {
break;
}
}
ListIterator<Text> back = this.children.listIterator(this.children.size());
while (back.hasPrevious()) {
if (back.previous().isEmpty()) {
back.remove();
} else {
break;
}
}
return this;
}
代码示例来源:origin: airbnb/lottie-android
@Override public void absorbContent(ListIterator<Content> contentsIter) {
// This check prevents a repeater from getting added twice.
// This can happen in the following situation:
// RECTANGLE
// REPEATER 1
// FILL
// REPEATER 2
// In this case, the expected structure would be:
// REPEATER 2
// REPEATER 1
// RECTANGLE
// FILL
// Without this check, REPEATER 1 will try and absorb contents once it is already inside of
// REPEATER 2.
if (contentGroup != null) {
return;
}
// Fast forward the iterator until after this content.
//noinspection StatementWithEmptyBody
while (contentsIter.hasPrevious() && contentsIter.previous() != this) {}
List<Content> contents = new ArrayList<>();
while (contentsIter.hasPrevious()) {
contents.add(contentsIter.previous());
contentsIter.remove();
}
Collections.reverse(contents);
contentGroup = new ContentGroup(lottieDrawable, layer, "Repeater", hidden, contents, null);
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
/**
* Try to remove extraneous items from the set of sampled items. This checks
* if an item is unnecessary based on the desired error bounds, and merges it
* with the adjacent item if it is.
*/
private void compress() {
if (samples.size() < 2) {
return;
}
ListIterator<SampleItem> it = samples.listIterator();
SampleItem prev = null;
SampleItem next = it.next();
while (it.hasNext()) {
prev = next;
next = it.next();
if (prev.g + next.g + next.delta <= allowableError(it.previousIndex())) {
next.g += prev.g;
// Remove prev. it.remove() kills the last thing returned.
it.previous();
it.previous();
it.remove();
// it.next() is now equal to next, skip it back forward again
it.next();
}
}
}
代码示例来源:origin: hankcs/HanLP
/**
* 随机挑一个近义词
* @param type 类型
* @return
*/
public Synonym randomSynonym(Type type, String preWord)
{
ArrayList<Synonym> synonymArrayList = new ArrayList<Synonym>(synonymList);
ListIterator<Synonym> listIterator = synonymArrayList.listIterator();
if (type != null) while (listIterator.hasNext())
{
Synonym synonym = listIterator.next();
if (synonym.type != type || (preWord != null && CoreBiGramTableDictionary.getBiFrequency(preWord, synonym.realWord) == 0)) listIterator.remove();
}
if (synonymArrayList.size() == 0) return null;
return synonymArrayList.get((int) (System.currentTimeMillis() % (long)synonymArrayList.size()));
}
代码示例来源:origin: commons-collections/commons-collections
public void testConcurrentModification_alwaysFastModErrorPrevious() {
FastArrayList list = new FastArrayList();
list.setFast(true);
list.add("a");
list.add("b");
list.add("c");
ListIterator iter = list.listIterator();
assertEquals("a", iter.next());
assertEquals("b", iter.next());
assertEquals("b", iter.previous());
list.remove(1);
try {
iter.remove();
} catch (ConcurrentModificationException ex) {
// expected
}
// iterator state now invalid
}
代码示例来源:origin: commons-collections/commons-collections
listIterator.remove();
listIterator.add("a");
listIterator.next();
listIterator.remove();
listIterator.add("a");
代码示例来源:origin: hankcs/HanLP
protected void filter(List<Term> termList)
{
ListIterator<Term> listIterator = termList.listIterator();
while (listIterator.hasNext())
{
if (!shouldInclude(listIterator.next()))
listIterator.remove();
}
}
内容来源于网络,如有侵权,请联系作者删除!