Package sprouts.impl
Class Sprouts
java.lang.Object
sprouts.impl.Sprouts
- All Implemented Interfaces:
SproutsFactory
Exposes an API for configuring the
So technically speaking, this is a configurable singleton, so be careful when using it as it effectively maintains global + mutable state!
SproutsFactory,
which serves implementations of the various property types in the Sprouts library,
like Event, Val, Var, Vals and Vars.
The methods implemented here are used by the various factory methods of the sprouts API like
Var.of(Object), Vals.of(Object, Object[])...So technically speaking, this is a configurable singleton, so be careful when using it as it effectively maintains global + mutable state!
You can also configure general library defaults here,
like a library global logging marker (see loggingMarker()).
-
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.static SproutsFactoryfactory()ASproutsFactoryis used by the various factory methods of this API likeVar.of(Object),Vals.of(Object, Object[])...The regexPatternused to validate property ids.<T,B> Var <B> 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.<T,B> Var <B> 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.<T,B> 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 theSproutsFactory.lensOf(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.static voidsetFactory(SproutsFactory factory) Sets the factory to be used by the various factory methods of this API likeVar.of(Object),Vals.of(Object, Object[])...voidsetLoggingMarker(org.slf4j.Marker marker) You may want to set this to filter logging done by Sprouts, which is typically a type of log that is contains exceptions caused by bugs and failed sanity checks.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.<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... values) 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.<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.<T> Val<@Nullable T> valOfNullable(Val<@Nullable 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<T> Creates an emptyVarinstance (storing anullitem) of the given type.<T> Var<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<T> varsOfNullable(Class<T> type, Iterable<Var<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) <T,U> Viewable <T> <T> Viewable<T> viewOf(Val<T> first, Val<U> second, BiFunction<T, U, @NonNull T> combiner) <T> Viewables<T> <T,U> Viewable <U> 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.<T,U> Viewables <U> viewOfNullable(Class<R> type, Val<T> first, Val<U> second, BiFunction<T, U, @Nullable R> combiner) <T,U> 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.viewOfNullable(Val<T> first, Val<U> second, BiFunction<T, U, @Nullable T> combiner) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface sprouts.impl.SproutsFactory
maybeOf, maybeOf, maybeOfNull, maybeOfNullable, maybeOfNullable, tupleOf, tupleOfNullable, tupleOfNullable
-
Method Details
-
factory
ASproutsFactoryis used by the various factory methods of this API likeVar.of(Object),Vals.of(Object, Object[])... to create instances of these properties.
You can plug in your own factory implementation through thesetFactory(SproutsFactory)method, where you can then serve your own implementations of the various property types in the Sprouts library.- Returns:
- The default factory for creating instances of the various property types in the Sprouts library.
-
setFactory
Sets the factory to be used by the various factory methods of this API likeVar.of(Object),Vals.of(Object, Object[])... to create instances of these properties.
You can use a customSproutsFactoryto instantiate and serve your own implementations of the various property types in the Sprouts library.
WARNING: This is a global + mutable state, so be careful when using it
as it will have global side effects on the various factory methods of this API.- Parameters:
factory- The factory to be used by the various factory methods of this API.- Throws:
NullPointerException- if the factory is null.
-
delegateOf
public <T> ValDelegate<T> delegateOf(Val<T> source, Channel channel, SingleChange change, @Nullable T newValue, @Nullable T oldValue) Description copied from interface:SproutsFactoryCreates a delegate for when aVal/Varproperty changes its value or is explicitly triggered to propagate the event to all derivedViewableinstances and theirActions.- Specified by:
delegateOfin interfaceSproutsFactory- 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
public <T> ValsDelegate<T> delegateOf(Vals<T> source, SequenceChange changeType, int index, Vals<T> newValues, Vals<T> oldValues) Description copied from interface:SproutsFactoryCreates 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.- Specified by:
delegateOfin interfaceSproutsFactory- 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
Description copied from interface:SproutsFactoryA 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.- Specified by:
eventin interfaceSproutsFactory- Returns:
- A new
Eventinstance with the default executor.
-
eventOf
Description copied from interface:SproutsFactoryA 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.- Specified by:
eventOfin interfaceSproutsFactory- Parameters:
executor- The executor to be used for the event. It must not benull.- Returns:
- A new
Eventinstance with the specified executor.
-
valOfNullable
Description copied from interface:SproutsFactoryCreates 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().- Specified by:
valOfNullablein interfaceSproutsFactory- 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.
-
valOfNull
Description copied from interface:SproutsFactoryCreates an emptyValproperty from the given type class. TheMaybe.isEmpty()method of the returned instance will always returntrue, indicating that theValdoes not contain a value.- Specified by:
valOfNullin interfaceSproutsFactory- Type Parameters:
T- The type of the item to be wrapped in theVal.- Parameters:
type- The type of the item to be wrapped in theVal. It must not benull.- Returns:
- An immutable and empty
Valinstance containing anullitem.
-
valOf
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
valOfin interfaceSproutsFactory- 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.
-
valOf
Description copied from interface:SproutsFactoryCreates 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. -
valOfNullable
Description copied from interface:SproutsFactory- Specified by:
valOfNullablein interfaceSproutsFactory- 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.
-
viewOf
Description copied from interface:SproutsFactory -
viewOf
public <T extends @Nullable Object,U extends @Nullable Object> Viewable<@NonNull T> viewOf(Val<T> first, Val<U> second, BiFunction<T, U, @NonNull T> combiner) Description copied from interface:SproutsFactoryCreates 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.- Specified by:
viewOfin interfaceSproutsFactory- 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.
-
viewOfNullable
public <T extends @Nullable Object,U extends @Nullable Object> Viewable<@Nullable T> viewOfNullable(Val<T> first, Val<U> second, BiFunction<T, U, @Nullable T> combiner) Description copied from interface:SproutsFactoryCreates 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.- Specified by:
viewOfNullablein interfaceSproutsFactory- 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.
-
viewOf
public <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) Description copied from interface:SproutsFactoryCreates 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.- Specified by:
viewOfin interfaceSproutsFactory- 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.
-
viewOfNullable
public <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) Description copied from interface:SproutsFactoryCreates 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.- Specified by:
viewOfNullablein interfaceSproutsFactory- 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.
-
viewOf
Description copied from interface:SproutsFactory -
viewOf
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
viewOfin interfaceSproutsFactory- 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.
-
viewOf
public <T,U> Viewables<U> viewOf(U nullObject, U errorObject, Vals<T> source, Function<T, @Nullable U> mapper) Description copied from interface:SproutsFactoryCreates 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.- Specified by:
viewOfin interfaceSproutsFactory- 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.
-
viewOf
public <T,U> Viewable<U> viewOf(U nullObject, U errorObject, Val<T> source, Function<T, @Nullable U> mapper) Description copied from interface:SproutsFactoryCreates 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.- Specified by:
viewOfin interfaceSproutsFactory- 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.
-
viewOfNullable
public <T,U> Viewable<@Nullable U> viewOfNullable(Class<U> type, Val<T> source, Function<T, @Nullable U> mapper) Description copied from interface:SproutsFactoryCreates 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.- Specified by:
viewOfNullablein interfaceSproutsFactory- 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.
-
lensOf
Description copied from interface:SproutsFactoryA 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.- Specified by:
lensOfin interfaceSproutsFactory- 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
Description copied from interface:SproutsFactoryA 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 theSproutsFactory.lensOfNullable(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.- Specified by:
lensOfin interfaceSproutsFactory- 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
Description copied from interface:SproutsFactoryA 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 theSproutsFactory.lensOf(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.- Specified by:
lensOfNullablein interfaceSproutsFactory- 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
Description copied from interface:SproutsFactoryCreates 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, useSproutsFactory.varOf(Class, Object)instead of this method.- Specified by:
varOfNullablein interfaceSproutsFactory- 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.
-
varOfNull
Description copied from interface:SproutsFactoryCreates an emptyVarinstance (storing anullitem) of the given type. If you want to create a property which can never holdnullvalues, useSproutsFactory.varOf(Class, Object)instead of this method.- Specified by:
varOfNullin interfaceSproutsFactory- 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.
-
varOf
Description copied from interface:SproutsFactoryCreates aVarproperty instance from a given non-nullable item, where theMaybe.type()is inferred from the type of the item.- Specified by:
varOfin interfaceSproutsFactory- 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.
-
varOf
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
varOfin interfaceSproutsFactory- 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.
-
valsOf
Description copied from interface:SproutsFactoryA factory method which creates an emptyValsinstance dedicated to hold properties storing non-nullable items of the specified type.- Specified by:
valsOfin interfaceSproutsFactory- 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.
-
valsOf
Description copied from interface:SproutsFactoryThis 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.- Specified by:
valsOfin interfaceSproutsFactory- 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.
-
valsOf
Description copied from interface:SproutsFactoryA 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, useSproutsFactory.valsOfNullable(Class, Val...)instead of this method.- Specified by:
valsOfin interfaceSproutsFactory- 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.
-
valsOf
Description copied from interface:SproutsFactoryA 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, useSproutsFactory.valsOfNullable(Class, Object...)instead of this method.- Specified by:
valsOfin interfaceSproutsFactory- 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.
-
valsOf
Description copied from interface:SproutsFactoryA 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, useSproutsFactory.valsOfNullable(Class, Object...)instead of this method.- Specified by:
valsOfin interfaceSproutsFactory- 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.
-
valsOf
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
valsOfin interfaceSproutsFactory- 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.
-
valsOf
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
valsOfin interfaceSproutsFactory- 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.
-
valsOfNullable
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
valsOfNullablein interfaceSproutsFactory- 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.
-
valsOfNullable
Description copied from interface:SproutsFactoryThis 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, useSproutsFactory.valsOf(Class)instead of this method.- Specified by:
valsOfNullablein interfaceSproutsFactory- 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.
-
valsOfNullable
Description copied from interface:SproutsFactoryCreates 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, useSproutsFactory.valsOf(Class, Object...)instead of this method.- Specified by:
valsOfNullablein interfaceSproutsFactory- 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.
-
valsOfNullable
Description copied from interface:SproutsFactoryCreates 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, useSproutsFactory.valsOf(Class, Val...)instead of this method.- Specified by:
valsOfNullablein interfaceSproutsFactory- 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.
-
valsOfNullable
Description copied from interface:SproutsFactoryThis 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.- Specified by:
valsOfNullablein interfaceSproutsFactory- 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.
-
varsOfNullable
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
varsOfNullablein interfaceSproutsFactory- 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
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
tupleOfin interfaceSproutsFactory- 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.
-
tupleOf
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
tupleOfin interfaceSproutsFactory- 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.
-
tupleOf
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
tupleOfin interfaceSproutsFactory- 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.
-
tupleOf
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
tupleOfin interfaceSproutsFactory- 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.
-
tupleOf
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
tupleOfin interfaceSproutsFactory- 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.
-
tupleOf
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
tupleOfin interfaceSproutsFactory- 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.
-
tupleOf
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
tupleOfin interfaceSproutsFactory- 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.
-
tupleOf
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
tupleOfin interfaceSproutsFactory- 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.
-
tupleOf
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
tupleOfin interfaceSproutsFactory- 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.
-
tupleOf
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
tupleOfin interfaceSproutsFactory- 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.
-
tupleOfNullable
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
tupleOfNullablein interfaceSproutsFactory- 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.
-
tupleOfNullable
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
tupleOfNullablein interfaceSproutsFactory- Type Parameters:
T- the type of the values.- Parameters:
type- the type of the items in the tuple.values- The items to be stored by the newTupleinstance. The values may be null.- Returns:
- a new
Tupleinstance.
-
tupleOfNullable
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
tupleOfNullablein interfaceSproutsFactory- 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
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
associationOfin interfaceSproutsFactory- 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
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
associationOfLinkedin interfaceSproutsFactory- 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
public <K,V> Association<K,V> associationOfSorted(Class<K> keyType, Class<V> valueType, Comparator<K> comparator) Description copied from interface:SproutsFactoryCreates 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.- Specified by:
associationOfSortedin interfaceSproutsFactory- 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
public <K extends Comparable<K>,V> Association<K,V> associationOfSorted(Class<K> keyType, Class<V> valueType) Description copied from interface:SproutsFactoryCreates 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.- Specified by:
associationOfSortedin interfaceSproutsFactory- 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
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
valueSetOfin interfaceSproutsFactory- 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
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
valueSetOfLinkedin interfaceSproutsFactory- 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
Description copied from interface:SproutsFactoryCreates 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) );- Specified by:
valueSetOfSortedin interfaceSproutsFactory- 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
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
valueSetOfSortedin interfaceSproutsFactory- 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.
-
varsOf
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
varsOfin interfaceSproutsFactory- 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.
-
varsOf
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
varsOfin interfaceSproutsFactory- 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.
-
varsOf
Description copied from interface:SproutsFactoryCreates a list of non-nullable properties from one or more non-nullable properties.- Specified by:
varsOfin interfaceSproutsFactory- 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.
-
varsOf
Description copied from interface:SproutsFactoryCreates a list of non-nullable properties from one or more non-null values.- Specified by:
varsOfin interfaceSproutsFactory- 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.
-
varsOf
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
varsOfin interfaceSproutsFactory- 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.
-
varsOf
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
varsOfin interfaceSproutsFactory- Type Parameters:
T- the type of the properties.- Parameters:
type- the type of the properties.vars- the iterable of values.- Returns:
- a new
Varsinstance.
-
varsOfNullable
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
varsOfNullablein interfaceSproutsFactory- 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.
-
varsOfNullable
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
varsOfNullablein interfaceSproutsFactory- 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.
-
varsOfNullable
Description copied from interface:SproutsFactoryCreates 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.- Specified by:
varsOfNullablein interfaceSproutsFactory- 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
Description copied from interface:SproutsFactoryCreates a list of nullable properties from the supplied properties.- Specified by:
varsOfNullablein interfaceSproutsFactory- 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.
-
defaultId
Description copied from interface:SproutsFactoryThe 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.- Specified by:
defaultIdin interfaceSproutsFactory- 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
Description copied from interface:SproutsFactoryThe regexPatternused to validate property ids. All ids must match this pattern.- Specified by:
idPatternin interfaceSproutsFactory- 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
Description copied from interface:SproutsFactoryThe default channel used for change events. This channel is used to give events a chanel when no channel is explicitly specified.- Specified by:
defaultChannelin interfaceSproutsFactory- 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
Description copied from interface:SproutsFactoryThe default channel used forObservableevents, registered through theObservable.subscribe(Observer)method.- Specified by:
defaultObservableChannelin interfaceSproutsFactory- 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
public org.slf4j.Marker loggingMarker()Description copied from interface:SproutsFactoryMany 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.- Specified by:
loggingMarkerin interfaceSproutsFactory- Returns:
- A constant which serves as a sort of logging channel used on all logging sites of the sprouts library.
-
setLoggingMarker
public void setLoggingMarker(org.slf4j.Marker marker) You may want to set this to filter logging done by Sprouts, which is typically a type of log that is contains exceptions caused by bugs and failed sanity checks. So you may want to filter that using this marker...- Parameters:
marker- The Slf4jMarkerconstant which should be used for all logging that occurs in Sprouts.
-