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 forObservableevents, 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/Varsproperty list to be specifically designed as a context object passed toActions registered onViewables, like for example through theViewable.onChange(Channel, Action)method.event()A factory method to create a newEventinstance.eventOf(Event.Executor executor) A factory method to create a newEventinstance with the given executor.The regexPatternused to validate property ids.A factory method for creating aLensbasedVarproperty, which is a zoomed in handle to a field variable of a non-nullClassof a non-nullable typeBthat is a member part of the source property item typeT.
The resultingVarcan be mutated, and the changes will be propagated to the source property value through the lens.
If the item in the source property valueTisnull, then the resultingVarwill use the providednullObjectas a default value.A factory method for creating aLensbasedVarproperty, which is a zoomed in handle to a field variable of a non-nullClassof a non-nullable typeBthat is a member part of the source property item typeT.
The resultingVarcan be mutated, and the changes will be propagated to the source property value through the lens.
BothTandBare expected to be data types with value semantics, meaning they should be immutable and have properequalsandhashCodeimplementations.lensOfNullable(Class<B> type, Var<T> source, Lens<T, B> lens) A factory method for creating aLensbasedVarproperty, which is a zoomed in handle to a field variable of a non-nullClassof a nullable typeBthat is a member part of the source property item typeT.
If you want to create a lens property which can never storenullvalues, use thelensOf(Var, Object, Lens)factory method instead.
The resultingVarcan be mutated, and the changes will be propagated to the source property value through the lens.org.slf4j.MarkerMany features in Sprouts are designed to preserve the control flow of your application by catching exceptions and then logging them.default <T> Maybe<T> default <T> Maybe<T> maybeOf(T item) Creates aMaybeinstance from a non-nullable item.default <T> Maybe<@Nullable T> maybeOfNull(Class<T> type) Creates aMaybeinstance of the given type with anullitem.default <T> Maybe<@Nullable T> maybeOfNullable(Class<T> type, @Nullable T item) Creates a nullableMaybeinstance 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 byMaybeproperties.<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-nullValinstance of the given non-null item.<T> Val<@Nullable T> Creates an emptyValproperty from the given type class.<T> Val<@Nullable T> valOfNullable(Class<T> type, @Nullable T item) Creates a newValproperty 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 emptyValsinstance 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 aValsproperty 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 aValsproperty 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 emptyValsinstance 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 aVarproperty instance of the given non-nullable type with the specified non-null item.<T> Var<T> varOf(T item) Creates aVarproperty instance from a given non-nullable item, where theMaybe.type()is inferred from the type of the item.<T> Var<@Nullable T> Creates an emptyVarinstance (storing anullitem) 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 aViewableinstance where he item of a supplied sourceValis 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 isnullor an error occurs during mapping.
You can registerActions orObservers on the returnedViewableto 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 aViewableinstance of the given nullable type which is a view of the value of the specified sourceValmapped to a different (nullable) type using the provided mapper function.
You can register observers on the returnedViewableto 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/Varproperty changes its value or is explicitly triggered to propagate the event to all derivedViewableinstances and theirActions.- 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.NONEif 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
Valproperty.
-
delegateOf
<T> ValsDelegate<T> delegateOf(Vals<T> source, SequenceChange changeType, int index, Vals<T> newValues, Vals<T> oldValues) Creates a delegate for when aVals/Varsproperty list to be specifically designed as a context object passed toActions registered onViewables, 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
Valsproperty.
-
event
Event event()A factory method to create a newEventinstance. AnEventcan be triggered using theEvent.fire()method, and it will notify allActions registered onObservers derived from theEventinstance through theEvent.observable()method.- Returns:
- A new
Eventinstance with the default executor.
-
eventOf
A factory method to create a newEventinstance with the given executor. AnEventcan be triggered using theEvent.fire()method, and it will notify allActions registered onObservers derived from theEventinstance through theEvent.observable()method.- Parameters:
executor- The executor to be used for the event. It must not benull.- Returns:
- A new
Eventinstance with the specified executor.
-
maybeOfNullable
Creates a nullableMaybeinstance 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
Maybeinstance containing the item, or an emptyMaybeif the item isnull.
-
maybeOfNull
Creates aMaybeinstance of the given type with anullitem. TheMaybe.isEmpty()method of the returned instance will always returntrue, indicating that theMaybedoes not contain a value. -
maybeOf
Creates aMaybeinstance from a non-nullable item. TheMaybe.isPresent()method of the returned instance will always returntrue, indicating that theMaybecontains a value. -
maybeOf
Creates a non-emptyMaybecopy from the suppliedMaybe. The suppliedMaybemust 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 theMaybecontains a value. The returned instance is effectively an immutable copy of the suppliedMaybe. -
maybeOfNullable
Creates a potentially emptyMaybecopy 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- TheMaybeinstance to be copied.- Returns:
- A new
Maybeinstance containing the value from the givenMaybe, or an emptyMaybeif the value isnull. - Throws:
NullPointerException- iftoBeCopiedisnull. (However, the item in the suppliedMaybecan benull.)
-
valOfNullable
Creates a newValproperty 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 theValproperty.- 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
Valinstance containing the item, or an emptyValif the item isnull. - Throws:
NullPointerException- iftypeisnull.
-
valOfNull
Creates an emptyValproperty from the given type class. TheMaybe.isEmpty()method of the returned instance will always returntrue, indicating that theValdoes not contain a value. -
valOf
Creates a non-nullValinstance of the given non-null item. TheMaybe.isPresent()method of the returned instance will always returntrue, indicating that theValdoes 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
Valinstance containing the item. - Throws:
NullPointerException- ifitemisnull.
-
valOf
Creates a non-emptyValcopy from the suppliedVal. The suppliedValmust 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 theValcontains 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- TheValinstance to be copied. It must not benulland it must not contain anullvalue.- Returns:
- A new
Valinstance containing the value from the givenVal. - Throws:
NullPointerException- iftoBeCopiedisnull.
-
valOfNullable
- Type Parameters:
T- The type of the item to be wrapped in theVal.- Parameters:
toBeCopied- TheValinstance to be copied. It must not benull, however, the value in theValcan benull.- Returns:
- A new
Valinstance containing the value from the givenVal, or an emptyValif the value isnull. - Throws:
NullPointerException- iftoBeCopiedisnull.
-
viewOf
Creates aViewableinstance of the givenVal. You can register observers on the returnedViewableto receive updates when the value of theValchanges.- Type Parameters:
T- The type of the item in theVal.- Parameters:
source- The sourceValfor which the view is created.- Returns:
- A
Viewableinstance that wraps the givenVal. The source may not benull. - Throws:
NullPointerException- ifsourceisnull.
-
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-nullViewableinstance which is a composite of twoValinstances 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 twoValinstances change.- Type Parameters:
T- The type of the firstValvalue.U- The type of the secondValvalue.- Parameters:
first- The firstValto be combined into aViewablecomposite.second- The secondValto be combined into aViewablecomposite.combiner- The function that combines the values of the twoValinstances into a single value.- Returns:
- A
Viewableinstance that combines the values of the twoValinstances 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 nullableViewableinstance which is a composite of twoValinstances 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 twoValinstances change.- Type Parameters:
T- The type of the firstValvalue.U- The type of the secondValvalue.- Parameters:
first- The firstValto be combined into aViewablecomposite.second- The secondValto be combined into aViewablecomposite.combiner- The function that combines the values of the twoValinstances into a single value.- Returns:
- A
Viewableinstance that combines the values of the twoValinstances 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-nullableViewableinstance of the given type which is a composite of twoValinstances 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 twoValinstances change.- Type Parameters:
T- The type of the firstValvalue.U- The type of the secondValvalue.R- The type of the resultingViewable.- Parameters:
type- The type of the resultingViewable.first- The firstValto be combined into aViewablecomposite.second- The secondValto be combined into aViewablecomposite.combiner- The function that combines the values of the twoValinstances into a single value.- Returns:
- A
Viewableinstance that combines the values of the twoValinstances 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 nullableViewableinstance of the given type which is a composite of twoValinstances 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 twoValinstances change.- Type Parameters:
T- The type of the firstValvalue.U- The type of the secondValvalue.R- The type of the resultingViewable.- Parameters:
type- The type of the resultingViewable.first- The firstValto be combined into aViewablecomposite.second- The secondValto be combined into aViewablecomposite.combiner- The function that combines the values of the twoValinstances into a single value.- Returns:
- A
Viewableinstance that combines the values of the twoValinstances using the specified combiner function. - Throws:
NullPointerException- if any of the supplied parameters arenull.
-
viewOf
Creates aViewablesinstance of the givenVals. You can register observers on the returnedViewablesto receive updates when the items in theValschange.- Type Parameters:
T- The type of the items in theVals.- Parameters:
source- The sourceValsfor which the view is created.- Returns:
- A
Viewablesinstance that wraps the givenVals. - Throws:
NullPointerException- ifsourceisnull.
-
viewOf
<T extends @Nullable Object,U> Viewables<U> viewOf(U nullObject, U errorObject, Vals<T> source, Function<T, @Nullable U> mapper) Creates a mappedViewablesinstance of the givenValswith specified null and error objects. This is useful when you want to provide default values for theViewableswhen the source property contains anullvalue 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 sourceValsfor which the view is created.mapper- The function that maps the source value to the resulting value.- Returns:
- A
Viewablesinstance that wraps the givenValswith 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 mappedViewableinstance of the given type which is a view of the value of the specified sourceValmapped to a different type using the provided mapper function.
You can register observers on the returnedViewableto 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 sourceValfor which the view is created.mapper- The function that maps the source value to the resulting value in theViewable.- Returns:
- A
Viewableinstance which is a view of the specified sourceValmapped 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 aViewableinstance where he item of a supplied sourceValis 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 isnullor an error occurs during mapping.
You can registerActions orObservers on the returnedViewableto receive updates when the value of the source property changes. This method is useful when you want a mappedViewablewith a default/fallback values in case the source property contains anullvalue or an error occurs during mapping.- Type Parameters:
T- The type of the item in the sourceValto be mapped. It can be nullable.U- The type of the item to map to in the resultingViewable. It may never benullin 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 sourceValfor which the view is created.mapper- The function that maps the source value to the resulting value in theViewablereturned by this method.- Returns:
- A
Viewableinstance 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 aViewableinstance of the given nullable type which is a view of the value of the specified sourceValmapped to a different (nullable) type using the provided mapper function.
You can register observers on the returnedViewableto 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 resultingViewablecan containnullvalues).source- The sourceValfor which the view is created.mapper- The function that maps the source value to the resulting value in theViewable.- Returns:
- A
Viewableinstance which is a view of the specified sourceValmapped 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 aLensbasedVarproperty, which is a zoomed in handle to a field variable of a non-nullClassof a non-nullable typeBthat is a member part of the source property item typeT.
The resultingVarcan be mutated, and the changes will be propagated to the source property value through the lens.
BothTandBare expected to be data types with value semantics, meaning they should be immutable and have properequalsandhashCodeimplementations. We recommend using record types forTandBto 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 sourceVarfrom which the lens is created.lens- The lens that defines how to access the field of typeBin the source property valueT.- Returns:
- A
Varinstance that represents the field of typeBin 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 aLensbasedVarproperty, which is a zoomed in handle to a field variable of a non-nullClassof a non-nullable typeBthat is a member part of the source property item typeT.
The resultingVarcan be mutated, and the changes will be propagated to the source property value through the lens.
If the item in the source property valueTisnull, then the resultingVarwill use the providednullObjectas a default value. If you want to create a lens property which can storenullvalues, use thelensOfNullable(Class, Var, Lens)method instead.
BothTandBare expected to be data types with value semantics, meaning they should be immutable and have properequalsandhashCodeimplementations. We recommend using record types forTandBto 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 sourceVarfrom 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 typeBin the source property valueT. This lens property may never storenullvalues.- Returns:
- A
Varinstance that represents the field of typeBin 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 aLensbasedVarproperty, which is a zoomed in handle to a field variable of a non-nullClassof a nullable typeBthat is a member part of the source property item typeT.
If you want to create a lens property which can never storenullvalues, use thelensOf(Var, Object, Lens)factory method instead.
The resultingVarcan be mutated, and the changes will be propagated to the source property value through the lens.
Both
TandBare expected to be data types with value semantics, so they should be immutable and have properequalsandhashCodeimplementations. We recommend using record types forTandBto 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 sourceVarfrom which the lens is created.lens- The lens that defines how to access the field of typeBin the source property valueT.- Returns:
- A
Varinstance that represents the field of typeBin the source property valueT.
-
varOfNullable
Creates aVarproperty instance from a given non-nullClassof 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 holdnullvalues, 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
Varinstance containing the item, or an emptyVarif the item isnull. - Throws:
NullPointerException- iftypeisnull.
-
varOfNull
Creates an emptyVarinstance (storing anullitem) of the given type. If you want to create a property which can never holdnullvalues, 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
Varinstance containing anullitem. - Throws:
NullPointerException- iftypeisnull.
-
varOf
Creates aVarproperty 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
Varinstance containing the item. - Throws:
NullPointerException- ifitemisnull.
-
varOf
Creates aVarproperty 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 benulland it must be a subtype of the specifiedtype.- Returns:
- A non-nullable
Varinstance containing the item. - Throws:
NullPointerException- iftypeoritemisnull.
-
valsOf
A factory method which creates an emptyValsinstance 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
Valsinstance that can hold items of the specified type. - Throws:
NullPointerException- iftypeisnull.
-
valsOf
This factory method creates aValsinstance from a type class and an array ofValproperties, each wrapping a non-nullable item of the specified type. A property list can store multipleValproperties 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 ofValproperties to be wrapped in theVals. Properties in the array cannot benull, and their items also cannot benull.- Returns:
- A
Valsinstance that can hold the specified items of the given type. - Throws:
NullPointerException- iftypeorvarsisnull.
-
valsOf
A factory method for creating aValsproperty list from one or moreValproperties, 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 holdnulls, usevalsOfNullable(Class, Val...)instead of this method.- Type Parameters:
T- The type of the items to be wrapped in theVals.- Parameters:
first- The firstValto be wrapped in theVals. It must not benulland it must not contain anullitem (Val.allowsNull()must returnfalse).rest- AdditionalValitems to be wrapped in theVals. They are not permitted to benull, and they also may not containnullitems (Val.allowsNull()must returnfalse).- Returns:
- A
Valsinstance that can hold the specified items of the inferred type. - Throws:
NullPointerException- iffirstor any item inrestisnull.
-
valsOf
A factory method for creating aValsproperty 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 holdnulls, 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
Valsinstance that can hold the specified items of the inferred type. - Throws:
NullPointerException- iffirstorrestisnull, or if any item inrestisnull.
-
valsOf
A factory method for creating aValsproperty list from a type class and an array of items, which are all instances of the given type and may not benull. The resultingValscan hold multiple values of the specified type. If you want to create a property list which can holdnullreferences, 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
Valsinstance that can hold the specified items of the given type. - Throws:
NullPointerException- iftypeoritemsisnull.
-
valsOf
Creates aValsproperty list from a type class and an iterable ofValproperties, each wrapping a non-nullable item of the specified type. A property list can store multipleValproperties 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 ofValproperties to be wrapped in theVals. Properties in the iterable cannot benull, and their items cannot benull.- Returns:
- A
Valsinstance that can hold the specified items of the given type. - Throws:
NullPointerException- iftypeorpropertiesisnull.
-
valsOf
Creates aValsproperty list of the given type with the specified items from anotherValsinstance. A property list can store multipleValproperties 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 theValsare not permitted to benull.- Returns:
- A
Valsinstance that can hold the specified items of the given (non-nullable) type. - Throws:
NullPointerException- iftypeorvalsisnull.
-
valsOfNullable
This factory method instantiates an emptyValsinstance from a type class of a nullable typeT. The resultingValscan hold multiple properties wrapping either instances of the specified typeTornullreferences. If you want to create a property list which can never holdnulls, 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
Valsinstance that can hold items of the specified nullable type. - Throws:
NullPointerException- iftypeisnull.
-
valsOfNullable
Creates aValsproperty list ofValproperties from a type class and an array of properties, holding nullable items which are all instances of the given type ornull. So everyValproperty in the resultingValsis permitted to hold anullreference 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 ofVals to be wrapped in theVals. The properties themselves cannot benull, but the items they hold can benull.- Returns:
- A
Valsinstance that can hold the specified items of the given type, includingnullvalues. - Throws:
NullPointerException- iftypeorvalsisnull, or if any of theValproperties invalsarray isnull. (Note that the items in theValproperties are permitted to benull!)
-
valsOfNullable
Creates aValsproperty list ofValproperties from a type class and an array of items, which are all instances of the given type ornull. EveryValproperty in the resultingValsis permitted to hold anullreference, in which case it will reportMaybe.isEmpty()astrue. If you want to create a property list which can never holdnulls, 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 benullitself.- Returns:
- A
Valsinstance that can hold the specified items of the given type, includingnullvalues. - Throws:
NullPointerException- iftypeor theitemsarray isnull.
-
valsOfNullable
Creates aValsproperty list ofValproperties from one or moreValproperties, which are all instances of the same type and may holdnullvalues. TheVals.type()is inferred from the type of the first propertiesMaybe.type(). If you want to create a property list which can never holdnulls, usevalsOf(Class, Val...)instead of this method.- Type Parameters:
T- The type of the items to be wrapped in theVals.- Parameters:
first- The firstValto be wrapped in theVals. It must not benulland it may contain anullitem (Val.allowsNull()may returntrue).rest- AdditionalValitems to be wrapped in theVals. They are not permitted to benull, but they may containnullitems (Val.allowsNull()may returntrue).- Returns:
- A
Valsinstance that can hold the specified items of the inferred type, including nullable values. - Throws:
NullPointerException- iffirstorrestisnull, as well as if any item inrestisnull.
-
valsOfNullable
This factory method creates aValsproperty list from a type class representing a nullable typeTand anotherValsinstance, which contains nullable items being compatible with the specified typeT. A property list can store multipleValproperties 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 theValsare permitted to benull.- Returns:
- A
Valsinstance that can hold the specified items of the given (nullable) type. - Throws:
NullPointerException- iftypeorvalsisnull.
-
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
Varsinstance. - Throws:
NullPointerException- iftypeisnull, orvarsisnull.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
Varsinstance. - Throws:
NullPointerException- iftypeisnull.
-
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
Varsinstance. - Throws:
NullPointerException- iffirstisnull, orrestisnull.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
Varsinstance. - Throws:
NullPointerException- iffirstisnull, orrestisnull.IllegalArgumentException- if any value inrestisnull.
-
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
Varsinstance. - Throws:
NullPointerException- iftypeisnull, oritemsisnull.
-
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
Varsinstance. - Throws:
NullPointerException- iftypeisnull, orvarsisnull.IllegalArgumentException- if any property invarsallowsnull.
-
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
Varsinstance. - Throws:
NullPointerException- iftypeisnull, orvarsisnull.
-
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
Varsinstance. - Throws:
NullPointerException- iftypeisnull.
-
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
Varsinstance.
-
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
Varsinstance.
-
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
Varsinstance.
-
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 newTupleinstance.- Returns:
- a new
Tupleinstance. - Throws:
NullPointerException- iftypeisnull, orvecisnull.IllegalArgumentException- if anyMaybeallowsnull.
-
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
Tupleinstance. - Throws:
NullPointerException- iftypeisnull.
-
tupleOf
Creates an immutable tuple of non-nullable items from one or more non-nullable items wrapped byMaybeproperties.- Type Parameters:
T- the type of the items in the tuple.- Parameters:
first- the firstMaybeto add to the newTupleinstance.rest- the remaining items to add to the newTupleinstance.- Returns:
- a new
Tupleinstance. - Throws:
NullPointerException- iffirstisnull, orrestisnull.IllegalArgumentException- if anyMaybeallowsnull.
-
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 newTupleinstance.rest- the remaining values to add to the newTupleinstance.- Returns:
- a new
Tupleinstance. - Throws:
NullPointerException- iffirstisnull, orrestisnull.IllegalArgumentException- if any value inrestisnull.
-
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
Tupleinstance backed by a single primitive array of floats. - Throws:
NullPointerException- iffloatsisnull.
-
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
Tupleinstance backed by a single primitive array of doubles. - Throws:
NullPointerException- ifdoublesisnull.
-
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
Tupleinstance backed by a single primitive array of integers. - Throws:
NullPointerException- ifintsisnull.
-
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
Tupleinstance backed by a single primitive array of bytes. - Throws:
NullPointerException- ifbytesisnull.
-
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
Tupleinstance backed by a single primitive array of longs. - Throws:
NullPointerException- iflongsisnull.
-
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 newTupleinstance. The values may not be null.- Returns:
- a new
Tupleinstance. - Throws:
NullPointerException- iftypeisnull, oritemsisnull.
-
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
Tupleinstance. - Throws:
NullPointerException- iftypeisnull, orvecisnull.IllegalArgumentException- if anyMaybeinvecallowsnull.
-
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 newTupleinstance. The items may be nullable items, but they may not be null themselves.- Returns:
- a new
Tupleinstance. - Throws:
NullPointerException- iftypeisnull, orvecisnull.
-
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
Tupleinstance. - Throws:
NullPointerException- iftypeisnull.
-
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 newTupleinstance. The values may be null.- Returns:
- a new
Tupleinstance.
-
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 firstMaybeto add to the newTupleinstance.rest- the remaining items to add to the newTupleinstance.- Returns:
- a new
Tupleinstance.
-
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
Tupleinstance.
-
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
nulland it is recommended to be a constant or cached object due to this method being called frequently.
-
idPattern
Pattern idPattern()The regexPatternused to validate property ids. All ids must match this pattern.- Returns:
- The regex
Patternused to validate property ids. This must never returnnulland 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
nulland it is recommended to be a constant or cached object due to this method being called frequently.
-
defaultObservableChannel
Channel defaultObservableChannel()The default channel used forObservableevents, registered through theObservable.subscribe(Observer)method.- Returns:
- The default channel used for change events.
This must never return
nulland it is recommended to be a constant or cached object due to this method being called frequently.
-
loggingMarker
org.slf4j.Marker loggingMarker()Many features in Sprouts are designed to preserve the control flow of your application by catching exceptions and then logging them. This typically happens in aResultorVarproperty when a userActionfails...
This method configures a Slf4jMarkerto be used by Sprouts at all places where logging is being done. You can then use this marker to identify and filter these log entries.- Returns:
- A constant which serves as a sort of logging channel used on all logging sites of the sprouts library.
-