/** * Returns the element at the specified position in this list. * * @param index index of element to return. * @return the element at the specified position in this list. * @throws IndexOutOfBoundsException if index is out of range <tt>(index * < 0 || index >= size())</tt>. */ @Override public Long get(int index) { RangeCheck(index); return elementData[index]; }
/** * Appends the specified element to the end of this list. * * @param o element to be appended to this list. * @return <tt>true</tt> (as per the general contract of Collection.add). */ @Override public boolean add(Long o) { return add(o.longValue()); }
/** * Returns <tt>true</tt> if this list contains the specified element. * * @param elem element whose presence in this List is to be tested. * @return <code>true</code> if the specified element is present; * <code>false</code> otherwise. */ @Override public boolean contains(Object elem) { if (elem == null) return false; if (elem instanceof Number) return contains(((Number)elem).longValue()); return false; }
/** * Appends the specified element to the end of this list. * * @param o element to be appended to this list. * @return <tt>true</tt> (as per the general contract of Collection.add). */ @Override public boolean add(long o) { ensureCapacity(size + 1); // Increments modCount!! elementData[size++] = o; return true; }
/** * Returns <tt>true</tt> if this list contains the specified element. * * @param elem element whose presence in this List is to be tested. * @return <code>true</code> if the specified element is present; * <code>false</code> otherwise. */ @Override public boolean contains(long elem) { return indexOf(elem) >= 0; }
/** * Removes the element at the specified position in this list. * Shifts any subsequent elements to the left (subtracts one from their * indices). * * @param index the index of the element to removed. * @return the element that was removed from the list. * @throws IndexOutOfBoundsException if index out of range <tt>(index * < 0 || index >= size())</tt>. */ @Override public Long remove(int index) { return removeAtIndex(index); }
/** * Removes a single instance of the specified element from this * list, if it is present (optional operation). More formally, * removes an element <tt>e</tt> such that <tt>(o==null ? e==null : * o.equals(e))</tt>, if the list contains one or more such * elements. Returns <tt>true</tt> if the list contained the * specified element (or equivalently, if the list changed as a * result of the call).<p> * * @param value element to be removed from this list, if present. * @return <tt>true</tt> if the list contained the specified element. */ @Override public boolean removeByValue(long value) { for (int index = 0; index < size; index++) if (value==elementData[index]) { fastRemove(index); return true; } return false; }
/** * Returns the index of the last occurrence of the specified object in * this list. * * @param elem the desired element. * @return the index of the last occurrence of the specified object in * this list; returns -1 if the object is not found. */ @Override public int lastIndexOf(Object elem) { if (elem == null) return -1; if (elem instanceof Number) return lastIndexOf(((Number)elem).longValue()); return -1; }
/** * Removes a single instance of the specified element from this * list, if it is present (optional operation). More formally, * removes an element <tt>e</tt> such that <tt>(o==null ? e==null : * o.equals(e))</tt>, if the list contains one or more such * elements. Returns <tt>true</tt> if the list contained the * specified element (or equivalently, if the list changed as a * result of the call).<p> * * @param o element to be removed from this list, if present. * @return <tt>true</tt> if the list contained the specified element. */ @Override public boolean remove(Object o) { if (o != null && (o instanceof Number)) return removeByValue(((Number)o).longValue()); return false; }
@Override public LongList executeLongListQuery(int isolationLevel, boolean readOnly, String sql, Object ... params) throws SQLException { Connection conn = getConnection(isolationLevel, readOnly); conn.setAutoCommit(false); try (PreparedStatement pstmt = conn.prepareStatement(sql)) { try { pstmt.setFetchSize(FETCH_SIZE); setParams(conn, pstmt, params); try (ResultSet results = pstmt.executeQuery()) { LongList V=new LongArrayList(); while(results.next()) V.add(results.getLong(1)); return V; } } catch(SQLException err) { throw new WrappedSQLException(err, pstmt); } } }
/** * Inserts the specified element at the specified position in this * list. Shifts the element currently at that position (if any) and * any subsequent elements to the right (adds one to their indices). * * @param index index at which the specified element is to be inserted. * @param element element to be inserted. * @throws IndexOutOfBoundsException if index is out of range * <tt>(index < 0 || index > size())</tt>. */ @Override public void add(int index, long element) { if (index > size || index < 0) throw new IndexOutOfBoundsException( "Index: "+index+", Size: "+size); ensureCapacity(size+1); // Increments modCount!! System.arraycopy(elementData, index, elementData, index + 1, size - index); elementData[index] = element; size++; }
/** * Searches for the first occurrence of the given argument, testing * for equality using the <tt>equals</tt> method. * * @param elem an object. * @return the index of the first occurrence of the argument in this * list; returns <tt>-1</tt> if the object is not found. * @see Object#equals(Object) */ @Override public int indexOf(Object elem) { if (elem == null) return -1; if (elem instanceof Number) return indexOf(((Number)elem).longValue()); return -1; }
/** * Appends all of the elements in the specified Collection to the end of * this list, in the order that they are returned by the * specified Collection's Iterator. The behavior of this operation is * undefined if the specified Collection is modified while the operation * is in progress. (This implies that the behavior of this call is * undefined if the specified Collection is this list, and this * list is nonempty.) * * @param c the elements to be inserted into this list. * @return <tt>true</tt> if this list changed as a result of the call. * @throws NullPointerException if the specified collection is null. */ @Override public boolean addAll(Collection<? extends Long> c) { int numNew = c.size(); ensureCapacity(size + numNew); // Increments modCount Iterator<? extends Long> iter=c.iterator(); while(iter.hasNext()) elementData[size++]=iter.next(); return numNew != 0; }
/** * Returns the element at the specified position in this list. * * @param index index of element to return. * @return the element at the specified position in this list. * @throws IndexOutOfBoundsException if index is out of range <tt>(index * < 0 || index >= size())</tt>. */ @Override public long getLong(int index) { RangeCheck(index); return elementData[index]; }
/** * Inserts the specified element at the specified position in this * list. Shifts the element currently at that position (if any) and * any subsequent elements to the right (adds one to their indices). * * @param index index at which the specified element is to be inserted. * @param element element to be inserted. * @throws IndexOutOfBoundsException if index is out of range * <tt>(index < 0 || index > size())</tt>. */ @Override public void add(int index, Long element) { add(index, element.longValue()); }
ensureCapacity(size + numNew); // Increments modCount
/** * Replaces the element at the specified position in this list with * the specified element. * * @param index index of element to replace. * @param element element to be stored at the specified position. * @return the element previously at the specified position. * @throws IndexOutOfBoundsException if index out of range * <tt>(index < 0 || index >= size())</tt>. */ @Override public long set(int index, long element) { RangeCheck(index); long oldValue = elementData[index]; elementData[index] = element; return oldValue; }
/** * Adds the specified element in sorted position within this list. * * @param o element to be appended to this list. * @return <tt>true</tt> (as per the general contract of Collection.add). */ @Override public boolean add(long o) { // Shortcut for empty int mySize=size(); if(mySize==0) { super.add(o); } else { // Shortcut for adding to end (makes imports of already-sorted data operate at constant-time instead of logarithmic complexity) if(o>=elementData[mySize-1]) { super.add(o); } else { int index=binarySearch(o); if(index<0) { // Not found in list super.add(-(index+1), o); } else { // Add after existing super.add(index+1, o); } } } return true; }
/** * Removes the element at the specified position in this list. * Shifts any subsequent elements to the left (subtracts one from their * indices). * * @param index the index of the element to removed. * @return the element that was removed from the list. * @throws IndexOutOfBoundsException if index out of range <tt>(index * < 0 || index >= size())</tt>. */ @Override public long removeAtIndex(int index) { RangeCheck(index); modCount++; long oldValue = elementData[index]; int numMoved = size - index - 1; if (numMoved > 0) System.arraycopy(elementData, index+1, elementData, index, numMoved); elementData[--size] = 0; // Let gc do its work return oldValue; }