Package com.github.ambry.account
Class AccountBuilder
- java.lang.Object
-
- com.github.ambry.account.AccountBuilder
-
public class AccountBuilder extends java.lang.Object
A builder class forAccount
. SinceAccount
is immutable, modifying anAccount
needs to build a newAccount
object with updated fields through this builder. AnAccount
can be built in two ways: 1) from an existingAccount
object; and 2) by supplying required fields of anAccount
. This class is not thread safe.
-
-
Constructor Summary
Constructors Constructor Description AccountBuilder(short id, java.lang.String name, Account.AccountStatus status)
Constructor.AccountBuilder(Account origin)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AccountBuilder
addOrUpdateContainer(Container container)
Account
build()
Builds anAccount
object.AccountBuilder
containers(java.util.Collection<Container> containers)
Clear the set of containers for theAccount
to build and add the provided ones.AccountBuilder
id(short id)
Sets the id of theAccount
to build.AccountBuilder
lastModifiedTime(long lastModifiedTime)
Sets the created/modified time of theAccount
to build.AccountBuilder
name(java.lang.String name)
Sets the name of theAccount
to build.AccountBuilder
removeContainer(Container container)
AccountBuilder
snapshotVersion(int snapshotVersion)
Sets the snapshot version of theAccount
to build.AccountBuilder
status(Account.AccountStatus status)
Sets the status of theAccount
to build.
-
-
-
Constructor Detail
-
AccountBuilder
public AccountBuilder(Account origin)
Constructor. This will build a newAccount
from an existingAccount
object. The builder will include all the information including theContainer
s of the existingAccount
.- Parameters:
origin
- TheAccount
to build from.
-
AccountBuilder
public AccountBuilder(short id, java.lang.String name, Account.AccountStatus status)
Constructor. The builder will not include anyContainer
information.
-
-
Method Detail
-
id
public AccountBuilder id(short id)
Sets the id of theAccount
to build.- Parameters:
id
- The id to set.- Returns:
- This builder.
-
name
public AccountBuilder name(java.lang.String name)
Sets the name of theAccount
to build.- Parameters:
name
- The name to set.- Returns:
- This builder.
-
status
public AccountBuilder status(Account.AccountStatus status)
Sets the status of theAccount
to build.- Parameters:
status
- The id to set.- Returns:
- This builder.
-
snapshotVersion
public AccountBuilder snapshotVersion(int snapshotVersion)
Sets the snapshot version of theAccount
to build.- Parameters:
snapshotVersion
- The version to set.- Returns:
- This builder.
-
lastModifiedTime
public AccountBuilder lastModifiedTime(long lastModifiedTime)
Sets the created/modified time of theAccount
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 theAccount
to build and add the provided ones.- Parameters:
containers
- A collection ofContainer
s to use. Can benull
to just remove all containers.- Returns:
- This builder.
-
addOrUpdateContainer
public AccountBuilder addOrUpdateContainer(Container container)
Adds aContainer
for theAccount
to build. If the builder already has aContainer
with the same id as newContainer
to set, the newContainer
will replace the existingContainer
.- Parameters:
container
- The newContainer
to set.- Returns:
- This builder.
-
removeContainer
public AccountBuilder removeContainer(Container container)
Removes aContainer
in this builder, so that anAccount
to build will not have thisContainer
. It will be a no-op if noContainer
with the id exists in this builder.- Parameters:
container
- TheContainer
to remove.- Returns:
- This builder.
-
-