com.clumd.projects.java_common_utils.models.ImmutablePair Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-common-utils Show documentation
Show all versions of java-common-utils Show documentation
A collection of common utilities I find myself writing for most Java projects
package com.clumd.projects.java_common_utils.models;
import java.io.Serializable;
/**
* An instance of {@link Pair}, but where the values are immutable, and references cannot be changed once set. Be aware,
* that values within these object references CAN still be updated or changed.
*
* @param The First object within the Pair.
* @param The Second object within the Pair.
*/
public class ImmutablePair extends Pair implements Serializable {
private static final String SETTER_EXCEPTION_MESSAGE = "Field setting not supported on ImmutablePair.";
public ImmutablePair(final L left, final R right) {
super(left, right);
}
public static Pair of(final L left, final R right) {
return new ImmutablePair<>(left, right);
}
@Override
public void setLeft(final L left) {
throw new UnsupportedOperationException(SETTER_EXCEPTION_MESSAGE);
}
@Override
public void setRight(final R right) {
throw new UnsupportedOperationException(SETTER_EXCEPTION_MESSAGE);
}
@Override
public void setFirst(final L updatedFirst) {
throw new UnsupportedOperationException(SETTER_EXCEPTION_MESSAGE);
}
@Override
public void setSecond(final R updatedSecond) {
throw new UnsupportedOperationException(SETTER_EXCEPTION_MESSAGE);
}
}