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.
Description
Section titled “Description”Color and TextInfo extend it: lock a value kept in a constant, so code that receives it cannot change it for everyone.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
| LockableValue() | Creates a value that is not locked, for a subclass. |
Methods
Section titled “Methods”| Returns | Signature | Summary |
|---|---|---|
T | lock() | Locks the value for good, then returns it. |
T | mutate(String copy, Runnable mutation) protected | 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 | Returns the result of mutation applied to a copy of this value, which stays unchanged. |
boolean | isLocked() | If true, the setters throw an IllegalStateException. |
For subclasses
Section titled “For subclasses”| Returns | Signature | Summary |
|---|---|---|
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. |
Creation details
Section titled “Creation details”LockableValue
Section titled “LockableValue”LockableValue()
Creates a value that is not locked, for a subclass.
Method details
Section titled “Method details”T lock()
Locks the value for good, then returns it.
mutate
Section titled “mutate”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.
derive
Section titled “derive”T derive(UnaryOperator<T> mutation) protected
Returns the result of mutation applied to a copy of this value, which stays unchanged.
isLocked
Section titled “isLocked”boolean isLocked()
If true, the setters throw an IllegalStateException.
T copy() hook abstract
Returns an unlocked copy of the value.
describeLocked
Section titled “describeLocked”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
