/** * Adds all of the elements in <tt>collection</tt> to the set. * * @param collection a <code>Collection</code> value * @return true if the set was modified by the add all operation. */ public boolean addAll( Collection<? extends E> collection ) { boolean changed = false; int size = collection.size(); ensureCapacity( size ); Iterator<? extends E> it = collection.iterator(); while ( size-- > 0 ) { if ( add( it.next() ) ) { changed = true; } } return changed; }
/** * Creates a new <code>THashSet</code> instance containing the * elements of <tt>collection</tt>. * * @param collection a <code>Collection</code> value */ public TCustomHashSet( HashingStrategy<? super E> strategy, Collection<? extends E> collection ) { this( strategy, collection.size() ); addAll( collection ); }
/** * Inserts a value into the set. * * @param obj an <code>Object</code> value * @return true if the set was modified by the add operation */ public boolean add( E obj ) { int index = insertKey( obj ); if ( index < 0 ) { return false; // already present in set, nothing to add } postInsertHook( consumeFreeSlot ); return true; // yes, we added something }
/** * Removes <tt>obj</tt> from the set. * * @param obj an <code>Object</code> value * @return true if the set was modified by the remove operation. */ @SuppressWarnings({"unchecked"}) public boolean remove( Object obj ) { int index = index( obj ); if ( index >= 0 ) { removeAt( index ); return true; } return false; }
@SuppressWarnings({"SimplifiableIfStatement"}) public boolean equals( Object other ) { if ( !( other instanceof Set ) ) { return false; } Set that = (Set) other; if ( that.size() != this.size() ) { return false; } return containsAll( that ); }
/** * Expands the set to accommodate new values. * * @param newCapacity an <code>int</code> value */ @SuppressWarnings({"unchecked"}) protected void rehash( int newCapacity ) { int oldCapacity = _set.length; int oldSize = size(); Object oldSet[] = _set; _set = new Object[newCapacity]; Arrays.fill( _set, FREE ); for ( int i = oldCapacity; i-- > 0; ) { E o = (E) oldSet[i]; if ( o != FREE && o != REMOVED ) { int index = insertKey( o ); if ( index < 0 ) { // everyone pays for this because some people can't RTFM throwObjectContractViolation( _set[( -index - 1 )], o, size(), oldSize, oldSet); } } } }
@SuppressWarnings({"unchecked"}) public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION byte version = in.readByte(); // NOTE: super was not written in version 0 if ( version != 0 ) { super.readExternal( in ); } // NUMBER OF ENTRIES int size = in.readInt(); setUp( size ); // ENTRIES while ( size-- > 0 ) { E val = (E) in.readObject(); add( val ); } } }
/** * Removes any values in the set which are not contained in * <tt>collection</tt>. * * @param collection a <code>Collection</code> value * @return true if the set was modified by the retain all operation */ @SuppressWarnings({"SuspiciousMethodCalls"}) public boolean retainAll( Collection<?> collection ) { boolean changed = false; int size = size(); Iterator<E> it = iterator(); while ( size-- > 0 ) { if ( !collection.contains( it.next() ) ) { it.remove(); changed = true; } } return changed; }
public String toString() { final StringBuilder buf = new StringBuilder( "{" ); forEach( new TObjectProcedure<E>() { private boolean first = true; public boolean execute( Object value ) { if ( first ) { first = false; } else { buf.append( ", " ); } buf.append( value ); return true; } } ); buf.append( "}" ); return buf.toString(); }
/** * returns a new whiteset of all formulas that can be explained with the given mass and one * of the precursor ions */ public List<Decomposition> resolve(double parentMass, Deviation deviation, Collection<PrecursorIonType> allowedPrecursorIonTypes) { final TCustomHashSet<Decomposition> decompositionSet = Decomposition.newDecompositionSet(); eachFormula: for (MolecularFormula formula : formulas) { for (PrecursorIonType ionType : allowedPrecursorIonTypes) { if (deviation.inErrorWindow(parentMass, ionType.neutralMassToPrecursorMass(formula.getMass()))) { decompositionSet.add(new Decomposition(ionType.neutralMoleculeToMeasuredNeutralMolecule(formula), ionType.getIonization(), 0d)); continue eachFormula; } } } return Arrays.asList(decompositionSet.toArray(new Decomposition[decompositionSet.size()])); }
/** * Tests the set to determine if all of the elements in * <tt>collection</tt> are present. * * @param collection a <code>Collection</code> value * @return true if all elements were present in the set. */ @SuppressWarnings("ForLoopReplaceableByForEach") public boolean containsAll( Collection<?> collection ) { for ( Iterator i = collection.iterator(); i.hasNext(); ) { if ( !contains( i.next() ) ) { return false; } } return true; }
/** * Inserts a value into the set. * * @param obj an <code>Object</code> value * @return true if the set was modified by the add operation */ public boolean add( E obj ) { int index = insertionIndex( obj ); if ( index < 0 ) { return false; // already present in set, nothing to add } Object old = _set[index]; _set[index] = obj; postInsertHook( old == FREE ); return true; // yes, we added something }
/** * Expands the set to accommodate new values. * * @param newCapacity an <code>int</code> value */ @SuppressWarnings({"unchecked"}) protected void rehash( int newCapacity ) { int oldCapacity = _set.length; int oldSize = size(); Object oldSet[] = _set; _set = new Object[newCapacity]; Arrays.fill( _set, FREE ); for ( int i = oldCapacity; i-- > 0; ) { E o = (E) oldSet[i]; if ( o != FREE && o != REMOVED ) { int index = insertKey( o ); if ( index < 0 ) { // everyone pays for this because some people can't RTFM throwObjectContractViolation( _set[( -index - 1 )], o, size(), oldSize, oldSet); } } } }
@SuppressWarnings({"SimplifiableIfStatement"}) public boolean equals( Object other ) { if ( !( other instanceof Set ) ) { return false; } Set that = (Set) other; if ( that.size() != this.size() ) { return false; } return containsAll( that ); }
@SuppressWarnings({"unchecked"}) public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION byte version = in.readByte(); // NOTE: super was not written in version 0 if ( version != 0 ) { super.readExternal( in ); } // NUMBER OF ENTRIES int size = in.readInt(); setUp( size ); // ENTRIES while ( size-- > 0 ) { E val = (E) in.readObject(); add( val ); } } }
/** * Removes any values in the set which are not contained in * <tt>collection</tt>. * * @param collection a <code>Collection</code> value * @return true if the set was modified by the retain all operation */ @SuppressWarnings({"SuspiciousMethodCalls"}) public boolean retainAll( Collection<?> collection ) { boolean changed = false; int size = size(); Iterator<E> it = iterator(); while ( size-- > 0 ) { if ( !collection.contains( it.next() ) ) { it.remove(); changed = true; } } return changed; }
/** * Removes <tt>obj</tt> from the set. * * @param obj an <code>Object</code> value * @return true if the set was modified by the remove operation. */ @SuppressWarnings({"unchecked"}) public boolean remove( Object obj ) { int index = index( obj ); if ( index >= 0 ) { removeAt( index ); return true; } return false; }
/** * Inserts a value into the set. * * @param obj an <code>Object</code> value * @return true if the set was modified by the add operation */ public boolean add( E obj ) { int index = insertKey( obj ); if ( index < 0 ) { return false; // already present in set, nothing to add } postInsertHook( consumeFreeSlot ); return true; // yes, we added something }
public int hashCode() { HashProcedure p = new HashProcedure(); forEach( p ); return p.getHashCode(); }