@Immutable GroupEntity 55/58055/1
authorMichael Vorburger <vorburger@redhat.com>
Tue, 30 May 2017 17:38:30 +0000 (19:38 +0200)
committerMichael Vorburger <vorburger@redhat.com>
Tue, 30 May 2017 17:38:30 +0000 (19:38 +0200)
Contrary to the earlier 3a5d1e58dadf17654064234bdeb08597b7a48fe5 which
made FlowEntity @Immutable about 3 months ago, this change has no
impacts in downstream project netvirt (because all of its GroupEntity
instantiations go through MDSALUtil, which is adjusted here as well).

Change-Id: Id862698ebd5d00c30fdb52f5230ac35046062d44
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/GroupEntity.java
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/MDSALUtil.java

index b46affd49ebd67764ea06183a23307f9ef5f8116..982978f06015914826f2160c2515fe11de7fda38 100644 (file)
@@ -7,47 +7,25 @@
  */
 package org.opendaylight.genius.mdsalutil;
 
-import java.math.BigInteger;
 import java.util.List;
-import java.util.Objects;
+import org.immutables.value.Value.Immutable;
+import org.opendaylight.genius.infra.OpenDaylightImmutableStyle;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
-import org.opendaylight.yangtools.util.EvenMoreObjects;
 
-public class GroupEntity extends AbstractSwitchEntity {
+@Immutable
+@OpenDaylightImmutableStyle
+public abstract class GroupEntity extends AbstractSwitchEntity {
 
-    private final BigInteger dpnId;
-    private long groupId;
-    private String groupName;
-    private GroupTypes groupType;
-    private List<BucketInfo> bucketInfos;
+    // This is required as it will cause the code generation by @Immutable.org to implement Builder,
+    // which is required Xtend sources can use the XtendBuilderExtensions.operator_doubleGreaterThan
+    public abstract static class Builder implements org.opendaylight.yangtools.concepts.Builder<GroupEntity> {}
 
     private transient GroupBuilder groupBuilder;
 
-    public GroupEntity(BigInteger dpnId) {
-        this.dpnId = dpnId;
-    }
-
-    public GroupEntity(long dpnId) {
-        this(BigInteger.valueOf(dpnId));
-    }
-
-    @Override
-    public BigInteger getDpnId() {
-        return dpnId;
-    }
-
-    @Override
-    public String toString() {
-        return "GroupEntity [dpnId=" + getDpnId() + ", groupId=" + groupId + ", groupName=" + groupName
-                + ", groupType=" + groupType + ", bucketInfo=" + bucketInfos + "]";
-    }
-
-    public List<BucketInfo> getBucketInfoList() {
-        return bucketInfos;
-    }
+    public abstract List<BucketInfo> getBucketInfoList();
 
     public GroupBuilder getGroupBuilder() {
         if (groupBuilder == null) {
@@ -65,53 +43,10 @@ public class GroupEntity extends AbstractSwitchEntity {
         return groupBuilder;
     }
 
-    public long getGroupId() {
-        return groupId;
-    }
+    public abstract long getGroupId();
 
-    public String getGroupName() {
-        return groupName;
-    }
+    public abstract String getGroupName();
 
-    public GroupTypes getGroupType() {
-        return groupType;
-    }
+    public abstract GroupTypes getGroupType();
 
-    public void setBucketInfoList(List<BucketInfo> listBucketInfo) {
-        this.bucketInfos = listBucketInfo;
-    }
-
-    public void setGroupId(long groupIdAsLong) {
-        this.groupId = groupIdAsLong;
-        if (this.groupBuilder != null) {
-            GroupId groupId = new GroupId(getGroupId());
-            this.groupBuilder.setKey(new GroupKey(groupId));
-            this.groupBuilder.setGroupId(groupId);
-        }
-    }
-
-    public void setGroupName(String groupName) {
-        this.groupName = groupName;
-        this.groupBuilder = null;
-    }
-
-    public void setGroupType(GroupTypes groupType) {
-        this.groupType = groupType;
-        this.groupBuilder = null;
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hash(getDpnId(), groupId, groupName, groupType, bucketInfos);
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        return EvenMoreObjects.equalsHelper(this, obj,
-            (self, other) -> Objects.equals(self.getDpnId(), other.getDpnId())
-                          && Objects.equals(this.groupId, other.groupId)
-                          && Objects.equals(this.groupName, other.groupName)
-                          && Objects.equals(this.groupType, other.groupType)
-                          && Objects.equals(this.bucketInfos, other.bucketInfos));
-    }
 }
index ebbf828a0d86bb9319279fa5e8523677196b6e04..621dea309bc9d8684c990b1c1e995b979dc14b3e 100644 (file)
@@ -177,14 +177,13 @@ public class MDSALUtil {
     public static GroupEntity buildGroupEntity(BigInteger dpnId, long groupId, String groupName, GroupTypes groupType,
             List<BucketInfo> listBucketInfo) {
 
-        GroupEntity groupEntity = new GroupEntity(dpnId);
-
+        GroupEntityBuilder groupEntity = new GroupEntityBuilder();
+        groupEntity.setDpnId(dpnId);
         groupEntity.setGroupId(groupId);
         groupEntity.setGroupName(groupName);
         groupEntity.setGroupType(groupType);
         groupEntity.setBucketInfoList(listBucketInfo);
-
-        return groupEntity;
+        return groupEntity.build();
     }
 
     public static Group buildGroup(long groupId, String groupName, GroupTypes groupType, Buckets buckets) {