本文整理了Java中java.util.LinkedList.listIterator()
方法的一些代码示例,展示了LinkedList.listIterator()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LinkedList.listIterator()
方法的具体详情如下:
包路径:java.util.LinkedList
类名称:LinkedList
方法名:listIterator
[英]Returns a list-iterator of the elements in this list (in proper sequence), starting at the specified position in the list. Obeys the general contract of List.listIterator(int).
The list-iterator is fail-fast: if the list is structurally modified at any time after the Iterator is created, in any way except through the list-iterator's own remove or addmethods, the list-iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.
[中]返回此列表中元素的列表迭代器(按正确顺序),从列表中的指定位置开始。遵守列表的总合同。列表迭代器(int)。
列表迭代器是快速失效的:如果在创建迭代器后的任何时间,列表迭代器以任何方式(除了通过列表迭代器自己的remove或addmethods)在结构上被修改,列表迭代器将抛出ConcurrentModificationException。因此,在面对并发修改时,迭代器会快速、干净地失败,而不是在将来的不确定时间冒着任意、不确定行为的风险。
代码示例来源:origin: hankcs/HanLP
/**
* 将一个词语从词网中彻底抹除
* @param cur 词语
* @param wordNetAll 词网
* @param line 当前扫描的行数
* @param length 当前缓冲区的长度
*/
private static void removeFromWordNet(Vertex cur, WordNet wordNetAll, int line, int length)
{
LinkedList<Vertex>[] vertexes = wordNetAll.getVertexes();
// 将其从wordNet中删除
for (Vertex vertex : vertexes[line + length])
{
if (vertex.from == cur)
vertex.from = null;
}
ListIterator<Vertex> iterator = vertexes[line + length - cur.realWord.length()].listIterator();
while (iterator.hasNext())
{
Vertex vertex = iterator.next();
if (vertex == cur) iterator.remove();
}
}
代码示例来源:origin: igniterealtime/Openfire
/**
* Obtain the current history to be iterated in reverse mode. This means that the returned list
* iterator will be positioned at the end of the history so senders of this message must
* traverse the list in reverse mode.
*
* @return A list iterator of Message objects positioned at the end of the list.
*/
public ListIterator<Message> getReverseMessageHistory(){
LinkedList<Message> list = new LinkedList<>(history);
// Sort messages. Messages may be out of order when running inside of a cluster
Collections.sort(list, new MessageComparator());
return list.listIterator(list.size());
}
代码示例来源:origin: cmusphinx/sphinx4
/**
* convert the list of words back to a space separated string
*
* @param list the list of words
* @return a space separated string
*/
private String toString(LinkedList<? extends Object> list) {
if (list == null || list.isEmpty())
return "";
StringBuilder sb = new StringBuilder();
ListIterator<? extends Object> iterator = list.listIterator();
while (iterator.hasNext())
sb.append(iterator.next()).append(' ');
sb.setLength(sb.length() - 1);
return sb.toString();
}
代码示例来源:origin: org.codehaus.groovy/groovy
public void applyFinallyBlocks(Label label, boolean isBreakLabel) {
// first find the state defining the label. That is the state
// directly after the state not knowing this label. If no state
// in the list knows that label, then the defining state is the
// current state.
StateStackElement result = null;
for (ListIterator iter = stateStack.listIterator(stateStack.size()); iter.hasPrevious();) {
StateStackElement element = (StateStackElement) iter.previous();
if (!element.currentBlockNamedLabels.values().contains(label)) {
if (isBreakLabel && element.breakLabel != label) {
result = element;
break;
}
if (!isBreakLabel && element.continueLabel != label) {
result = element;
break;
}
}
}
List<BlockRecorder> blocksToRemove;
if (result==null) {
// all Blocks do know the label, so use all finally blocks
blocksToRemove = (List<BlockRecorder>) Collections.EMPTY_LIST;
} else {
blocksToRemove = result.finallyBlocks;
}
List<BlockRecorder> blocks = new LinkedList<BlockRecorder>(finallyBlocks);
blocks.removeAll(blocksToRemove);
applyBlockRecorder(blocks);
}
代码示例来源: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: apache/hbase
ListIterator<SampleItem> it = samples.listIterator();
SampleItem item = it.next();
for (int i = start; i < bufferCount; i++) {
long v = buffer[i];
while (it.nextIndex() < samples.size() && item.value < v) {
item = it.next();
it.previous();
if (it.previousIndex() == 0 || it.nextIndex() == samples.size()) {
delta = 0;
} else {
代码示例来源:origin: marytts/marytts
throw new IllegalArgumentException("Cannot syllabify null string");
ListIterator<String> it = phoneList.listIterator(0);
if (!it.hasNext()) {
return phoneList;
it.previous(); // one step back
it.add("-"); // insert syllable boundary
it.next(); // and forward again
it = phoneList.listIterator(0);
int minSonority = 7; // one higher than possible maximum.
int minIndex = -1; // position of the sonority minimum
int syllableStart = -1;
while (it.hasNext()) {
it = phoneList.listIterator(0);
if (s.equals(".")) {
it.previous(); // skip . backwards
it.remove(); // remove the .
it = phoneList.listIterator(0);
it.remove(); // remove _
代码示例来源: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: org.apache.hadoop/hadoop-common
/**
* Get the estimated value at the specified quantile.
*
* @param quantile Queried quantile, e.g. 0.50 or 0.99.
* @return Estimated value at that quantile.
*/
private long query(double quantile) {
Preconditions.checkState(!samples.isEmpty(), "no data in estimator");
int rankMin = 0;
int desired = (int) (quantile * count);
ListIterator<SampleItem> it = samples.listIterator();
SampleItem prev = null;
SampleItem cur = it.next();
for (int i = 1; i < samples.size(); i++) {
prev = cur;
cur = it.next();
rankMin += prev.g;
if (rankMin + cur.g + cur.delta > desired + (allowableError(i) / 2)) {
return prev.value;
}
}
// edge case of wanting max value
return samples.get(samples.size() - 1).value;
}
代码示例来源:origin: hibernate/hibernate-orm
/**
* Start buffering events
* @param eventLimit the maximum number of events to buffer. -1 will buffer all events, 0 will buffer no events.
*/
public void mark(int eventLimit) {
this.eventLimit = eventLimit;
//Buffering no events now, clear the buffer and buffered reader
if (this.eventLimit == 0) {
this.eventBuffer.clear();
this.bufferReader = null;
}
//Buffering limited set of events, lets trim the buffer if needed
else if (this.eventLimit > 0) {
//If there is an iterator check its current position and calculate the new iterator start position
int iteratorIndex = 0;
if (this.bufferReader != null) {
final int nextIndex = this.bufferReader.nextIndex();
iteratorIndex = Math.max(0, nextIndex - (this.eventBuffer.size() - this.eventLimit));
}
//Trim the buffer until it is not larger than the limit
while (this.eventBuffer.size() > this.eventLimit) {
this.eventBuffer.poll();
}
//If there is an iterator re-create it using the newly calculated index
if (this.bufferReader != null) {
this.bufferReader = this.eventBuffer.listIterator(iteratorIndex);
}
}
}
代码示例来源:origin: neo4j/neo4j
ListIterator<LockRequest> listItr = waitingThreadList.listIterator(
waitingThreadList.lastIndexOf( lockRequest ) );
lockRequest = listItr.previous();
if ( lockRequest.lockType == LockType.WRITE && totalReadCount == lockRequest.element.readCount )
listItr.remove();
lockRequest.waitingThread.interrupt();
break;
listItr.remove();
lockRequest.waitingThread.interrupt();
代码示例来源:origin: org.netbeans.api/org-openide-util
public void remove() {
delegate.previous();
Item item = findNext();
if (item == null) {
throw new IllegalStateException();
}
int index = delegate.nextIndex();
writeOperation();
Item removed = state.items.remove(index);
assert removed.getKey().equals(item.getKey());
state.itemIndex.remove(item.getKey());
delegate = state.items.listIterator(index);
}
代码示例来源:origin: org.apache.zookeeper/zookeeper
ListIterator<Packet> iter = outgoingQueue.listIterator();
while (iter.hasNext()) {
Packet p = iter.next();
if (p.requestHeader == null) {
iter.remove();
outgoingQueue.add(0, p);
return p;
代码示例来源:origin: pentaho/pentaho-kettle
/**
* Finds the JobTracker for the job entry specified. Use this to
*
* @param jobEntryCopy
* The entry to search the job tracker for
* @return The JobTracker of null if none could be found...
*/
public JobTracker findJobTracker( JobEntryCopy jobEntryCopy ) {
if ( jobEntryCopy.getName() == null ) {
return null;
}
lock.readLock().lock();
try {
ListIterator<JobTracker> it = jobTrackers.listIterator( jobTrackers.size() );
while ( it.hasPrevious() ) {
JobTracker tracker = it.previous();
JobEntryResult result = tracker.getJobEntryResult();
if ( result != null ) {
if ( jobEntryCopy.getName().equals( result.getJobEntryName() )
&& jobEntryCopy.getNr() == result.getJobEntryNr() ) {
return tracker;
}
}
}
} finally {
lock.readLock().unlock();
}
return 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: org.apache.hadoop/hadoop-common
if (samples.size() == 0) {
SampleItem newItem = new SampleItem(buffer[0], 1, 0);
samples.add(newItem);
ListIterator<SampleItem> it = samples.listIterator();
SampleItem item = it.next();
for (int i = start; i < bufferCount; i++) {
long v = buffer[i];
while (it.nextIndex() < samples.size() && item.value < v) {
item = it.next();
it.previous();
if (it.previousIndex() == 0 || it.nextIndex() == samples.size()) {
delta = 0;
} else {
代码示例来源:origin: marytts/marytts
throw new IllegalArgumentException("Cannot syllabify null string");
ListIterator<String> it = phoneList.listIterator(0);
if (!it.hasNext()) {
return phoneList;
it.previous(); // one step back
it.add("-"); // insert syllable boundary
it.next(); // and forward again
it = phoneList.listIterator(0);
int minSonority = 7; // one higher than possible maximum.
int minIndex = -1; // position of the sonority minimum
int syllableStart = -1;
while (it.hasNext()) {
it = phoneList.listIterator(0);
if (s.equals(".")) {
it.previous(); // skip . backwards
it.remove(); // remove the .
it = phoneList.listIterator(0);
it.remove(); // remove _
代码示例来源:origin: apache/ignite
for (ListIterator<GridCacheMvccCandidate> it = rmts.listIterator(rmts.size()); it.hasPrevious(); ) {
GridCacheMvccCandidate cur = it.previous();
mvAfter = new LinkedList<>();
it.remove();
ListIterator<GridCacheMvccCandidate> it = rmts.listIterator(maxIdx + 1);
代码示例来源:origin: cmusphinx/sphinx4
ListIterator<Object> referenceWordsIterator = referenceItems.listIterator();
ListIterator<Object> hypothesisWordsIterator = hypothesisItems.listIterator();
String referenceWord;
String hypothesisWord;
for (int m = backtrace.size() - 2; m >= 0; m--) {
int backtraceEntry = backtrace.get(m);
a = referenceWordsIterator.next();
referenceWord = renderer.getRef(a, b);
} else {
b = hypothesisWordsIterator.next();
hypothesisWord = renderer.getHyp(a, b);
} else {
代码示例来源:origin: hankcs/HanLP
while (listIteratorFrom.hasNext())
Vertex from = listIteratorFrom.next();
if (from.getNature() == Nature.ns)
ListIterator<Vertex> listIteratorTo = vertexes[toIndex].listIterator();
while (listIteratorTo.hasNext())
Vertex to = listIteratorTo.next();
if (to.getNature() == Nature.ns)
内容来源于网络,如有侵权,请联系作者删除!