Package no.digipost.util
Class JustALong
- java.lang.Object
-
- no.digipost.util.JustALong
-
- All Implemented Interfaces:
Serializable
public abstract class JustALong extends Object implements Serializable
Base class for creating simple "typedlong
" value classes, for cases when you do not want to pass around simplelong
s for numbers that has certain (business-) semantics in your application, even though along
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 anextends JustALong
decalaration in your class definition.This is a special case implementation of
JustA
to avoid the boxing cost for primitivelong
s. The typical use for this are for ids, and classes where instances are uniquely distinguished by theirlong
ids, and equals/hashcode will exercise correct behavior when only operating on the id. Any additional fields in an extending class should usually be declaredfinal
.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 Modifier and Type Field Description protected long
theLong
-
Constructor Summary
Constructors Modifier Constructor Description protected
JustALong(long theValue)
protected
JustALong(long theValue, String description)
protected
JustALong(long theValue, String description, SerializableFunction<? super Long,String> valueToString)
protected
JustALong(long theValue, SerializableFunction<? super Long,String> valueToString)
-
-
-
Constructor Detail
-
JustALong
protected JustALong(long theValue)
-
JustALong
protected JustALong(long theValue, String description)
-
JustALong
protected JustALong(long theValue, SerializableFunction<? super Long,String> valueToString)
-
JustALong
protected JustALong(long theValue, String description, SerializableFunction<? super Long,String> valueToString)
-
-