All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.gatein.common.util.SetMap Maven / Gradle / Ivy

The newest version!
/******************************************************************************
 * JBoss, a division of Red Hat                                               *
 * Copyright 2009, Red Hat Middleware, LLC, and individual                    *
 * contributors as indicated by the @authors tag. See the                     *
 * copyright.txt in the distribution for a full listing of                    *
 * individual contributors.                                                   *
 *                                                                            *
 * This 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 software 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 software; if not, write to the Free                *
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
 ******************************************************************************/
package org.gatein.common.util;

import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

/**
 * A map of set. This object does not handle synchronization and use HashMap and HashSet as underlying data structures;
 *
 * @author Julien Viet
 * @version $Revision: 7322 $
 */
public class SetMap extends CollectionMap
{

   /** Version. */
   static final long serialVersionUID = -7239767000556095977L;

   public SetMap()
   {
   }

   public SetMap(SetMap other) throws IllegalArgumentException
   {
      super(other);
   }

   public SetMap(SetMap other, Comparator comparator) throws IllegalArgumentException
   {
      super(other);

      //
      if (comparator == null)
      {
         throw new IllegalArgumentException("No null comparator allowed");
      }

      //
      this.comparator = comparator;
   }

   public SetMap(Comparator comparator)
   {
      super();

      //
      if (comparator == null)
      {
         throw new IllegalArgumentException("No null comparator allowed");
      }

      //
      this.comparator = comparator;
   }

   /** Return the set specified by the key. */
   public Set get(K key)
   {
      return (Set)super.get(key);
   }

   protected void add(Collection c, V o)
   {
      c.add(o);
   }

   protected void remove(Collection c, Object o)
   {
      c.remove(o);
   }

   protected Collection newCollection()
   {
      if (comparator == null)
      {
         return new HashSet();
      }
      else
      {
         return new TreeSet(comparator);
      }
   }

   protected Collection newCollection(Collection other)
   {
      if (comparator == null)
      {
         return new HashSet(other);
      }
      else
      {
         SortedSet set = new TreeSet(comparator);
         set.addAll(other);
         return set;
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy