Package sprouts.impl
Interface SproutsFactory
- All Known Implementing Classes:
Sprouts
public interface SproutsFactory
Creates instances of the various types of the Sprouts library, like its
persistent data structures (see
This interface allows you to plug in your own implementations of the Sprouts properties and collections, through the
Tuple
, Association
, ValueSet
)
or reactive properties (Val
, Var
, Vals
, Vars
).This interface allows you to plug in your own implementations of the Sprouts properties and collections, through the
Sprouts.setFactory(SproutsFactory)
method.All other (static) factory methods on the various Sprouts types delegate to this API for instantiation. So please be careful when plugging a custom implementation!
-
Method Summary
Modifier and TypeMethodDescription<K,
V> Association <K, V> associationOf
(Class<K> keyType, Class<V> valueType) Creates a new association between keys and values with the given key and value types.<K,
V> Association <K, V> associationOfLinked
(Class<K> keyType, Class<V> valueType) Creates a new linked association between keys and values with the given key and value types, where the order of key-value pairs in this type of association is based on the order in which the pairs are added to the association.<K extends Comparable<K>,
V>
Association<K, V> associationOfSorted
(Class<K> keyType, Class<V> valueType) Creates a new association between keys and values with the given key and value types, where the keys are sorted in natural order.<K,
V> Association <K, V> associationOfSorted
(Class<K> keyType, Class<V> valueType, Comparator<K> comparator) Creates a new association between keys and values with the given key and value types, where the key-value pairs are sorted using the supplied comparator.The default channel used for change events.The default id for properties which do not have an id explicitly specified.The default channel used forObservable
events, registered through theObservable.subscribe(Observer)
method.<T> ValDelegate
<T> delegateOf
(Val<T> source, Channel channel, SingleChange change, @Nullable T newValue, @Nullable T oldValue) <T> ValsDelegate
<T> delegateOf
(Vals<T> source, SequenceChange changeType, int index, Vals<T> newValues, Vals<T> oldValues) Creates a delegate for when aVals
/Vars
property list to be specifically designed as a context object passed toAction
s registered onViewable
s, like for example through theViewable.onChange(Channel, Action)
method.event()
A factory method to create a newEvent
instance.eventOf
(Event.Executor executor) A factory method to create a newEvent
instance with the given executor.The regexPattern
used to validate property ids.A factory method for creating aLens
basedVar
property, which is a zoomed in handle to a field variable of a non-nullClass
of a non-nullable typeB
that is a member part of the source property item typeT
.
The resultingVar
can be mutated, and the changes will be propagated to the source property value through the lens.
If the item in the source property valueT
isnull
, then the resultingVar
will use the providednullObject
as a default value.A factory method for creating aLens
basedVar
property, which is a zoomed in handle to a field variable of a non-nullClass
of a non-nullable typeB
that is a member part of the source property item typeT
.
The resultingVar
can be mutated, and the changes will be propagated to the source property value through the lens.
BothT
andB
are expected to be data types with value semantics, meaning they should be immutable and have properequals
andhashCode
implementations.lensOfNullable
(Class<B> type, Var<T> source, Lens<T, B> lens) A factory method for creating aLens
basedVar
property, which is a zoomed in handle to a field variable of a non-nullClass
of a nullable typeB
that is a member part of the source property item typeT
.
If you want to create a lens property which can never storenull
values, use thelensOf(Var, Object, Lens)
factory method instead.
The resultingVar
can be mutated, and the changes will be propagated to the source property value through the lens.default <T> Maybe
<T> default <T> Maybe
<T> maybeOf
(T item) Creates aMaybe
instance from a non-nullable item.default <T> Maybe
<@Nullable T> maybeOfNull
(Class<T> type) Creates aMaybe
instance of the given type with anull
item.default <T> Maybe
<@Nullable T> maybeOfNullable
(Class<T> type, @Nullable T item) Creates a nullableMaybe
instance of the given type with the specified item.maybeOfNullable
(Maybe<T> toBeCopied) tupleOf
(byte... bytes) Creates an immutable tuple of non-nullable items from a primitive array of bytes.tupleOf
(double... doubles) Creates an immutable, non-nullableTuple<Double>
from a primitive array of doubles.tupleOf
(float... floats) Creates an immutable, non-nullableTuple<Float>
from a primitive array of floats.tupleOf
(int... ints) Creates an immutable tuple of non-nullable items from a primitive array of integers.tupleOf
(long... longs) Creates an immutable tuple of non-nullable items from a primitive array of longs.<T> Tuple
<T> Creates an empty tuple of non-nullable items from the supplied type.<T> Tuple
<T> Creates an immutable tuple of non-nullable items from the supplied type and iterable of values.<T> Tuple
<T> Creates an immutable tuple of non-nullable items from the supplied type and vararg values.<T> Tuple
<T> Creates an immutable tuple of non-nullable items from the supplied type and values.default <T> Tuple
<T> Creates an immutable tuple of non-nullable items from one or more non-nullable items wrapped byMaybe
properties.<T> Tuple
<T> tupleOf
(T first, T... rest) Creates an immutable tuple of non-nullable items from one or more non-null items.<T> Tuple
<@Nullable T> tupleOfNullable
(Class<T> type) Creates an empty tuple of nullable items from the supplied type.<T> Tuple
<@Nullable T> tupleOfNullable
(Class<T> type, @Nullable T... items) Creates an immutable tuple of nullable items from the supplied type and values.<T> Tuple
<@Nullable T> tupleOfNullable
(Class<T> type, Iterable<@Nullable T> iterable) Creates an immutable tuple of nullable items from the supplied type and iterable of values.default <T> Tuple
<@Nullable T> tupleOfNullable
(Class<T> type, Maybe<@Nullable T>... maybes) Creates an immutable tuple of nullable items from the supplied type and varargs items.default <T> Tuple
<@Nullable T> tupleOfNullable
(Maybe<@Nullable T> first, Maybe<@Nullable T>... rest) Creates an immutable tuple of nullable items from the supplied items.<T> Val
<T> <T> Val
<T> valOf
(T item) Creates a non-nullVal
instance of the given non-null item.<T> Val
<@Nullable T> Creates an emptyVal
property from the given type class.<T> Val
<@Nullable T> valOfNullable
(Class<T> type, @Nullable T item) Creates a newVal
property from a type class and an item which may or may not be null.valOfNullable
(Val<T> toBeCopied) <T> Vals
<T> A factory method which creates an emptyVals
instance dedicated to hold properties storing non-nullable items of the specified type.<T> Vals
<T> <T> Vals
<T> <T> Vals
<T> <T> Vals
<T> A factory method for creating aVals
property list from a type class and an array of items, which are all instances of the given type and may not benull
.<T> Vals
<T> <T> Vals
<T> valsOf
(T first, T... rest) A factory method for creating aVals
property list from one or more items, which are all instances of the same type and may not benull
.<T> Vals
<@Nullable T> valsOfNullable
(Class<T> type) This factory method instantiates an emptyVals
instance from a type class of a nullable typeT
.<T> Vals
<@Nullable T> valsOfNullable
(Class<T> type, @Nullable T... items) <T> Vals
<@Nullable T> valsOfNullable
(Class<T> type, Val<@Nullable T>... vals) <T> Vals
<@Nullable T> valsOfNullable
(Class<T> type, Vals<@Nullable T> vals) <T> Vals
<@Nullable T> valsOfNullable
(Val<@Nullable T> first, Val<@Nullable T>... rest) <E> ValueSet
<E> valueSetOf
(Class<E> type) Creates a new value set specifically for holding elements of the supplied type.<E> ValueSet
<E> valueSetOfLinked
(Class<E> type) Creates a new value set specifically for holding elements of the supplied type, and where the order of the elements is defined by the insertion order.<E extends Comparable<? super E>>
ValueSet<E> valueSetOfSorted
(Class<E> type) Creates a new value set specifically for holding elements of the supplied type, elements are sorted based on the natural ordering of the elements (which are expected to implementComparable
).<E> ValueSet
<E> valueSetOfSorted
(Class<E> type, Comparator<E> comparator) Creates a new value set specifically for holding elements of the supplied type, but with an explicit order defined by the supplied comparator.<T,
V extends T>
Var<T> Creates aVar
property instance of the given non-nullable type with the specified non-null item.<T> Var
<T> varOf
(T item) Creates aVar
property instance from a given non-nullable item, where theMaybe.type()
is inferred from the type of the item.<T> Var
<@Nullable T> Creates an emptyVar
instance (storing anull
item) of the given type.<T> Var
<@Nullable T> varOfNullable
(Class<T> type, @Nullable T item) <T> Vars
<T> Creates an empty list of non-nullable properties from the supplied type.<T> Vars
<T> Creates a list of non-nullable properties from the supplied type and iterable of values.<T> Vars
<T> Creates a list of non-nullable properties from the supplied type and vararg values.<T> Vars
<T> Creates a list of non-nullable properties from the supplied type and values.<T> Vars
<T> Creates a list of non-nullable properties from one or more non-nullable properties.<T> Vars
<T> varsOf
(T first, T... rest) Creates a list of non-nullable properties from one or more non-null values.<T> Vars
<@Nullable T> varsOfNullable
(Class<T> type) Creates an empty list of nullable properties from the supplied type.<T> Vars
<@Nullable T> varsOfNullable
(Class<T> type, @Nullable T... values) Creates a list of nullable properties from the supplied type and values.<T> Vars
<@Nullable T> varsOfNullable
(Class<T> type, Iterable<Var<@Nullable T>> vars) Creates a list of nullable properties from the supplied type and iterable of values.<T> Vars
<@Nullable T> varsOfNullable
(Class<T> type, Var<@Nullable T>... vars) Creates a list of nullable properties from the supplied type and varargs properties.<T> Vars
<@Nullable T> varsOfNullable
(Var<@Nullable T> first, Var<@Nullable T>... rest) Creates a list of nullable properties from the supplied properties.viewOf
(Class<R> type, Val<T> first, Val<U> second, BiFunction<T, U, R> combiner) viewOf
(Val<T> first, Val<U> second, BiFunction<T, U, @NonNull T> combiner) Creates aViewable
instance where he item of a supplied sourceVal
is mapped to a different (non-null) type using the provided mapper function as well as an error and null object in case the source value isnull
or an error occurs during mapping.
You can registerAction
s orObserver
s on the returnedViewable
to receive updates when the value of the source property changes.viewOfNullable
(Class<R> type, Val<T> first, Val<U> second, BiFunction<T, U, @Nullable R> combiner) viewOfNullable
(Class<U> type, Val<T> source, Function<T, @Nullable U> mapper) Creates aViewable
instance of the given nullable type which is a view of the value of the specified sourceVal
mapped to a different (nullable) type using the provided mapper function.
You can register observers on the returnedViewable
to receive updates when the value of the source property changes.viewOfNullable
(Val<T> first, Val<U> second, BiFunction<T, U, @Nullable T> combiner)
-
Method Details
-
delegateOf
<T> ValDelegate<T> delegateOf(Val<T> source, Channel channel, SingleChange change, @Nullable T newValue, @Nullable T oldValue) Creates a delegate for when aVal
/Var
property changes its value or is explicitly triggered to propagate the event to all derivedViewable
instances and theirAction
s.- Type Parameters:
T
- The item type of the property for which the delegate is created.- Parameters:
source
- The source property for which the delegate is created.channel
- The channel on which the change event was triggered (seeVal.fireChange(Channel)
).change
- The type of change that occurred in the property, which may also beSingleChange.NONE
if the change was triggered explicitly without any actual change in the value.newValue
- The new value of the property after the change.oldValue
- The old value of the property before the change.- Returns:
- A delegate for the given
Val
property.
-
delegateOf
<T> ValsDelegate<T> delegateOf(Vals<T> source, SequenceChange changeType, int index, Vals<T> newValues, Vals<T> oldValues) Creates a delegate for when aVals
/Vars
property list to be specifically designed as a context object passed toAction
s registered onViewable
s, like for example through theViewable.onChange(Channel, Action)
method.- Type Parameters:
T
- The type of the property for which the delegate is created.- Parameters:
source
- The source property for which the delegate is created.changeType
- The type of change that occurred in the property.index
- The (start) index at which the change occurred.newValues
- The new values of the property after the change.oldValues
- The old values of the property before the change.- Returns:
- A delegate for the given
Vals
property.
-
event
Event event()A factory method to create a newEvent
instance. AnEvent
can be triggered using theEvent.fire()
method, and it will notify allAction
s registered onObserver
s derived from theEvent
instance through theEvent.observable()
method.- Returns:
- A new
Event
instance with the default executor.
-
eventOf
A factory method to create a newEvent
instance with the given executor. AnEvent
can be triggered using theEvent.fire()
method, and it will notify allAction
s registered onObserver
s derived from theEvent
instance through theEvent.observable()
method.- Parameters:
executor
- The executor to be used for the event. It must not benull
.- Returns:
- A new
Event
instance with the specified executor.
-
maybeOfNullable
Creates a nullableMaybe
instance of the given type with the specified item.- Type Parameters:
T
- The type of the item to be wrapped in theMaybe
.- Parameters:
type
- The type of the item to be wrapped in theMaybe
. It must not benull
.item
- The item to be wrapped in theMaybe
. It can benull
.- Returns:
- A
Maybe
instance containing the item, or an emptyMaybe
if the item isnull
.
-
maybeOfNull
Creates aMaybe
instance of the given type with anull
item. TheMaybe.isEmpty()
method of the returned instance will always returntrue
, indicating that theMaybe
does not contain a value. -
maybeOf
Creates aMaybe
instance from a non-nullable item. TheMaybe.isPresent()
method of the returned instance will always returntrue
, indicating that theMaybe
contains a value. -
maybeOf
Creates a non-emptyMaybe
copy from the suppliedMaybe
. The suppliedMaybe
must not contain a null item. So if the factory call was successful, then theMaybe.isPresent()
method of the returned instance will always returntrue
, indicating that theMaybe
contains a value. The returned instance is effectively an immutable copy of the suppliedMaybe
. -
maybeOfNullable
Creates a potentially emptyMaybe
copy from the suppliedMaybe
, which may or may not contain a null item. The returned instance is effectively an immutable copy of the suppliedMaybe
.- Type Parameters:
T
- The type of the item to be wrapped in theMaybe
.- Parameters:
toBeCopied
- TheMaybe
instance to be copied.- Returns:
- A new
Maybe
instance containing the value from the givenMaybe
, or an emptyMaybe
if the value isnull
. - Throws:
NullPointerException
- iftoBeCopied
isnull
. (However, the item in the suppliedMaybe
can benull
.)
-
valOfNullable
Creates a newVal
property from a type class and an item which may or may not be null. The resulting property may or may not be empty (seeMaybe.isEmpty()
.- Type Parameters:
T
- The type of the item to be wrapped in theVal
property.- Parameters:
type
- The type of the item to be wrapped in theVal
, which must not be null.item
- The item to be wrapped in theVal
. It can benull
.- Returns:
- A
Val
instance containing the item, or an emptyVal
if the item isnull
. - Throws:
NullPointerException
- iftype
isnull
.
-
valOfNull
Creates an emptyVal
property from the given type class. TheMaybe.isEmpty()
method of the returned instance will always returntrue
, indicating that theVal
does not contain a value. -
valOf
Creates a non-nullVal
instance of the given non-null item. TheMaybe.isPresent()
method of the returned instance will always returntrue
, indicating that theVal
does contain a value.- Type Parameters:
T
- The type of the item to be wrapped in theVal
.- Parameters:
item
- The item to be wrapped in theVal
. It must not benull
.- Returns:
- An immutable and non-empty
Val
instance containing the item. - Throws:
NullPointerException
- ifitem
isnull
.
-
valOf
Creates a non-emptyVal
copy from the suppliedVal
. The suppliedVal
must not contain a null item. So if the factory call was successful, then theMaybe.isPresent()
method of the returned instance will always returntrue
, indicating that theVal
contains a value. The returned instance is effectively an immutable copy of the suppliedVal
.- Type Parameters:
T
- The type of the item to be wrapped in theVal
.- Parameters:
toBeCopied
- TheVal
instance to be copied. It must not benull
and it must not contain anull
value.- Returns:
- A new
Val
instance containing the value from the givenVal
. - Throws:
NullPointerException
- iftoBeCopied
isnull
.
-
valOfNullable
- Type Parameters:
T
- The type of the item to be wrapped in theVal
.- Parameters:
toBeCopied
- TheVal
instance to be copied. It must not benull
, however, the value in theVal
can benull
.- Returns:
- A new
Val
instance containing the value from the givenVal
, or an emptyVal
if the value isnull
. - Throws:
NullPointerException
- iftoBeCopied
isnull
.
-
viewOf
Creates aViewable
instance of the givenVal
. You can register observers on the returnedViewable
to receive updates when the value of theVal
changes.- Type Parameters:
T
- The type of the item in theVal
.- Parameters:
source
- The sourceVal
for which the view is created.- Returns:
- A
Viewable
instance that wraps the givenVal
. The source may not benull
. - Throws:
NullPointerException
- ifsource
isnull
.
-
viewOf
<T extends @Nullable Object,U extends @Nullable Object> Viewable<@NonNull T> viewOf(Val<T> first, Val<U> second, BiFunction<T, U, @NonNull T> combiner) Creates a non-nullViewable
instance which is a composite of twoVal
instances whose values are combined using the specified combiner function. You may register observers on the resulting viewable to receive updates when the values of either of the twoVal
instances change.- Type Parameters:
T
- The type of the firstVal
value.U
- The type of the secondVal
value.- Parameters:
first
- The firstVal
to be combined into aViewable
composite.second
- The secondVal
to be combined into aViewable
composite.combiner
- The function that combines the values of the twoVal
instances into a single value.- Returns:
- A
Viewable
instance that combines the values of the twoVal
instances using the specified combiner function. - Throws:
NullPointerException
- if any of the supplied parameters arenull
.
-
viewOfNullable
<T extends @Nullable Object,U extends @Nullable Object> Viewable<@Nullable T> viewOfNullable(Val<T> first, Val<U> second, BiFunction<T, U, @Nullable T> combiner) Creates a nullableViewable
instance which is a composite of twoVal
instances whose values are combined using the specified combiner function. You may register observers on the resulting viewable to receive updates when the values of either of the twoVal
instances change.- Type Parameters:
T
- The type of the firstVal
value.U
- The type of the secondVal
value.- Parameters:
first
- The firstVal
to be combined into aViewable
composite.second
- The secondVal
to be combined into aViewable
composite.combiner
- The function that combines the values of the twoVal
instances into a single value.- Returns:
- A
Viewable
instance that combines the values of the twoVal
instances using the specified combiner function. - Throws:
NullPointerException
- if any of the supplied parameters arenull
.
-
viewOf
<T extends @Nullable Object,U extends @Nullable Object, Viewable<R> viewOfR> (Class<R> type, Val<T> first, Val<U> second, BiFunction<T, U, R> combiner) Creates a non-nullableViewable
instance of the given type which is a composite of twoVal
instances whose values are combined using the specified combiner function. You may register observers on the resulting viewable to receive updates when the values of either of the twoVal
instances change.- Type Parameters:
T
- The type of the firstVal
value.U
- The type of the secondVal
value.R
- The type of the resultingViewable
.- Parameters:
type
- The type of the resultingViewable
.first
- The firstVal
to be combined into aViewable
composite.second
- The secondVal
to be combined into aViewable
composite.combiner
- The function that combines the values of the twoVal
instances into a single value.- Returns:
- A
Viewable
instance that combines the values of the twoVal
instances using the specified combiner function. - Throws:
NullPointerException
- if any of the supplied parameters arenull
.
-
viewOfNullable
<T extends @Nullable Object,U extends @Nullable Object, Viewable<@Nullable R> viewOfNullableR> (Class<R> type, Val<T> first, Val<U> second, BiFunction<T, U, @Nullable R> combiner) Creates a nullableViewable
instance of the given type which is a composite of twoVal
instances whose values are combined using the specified combiner function. You may register observers on the resulting viewable to receive updates when the values of either of the twoVal
instances change.- Type Parameters:
T
- The type of the firstVal
value.U
- The type of the secondVal
value.R
- The type of the resultingViewable
.- Parameters:
type
- The type of the resultingViewable
.first
- The firstVal
to be combined into aViewable
composite.second
- The secondVal
to be combined into aViewable
composite.combiner
- The function that combines the values of the twoVal
instances into a single value.- Returns:
- A
Viewable
instance that combines the values of the twoVal
instances using the specified combiner function. - Throws:
NullPointerException
- if any of the supplied parameters arenull
.
-
viewOf
Creates aViewables
instance of the givenVals
. You can register observers on the returnedViewables
to receive updates when the items in theVals
change.- Type Parameters:
T
- The type of the items in theVals
.- Parameters:
source
- The sourceVals
for which the view is created.- Returns:
- A
Viewables
instance that wraps the givenVals
. - Throws:
NullPointerException
- ifsource
isnull
.
-
viewOf
<T extends @Nullable Object,U> Viewables<U> viewOf(U nullObject, U errorObject, Vals<T> source, Function<T, @Nullable U> mapper) Creates a mappedViewables
instance of the givenVals
with specified null and error objects. This is useful when you want to provide default values for theViewables
when the source property contains anull
value or an error occurs during mapping.- Type Parameters:
T
- The type of the items in theVals
.U
- The type of the items in the resultingViewables
.- Parameters:
nullObject
- The default value to be used when the source value is null.errorObject
- The default value to be used when an error occurs during mapping.source
- The sourceVals
for which the view is created.mapper
- The function that maps the source value to the resulting value.- Returns:
- A
Viewables
instance that wraps the givenVals
with specified null and error objects. - Throws:
NullPointerException
- if any of the supplied parameters arenull
.
-
viewOf
<T extends @Nullable Object,U extends @Nullable Object> Viewable<T> viewOf(Class<T> type, Val<U> source, Function<U, T> mapper) Creates a mappedViewable
instance of the given type which is a view of the value of the specified sourceVal
mapped to a different type using the provided mapper function.
You can register observers on the returnedViewable
to receive updates when the value of the source property changes.- Type Parameters:
T
- The type parameter to which the source value will be mapped in the resultingViewable
.U
- The type of the value in the sourceVal
.- Parameters:
type
- The type class to which the source value will be mapped into the resultingViewable
.source
- The sourceVal
for which the view is created.mapper
- The function that maps the source value to the resulting value in theViewable
.- Returns:
- A
Viewable
instance which is a view of the specified sourceVal
mapped to the given type. - Throws:
NullPointerException
- if any of the supplied parameters arenull
.
-
viewOf
<T extends @Nullable Object,U extends @Nullable Object> Viewable<U> viewOf(U nullObject, U errorObject, Val<T> source, Function<T, @Nullable U> mapper) Creates aViewable
instance where he item of a supplied sourceVal
is mapped to a different (non-null) type using the provided mapper function as well as an error and null object in case the source value isnull
or an error occurs during mapping.
You can registerAction
s orObserver
s on the returnedViewable
to receive updates when the value of the source property changes. This method is useful when you want a mappedViewable
with a default/fallback values in case the source property contains anull
value or an error occurs during mapping.- Type Parameters:
T
- The type of the item in the sourceVal
to be mapped. It can be nullable.U
- The type of the item to map to in the resultingViewable
. It may never benull
in the resultingViewable
.- Parameters:
nullObject
- The default value to be used when the source value is null.errorObject
- The default value to be used when an error occurs during mapping.source
- The sourceVal
for which the view is created.mapper
- The function that maps the source value to the resulting value in theViewable
returned by this method.- Returns:
- A
Viewable
instance that dynamically maps the source value or alternatively uses the specified null and error objects. - Throws:
NullPointerException
- if any of the supplied parameters arenull
.
-
viewOfNullable
<T extends @Nullable Object,U extends @Nullable Object> Viewable<@Nullable U> viewOfNullable(Class<U> type, Val<T> source, Function<T, @Nullable U> mapper) Creates aViewable
instance of the given nullable type which is a view of the value of the specified sourceVal
mapped to a different (nullable) type using the provided mapper function.
You can register observers on the returnedViewable
to receive updates when the value of the source property changes.- Type Parameters:
T
- The type parameter to which the source value will be mapped in the resultingViewable
. It can be nullable.U
- The type of the value in the sourceVal
. It can also be nullable.- Parameters:
type
- The type class to which the source value will be mapped into the resultingViewable
. This argument may not benull
(Although the resultingViewable
can containnull
values).source
- The sourceVal
for which the view is created.mapper
- The function that maps the source value to the resulting value in theViewable
.- Returns:
- A
Viewable
instance which is a view of the specified sourceVal
mapped to the given (nullable) type. - Throws:
NullPointerException
- if any of the supplied parameters arenull
.
-
lensOf
<T extends @Nullable Object,B extends @NonNull Object> Var<B> lensOf(Var<T> source, Lens<T, B> lens) A factory method for creating aLens
basedVar
property, which is a zoomed in handle to a field variable of a non-nullClass
of a non-nullable typeB
that is a member part of the source property item typeT
.
The resultingVar
can be mutated, and the changes will be propagated to the source property value through the lens.
BothT
andB
are expected to be data types with value semantics, meaning they should be immutable and have properequals
andhashCode
implementations. We recommend using record types forT
andB
to reliably ensure value semantics.- Type Parameters:
T
- The type of the source property value, which is expected to be non-nullable.B
- The type of the field in the source property valueT
, which can be nullable.- Parameters:
source
- The sourceVar
from which the lens is created.lens
- The lens that defines how to access the field of typeB
in the source property valueT
.- Returns:
- A
Var
instance that represents the field of typeB
in the source property valueT
.
-
lensOf
<T extends @Nullable Object,B extends @NonNull Object> Var<B> lensOf(Var<T> source, B nullObject, Lens<T, B> lens) A factory method for creating aLens
basedVar
property, which is a zoomed in handle to a field variable of a non-nullClass
of a non-nullable typeB
that is a member part of the source property item typeT
.
The resultingVar
can be mutated, and the changes will be propagated to the source property value through the lens.
If the item in the source property valueT
isnull
, then the resultingVar
will use the providednullObject
as a default value. If you want to create a lens property which can storenull
values, use thelensOfNullable(Class, Var, Lens)
method instead.
BothT
andB
are expected to be data types with value semantics, meaning they should be immutable and have properequals
andhashCode
implementations. We recommend using record types forT
andB
to reliably ensure value semantics.- Type Parameters:
T
- The type of the source property value, which is expected to be non-nullable.B
- The type of the field in the source property valueT
, which can be nullable.- Parameters:
source
- The sourceVar
from which the lens is created.nullObject
- The default value to be used when the source value is null.lens
- The lens that defines how to access the field of typeB
in the source property valueT
. This lens property may never storenull
values.- Returns:
- A
Var
instance that represents the field of typeB
in the source property valueT
.
-
lensOfNullable
<T extends @Nullable Object,B extends @Nullable Object> Var<B> lensOfNullable(Class<B> type, Var<T> source, Lens<T, B> lens) A factory method for creating aLens
basedVar
property, which is a zoomed in handle to a field variable of a non-nullClass
of a nullable typeB
that is a member part of the source property item typeT
.
If you want to create a lens property which can never storenull
values, use thelensOf(Var, Object, Lens)
factory method instead.
The resultingVar
can be mutated, and the changes will be propagated to the source property value through the lens.
Both
T
andB
are expected to be data types with value semantics, so they should be immutable and have properequals
andhashCode
implementations. We recommend using record types forT
andB
to reliably ensure value semantics.- Type Parameters:
T
- The type of the source property value, which is expected to be non-nullable.B
- The type of the field in the source property valueT
, which can be nullable.- Parameters:
type
- The type of the resultingVar
.source
- The sourceVar
from which the lens is created.lens
- The lens that defines how to access the field of typeB
in the source property valueT
.- Returns:
- A
Var
instance that represents the field of typeB
in the source property valueT
.
-
varOfNullable
Creates aVar
property instance from a given non-nullClass
of a nullable type and as well as an item of that type, which therefore may benull
. The resulting property is nullable, meaning it can hold a value of the given type or benull
. If you want to create a property which can never holdnull
values, usevarOf(Class, Object)
instead of this method.- Type Parameters:
T
- The type of the item to be wrapped in theVar
.- Parameters:
type
- The type of the item to be wrapped in theVar
, which must not benull
.item
- The item to be wrapped in theVar
. It can benull
.- Returns:
- A
Var
instance containing the item, or an emptyVar
if the item isnull
. - Throws:
NullPointerException
- iftype
isnull
.
-
varOfNull
Creates an emptyVar
instance (storing anull
item) of the given type. If you want to create a property which can never holdnull
values, usevarOf(Class, Object)
instead of this method.- Type Parameters:
T
- The type of the item to be wrapped in theVar
.- Parameters:
type
- The type of the item to be wrapped in theVar
, which must not benull
.- Returns:
- A
Var
instance containing anull
item. - Throws:
NullPointerException
- iftype
isnull
.
-
varOf
Creates aVar
property instance from a given non-nullable item, where theMaybe.type()
is inferred from the type of the item.- Type Parameters:
T
- The type of the item to be wrapped in theVar
.- Parameters:
item
- The item to be wrapped in theVar
. It must not benull
.- Returns:
- A
Var
instance containing the item. - Throws:
NullPointerException
- ifitem
isnull
.
-
varOf
Creates aVar
property instance of the given non-nullable type with the specified non-null item. The resulting property is non-nullable, meaning it can only hold a value of the given type and cannot benull
. The supplied item must be a subtype of the specifiedtype
.- Type Parameters:
T
- The type of the item to be wrapped in theVar
.V
- The type of the item to be wrapped in theVar
, which must be a subtype ofT
.- Parameters:
type
- The type of the item to be wrapped in theVar
.item
- The item to be wrapped in theVar
. It must not benull
and it must be a subtype of the specifiedtype
.- Returns:
- A non-nullable
Var
instance containing the item. - Throws:
NullPointerException
- iftype
oritem
isnull
.
-
valsOf
A factory method which creates an emptyVals
instance dedicated to hold properties storing non-nullable items of the specified type.- Type Parameters:
T
- The type of the items to be wrapped in theVals
.- Parameters:
type
- The type of the items to be wrapped in theVals
. It must not benull
.- Returns:
- A
Vals
instance that can hold items of the specified type. - Throws:
NullPointerException
- iftype
isnull
.
-
valsOf
This factory method creates aVals
instance from a type class and an array ofVal
properties, each wrapping a non-nullable item of the specified type. A property list can store multipleVal
properties wrapping non-nullable items of the specified type.- Type Parameters:
T
- The non-nullable type of the items to be wrapped in theVals
.- Parameters:
type
- The type of the items to be wrapped in theVals
. It must not benull
.vars
- An array ofVal
properties to be wrapped in theVals
. Properties in the array cannot benull
, and their items also cannot benull
.- Returns:
- A
Vals
instance that can hold the specified items of the given type. - Throws:
NullPointerException
- iftype
orvars
isnull
.
-
valsOf
A factory method for creating aVals
property list from one or moreVal
properties, which are all instances of the same type and may not benull
. TheVals.type()
is inferred from the type of the first propertiesMaybe.type()
. If you want to create a property list which can holdnull
s, usevalsOfNullable(Class, Val...)
instead of this method.- Type Parameters:
T
- The type of the items to be wrapped in theVals
.- Parameters:
first
- The firstVal
to be wrapped in theVals
. It must not benull
and it must not contain anull
item (Val.allowsNull()
must returnfalse
).rest
- AdditionalVal
items to be wrapped in theVals
. They are not permitted to benull
, and they also may not containnull
items (Val.allowsNull()
must returnfalse
).- Returns:
- A
Vals
instance that can hold the specified items of the inferred type. - Throws:
NullPointerException
- iffirst
or any item inrest
isnull
.
-
valsOf
A factory method for creating aVals
property list from one or more items, which are all instances of the same type and may not benull
. TheVals.type()
is inferred from the type of the first item. If you want to create a property list which can holdnull
s, usevalsOfNullable(Class, Object...)
instead of this method.- Type Parameters:
T
- The type of the items to be wrapped in theVals
.- Parameters:
first
- The first item to be wrapped in theVals
. It must not benull
.rest
- Additional items to be wrapped in theVals
. They can benull
.- Returns:
- A
Vals
instance that can hold the specified items of the inferred type. - Throws:
NullPointerException
- iffirst
orrest
isnull
, or if any item inrest
isnull
.
-
valsOf
A factory method for creating aVals
property list from a type class and an array of items, which are all instances of the given type and may not benull
. The resultingVals
can hold multiple values of the specified type. If you want to create a property list which can holdnull
references, usevalsOfNullable(Class, Object...)
instead of this method.- Type Parameters:
T
- The type of the items to be wrapped in theVals
.- Parameters:
type
- The type class of the items to be wrapped in theVals
. It must not benull
.items
- An array of items to be wrapped in theVals
. The items themselves cannot benull
.- Returns:
- A
Vals
instance that can hold the specified items of the given type. - Throws:
NullPointerException
- iftype
oritems
isnull
.
-
valsOf
Creates aVals
property list from a type class and an iterable ofVal
properties, each wrapping a non-nullable item of the specified type. A property list can store multipleVal
properties wrapping non-nullable items of the specified type.- Type Parameters:
T
- The non-nullable type of the items to be wrapped in theVals
.- Parameters:
type
- The type of the items to be wrapped in theVals
. It must not benull
.properties
- An iterable ofVal
properties to be wrapped in theVals
. Properties in the iterable cannot benull
, and their items cannot benull
.- Returns:
- A
Vals
instance that can hold the specified items of the given type. - Throws:
NullPointerException
- iftype
orproperties
isnull
.
-
valsOf
Creates aVals
property list of the given type with the specified items from anotherVals
instance. A property list can store multipleVal
properties wrapping non-nullable items of the specified type.- Type Parameters:
T
- The non-nullable type of the items to be wrapped in theVals
.- Parameters:
type
- The type of the items to be wrapped in theVals
. It must not benull
.vals
- The items to be wrapped in theVals
. Items in properties of theVals
are not permitted to benull
.- Returns:
- A
Vals
instance that can hold the specified items of the given (non-nullable) type. - Throws:
NullPointerException
- iftype
orvals
isnull
.
-
valsOfNullable
This factory method instantiates an emptyVals
instance from a type class of a nullable typeT
. The resultingVals
can hold multiple properties wrapping either instances of the specified typeT
ornull
references. If you want to create a property list which can never holdnull
s, usevalsOf(Class)
instead of this method.- Type Parameters:
T
- The nullable type of the items to be wrapped in theVals
.- Parameters:
type
- The type class of the nullable items to be wrapped in theVals
. It must not benull
.- Returns:
- A
Vals
instance that can hold items of the specified nullable type. - Throws:
NullPointerException
- iftype
isnull
.
-
valsOfNullable
Creates aVals
property list ofVal
properties from a type class and an array of properties, holding nullable items which are all instances of the given type ornull
. So everyVal
property in the resultingVals
is permitted to hold anull
reference and may therefore reportMaybe.isEmpty()
astrue
.- Type Parameters:
T
- The type of the items to be wrapped in theVals
.- Parameters:
type
- The type class of the nullable items to be wrapped in theVals
. It must not benull
.vals
- An array ofVal
s to be wrapped in theVals
. The properties themselves cannot benull
, but the items they hold can benull
.- Returns:
- A
Vals
instance that can hold the specified items of the given type, includingnull
values. - Throws:
NullPointerException
- iftype
orvals
isnull
, or if any of theVal
properties invals
array isnull
. (Note that the items in theVal
properties are permitted to benull
!)
-
valsOfNullable
Creates aVals
property list ofVal
properties from a type class and an array of items, which are all instances of the given type ornull
. EveryVal
property in the resultingVals
is permitted to hold anull
reference, in which case it will reportMaybe.isEmpty()
astrue
. If you want to create a property list which can never holdnull
s, usevalsOf(Class, Object...)
instead of this method.- Type Parameters:
T
- The type of the items to be wrapped in theVals
.- Parameters:
type
- The type class of the nullable items to be wrapped in theVals
. It must not benull
.items
- An array of items to be wrapped in theVals
. The items themselves can benull
, but the array is not permitted to benull
itself.- Returns:
- A
Vals
instance that can hold the specified items of the given type, includingnull
values. - Throws:
NullPointerException
- iftype
or theitems
array isnull
.
-
valsOfNullable
Creates aVals
property list ofVal
properties from one or moreVal
properties, which are all instances of the same type and may holdnull
values. TheVals.type()
is inferred from the type of the first propertiesMaybe.type()
. If you want to create a property list which can never holdnull
s, usevalsOf(Class, Val...)
instead of this method.- Type Parameters:
T
- The type of the items to be wrapped in theVals
.- Parameters:
first
- The firstVal
to be wrapped in theVals
. It must not benull
and it may contain anull
item (Val.allowsNull()
may returntrue
).rest
- AdditionalVal
items to be wrapped in theVals
. They are not permitted to benull
, but they may containnull
items (Val.allowsNull()
may returntrue
).- Returns:
- A
Vals
instance that can hold the specified items of the inferred type, including nullable values. - Throws:
NullPointerException
- iffirst
orrest
isnull
, as well as if any item inrest
isnull
.
-
valsOfNullable
This factory method creates aVals
property list from a type class representing a nullable typeT
and anotherVals
instance, which contains nullable items being compatible with the specified typeT
. A property list can store multipleVal
properties wrapping nullable items of the specified type.- Type Parameters:
T
- The nullable type of the items to be wrapped in theVals
.- Parameters:
type
- The type of the items to be wrapped in theVals
. It must not benull
.vals
- The items to be wrapped in theVals
. Items in properties of theVals
are permitted to benull
.- Returns:
- A
Vals
instance that can hold the specified items of the given (nullable) type. - Throws:
NullPointerException
- iftype
orvals
isnull
.
-
varsOf
Creates a list of non-nullable properties from the supplied type and vararg values. This factory method requires that the type be specified because the compiler cannot infer the type from a potentially empty vararg array.- Type Parameters:
T
- the type of the properties.- Parameters:
type
- the type of the properties.vars
- the properties to add to the new Vars instance.- Returns:
- a new
Vars
instance. - Throws:
NullPointerException
- iftype
isnull
, orvars
isnull
.IllegalArgumentException
- if any property allowsnull
.
-
varsOf
Creates an empty list of non-nullable properties from the supplied type. This factory method requires that the type be specified because the compiler cannot infer the type from a potentially empty vararg array.- Type Parameters:
T
- the type of the properties.- Parameters:
type
- the type of the properties. This is used to check if the item is of the correct type.- Returns:
- a new
Vars
instance. - Throws:
NullPointerException
- iftype
isnull
.
-
varsOf
Creates a list of non-nullable properties from one or more non-nullable properties.- Type Parameters:
T
- the type of the properties.- Parameters:
first
- the first property to add to the new Vars instance.rest
- the remaining properties to add to the new Vars instance.- Returns:
- a new
Vars
instance. - Throws:
NullPointerException
- iffirst
isnull
, orrest
isnull
.IllegalArgumentException
- if any property allowsnull
.
-
varsOf
Creates a list of non-nullable properties from one or more non-null values.- Type Parameters:
T
- the type of the values.- Parameters:
first
- the first value to add to the new Vars instance.rest
- the remaining values to add to the new Vars instance.- Returns:
- a new
Vars
instance. - Throws:
NullPointerException
- iffirst
isnull
, orrest
isnull
.IllegalArgumentException
- if any value inrest
isnull
.
-
varsOf
Creates a list of non-nullable properties from the supplied type and values. This factory method requires that the type be specified because the compiler cannot infer the type from the values.- Type Parameters:
T
- the type of the values.- Parameters:
type
- the type of the properties.items
- the values to be wrapped by properties and then added to the new Vars instance. The values may not be null.- Returns:
- a new
Vars
instance. - Throws:
NullPointerException
- iftype
isnull
, oritems
isnull
.
-
varsOf
Creates a list of non-nullable properties from the supplied type and iterable of values. This factory method requires that the type be specified because the compiler cannot infer the type from a potentially empty iterable.- Type Parameters:
T
- the type of the properties.- Parameters:
type
- the type of the properties.vars
- the iterable of values.- Returns:
- a new
Vars
instance. - Throws:
NullPointerException
- iftype
isnull
, orvars
isnull
.IllegalArgumentException
- if any property invars
allowsnull
.
-
varsOfNullable
Creates a list of nullable properties from the supplied type and varargs properties. This factory method requires that the type be specified because the compiler cannot infer the type from the null values.- Type Parameters:
T
- the type of the properties.- Parameters:
type
- the type of the properties.vars
- the properties to add to the new Vars instance. The properties may be nullable properties, but they may not be null themselves.- Returns:
- a new
Vars
instance. - Throws:
NullPointerException
- iftype
isnull
, orvars
isnull
.
-
varsOfNullable
Creates an empty list of nullable properties from the supplied type. This factory method requires that the type be specified because the compiler cannot infer the type from a potentially empty vararg array.- Type Parameters:
T
- the type of the properties.- Parameters:
type
- the type of the properties. This is used to check if the item is of the correct type.- Returns:
- a new
Vars
instance. - Throws:
NullPointerException
- iftype
isnull
.
-
varsOfNullable
Creates a list of nullable properties from the supplied type and values. This factory method requires that the type be specified because the compiler cannot infer the type from the null values.- Type Parameters:
T
- the type of the values.- Parameters:
type
- the type of the properties.values
- the values to be wrapped by properties and then added to the new Vars instance. The values may be null.- Returns:
- a new
Vars
instance.
-
varsOfNullable
Creates a list of nullable properties from the supplied properties.- Type Parameters:
T
- the type of the properties.- Parameters:
first
- the first property to add to the new Vars instance.rest
- the remaining properties to add to the new Vars instance.- Returns:
- a new
Vars
instance.
-
varsOfNullable
Creates a list of nullable properties from the supplied type and iterable of values. This factory method requires that the type be specified because the compiler cannot infer the type from a potentially empty iterable.- Type Parameters:
T
- the type of the properties.- Parameters:
type
- the type of the properties.vars
- the iterable of values.- Returns:
- a new
Vars
instance.
-
tupleOf
Creates an immutable tuple of non-nullable items from the supplied type and vararg values. This factory method requires the type to be specified, because the compiler cannot infer the type from a potentially empty vararg array.- Type Parameters:
T
- the type of the items in the tuple.- Parameters:
type
- the type of the items in the tuple.maybes
- the items to add to the newTuple
instance.- Returns:
- a new
Tuple
instance. - Throws:
NullPointerException
- iftype
isnull
, orvec
isnull
.IllegalArgumentException
- if anyMaybe
allowsnull
.
-
tupleOf
Creates an empty tuple of non-nullable items from the supplied type. This factory method requires the type to be specified, because the compiler cannot infer the type from a potentially empty vararg array.- Type Parameters:
T
- the type of the items in the tuple.- Parameters:
type
- the type of the items in the tuple. This is used to check if the item is of the correct type.- Returns:
- a new
Tuple
instance. - Throws:
NullPointerException
- iftype
isnull
.
-
tupleOf
Creates an immutable tuple of non-nullable items from one or more non-nullable items wrapped byMaybe
properties.- Type Parameters:
T
- the type of the items in the tuple.- Parameters:
first
- the firstMaybe
to add to the newTuple
instance.rest
- the remaining items to add to the newTuple
instance.- Returns:
- a new
Tuple
instance. - Throws:
NullPointerException
- iffirst
isnull
, orrest
isnull
.IllegalArgumentException
- if anyMaybe
allowsnull
.
-
tupleOf
Creates an immutable tuple of non-nullable items from one or more non-null items. At least one non-null item must be provided to this factory method.- Type Parameters:
T
- the type of the values.- Parameters:
first
- the first value to add to the newTuple
instance.rest
- the remaining values to add to the newTuple
instance.- Returns:
- a new
Tuple
instance. - Throws:
NullPointerException
- iffirst
isnull
, orrest
isnull
.IllegalArgumentException
- if any value inrest
isnull
.
-
tupleOf
Creates an immutable, non-nullableTuple<Float>
from a primitive array of floats. The returned tuple will contain the floats as a single dense array of primitives.
Note that in order to guarantee immutability, the array of floats is copied.- Parameters:
floats
- The floats to use as a basis for the new tuple.- Returns:
- a new
Tuple
instance backed by a single primitive array of floats. - Throws:
NullPointerException
- iffloats
isnull
.
-
tupleOf
Creates an immutable, non-nullableTuple<Double>
from a primitive array of doubles. The returned tuple will contain the doubles as a single dense array of primitives.
Note that in order to guarantee immutability, the array of doubles is copied.- Parameters:
doubles
- The doubles to use as a basis for the new tuple.- Returns:
- a new
Tuple
instance backed by a single primitive array of doubles. - Throws:
NullPointerException
- ifdoubles
isnull
.
-
tupleOf
Creates an immutable tuple of non-nullable items from a primitive array of integers. The returned tuple will contain the integers as a single dense array of primitives.
Note that in order to guarantee immutability, the array of integers is copied.- Parameters:
ints
- The integers to use as a basis for the new tuple.- Returns:
- a new
Tuple
instance backed by a single primitive array of integers. - Throws:
NullPointerException
- ifints
isnull
.
-
tupleOf
Creates an immutable tuple of non-nullable items from a primitive array of bytes. The returned tuple will contain the bytes as a single dense array of primitives.
Note that in order to guarantee immutability, the array of bytes is copied.- Parameters:
bytes
- The bytes to use as a basis for the new tuple.- Returns:
- a new
Tuple
instance backed by a single primitive array of bytes. - Throws:
NullPointerException
- ifbytes
isnull
.
-
tupleOf
Creates an immutable tuple of non-nullable items from a primitive array of longs. The returned tuple will contain the longs as a single dense array of primitives.
Note that in order to guarantee immutability, the array of longs is copied.- Parameters:
longs
- The longs to use as a basis for the new tuple.- Returns:
- a new
Tuple
instance backed by a single primitive array of longs. - Throws:
NullPointerException
- iflongs
isnull
.
-
tupleOf
Creates an immutable tuple of non-nullable items from the supplied type and values. This factory method requires the type to be specified, because the compiler cannot infer the type from the values.- Type Parameters:
T
- the type of the values.- Parameters:
type
- the type of the items in the tuple.items
- the values to be wrapped by items and then added to the newTuple
instance. The values may not be null.- Returns:
- a new
Tuple
instance. - Throws:
NullPointerException
- iftype
isnull
, oritems
isnull
.
-
tupleOf
Creates an immutable tuple of non-nullable items from the supplied type and iterable of values. This factory method requires the type to be specified, because the compiler cannot infer the type from a potentially empty iterable.- Type Parameters:
T
- the type of the items in the tuple.- Parameters:
type
- the type of the items in the tuple.iterable
- the iterable of values.- Returns:
- a new
Tuple
instance. - Throws:
NullPointerException
- iftype
isnull
, orvec
isnull
.IllegalArgumentException
- if anyMaybe
invec
allowsnull
.
-
tupleOfNullable
Creates an immutable tuple of nullable items from the supplied type and varargs items. This factory method requires the type to be specified, because the compiler cannot infer the type from the null values.- Type Parameters:
T
- the type of the items in the tuple.- Parameters:
type
- the type of the items in the tuple.maybes
- the items to add to the newTuple
instance. The items may be nullable items, but they may not be null themselves.- Returns:
- a new
Tuple
instance. - Throws:
NullPointerException
- iftype
isnull
, orvec
isnull
.
-
tupleOfNullable
Creates an empty tuple of nullable items from the supplied type. This factory method requires the type to be specified, because the compiler cannot infer the type from a potentially empty vararg array.- Type Parameters:
T
- the type of the items in the tuple.- Parameters:
type
- the type of the items in the tuple. This is used to check if the item is of the correct type.- Returns:
- a new
Tuple
instance. - Throws:
NullPointerException
- iftype
isnull
.
-
tupleOfNullable
Creates an immutable tuple of nullable items from the supplied type and values. This factory method requires the type to be specified, because the compiler cannot infer the type from the null values.- Type Parameters:
T
- the type of the values.- Parameters:
type
- the type of the items in the tuple.items
- The items to be stored by the newTuple
instance. The values may be null.- Returns:
- a new
Tuple
instance.
-
tupleOfNullable
default <T> Tuple<@Nullable T> tupleOfNullable(Maybe<@Nullable T> first, Maybe<@Nullable T>... rest) Creates an immutable tuple of nullable items from the supplied items.- Type Parameters:
T
- the type of the items in the tuple.- Parameters:
first
- the firstMaybe
to add to the newTuple
instance.rest
- the remaining items to add to the newTuple
instance.- Returns:
- a new
Tuple
instance.
-
tupleOfNullable
Creates an immutable tuple of nullable items from the supplied type and iterable of values. This factory method requires the type to be specified, because the compiler cannot infer the type from a potentially empty iterable.- Type Parameters:
T
- the type of the items in the tuple.- Parameters:
type
- the type of the items in the tuple.iterable
- the iterable of values.- Returns:
- a new
Tuple
instance.
-
associationOf
Creates a new association between keys and values with the given key and value types. An association knows the types of its keys and values, and so you can only put keys and values of the defined types into the association. This creates an empty association primed without any order of their key-value pairs.- Type Parameters:
K
- The type of the keys in the association, which must be immutable.V
- The type of the values in the association, which should be immutable.- Parameters:
keyType
- The type of the keys in the association.valueType
- The type of the values in the association.- Returns:
- A new association between keys and values.
-
associationOfLinked
Creates a new linked association between keys and values with the given key and value types, where the order of key-value pairs in this type of association is based on the order in which the pairs are added to the association. An association always knows the types of its keys and values, and so you can only put keys and values of the defined types into the association.- Type Parameters:
K
- The type of the keys in the association, which must be immutable.V
- The type of the values in the association, which should be immutable.- Parameters:
keyType
- The type of the keys in the association.valueType
- The type of the values in the association.- Returns:
- A new linked association between keys and values, where the order of key-value pairs is preserved in the order they are added.
-
associationOfSorted
<K,V> Association<K,V> associationOfSorted(Class<K> keyType, Class<V> valueType, Comparator<K> comparator) Creates a new association between keys and values with the given key and value types, where the key-value pairs are sorted using the supplied comparator. An association knows the types of its keys and values, and so you can only put keys and values of the defined types into the association.- Type Parameters:
K
- The type of the keys in the association, which must be immutable.V
- The type of the values in the association, which should be immutable.- Parameters:
keyType
- The type of the keys in the association.valueType
- The type of the values in the association.comparator
- The comparator to use for sorting the keys in the association.- Returns:
- A new sorted association between keys and values.
-
associationOfSorted
<K extends Comparable<K>,V> Association<K,V> associationOfSorted(Class<K> keyType, Class<V> valueType) Creates a new association between keys and values with the given key and value types, where the keys are sorted in natural order. An association knows the types of its keys and values, and so you can only put keys and values of the defined types into the association.- Type Parameters:
K
- The type of the keys in the association, which must be immutable.V
- The type of the values in the association, which should be immutable.- Parameters:
keyType
- The type of the keys in the association.valueType
- The type of the values in the association.- Returns:
- A new sorted association between keys and values.
-
valueSetOf
Creates a new value set specifically for holding elements of the supplied type. A value set knows the types of its elements, and so you can only add elements which are of the same type or a subtype of the type of the value set.- Type Parameters:
E
- The type of the elements in the value set, which must be an immutable value type.- Parameters:
type
- The type of the elements in the value set.- Returns:
- A new value set specific to the given element type.
-
valueSetOfLinked
Creates a new value set specifically for holding elements of the supplied type, and where the order of the elements is defined by the insertion order. Which means that during iteration over the value set, the elements will be returned in the order they were added. A value set knows the types of its elements, and so you can only add elements which are of the same type or a subtype of the type of the value set.- Type Parameters:
E
- The type of the elements in the value set, which must be an immutable value type.- Parameters:
type
- The type of the elements in the value set.- Returns:
- A new linked value set specific to the given element type.
-
valueSetOfSorted
Creates a new value set specifically for holding elements of the supplied type, but with an explicit order defined by the supplied comparator. A value set knows the types of its elements and values, and so you can only add elements which are of the same type or a subtype of the type of the value set.
Here is an example demonstrating how this method may be used to create a set with string elements sorted by their length:
ValueSet.ofSorted( String.class, Comparator.comparing(String::length) );
- Type Parameters:
E
- The type of the elements in the value set, which must be an immutable value type.- Parameters:
type
- The type of the elements in the value set.comparator
- The comparator to use for sorting the elements in the value set.- Returns:
- A new sorted value set specific to the given element type.
-
valueSetOfSorted
Creates a new value set specifically for holding elements of the supplied type, elements are sorted based on the natural ordering of the elements (which are expected to implementComparable
). A value set knows the types of its elements and values, and so you can only add elements which are of the same type or a subtype of the specified element type of the value set.- Type Parameters:
E
- The type of the elements in the value set, which must be an immutable value type.- Parameters:
type
- The type of the elements in the value set.- Returns:
- A new sorted value set specific to the given element type.
-
defaultId
String defaultId()The default id for properties which do not have an id explicitly specified. The id of a property is used to identify it in the system or as part of a view model and convert it into other data formats like key/value based data stores.- Returns:
- The default id for properties which do not have an id explicitly specified.
This must never return
null
and it is recommended to be a constant or cached object due to this method being called frequently.
-
idPattern
Pattern idPattern()The regexPattern
used to validate property ids. All ids must match this pattern.- Returns:
- The regex
Pattern
used to validate property ids. This must never returnnull
and it is recommended to be a constant or cached object due to this method being called frequently.
-
defaultChannel
Channel defaultChannel()The default channel used for change events. This channel is used to give events a chanel when no channel is explicitly specified.- Returns:
- The default channel used for change events.
This must never return
null
and it is recommended to be a constant or cached object due to this method being called frequently.
-
defaultObservableChannel
Channel defaultObservableChannel()The default channel used forObservable
events, registered through theObservable.subscribe(Observer)
method.- Returns:
- The default channel used for change events.
This must never return
null
and it is recommended to be a constant or cached object due to this method being called frequently.
-