Package org.fjank.jcache.collection

Source Code of org.fjank.jcache.collection.CollectionProxy

/*   Open Source Java Caching Service
*    Copyright (C) 2002 Frank Karlstr�m
*    This library is free software; you can redistribute it and/or
*    modify it under the terms of the GNU Lesser General Public
*    License as published by the Free Software Foundation; either
*    version 2.1 of the License, or (at your option) any later version.
*
*    This library is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
*    Lesser General Public License for more details.
*
*    You should have received a copy of the GNU Lesser General Public
*    License along with this library; if not, write to the Free Software
*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
*    The author can be contacted by email: fjankk@users.sourceforge.net
*/
package org.fjank.jcache.collection;

import java.util.Collection;
import java.util.Iterator;
import org.fjank.jcache.CacheGroup;
import org.fjank.jcache.CacheObject;

/**Acts as a proxy to the collectiton returned from the Map.
* @author Frank Karlstr�m
*
*/
public class CollectionProxy implements Collection {
  private Collection coll;
  private CacheGroup group;
    /**
     * @param collection
     * @param group
     */
    public CollectionProxy(Collection collection, CacheGroup group) {
        this.coll=collection;
        this.group=group;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    public int hashCode() {
        return coll.hashCode();
    }

    /**
     * @param o
     * @return
     */
    public boolean add(Object o) {
        return coll.add(o);
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    public String toString() {
        return coll.toString();
    }

    /**
     * @return
     */
    public Object[] toArray() {
        return coll.toArray();
    }

    /**
     * @param c
     * @return
     */
    public boolean addAll(Collection c) {
        return coll.addAll(c);
    }

    /**
     * @param c
     * @return
     */
    public boolean retainAll(Collection c) {
        return coll.retainAll(c);
    }

    /**
     * @param o
     * @return
     */
    public boolean contains(Object o) {
        //naive implementation, but it works.
        for (Iterator iter = coll.iterator(); iter.hasNext();) {
            CacheObject obj = (CacheObject) iter.next();
            if(obj.get()==o) return true;
        }
        return false;
    }

    /**
     *
     */
    public void clear() {
        coll.clear();
    }

    /**
     * @param c
     * @return
     */
    public boolean containsAll(Collection c) {
        return coll.containsAll(c);
    }

    /**
     * @return
     */
    public int size() {
        return coll.size();
    }

    /**
     * @param c
     * @return
     */
    public boolean removeAll(Collection c) {
        return coll.removeAll(c);
    }

    /**
     * @return
     */
    public boolean isEmpty() {
        return coll.isEmpty();
    }

    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public boolean equals(Object obj) {
        return coll.equals(obj);
    }

    /**
     * @param o
     * @return
     */
    public boolean remove(Object o) {
        return coll.remove(o);
    }

    /**
     * @return
     */
    public Iterator iterator() {
        return coll.iterator();
    }

    /**
     * @param a
     * @return
     */
    public Object[] toArray(Object[] a) {
        return coll.toArray(a);
    }

}
TOP

Related Classes of org.fjank.jcache.collection.CollectionProxy

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.