Collections

Automation Decision Services supports different patterns of collection usage.

Managed collections

Managed collections are exposed as read-only by getter methods.

There are different methods that you can use to update the content of a managed collection: setter, adder, remover, and clearer. You need to use the @CollectionAttribute annotation with those last three methods, as shown in the following example:

public class Customer {
  private List<Address> addresses;
  public List<Address> getAddresses() {
    return addresses == null ? Collections.emptyList() : Collections.unmodifiableList(addresses);
  }
  public void setAddresses(List<Address> addresses) {
    if (addresses == null)
      this.addresses = null;
    else
      this.addresses = new ArrayList<>(addresses);
  }
  @CollectionAttribute("addresses")
  public void addAddress(Address address) {
    if (addresses == null)
      addresses = new ArrayList<>();
    addresses.add(address);
  }
  @CollectionAttribute("addresses")
  public void removeAddress(Address address) {
    if (addresses != null)
    addresses.remove(address);
  }
  @CollectionAttribute("addresses")
  public void clearAddresses() {
    addresses = null;
  }
}

Fully accessible collections

Fully accessible collections are directly returned by getter methods.

Methods are not necessary to update the content of a fully accessible collection. You must use the @MutableCollection annotation to access the whole range of verbalized ways available to update the content of an accessible collection, as shown in the following example:

public class Client {
  private List<Address> addresses = new ArrayList<>();
  @MutableCollection
  public List<Adress> getAdresses() {
    return addresses;
  }
}