/** * Gets the index to the first element if it exists. * @return The index of the first element (head) or -1 if no elements exist. */ public long getFirst() { if (isEmpty()) { return -1; } return this.first; }
/** * Gets the index to the first element if it exists. * @return The index of the first element (head) or -1 if no elements exist. */ public long getFirst() { if (isEmpty()) { return -1; } return this.first; }
/** * Gets the index to the last element if it exists. * @return The index of the last element (tail) or -1 if no elements exist. */ public long getLast() { if (isEmpty()) { return -1; } // next points to current free space, so the one directly before it // would actually be the last item // NOTE: -1 mod 4 = 3 (isn't the modulus operator schweet?) //return ((next - 1) % capacity); return calculateNewIndex(next, -1); }
/** * Gets the index to the last element if it exists. * @return The index of the last element (tail) or -1 if no elements exist. */ public long getLast() { if (isEmpty()) { return -1; } // next points to current free space, so the one directly before it // would actually be the last item // NOTE: -1 mod 4 = 3 (isn't the modulus operator schweet?) //return ((next - 1) % capacity); return calculateNewIndex(next, -1); }
/** * Gets the index where the next last element will be put. This is the index * where the next "addLast" operation would put the element. Will return -1 if * the index is full (i.e. no next space available). * @return The index of where the next last element will be put or -1 if the * the index is full. */ public long getNextLast() { if (isFull()) { return -1; } else if (isEmpty()) { // interesting case, always the same as the first return first; } else { return next; } }
/** * Gets the index where the next last element will be put. This is the index * where the next "addLast" operation would put the element. Will return -1 if * the index is full (i.e. no next space available). * @return The index of where the next last element will be put or -1 if the * the index is full. */ public long getNextLast() { if (isFull()) { return -1; } else if (isEmpty()) { // interesting case, always the same as the first return first; } else { return next; } }
/** * Gets the index where the next first element will be put. This is the index * where the next "addFirst" operation would put the element. Will return -1 if * the index is full (i.e. no next space available). * @return The index of where the next first element will be put or -1 if the * the index is full. */ public long getNextFirst() { if (isFull()) { return -1; } else if (isEmpty()) { // interesting case, always the current first return first; } else { return calculateNewIndex(first, -1); } }
/** * Gets the index where the next first element will be put. This is the index * where the next "addFirst" operation would put the element. Will return -1 if * the index is full (i.e. no next space available). * @return The index of where the next first element will be put or -1 if the * the index is full. */ public long getNextFirst() { if (isFull()) { return -1; } else if (isEmpty()) { // interesting case, always the current first return first; } else { return calculateNewIndex(first, -1); } }
/** * Removes the first element from the front of the index if its not empty. * @return True if the element was removed or false if the index was empty. */ public boolean removeFirst() { // check if queue is empty if (isEmpty()) { return false; } // increment first item, rollver to beginning if needed first = calculateNewIndex(first, 1); //first = (first + 1) % capacity; // always decrement size size--; // check if we should reset checkReset(); return true; }
/** * Removes the last element from the back of the index if its not empty. * @return True if the element was removed or false if the index was empty. */ public boolean removeLast() { // check if queue is empty if (isEmpty()) { return false; } // increment first item, rollver to beginning if needed next = calculateNewIndex(next, -1); //next = (next - 1) % capacity; // always decrement size size--; // check if we should reset checkReset(); return true; }
/** * Removes the last element from the back of the index if its not empty. * @return True if the element was removed or false if the index was empty. */ public boolean removeLast() { // check if queue is empty if (isEmpty()) { return false; } // increment first item, rollver to beginning if needed next = calculateNewIndex(next, -1); //next = (next - 1) % capacity; // always decrement size size--; // check if we should reset checkReset(); return true; }
/** * Removes the first element from the front of the index if its not empty. * @return True if the element was removed or false if the index was empty. */ public boolean removeFirst() { // check if queue is empty if (isEmpty()) { return false; } // increment first item, rollver to beginning if needed first = calculateNewIndex(first, 1); //first = (first + 1) % capacity; // always decrement size size--; // check if we should reset checkReset(); return true; }