Skip to content

LockableValue

abstract class LockableValue<T extends LockableValue<T>>
Known subtypes: Color, TextInfo
Package: dev.joid.lib.utils.lock · Module: core · Source: LockableValue.java

Mutable value that can be locked, after which its setters refuse to change it and point to the methods that return a copy.

Color and TextInfo extend it: lock a value kept in a constant, so code that receives it cannot change it for everyone.

ReturnsSignatureSummary
LockableValue()Creates a value that is not locked, for a subclass.

ReturnsSignatureSummary
Tlock()Locks the value for good, then returns it.
Tmutate(String copy, Runnable mutation) protectedRuns mutation on this value, then returns it; on a locked value, it throws an IllegalStateException whose message names the method copy that returns a modified copy.
Tderive(UnaryOperator mutation) protectedReturns the result of mutation applied to a copy of this value, which stays unchanged.
booleanisLocked()If true, the setters throw an IllegalStateException.
ReturnsSignatureSummary
Tcopy() hook abstractReturns an unlocked copy of the value.
StringdescribeLocked() hook protectedReturns the start of the message of a refused change, as in This Color is locked.

LockableValue()

Creates a value that is not locked, for a subclass.

T lock()

Locks the value for good, then returns it.

T mutate(String copy, Runnable mutation) protected

Throws:

  • IllegalStateException: …, use …(…) to get a modified copy

Runs mutation on this value, then returns it; on a locked value, it throws an IllegalStateException whose message names the method copy that returns a modified copy.

T derive(UnaryOperator<T> mutation) protected

Returns the result of mutation applied to a copy of this value, which stays unchanged.

boolean isLocked()

If true, the setters throw an IllegalStateException.

T copy() hook abstract

Returns an unlocked copy of the value.

String describeLocked() hook protected

Returns the start of the message of a refused change, as in This Color is locked.


fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses

Report a problem with this page