Package eu.bandm.tools.util.java
Class VirtualField.ReadOnly<T>
java.lang.Object
eu.bandm.tools.util.java.VirtualField.ReadOnly<T>
- Type Parameters:
T
- the value type of the attribute
- All Implemented Interfaces:
VirtualField<T>
,Consumer<T>
,Supplier<T>
- Enclosing interface:
VirtualField<T>
Base class for virtual fields that cannot be set.
A virtual field is read-only if and only if isReadOnly()
returns
true
. While that is ensured for instances of this class (as well
as that the value really cannot be set), read-only virtual fields may be
created also by other means.
-
Nested Class Summary
Nested classes/interfaces inherited from interface eu.bandm.tools.util.java.VirtualField
VirtualField.ReadOnly<T>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal VirtualField.ReadOnly
<T> Creates a virtual field that is a read-only proxy of this field.final boolean
Checks whether this virtual field is read-only.final boolean
Sets a new value for this virtual field and indicates change (optional operation).final T
Sets a new value for this virtual field and returns the old value (optional operation).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface eu.bandm.tools.util.java.VirtualField
accept, computeIfAbsent, computeIfPresent, get, guard, merge, modifyWith, swapWith
-
Constructor Details
-
ReadOnly
public ReadOnly()
-
-
Method Details
-
isReadOnly
public final boolean isReadOnly()Checks whether this virtual field is read-only.The default implementation always returns
false
; subclasses may override to realize read-only virtual fields.This implementation always returns
true
.- Specified by:
isReadOnly
in interfaceVirtualField<T>
- Returns:
false
if the value can be set;true
if the value cannot be set
-
asReadOnly
Creates a virtual field that is a read-only proxy of this field.This implementation always returns
this
.- Specified by:
asReadOnly
in interfaceVirtualField<T>
- Returns:
- a read-only virtual field from which the value can be gotten as from this field
-
swap
Sets a new value for this virtual field and returns the old value (optional operation).This implementation always throws
UnsupportedOperationException
.- Specified by:
swap
in interfaceVirtualField<T>
- Returns:
- the old value of this virtual field
-
modify
Sets a new value for this virtual field and indicates change (optional operation).This implementation always throws
UnsupportedOperationException
.- Specified by:
modify
in interfaceVirtualField<T>
- Returns:
true
if the value has changed
-