X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fidentifiers%2FShardIdentifier.java;h=e8824fbe11b1378774b644310d3878414b17d5a5;hb=81674d6fd50b419b868d0851062e23f34b34557d;hp=037bafda67b125909cfdcf3a80378ab65b9a72a0;hpb=4e3f49788c05730b29468deebc2aaa4ed0d94eef;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/identifiers/ShardIdentifier.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/identifiers/ShardIdentifier.java index 037bafda67..e8824fbe11 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/identifiers/ShardIdentifier.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/identifiers/ShardIdentifier.java @@ -23,30 +23,35 @@ public class ShardIdentifier { private final String type; private final String fullName; - public ShardIdentifier(String shardName, MemberName memberName, String type) { + private ShardIdentifier(String shardName, MemberName memberName, String type) { + this.shardName = Preconditions.checkNotNull(shardName, "shardName should not be null"); + this.memberName = Preconditions.checkNotNull(memberName, "memberName should not be null"); + this.type = Preconditions.checkNotNull(type, "type should not be null"); - Preconditions.checkNotNull(shardName, "shardName should not be null"); - Preconditions.checkNotNull(memberName, "memberName should not be null"); - Preconditions.checkNotNull(type, "type should not be null"); + fullName = memberName.getName() + "-shard-" + shardName + "-" + type; + } + + public static ShardIdentifier create(final String shardName, final MemberName memberName, final String type) { + return new ShardIdentifier(shardName, memberName, type); + } - this.shardName = shardName; - this.memberName = memberName; - this.type = type; + public static ShardIdentifier fromShardIdString(final String shardIdString) { + final Matcher matcher = PATTERN.matcher(shardIdString); + Preconditions.checkArgument(matcher.matches(), "Invalid shard id \"%s\"", shardIdString); - fullName = new StringBuilder(memberName.getName()).append("-shard-").append(shardName).append("-") - .append(type).toString(); + return new ShardIdentifier(matcher.group(2), MemberName.forName(matcher.group(1)), matcher.group(3)); } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object obj) { + if (this == obj) { return true; } - if (o == null || getClass() != o.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } - ShardIdentifier that = (ShardIdentifier) o; + ShardIdentifier that = (ShardIdentifier) obj; if (!memberName.equals(that.memberName)) { return false; @@ -71,14 +76,10 @@ public class ShardIdentifier { @Override public String toString() { - //ensure the output of toString matches the pattern above + // ensure the output of toString matches the pattern above return fullName; } - public static Builder builder(){ - return new Builder(); - } - public String getShardName() { return shardName; } @@ -96,26 +97,26 @@ public class ShardIdentifier { private MemberName memberName; private String type; - public ShardIdentifier build(){ + public ShardIdentifier build() { return new ShardIdentifier(shardName, memberName, type); } - public Builder shardName(String shardName){ - this.shardName = shardName; + public Builder shardName(String newShardName) { + this.shardName = newShardName; return this; } - public Builder memberName(MemberName memberName){ - this.memberName = memberName; + public Builder memberName(MemberName newMemberName) { + this.memberName = newMemberName; return this; } - public Builder type(String type){ - this.type = type; + public Builder type(String newType) { + this.type = newType; return this; } - public Builder fromShardIdString(String shardId){ + public Builder fromShardIdString(String shardId) { Matcher matcher = PATTERN.matcher(shardId); if (matcher.matches()) {