Class DefaultBuilderRef<T>
- Type Parameters:
T- The type of value being built, borrowed, and copied.
- All Implemented Interfaces:
BuilderRef<T>
BuilderRef.
This class is not threadsafe; it should only be used to build up
other objects using copy().
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes any borrowed or owned values from the reference.copy()Creates an immutable copy ofT.get()booleanhasValue()Checks if the reference currently has a borrowed or owned value.peek()voidsetBorrowed(T value) Sets a borrowed (immutable) value directly, clearing any owned state.
-
Constructor Details
-
DefaultBuilderRef
-
-
Method Details
-
get
-
peek
-
copy
Description copied from interface:BuilderRefCreates an immutable copy ofT.Subsequent calls to
BuilderRef.hasValue()may or may not return true after this method is called.- Specified by:
copyin interfaceBuilderRef<T>- Returns:
- Returns the copied immutable value.
-
hasValue
public boolean hasValue()Description copied from interface:BuilderRefChecks if the reference currently has a borrowed or owned value.This method does not check if the contained value is considered empty. This method only returns true if the reference contains any kind of previously built value. This might be useful for builder methods that attempt to remove values from the contained object. If there is no contained object, then there's no need to create one just to remove a value from an empty container.
- Specified by:
hasValuein interfaceBuilderRef<T>- Returns:
- Returns true if the reference contains a value of any kind.
-
clear
public void clear()Description copied from interface:BuilderRefRemoves any borrowed or owned values from the reference.Subsequent calls to
BuilderRef.hasValue()will return false after this method is called.- Specified by:
clearin interfaceBuilderRef<T>
-
setBorrowed
Description copied from interface:BuilderRefSets a borrowed (immutable) value directly, clearing any owned state.This enables the
toBuilder()optimization: when creating a builder from an existing built object, the already-immutable collections can be set directly without copying. A copy will only be made if the builder actually mutates the value viaget().- Specified by:
setBorrowedin interfaceBuilderRef<T>- Parameters:
value- The immutable value to borrow. May benullto clear.
-