net.sf.javagimmicks.collections8.mapping.AbstractValueMapping 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.collections8.mapping;
import java.io.Serializable;
import java.util.Objects;
import net.sf.javagimmicks.collections8.mapping.ValueMappings.Mapping;
/**
* An abstract implementation of {@link Mapping} that provides a default
* implementation for all derivable methods.
*/
public abstract class AbstractValueMapping implements Mapping, Serializable
{
private static final long serialVersionUID = -293860609319776316L;
protected AbstractValueMapping()
{}
@Override
public Mapping invert()
{
return new AbstractValueMapping()
{
private static final long serialVersionUID = 3460811385187106748L;
@Override
public R getLeftKey()
{
return AbstractValueMapping.this.getRightKey();
}
@Override
public L getRightKey()
{
return AbstractValueMapping.this.getLeftKey();
}
public Mapping invert()
{
return AbstractValueMapping.this;
}
@Override
public E getValue()
{
// TODO Auto-generated method stub
return null;
}
};
}
@Override
public boolean equals(final Object obj)
{
if (this == obj)
{
return true;
}
if (!(obj instanceof Mapping, ?, ?>))
{
return false;
}
final Mapping, ?, ?> other = (Mapping, ?, ?>) obj;
return getLeftKey().equals(other.getLeftKey()) && getRightKey().equals(other.getRightKey())
&& Objects.equals(getValue(), other.getValue());
}
@Override
public int hashCode()
{
return 5 * getLeftKey().hashCode() + 7 * getRightKey().hashCode() + 3872123;
}
@Override
public String toString()
{
return new StringBuilder()
.append("[")
.append(getLeftKey())
.append("/")
.append(getRightKey())
.append(": ")
.append(getValue())
.append("]")
.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy