net.sf.javagimmicks.collections.transformer.BidiTransformingSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gimmicks Show documentation
Show all versions of gimmicks Show documentation
Utility classes, APIs and tools for Java
package net.sf.javagimmicks.collections.transformer;
import java.util.Set;
import net.sf.javagimmicks.transform.BidiFunction;
import net.sf.javagimmicks.transform.BidiTransforming;
class BidiTransformingSet
extends TransformingSet
implements BidiTransforming
{
/**
* @deprecated Use TranformerUtils.decorate() instead
*/
@Deprecated
public 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