Class AccountBuilder


  • public class AccountBuilder
    extends java.lang.Object
    A builder class for Account. Since Account is immutable, modifying an Account needs to build a new Account object with updated fields through this builder. An Account can be built in two ways: 1) from an existing Account object; and 2) by supplying required fields of an Account. This class is not thread safe.
    • Constructor Detail

      • AccountBuilder

        public AccountBuilder​(Account origin)
        Constructor. This will build a new Account from an existing Account object. The builder will include all the information including the Containers of the existing Account.
        Parameters:
        origin - The Account to build from.
      • AccountBuilder

        public AccountBuilder​(short id,
                              java.lang.String name,
                              Account.AccountStatus status)
        Constructor. The builder will not include any Container information.
        Parameters:
        id - The id of the Account to build. Can be null, but should be set before calling build().
        name - The name of the Account. Can be null, but should be set before calling build().
        status - The status of the Account. Can be null, but should be set before calling build().
    • Method Detail

      • id

        public AccountBuilder id​(short id)
        Sets the id of the Account to build.
        Parameters:
        id - The id to set.
        Returns:
        This builder.
      • name

        public AccountBuilder name​(java.lang.String name)
        Sets the name of the Account to build.
        Parameters:
        name - The name to set.
        Returns:
        This builder.
      • snapshotVersion

        public AccountBuilder snapshotVersion​(int snapshotVersion)
        Sets the snapshot version of the Account to build.
        Parameters:
        snapshotVersion - The version to set.
        Returns:
        This builder.
      • lastModifiedTime

        public AccountBuilder lastModifiedTime​(long lastModifiedTime)
        Sets the created/modified time of the Account to build.
        Parameters:
        lastModifiedTime - time in milliseconds.
        Returns:
        This builder.
      • containers

        public AccountBuilder containers​(java.util.Collection<Container> containers)
        Clear the set of containers for the Account to build and add the provided ones.
        Parameters:
        containers - A collection of Containers to use. Can be null to just remove all containers.
        Returns:
        This builder.
      • build

        public Account build()
        Builds an Account object. id, name, status, lastModifiedTime and containers (if any) must be set before building.
        Returns:
        An Account object.
        Throws:
        java.lang.IllegalStateException - If any required fields is not set or there is inconsistency in containers.