Delete the first n items from the list

@param newStart the logsegment who's index smaller than newStart will be deleted.
@return the deleted segment
337124
public List<LogSegment> trunc(int newStart) {
        if (newStart < 0) {
            throw new IllegalArgumentException("Starting index must be positive.");
        }
        while (true) {
            List<LogSegment> curr = contents.get();
            int newLength = Math.max(curr.size() - newStart, 0);
            List<LogSegment> updatedList = new ArrayList<LogSegment>(curr.subList(Math.min(newStart, curr.size() - 1),
                    curr.size()));
            if (contents.compareAndSet(curr, updatedList)) {
                return curr.subList(0, curr.size() - newLength);
            }
        }
    }
551012
public List<LogEntry> truncateEntriesFrom(long entryIndex) {
        if (entryIndex <= snapshotIndex()) {
            throw new IllegalArgumentException("Illegal index: " + entryIndex + ", snapshot index: " + snapshotIndex());
        }
        if (entryIndex > lastLogOrSnapshotIndex()) {
            throw new IllegalArgumentException("Illegal index: " + entryIndex + ", last log index: " + lastLogOrSnapshotIndex());
        }

        long startSequence = toSequence(entryIndex);
        assert startSequence >= logs.headSequence() : "Entry index: " + entryIndex + ", Head Seq: " + logs.headSequence();

        List<LogEntry> truncated = new ArrayList<LogEntry>();
        for (long ix = startSequence; ix <= logs.tailSequence(); ix++) {
            truncated.add(logs.read(ix));
        }
        logs.setTailSequence(startSequence - 1);

        return truncated;
    }
97345
public void filterSegments(List<Interval> allSegments) {
        segmentsToDelete = Lists.newArrayList(Iterables.filter(allSegments, new Predicate<Interval>() {
            @Override
            public boolean apply(Interval i) {
                return i.fallsIn(interval);
            }
        }));
    }
657382
private int nextTopLevelArgStart(int partIndex) {
        if (partIndex != 0) {
            partIndex = msgPattern.getLimitPartIndex(partIndex);
        }
        for (;;) {
            MessagePattern.Part.Type type = msgPattern.getPartType(++partIndex);
            if (type == MessagePattern.Part.Type.ARG_START) {
                return partIndex;
            }
            if (type == MessagePattern.Part.Type.MSG_LIMIT) {
                return -1;
            }
        }
    }
1187337
public E removeFirst() {
        final Node<E> f = first;
        if (f == null)
            throw new NoSuchElementException();
        return unlinkFirst(f);
    }
1236919
int deleteList(int list) {
		clear(list);
		int prevList = m_lists.getField(list, 2);
		int nextList = m_lists.getField(list, 3);
		if (prevList != nullNode())
			setNextList_(prevList, nextList);
		else
			m_list_of_lists = nextList;

		if (nextList != nullNode())
			setPrevList_(nextList, prevList);

		freeList_(list);
		return nextList;
	}
766192
public Token removeFirst(Transaction transaction)
                    throws ObjectManagerException {
        final String methodName = "removeFirst";
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this, cclass, methodName, new Object[] { transaction });

        Link first;
        Token tokenToReturn;
        // Prevent a clash with a backing out transaction.
        synchronized (transaction.internalTransaction) {
            //TODO Having locked on the Internal transaction we should check that this still refers back to the
            //TODO callers external transaction.
            synchronized (this) {
                first = nextLink(null,
                                 transaction,
                                 getTransactionUnlockSequence());
                if (first == null) { // Is there a first element?
                    if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                        trace.exit(this, cclass, methodName, "via java.util.NoSuchElementException");
                    throw new java.util.NoSuchElementException();
                } // (first == null).

                // Assign the tokenToReturn while we have the list locked so that the ObjectManager 
                // cannot backout this transaction and remove the link under another transaction 
                // causing this thread to see a null Token as a return value.
                tokenToReturn = first.data;

                first.requestDelete(transaction); // Mark for deletion. 

                // If the link is available to all adjust list visible length available.
                // In the case where we delete a link added by the same transaction we have no incremented 
                // the available size yet because we have not yet committed so we would not decrement it.
                if (!first.isLocked())
                    decrementAvailableSize();
            } // synchronized (this).

            // We can release the synchronize lock on the list because we don't care if the
            // link which we are going to delete is changed before we write the log record.
            // Log what we intend to do. Reserve enough spare log space so that the eventual
            // optimistic replace that removes the link from the list is certain to succeed
            // in being written as well. 

            try {
                transaction.delete(first,
                                   logSpaceForDelete());
            } catch (LogFileFullException exception) {
                // No FFDC Code Needed, transaction.delete() has already done this.
                unRemove(first);
                if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                    trace.exit(this, cclass, methodName, exception);
                throw exception;

                // We should not see ObjectStoreFullException because the ObjectStore already 
                // holds sufficient space to guarantee deletes work.
//      } catch (ObjectStoreFullException exception) {
//        // No FFDC Code Needed, transaction.delete() has already done this.
//        unRemove(first);
//        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
//        trace.exit(this, cclass, methodName, exception);
//        throw exception;

            } catch (InvalidStateException exception) {
                // No FFDC Code Needed.
                ObjectManager.ffdc.processException(this,
                                                    cclass,
                                                    methodName,
                                                    exception,
                                                    "1:698:1.40");
                unRemove(first);
                if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                    trace.exit(this, cclass, methodName, exception);
                throw exception;
            } // catch (LogFileFullException exception).
        } // synchronized (transaction.internalTransaction).

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this, cclass, methodName, new Object[] { tokenToReturn });
        return tokenToReturn;
    }
1080241
@Override
    public java.util.concurrent.Future<DeleteMessageBatchResult> deleteMessageBatchAsync(String queueUrl, java.util.List<DeleteMessageBatchRequestEntry> entries) {

        return deleteMessageBatchAsync(new DeleteMessageBatchRequest().withQueueUrl(queueUrl).withEntries(entries));
    }
562479
public Node removeFirst()
    {
        Node node = header.getNextNode();
        firstByte += node.ba.last();
        return removeNode( node );
    }
1222964
protected void setLayoutToStartSegment(int segmentLength,
                                          int priority,
                                          boolean isPooled,
                                          boolean isExchange,
                                          int packetNumber,
                                          int segmentType,
                                          int conversationId,
                                          int requestNumber,
                                          long totalLength)
   {
      if (tc.isEntryEnabled()) SibTr.entry(this, tc, "setLayoutToStartSegment", new Object[]{""+segmentLength, ""+priority, ""+isPooled, ""+isExchange, ""+packetNumber, ""+segmentType, ""+conversationId, ""+requestNumber, ""+totalLength});
      setLayoutToConversation(segmentLength, priority, isPooled, isExchange, packetNumber, segmentType, conversationId, requestNumber, null, null);
      segmentedTransmissionHeaderFields.totalLength = totalLength;
      segmentedTransmissionHeaderFields.segmentType = segmentType;
      transmissionRemaining = segmentLength;
      primaryHeaderFields.segmentType = JFapChannelConstants.SEGMENT_SEGMENTED_FLOW_START;      
      layout = JFapChannelConstants.XMIT_SEGMENT_START;
      if (tc.isEntryEnabled()) SibTr.exit(this, tc, "setLayoutToStartSegment");
   }
1316491
@Override
    public String incomingClearText(String st) {
        StringBuffer sb = new StringBuffer(st);

        int idx = sb.indexOf("'IIDIA:");
        if (idx != -1) {
            int idx2 = sb.indexOf("'", idx + 1);
            log.warn("removing invalid segment '" + sb.substring(idx + 1, idx2 + 1) + "'");
            sb.delete(idx + 1, idx2 + 1);
        }

        return sb.toString();
    }
768655
function segmentNew(start, end){
		return {
			id: buildLog ? buildLog.segmentId() : -1,
			start: start,
			end: end,
			myFill: {
				above: null, // is there fill above us?
				below: null  // is there fill below us?
			},
			otherFill: null
		};
	}
697737
@SuppressWarnings("unchecked")
    private void delete(SoftHandle<K, V> n) {
        if (n.tree == null) {
            throw new IllegalArgumentException("Invalid handle!");
        }

        /*
         * Delete from belonging list. Care must be taken as the tree reference
         * is valid only if the node is the first in the list.
         */
        TreeNode<K, V> tree = n.tree;

        if (tree.cHead != n) {
            /*
             * Not first in list. Each case, remove and leave as ghost element.
             */
            if (n.next != null) {
                n.next.prev = n.prev;
            }
            n.prev.next = n.next;
        } else {
            /*
             * First in list
             */
            SoftHandle<K, V> nNext = n.next;
            tree.cHead = nNext;
            if (nNext != null) {
                /*
                 * More elements exists, remove and leave as ghost element.
                 * Update new first element to point to correct tree.
                 */
                nNext.prev = null;
                nNext.tree = tree;
            } else {
                /*
                 * No more elements, sift.
                 */
                sift(tree);

                /*
                 * If still no elements, remove tree.
                 */
                if (tree.cHead == null) {
                    if (tree.parent instanceof TreeNode) {
                        TreeNode<K, V> p = (TreeNode<K, V>) tree.parent;
                        if (p.left == tree) {
                            p.left = null;
                        } else {
                            p.right = null;
                        }
                    } else {
                        delete((RootListNode<K, V>) tree.parent);
                    }
                }

            }
        }

        n.tree = null;
        n.prev = null;
        n.next = null;

        size--;
    }
408898
public SpannableStringBuilder delete(int start, int end) {
        SpannableStringBuilder ret = replace(start, end, "", 0, 0);

        if (mGapLength > 2 * length())
            resizeFor(length());

        return ret; // == this
    }
766748
public List<Item> deleteAllSelectedItems() {
        List<Item> deletedItems = new ArrayList<>();

        final List<Integer> positions = new ArrayList<>();
        mFastAdapter.recursive(new AdapterPredicate<Item>() {
            @Override
            public boolean apply(@NonNull IAdapter<Item> lastParentAdapter, int lastParentPosition, Item item, int position) {
                if (item.isSelected()) {
                    //if it's a subitem remove it from the parent
                    if (item instanceof ISubItem) {
                        //a sub item which is not in the list can be instantly deleted
                        IExpandable parent = (IExpandable) ((ISubItem) item).getParent();
                        //parent should not be null, but check in any case..
                        if (parent != null) {
                            parent.getSubItems().remove(item);
                        }
                    }
                    if (position != -1) {
                        //a normal displayed item can only be deleted afterwards
                        positions.add(position);
                    }
                }
                return false;
            }
        }, false);

        //we have to re-fetch the selections array again and again as the position will change after one item is deleted
        for (int i = positions.size() - 1; i >= 0; i--) {
            FastAdapter.RelativeInfo<Item> ri = mFastAdapter.getRelativeInfo(positions.get(i));
            if (ri.item != null && ri.item.isSelected()) { //double verify
                if (ri.adapter != null && ri.adapter instanceof IItemAdapter) {
                    ((IItemAdapter) ri.adapter).remove(positions.get(i));
                }
            }
        }
        return deletedItems;
    }
1253664
public long clean(final int currentRevisionIndex, final int revisionIndex)
	{

		if (first == null) {
			return 0;
		}
		else if (this.set.isEmpty()) {
			this.first = null;
			this.size = 0;
			return 0;
		}

		ChronoStorageBlock next, prev, current = first;
		boolean remove;

		do {
			remove = false;

			if (current.isDelivered()) {

				next = current.getCounterNext();

				if (next != null) {
					if (current.getRevisionCounter() + 1 == next
							.getRevisionCounter()) {
						remove = true;
					}
				}

			}
			else if (current.getIndexNext() == null
					&& current.getIndexPrev() == null) {

				remove = (current.getRevisionIndex() < currentRevisionIndex)
						|| (current.getRevisionIndex() == revisionIndex);
			}

			if (remove) {
				// System.out.println("Clearn CFR : " +
				// current.getRevisionCounter());

				prev = current.getCounterPrev();
				next = current.getCounterNext();

				current.setCounterNext(null);
				current.setCounterPrev(null);

				if (prev != null) {
					prev.setCounterNext(next);
				}
				if (next != null) {
					next.setCounterPrev(prev);
				}
				if (current == first) {
					this.first = next;
				}

				this.size -= current.length();
				current = next;
			}

			if (current != null) {
				current = current.getCounterNext();
			}

		}
		while (current != null);

		return this.size;
	}
506790
public void closeNewList() throws IOException {
    if (!closed) {
      if (segmentRegistration != null) {
        this.segmentName = null;
      }
      if (newSize > 0) {
        // add remaining old
        while (position < getSize()) {
          if (newPosition == newSize) {
            increaseNewListSize();
          }
          newKeyList[newPosition] = keyList[position];
          newSourceNumberList[newPosition] = sourceNumberList[position];
          newErrorNumber[newPosition] = errorNumber[position];
          newErrorList[newPosition] = errorList[position];
          if (hasSub) {
            newSubCollectorListNextLevel[newPosition] = subCollectorListNextLevel[position];
          }
          copyToNew(position, newPosition);
          position++;
          newPosition++;
        }
        // copy
        keyList = newKeyList;
        sourceNumberList = newSourceNumberList;
        errorNumber = newErrorNumber;
        errorList = newErrorList;
        subCollectorListNextLevel = newSubCollectorListNextLevel;
        copyFromNew();
        size = newPosition;
        // sort and merge
        if (!sortedAndUnique(keyList, getSize())) {
          remapData(computeSortAndUniqueMapping(keyList, getSize()));
        }
      }
      position = 0;
      newSize = 0;
      newPosition = 0;
      newCurrentPosition = 0;
    }
  }