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

net.sf.javagimmicks.collections8.transformer.BidiTransformingSet Maven / Gradle / Ivy

There is a newer version: 0.99-alpha1
Show newest version
package net.sf.javagimmicks.collections8.transformer;

import java.util.Set;

import net.sf.javagimmicks.transform8.BidiFunction;
import net.sf.javagimmicks.transform8.BidiTransforming;

class BidiTransformingSet
   extends TransformingSet
   implements BidiTransforming
{
   BidiTransformingSet(Set set, BidiFunction transformer)
   {
      super(set, transformer);
   }
   
   public BidiFunction getTransformerBidiFunction()
   {
      return (BidiFunction)getTransformerFunction();
   }

   @Override
   public boolean add(T e)
   {
      return _internalSet.add(transformBack(e));
   }

   @SuppressWarnings("unchecked")
   @Override
   /**
    * Try to transform back the value, because the internal
    * {@link Set} might be faster performing this method.
    */
   public boolean contains(Object o)
   {
      try
      {
         return _internalSet.contains(transformBack((T)o));
      }
      catch (ClassCastException e)
      {
         return super.contains(o);
      }
   }

   @SuppressWarnings("unchecked")
   @Override
   /**
    * Try to transform back the value, because the internal
    * {@link Set} might be faster performing this method.
    */
   public boolean remove(Object o)
   {
      try
      {
         return _internalSet.remove(transformBack((T)o));
      }
      catch (ClassCastException e)
      {
         return super.remove(o);
      }
   }
   
   protected F transformBack(T element)
   {
      return getTransformerBidiFunction().applyReverse(element);
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy