T
- the type of elements.HasConfigurableValue
, HasMultipleValues<T>
, Provider<java.util.List<T>>
, SupportsConvention
public interface ListProperty<T> extends Provider<java.util.List<T>>, HasMultipleValues<T>
List
of elements of type ListProperty
.
You can create a ListProperty
instance using factory method ObjectFactory.listProperty(Class)
.
Note: This interface is not intended for implementation by build script or plugin authors.
Modifier and Type | Method | Description |
---|---|---|
ListProperty<T> |
convention(java.lang.Iterable<? extends T> elements) |
Specifies the value to use as the convention for this property.
|
ListProperty<T> |
convention(Provider<? extends java.lang.Iterable<? extends T>> provider) |
Specifies the provider of the value to use as the convention for this property.
|
ListProperty<T> |
empty() |
Sets the value of this property to an empty collection, and replaces any existing value.
|
void |
replace(Transformer<? extends @Nullable Provider<? extends java.lang.Iterable<? extends T>>,? super Provider<java.util.List<T>>> transformation) |
Replaces the current value of this property with a one computed by the provided transformation.
|
ListProperty<T> |
unset() |
Unsets this object's explicit value, allowing the convention to be
selected when evaluating this object's value.
|
ListProperty<T> |
unsetConvention() |
Unsets this object's convention value.
|
ListProperty<T> |
value(java.lang.Iterable<? extends T> elements) |
Sets the value of the property to the elements of the given iterable, and replaces any existing value.
|
ListProperty<T> |
value(Provider<? extends java.lang.Iterable<? extends T>> provider) |
Sets the property to have the same value of the given provider, and replaces any existing value.
|
disallowChanges, disallowUnsafeRead, finalizeValueOnRead
ListProperty<T> empty()
empty
in interface HasMultipleValues<T>
ListProperty<T> value(@Nullable java.lang.Iterable<? extends T> elements)
This is the same as HasMultipleValues.set(Iterable)
but returns this property to allow method chaining.
value
in interface HasMultipleValues<T>
elements
- The elements, can be null.ListProperty<T> value(Provider<? extends java.lang.Iterable<? extends T>> provider)
This is the same as HasMultipleValues.set(Provider)
but returns this property to allow method chaining.
value
in interface HasMultipleValues<T>
provider
- Provider of the elements.ListProperty<T> convention(@Nullable java.lang.Iterable<? extends T> elements)
convention
in interface HasMultipleValues<T>
elements
- The elements, or null
when the convention is that the property has no value.ListProperty<T> convention(Provider<? extends java.lang.Iterable<? extends T>> provider)
convention
in interface HasMultipleValues<T>
provider
- The provider of the elementsListProperty<T> unset()
This is similar to calling value(Iterable)
with a null
argument.
unset
in interface SupportsConvention
ListProperty<T> unsetConvention()
This is similar to calling convention(Iterable)
with a null
argument.
unsetConvention
in interface SupportsConvention
@Incubating void replace(Transformer<? extends @Nullable Provider<? extends java.lang.Iterable<? extends T>>,? super Provider<java.util.List<T>>> transformation)
def property = objects.listProperty(String).value(["a", "b"]) property.replace { it.map { value -> value.reverse() } } println(property.get()) // ["b", "a"]Note that simply writing
property.set(property.map { ... }
doesn't work and will cause an exception because of a circular reference evaluation at runtime.
Further changes to the value of the property, such as calls to HasMultipleValues.set(Iterable)
, are not transformed, and override the replacement instead.
Because of this, this method inherently depends on the order of property changes, and therefore must be used sparingly.
If the value of the property is specified via a provider, then the current value provider tracks that provider. For example, changes to the upstream property are visible:
def upstream = objects.listProperty(String).value(["a", "b"]) def property = objects.listProperty(String).value(upstream) property.replace { it.map { value -> value.reverse() } } upstream.set(["c", "d"]) println(property.get()) // ["d", "c"]The provided transformation runs eagerly, so it can capture any objects without introducing memory leaks and without breaking configuration caching. However, transformations applied to the current value provider (like
Provider.map(Transformer)
) are subject to the usual constraints.
If the property has no explicit value set, then the current value comes from the convention. Changes to convention of this property do not affect the current value provider in this case, though upstream changes are still visible if the convention was set to a provider. If there is no convention too, then the current value is a provider without a value. The replacement value becomes the explicit value of the property.
transformation
- the transformation to apply to the current value. May return null, which unsets the property.