Shireesh Anjal has uploaded a new change for review.

Change subject: engine: Moved generic methods from GlusterCoreUtil
......................................................................

engine: Moved generic methods from GlusterCoreUtil

Generic methods like objectsEqual, listsEquel have been moved to
appropriate new/existing utility classes like ListUtils and ObjectUtils.

Change-Id: I723c44dd08d29454de4bb77c43eadf6de3e57bad
Signed-off-by: Shireesh Anjal <san...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/AddBricksToGlusterVolumeCommand.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterBrickEntity.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterServerInfo.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterVolumeEntity.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ListUtils.java
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ObjectUtils.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/gluster/GlusterCoreUtil.java
M 
backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ListUtilsTest.java
A 
backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ObjectUtilsTest.java
M 
frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
10 files changed, 90 insertions(+), 63 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/34/8434/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/AddBricksToGlusterVolumeCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/AddBricksToGlusterVolumeCommand.java
index 9fb1b6f..cb1665d 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/AddBricksToGlusterVolumeCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/AddBricksToGlusterVolumeCommand.java
@@ -10,7 +10,7 @@
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus;
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity;
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeType;
-import org.ovirt.engine.core.common.utils.gluster.GlusterCoreUtil;
+import org.ovirt.engine.core.common.utils.ObjectUtils;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
 import 
org.ovirt.engine.core.common.vdscommands.gluster.GlusterVolumeBricksActionVDSParameters;
@@ -195,9 +195,9 @@
 
     public boolean brickExists(GlusterBrickEntity newBrick) {
         for (GlusterBrickEntity brick : 
getGlusterBrickDao().getGlusterVolumeBricksByServerId(newBrick.getServerId())) {
-            if (GlusterCoreUtil.objectsEqual(newBrick.getVolumeId(), 
brick.getVolumeId())
-                    && GlusterCoreUtil.objectsEqual(newBrick.getServerId(), 
brick.getServerId())
-                    && 
GlusterCoreUtil.objectsEqual(newBrick.getBrickDirectory(), 
brick.getBrickDirectory())) {
+            if (ObjectUtils.objectsEqual(newBrick.getVolumeId(), 
brick.getVolumeId())
+                    && ObjectUtils.objectsEqual(newBrick.getServerId(), 
brick.getServerId())
+                    && ObjectUtils.objectsEqual(newBrick.getBrickDirectory(), 
brick.getBrickDirectory())) {
                 return true;
             }
         }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterBrickEntity.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterBrickEntity.java
index f018e67..0071ee5 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterBrickEntity.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterBrickEntity.java
@@ -5,7 +5,7 @@
 import org.ovirt.engine.core.common.businessentities.BusinessEntity;
 import org.ovirt.engine.core.common.businessentities.IVdcQueryable;
 import org.ovirt.engine.core.common.businessentities.VdsStatic;
-import org.ovirt.engine.core.common.utils.gluster.GlusterCoreUtil;
+import org.ovirt.engine.core.common.utils.ObjectUtils;
 import org.ovirt.engine.core.common.validation.group.CreateEntity;
 import org.ovirt.engine.core.common.validation.group.gluster.AddBrick;
 import org.ovirt.engine.core.common.validation.group.gluster.RemoveBrick;
@@ -126,9 +126,9 @@
 
         GlusterBrickEntity brick = (GlusterBrickEntity) obj;
         return (getId().equals(brick.getId())
-                && (GlusterCoreUtil.objectsEqual(volumeId, 
brick.getVolumeId()))
-                && (GlusterCoreUtil.objectsEqual(serverId, 
brick.getServerId()))
-                && (GlusterCoreUtil.objectsEqual(brickDirectory, 
brick.getBrickDirectory()))
+                && (ObjectUtils.objectsEqual(volumeId, brick.getVolumeId()))
+                && (ObjectUtils.objectsEqual(serverId, brick.getServerId()))
+                && (ObjectUtils.objectsEqual(brickDirectory, 
brick.getBrickDirectory()))
                 && status == brick.getStatus());
     }
 
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterServerInfo.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterServerInfo.java
index 0fdbcd1..872c869 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterServerInfo.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterServerInfo.java
@@ -1,6 +1,6 @@
 package org.ovirt.engine.core.common.businessentities.gluster;
 
-import org.ovirt.engine.core.common.utils.gluster.GlusterCoreUtil;
+import org.ovirt.engine.core.common.utils.ObjectUtils;
 import org.ovirt.engine.core.compat.Guid;
 
 public class GlusterServerInfo {
@@ -61,9 +61,9 @@
         }
 
         GlusterServerInfo host = (GlusterServerInfo) obj;
-        return (GlusterCoreUtil.objectsEqual(getUuid(), host.getUuid())
-                && (GlusterCoreUtil.objectsEqual(getHostnameOrIp(), 
host.getHostnameOrIp()))
-                && (GlusterCoreUtil.objectsEqual(getStatus(), 
host.getStatus())));
+        return (ObjectUtils.objectsEqual(getUuid(), host.getUuid())
+                && (ObjectUtils.objectsEqual(getHostnameOrIp(), 
host.getHostnameOrIp()))
+                && (ObjectUtils.objectsEqual(getStatus(), host.getStatus())));
     }
 
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterVolumeEntity.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterVolumeEntity.java
index 1a1c723..b474f54 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterVolumeEntity.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterVolumeEntity.java
@@ -16,7 +16,7 @@
 import org.ovirt.engine.core.common.businessentities.BusinessEntity;
 import org.ovirt.engine.core.common.businessentities.IVdcQueryable;
 import org.ovirt.engine.core.common.constants.gluster.GlusterConstants;
-import org.ovirt.engine.core.common.utils.gluster.GlusterCoreUtil;
+import org.ovirt.engine.core.common.utils.ListUtils;
 import org.ovirt.engine.core.common.validation.group.CreateEntity;
 import org.ovirt.engine.core.common.validation.group.RemoveEntity;
 import 
org.ovirt.engine.core.common.validation.group.gluster.CreateReplicatedVolume;
@@ -381,19 +381,19 @@
             return false;
         }
 
-        if (!GlusterCoreUtil.listsEqual(getOptions(), volume.getOptions())) {
+        if (!ListUtils.listsEqual(getOptions(), volume.getOptions())) {
             return false;
         }
 
-        if (!GlusterCoreUtil.listsEqual(accessProtocols, 
volume.getAccessProtocols())) {
+        if (!ListUtils.listsEqual(accessProtocols, 
volume.getAccessProtocols())) {
             return false;
         }
 
-        if (!GlusterCoreUtil.listsEqual(transportTypes, 
volume.getTransportTypes())) {
+        if (!ListUtils.listsEqual(transportTypes, volume.getTransportTypes())) 
{
             return false;
         }
 
-        if (!GlusterCoreUtil.listsEqual(bricks, volume.getBricks())) {
+        if (!ListUtils.listsEqual(bricks, volume.getBricks())) {
             return false;
         }
 
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ListUtils.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ListUtils.java
index 12abdcc..8f7f019 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ListUtils.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ListUtils.java
@@ -1,6 +1,7 @@
 package org.ovirt.engine.core.common.utils;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 /**
@@ -80,4 +81,26 @@
         }
     }
 
+    /**
+     * Compares two lists for equality of all their elements. Returns true if 
both lists are of same size and every
+     * element in first list has an equal in the second.
+     *
+     * @param firstList
+     * @param secondList
+     * @return
+     */
+    public static <T> boolean listsEqual(Collection<T> firstList, 
Collection<T> secondList) {
+        if(firstList.size() != secondList.size()) {
+            return false;
+        }
+
+        for(T entity : firstList) {
+            if(!secondList.contains(entity)) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ObjectUtils.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ObjectUtils.java
new file mode 100644
index 0000000..db4fa59
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ObjectUtils.java
@@ -0,0 +1,19 @@
+package org.ovirt.engine.core.common.utils;
+
+public class ObjectUtils {
+
+    /**
+     * Compares if two objects are equal, handling the cases where one of both 
of them may be null
+     * @param obj1
+     * @param obj2
+     * @return
+     */
+    public static <T> boolean objectsEqual(T obj1, T obj2) {
+        if(obj1 == null) {
+            return obj2 == null;
+        } else {
+            return obj1.equals(obj2);
+        }
+    }
+
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/gluster/GlusterCoreUtil.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/gluster/GlusterCoreUtil.java
index 990e3ac..1c070c8 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/gluster/GlusterCoreUtil.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/gluster/GlusterCoreUtil.java
@@ -7,51 +7,6 @@
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity;
 
 public class GlusterCoreUtil {
-    /**
-     * Compares two lists for equality of all their elements. Returns true if 
both lists are of same size and every
-     * element in first list has an equal in the second.
-     *
-     * @param firstList
-     * @param secondList
-     * @return
-     */
-    public static <T> boolean listsEqual(Collection<T> firstList, 
Collection<T> secondList) {
-        if(firstList.size() != secondList.size()) {
-            return false;
-        }
-
-        for(T entity : firstList) {
-            if(!secondList.contains(entity)) {
-                return false;
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * Compares if two objects are equal, handling the cases where one of both 
of them may be null
-     * @param obj1
-     * @param obj2
-     * @return
-     */
-    public static <T> boolean objectsEqual(T obj1, T obj2) {
-        if(obj1 == null) {
-            return obj2 == null;
-        } else {
-            return obj1.equals(obj2);
-        }
-    }
-
-    /**
-     * Returns a random number between zero and the given {@code maxNum}
-     * @param maxNum
-     * @return
-     */
-    public static int random(int maxNum) {
-        return (int) (Math.random() * (maxNum + 1));
-    }
-
     public static final List<String> 
getQualifiedBrickList(Collection<GlusterBrickEntity> bricks) {
         List<String> qualifiedBricks = new ArrayList<String>();
         for (GlusterBrickEntity GlusterBrick : bricks) {
diff --git 
a/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ListUtilsTest.java
 
b/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ListUtilsTest.java
index cdd3195..0a5d5eb 100644
--- 
a/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ListUtilsTest.java
+++ 
b/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ListUtilsTest.java
@@ -1,6 +1,7 @@
 package org.ovirt.engine.core.common.utils;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import org.junit.Assert;
@@ -52,4 +53,14 @@
         Assert.assertTrue(list.contains("foo"));
     }
 
+    @Test
+    public void testListsEqual() {
+        List<String> lst1 = Arrays.asList("a", "b", "c");
+
+        Assert.assertFalse(ListUtils.listsEqual(lst1, Arrays.asList("a")));
+        Assert.assertFalse(ListUtils.listsEqual(lst1, Arrays.asList("d", "e", 
"f")));
+        Assert.assertFalse(ListUtils.listsEqual(lst1, Arrays.asList("b", "c", 
"d")));
+        Assert.assertTrue(ListUtils.listsEqual(lst1, Arrays.asList("c", "b", 
"a")));
+    }
+
 }
diff --git 
a/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ObjectUtilsTest.java
 
b/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ObjectUtilsTest.java
new file mode 100644
index 0000000..809e41b
--- /dev/null
+++ 
b/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ObjectUtilsTest.java
@@ -0,0 +1,18 @@
+package org.ovirt.engine.core.common.utils;
+
+import org.junit.Test;
+import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.assertFalse;
+
+public class ObjectUtilsTest {
+
+    @Test
+    public void testObjectsEqual() {
+        Integer ten = new Integer(10);
+        assertFalse(ObjectUtils.objectsEqual(ten, new Integer(20)));
+        assertTrue(ObjectUtils.objectsEqual(ten, new Integer(10)));
+        assertTrue(ObjectUtils.objectsEqual(null, null));
+        assertFalse(ObjectUtils.objectsEqual(ten, null));
+        assertFalse(ObjectUtils.objectsEqual(null, ten));
+    }
+}
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
 
b/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
index 6e88b11..c7f16d3 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
@@ -181,6 +181,8 @@
                <include name="common/utils/ObjectDescriptor.java" />
                <include name="common/utils/EnumUtils.java" />
                <include name="common/utils/ListUtils.java" />
+               <include name="common/utils/StringUtil.java"/>
+               <include name="common/utils/ObjectUtils.java" />
                <include name="common/utils/VmDeviceCommonUtils.java" />
                <include name="common/utils/VmDeviceType.java" />
                <include name="common/interfaces/IVdcUser.java" />
@@ -292,7 +294,6 @@
                <include name="common/action/gluster/*.java"/>
                <include name="common/queries/gluster/*.java"/>
                <include name="common/constants/gluster/GlusterConstants.java"/>
-               <include name="common/utils/StringUtil.java"/>
                <include name="common/utils/gluster/GlusterCoreUtil.java"/>
        </source>
 


--
To view, visit http://gerrit.ovirt.org/8434
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I723c44dd08d29454de4bb77c43eadf6de3e57bad
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Shireesh Anjal <san...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to