/** * 将一个词语从词网中彻底抹除 * @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(); } }
/** * 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()); }
/** * 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(); }
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); }
/** * 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(); } } }
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 {
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 _
/** * 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; }
/** * 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; }
/** * 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); } } }
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();
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); }
ListIterator<Packet> iter = outgoingQueue.listIterator(); while (iter.hasNext()) { Packet p = iter.next(); if (p.requestHeader == null) { iter.remove(); outgoingQueue.add(0, p); return p;
/** * 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; }
/** * 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(); } } }
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 {
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 _
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);
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 {
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)