Weak HashSet from objectweb jac : Weak Set « Collections Data Structure « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » Collections Data Structure » Weak Set 




Weak HashSet from objectweb jac
  
// Revised from objectweb jac

import java.lang.Cloneable;
import java.util.AbstractSet;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import java.util.WeakHashMap;


public class WeakHashSet extends AbstractSet
    implements Set
{
    private transient WeakHashMap map;

    public WeakHashSet() {
        map = new WeakHashMap();
    }
    public WeakHashSet(Collection c) {
        map = new WeakHashMap(Math.max((int) (c.size()/.75f116));
        addAll(c);
    }
    public WeakHashSet(int initialCapacity, float loadFactor) {
        map = new WeakHashMap(initialCapacity, loadFactor);
    }
    public WeakHashSet(int initialCapacity) {
        map = new WeakHashMap(initialCapacity);
    }

    public Iterator iterator() {
        return map.keySet().iterator();
    }

    public int size() {
        return map.size();
    }
    public boolean isEmpty() {
        return map.isEmpty();
    }

    public boolean contains(Object o) {
        return map.containsKey(o);
    }

    public boolean add(Object o) {
        return map.put(o, Boolean.TRUE)==null;
    }
    public boolean remove(Object o) {
        return map.remove(o)==Boolean.TRUE;
    }
    public void clear() {
        map.clear();
    }
}

   
    
  














Related examples in the same category
1.Weak HashSet
2.Weak HashSet from TJDO
3.Set which holds its members by using of WeakReferences.
4.A weak HashSet: element stored in the WeakHashSet might be garbage collected
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.