Package net.tangly.commons.lang
Class Reference<T>
java.lang.Object
net.tangly.commons.lang.Reference<T>
- Type Parameters:
T
- type of the reference
A reference to an object, emulating the concept of typed pointer to typed variable. The indirection can be updated to emulate indirection such as pointer to
pointer in other languages.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Reference
<T> empty()
Return a new empty reference to the given object.get()
Return the reference object.void
If a value is present, performs the given action with the value, otherwise does nothing.boolean
isEmpty()
If a value is not present, returns true, otherwise false.boolean
If a value is present, returns true, otherwise false.static <T> Reference
<T> of
(T reference) Return a new reference to the given object.void
Set the referenced object.
-
Constructor Details
-
Reference
-
Reference
public Reference()Constructor of the class to build an empty reference.
-
-
Method Details
-
of
Return a new reference to the given object.- Type Parameters:
T
- type of the reference- Parameters:
reference
- referenced object- Returns:
- new reference
-
empty
Return a new empty reference to the given object.- Type Parameters:
T
- type of the reference- Returns:
- new empty reference
-
set
Set the referenced object.- Parameters:
reference
- referenced object- See Also:
-
get
-
isEmpty
public boolean isEmpty()If a value is not present, returns true, otherwise false.- Returns:
- true if a value is not present, otherwise false
-
isPresent
public boolean isPresent()If a value is present, returns true, otherwise false.- Returns:
- true if a value is present, otherwise false
-
ifPresent
-