Package org.apache.juneau
Class Value<T>
java.lang.Object
org.apache.juneau.Value<T>
- Type Parameters:
- T- The value type.
Represents a simple settable value.
 
 Similar to an Optional but mutable.
 
Notes:
- This class is not thread safe.
See Also:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic <T> Value<T>empty()Static creator.get()Returns the value.Returns the value and then unsets it.static TypeReturns the generic parameter type of the Value type.voidIf a value is present, invoke the specified consumer with the value, otherwise do nothing.booleanisEmpty()Returnstrue if the value is empty.booleanReturnstrue if the value is set.static booleanConvenience method for checking if the specified type is this class.listener(ValueListener<T> listener) Adds a listener for this value.<T2> Value<T2>Applies a mapping function against the contents of this value.static <T> Value<T>of(T object) Static creator.Returns the contents of this value or the default value ifnull .Return the value if present, otherwise invokeotherand return the result of that invocation.orElseThrow(Supplier<? extends X> exceptionSupplier) Return the contained value, if present, otherwise throw an exception to be created by the provided supplier.Sets the value.setIfEmpty(T t) Sets the value if it's not already set.toString()static TypeReturns the unwrapped type.
- 
Constructor Details- 
Valuepublic Value()Constructor.
- 
ValueConstructor.- Parameters:
- t- Initial value.
 
 
- 
- 
Method Details- 
ofStatic creator.- Type Parameters:
- T- The value type.
- Parameters:
- object- The object being wrapped.
- Returns:
- A new Valueobject.
 
- 
emptyStatic creator.- Type Parameters:
- T- The value type.
- Returns:
- An empty Valueobject.
 
- 
getParameterTypeReturns the generic parameter type of the Value type.- Parameters:
- t- The type to find the parameter type of.
- Returns:
- The parameter type of the value, or null if the type is not a subclass ofValue .
 
- 
unwrapReturns the unwrapped type.- Parameters:
- t- The type to unwrap.
- Returns:
- The unwrapped type, or the same type if the type isn't Value.
 
- 
isTypeConvenience method for checking if the specified type is this class.- Parameters:
- t- The type to check.
- Returns:
- true if the specified type is this class.
 
- 
listenerAdds a listener for this value.- Parameters:
- listener- The new listener for this value.
- Returns:
- This object.
 
- 
setSets the value.- Parameters:
- t- The new value.
- Returns:
- This object.
 
- 
setIfEmptySets the value if it's not already set.- Parameters:
- t- The new value.
- Returns:
- This object.
 
- 
getReturns the value.- Returns:
- The value, or null if it is not set.
 
- 
getAndUnsetReturns the value and then unsets it.- Returns:
- The value before it was unset.
 
- 
isPresentReturnstrue if the value is set.- Returns:
- true if the value is set.
 
- 
ifPresentIf a value is present, invoke the specified consumer with the value, otherwise do nothing.- Parameters:
- consumer- Block to be executed if a value is present.
 
- 
mapApplies a mapping function against the contents of this value.- Type Parameters:
- T2- The mapped value type.
- Parameters:
- mapper- The mapping function.
- Returns:
- The mapped value.
 
- 
orElseReturns the contents of this value or the default value ifnull .- Parameters:
- def- The default value.
- Returns:
- The contents of this value or the default value if null .
 
- 
isEmptyReturnstrue if the value is empty.- Returns:
- true if the value is empty.
 
- 
orElseGetReturn the value if present, otherwise invokeotherand return the result of that invocation.- Parameters:
- other- a- Supplierwhose result is returned if no value is present
- Returns:
- the value if present otherwise the result of other.get()
- Throws:
- NullPointerException- if value is not present and- otheris null
 
- 
orElseThrowReturn the contained value, if present, otherwise throw an exception to be created by the provided supplier.- Type Parameters:
- X- The exception type.
- Parameters:
- exceptionSupplier- The supplier which will return the exception to be thrown
- Returns:
- the present value
- Throws:
- X- if there is no value present
- NullPointerException- if no value is present and- exceptionSupplieris null
 
- 
toString
 
-