Package no.digipost.util
Class JustALong
java.lang.Object
no.digipost.util.JustALong
- All Implemented Interfaces:
Serializable
Base class for creating simple "typed
long" value classes, for cases
when you do not want to pass around simple longs for numbers that has
certain (business-) semantics in your application, even though a long
does adequately express the value. By extending this class you do not have to
implement the equals and hashcode. You would not refer to this class
other than with an extends JustALong decalaration in your class definition.
This is a special case implementation of JustA to avoid the boxing cost
for primitive longs. The typical use for this are for ids, and classes
where instances are uniquely distinguished by their long ids, and equals/hashcode
will exercise correct behavior when only operating on the id. Any additional
fields in an extending class should usually be declared final.
A common pattern for using this class would be:
interface WithId {
static JustAnId of(long id) {
return new JustAnId(id);
}
final class JustAnId extends JustALong implements WithId {
private JustAnId(String id) {
super(id);
}
public long getId() {
return theValue;
}
}
long getId();
}-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedJustALong(long theValue) protectedprotectedJustALong(long theValue, String description, SerializableFunction<? super Long, String> valueToString) protectedJustALong(long theValue, SerializableFunction<? super Long, String> valueToString) -
Method Summary
-
Field Details
-
theLong
protected final long theLong
-
-
Constructor Details
-
JustALong
protected JustALong(long theValue) -
JustALong
-
JustALong
-
JustALong
protected JustALong(long theValue, String description, SerializableFunction<? super Long, String> valueToString)
-
-
Method Details