Package alexiil.mc.lib.attributes.misc
Interface Reference<T>
- All Known Subinterfaces:
- StackReference
- All Known Implementing Classes:
- CallableRef,- DestroyableRef,- Ref,- SimulatableRef,- SingleCopyingItemSlot,- SingleFluidTank,- SingleItemSlot,- UnmodifiableRef
public interface Reference<T>
A reference to some object. The object can either be obtained from (
get()), or changed with
 (set(Object)). Note that changing the object isn't always permitted, and so it may return false if no change
 happened.
 
 Most users will only need to construct Ref instances to create a Reference, which is a simple
 reference that stores the object in a public modifiable field. However there are also 4 other basic implementations:
 
- UnmodifiableRefis a Reference which always returns the same object from- get(), and returns false from- set(Object)and- isValid(Object). You can either construct instances directly or via the factory method- unmodifiable(Object).
- CallableRefis a Reference which delegates to 3 objects: a- Supplierfor- get(), a- Consumerfor- set(Object), and a- Predicatefor- isValid(Object). You can either construct instances directly, or use the factory method- callable(Supplier, Consumer, Predicate).
- SimulatableRefis similar to- CallableRef, but uses a single- LimitedConsumerfor both- set(Object)and- isValid(Object).
- DestroyableRefis a bit different from the others, as it wraps another- Referenceinternally, and delegates all calls to it. However you can call- DestroyableRef.destroy()to disallow any further modifications to the backing reference.
- 
Method SummaryModifier and TypeMethodDescriptiondefault DestroyableRef<T>static <T> CallableRef<T>static <T> DestroyableRef<T>destroying(Reference<T> ref)get()booleanbooleandefault booleanset(T value, Simulation simulation)Delegates toset(Object)if the simulation isSimulation.ACTION, otherwise it delegates toisValid(Object).static <T> SimulatableRef<T>simulating(Supplier<T> getter, LimitedConsumer<T> setter)static <T> UnmodifiableRef<T>unmodifiable(T obj)
- 
Method Details- 
getT get()- Returns:
- The object referenced. Note that you should generally not modify the returned value directly - instead
         copy it before passing it to set(Object)orisValid(Object)to see if your modifications are permitted.
 
- 
set- Returns:
- True if the new value was accepted, false otherwise.
 
- 
isValid- Returns:
- True if set(Object)was called with the same value.
 
- 
setDelegates toset(Object)if the simulation isSimulation.ACTION, otherwise it delegates toisValid(Object).
- 
asDestroyable- Returns:
- A DestroyableRefthat can be modified untilDestroyableRef.destroy()is called, after which all calls toset(Object)andisValid(Object)will return false.
 
- 
unmodifiable- Returns:
- A new Referencethat doesn't permit modifications to the given object.
 
- 
callable- Parameters:
- getter- The- Supplierwhich is used for- get().
- setter- The- Consumerwhich is used for- set(Object)(after the filter).
- filter- The- Predicatewhich is used to test inputs for both- set(Object)and- isValid(Object).
- Returns:
- A new CallableRefthat delegates to the getter, setter, and filter for all of the functions.
 
- 
simulating- Parameters:
- getter- The- Supplierwhich is used for- get()
- setter- The- LimitedConsumerwhich is used for- set(Object)and- isValid(Object).
- Returns:
- A new SimulatableRefthat delegates to the getter and setter for all of it's functions.
 
- 
destroying- Returns:
- A new DestroyableRefthat delegates to the given reference for getting, although setting only succeeds untilDestroyableRef.destroy()is called.
 
 
-