+ protected void checkSealed() {
+ Preconditions.checkState(!sealed, "Builder isalready sealed - further modifications are not allowed");
+ }
+
+ @SuppressWarnings("unchecked")
+ private T self() {
+ return (T) this;
+ }
+
+ public T id(final ShardIdentifier newId) {
+ checkSealed();
+ this.id = newId;
+ return self();
+ }
+
+ public T peerAddresses(final Map<String, String> newPeerAddresses) {
+ checkSealed();
+ this.peerAddresses = newPeerAddresses;
+ return self();
+ }
+
+ public T datastoreContext(final DatastoreContext newDatastoreContext) {
+ checkSealed();
+ this.datastoreContext = newDatastoreContext;
+ return self();
+ }
+
+ public T schemaContext(final SchemaContext newSchemaContext) {
+ checkSealed();
+ this.schemaContext = newSchemaContext;
+ return self();
+ }
+
+ public T restoreFromSnapshot(final DatastoreSnapshot.ShardSnapshot newRestoreFromSnapshot) {
+ checkSealed();
+ this.restoreFromSnapshot = newRestoreFromSnapshot;
+ return self();
+ }
+
+ public T dataTree(final TipProducingDataTree newDataTree) {
+ checkSealed();
+ this.dataTree = newDataTree;
+ return self();
+ }
+
+ public ShardIdentifier getId() {
+ return id;
+ }
+
+ public Map<String, String> getPeerAddresses() {
+ return peerAddresses;
+ }
+
+ public DatastoreContext getDatastoreContext() {
+ return datastoreContext;
+ }
+
+ public SchemaContext getSchemaContext() {
+ return schemaContext;
+ }
+
+ public DatastoreSnapshot.ShardSnapshot getRestoreFromSnapshot() {
+ return restoreFromSnapshot;
+ }
+
+ public TipProducingDataTree getDataTree() {
+ return dataTree;
+ }
+
+ public TreeType getTreeType() {
+ switch (datastoreContext.getLogicalStoreType()) {
+ case CONFIGURATION:
+ return TreeType.CONFIGURATION;
+ case OPERATIONAL:
+ return TreeType.OPERATIONAL;
+ default:
+ throw new IllegalStateException("Unhandled logical store type "
+ + datastoreContext.getLogicalStoreType());
+ }
+ }
+
+ protected void verify() {
+ Preconditions.checkNotNull(id, "id should not be null");
+ Preconditions.checkNotNull(peerAddresses, "peerAddresses should not be null");
+ Preconditions.checkNotNull(datastoreContext, "dataStoreContext should not be null");
+ Preconditions.checkNotNull(schemaContext, "schemaContext should not be null");
+ }
+
+ public Props props() {
+ sealed = true;
+ verify();
+ return Props.create(shardClass, this);