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>

public abstract static class VirtualField.ReadOnly<T> extends Object implements 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.

  • 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 interface VirtualField<T>
      Returns:
      false if the value can be set; true if the value cannot be set
    • asReadOnly

      public final VirtualField.ReadOnly<T> asReadOnly()
      Creates a virtual field that is a read-only proxy of this field.

      This implementation always returns this.

      Specified by:
      asReadOnly in interface VirtualField<T>
      Returns:
      a read-only virtual field from which the value can be gotten as from this field
    • swap

      public final T swap(T newValue)
      Sets a new value for this virtual field and returns the old value (optional operation).

      This implementation always throws UnsupportedOperationException.

      Specified by:
      swap in interface VirtualField<T>
      Returns:
      the old value of this virtual field
    • modify

      public final boolean modify(T newValue)
      Sets a new value for this virtual field and indicates change (optional operation).

      This implementation always throws UnsupportedOperationException.

      Specified by:
      modify in interface VirtualField<T>
      Returns:
      true if the value has changed