/** * Construct a WeakSet based on a HashSet. */ public WeakSet() { this.set = SCollection.createHashSet(); }
/** * Transform an array to a vector. * * @param a The array. * @return The vector for the array. */ public static <T> Set<T> arrayToSet(Object a) { int l = Array.getLength(a); Set<T> ret = SCollection.createHashSet(); for(int i = 0; i < l; i++) { ret.add((T)Array.get(a, i)); } return ret; }
/** * Create a new multi stream. * @param outs The output streams. */ public MultiStream(OutputStream[] outs) { this.outs = outs.clone(); this.disabled = SCollection.createHashSet(); }
/** * Perform special handling on serialization. */ protected Object readResolve() throws ObjectStreamException { // Restore weak references as they are not serialized. this.set = SCollection.createHashSet(); this.queue = new ReferenceQueue(); for(Iterator it=serialized_set.iterator(); it.hasNext(); ) { set.add(new WeakObject(it.next(), queue)); } this.serialized_set = null; return this; } }
/** * Perform special handling on serialization. */ protected Object writeReplace() throws ObjectStreamException { // Extract weak references as they are not serializable. expungeStaleEntries(); this.serialized_set = SCollection.createHashSet(); for(Iterator it=set.iterator(); it.hasNext(); ) { Object next = ((WeakObject)it.next()).get(); if(next!=null) serialized_set.add(next); } return this; }
public static void main(String[] args) throws InterruptedException { for(int i=1; i<5000; i++) { createArrayList(); createHashMap(); createHashSet(); createHashtable(); createIndexMap(); createVector(); Thread.sleep(10); } System.out.println("finished"); Thread.sleep(10000); System.exit(0); } }