Michael Kublin has uploaded a new change for review. Change subject: core: Clean up of EnumUtils ......................................................................
core: Clean up of EnumUtils Removed unused and unneeded methods. Change-Id: I939be2b873812d00fe33b2d3a498f6f0a90e8ec1 Signed-off-by: Michael Kublin <mkub...@redhat.com> --- M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/EnumUtils.java M backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/EnumUtilsTest.java M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java 3 files changed, 2 insertions(+), 75 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/32/8432/1 diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/EnumUtils.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/EnumUtils.java index 11fd94b..ffa7686 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/EnumUtils.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/EnumUtils.java @@ -1,39 +1,18 @@ package org.ovirt.engine.core.common.utils; -import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; -import java.util.List; import java.util.Map; - -import org.ovirt.engine.core.compat.MatchCollection; -import org.ovirt.engine.core.compat.Regex; public class EnumUtils { private static Map<Class<?>, Map> cacheEnumValuesInCapitalLetters = new HashMap<Class<?>, Map>(); - - public static String ConvertToStringWithSpaces(String value) { - StringBuilder result = new StringBuilder(); - Regex r = new Regex("([A-Z]{1,}[a-z]*)|([0-9]*)"); - MatchCollection coll = r.Matches(value); - for (int i = 0; i < coll.size(); i++) { - result.append(coll.get(i).getValue()); - if (i + 1 != coll.size()) { - result.append(" "); - } - } - return result.toString().trim(); - } public static <E extends Enum<E>> E valueOf(Class<E> c, String name, boolean ignorecase) { // trim any leading or trailing spaces from the name name = name.trim(); if (!ignorecase) { - { - return Enum.<E> valueOf(c, name); - } + return Enum.<E> valueOf(c, name); } E[] universe = c.getEnumConstants(); @@ -72,27 +51,5 @@ */ public static <E extends Enum<E>> String nameOrNull(E enumInstance) { return enumInstance == null ? null : enumInstance.name(); - } - - /** - * Converts the given collection of enum values to a collection of strings, containing enum names (retrieved using - * {@link Enum#name()} method) of each element of the collection. - * - * @param collection - * The collection of Enum values to be converted to a delimiter-separated string. - * @return A String collection containing enum names of all elements of the given collection. - */ - public static <T extends Enum<?>> List<String> enumCollectionToStringList(Collection<T> collection) { - if(collection == null) { - return null; - } - - List<String> stringList = new ArrayList<String>(); - - for(T element : collection) { - stringList.add(element.name()); - } - - return stringList; } } diff --git a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/EnumUtilsTest.java b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/EnumUtilsTest.java index e9a7156..dfabee4 100644 --- a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/EnumUtilsTest.java +++ b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/EnumUtilsTest.java @@ -1,13 +1,7 @@ package org.ovirt.engine.core.utils; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.List; - import org.junit.Test; import org.ovirt.engine.core.common.utils.EnumUtils; @@ -18,11 +12,6 @@ } @Test - public void convertToStringWithSpaces() { - assertEquals("Hello There", EnumUtils.ConvertToStringWithSpaces("HelloThere")); - } - - @Test public void nameOrNullForNull() { assertNull(EnumUtils.<EnumForTesting>nameOrNull(null)); } @@ -30,23 +19,5 @@ @Test public void nameOrNullForEnum() { assertEquals(EnumForTesting.ENUM1.name(), EnumUtils.nameOrNull(EnumForTesting.ENUM1)); - } - - @Test - public void testEnumCollectionToStringListForNullInput() { - assertNull(EnumUtils.enumCollectionToStringList(null)); - } - - @Test - public void testEnumCollectionToStringList() { - List<EnumForTesting> enumCollection = new ArrayList<EnumForTesting>(); - enumCollection.add(EnumForTesting.ENUM1); - enumCollection.add(EnumForTesting.ENUM2); - - List<String> stringList = EnumUtils.enumCollectionToStringList(enumCollection); - assertNotNull(stringList); - assertEquals(2, stringList.size()); - assertTrue(stringList.contains(EnumForTesting.ENUM1.name())); - assertTrue(stringList.contains(EnumForTesting.ENUM2.name())); } } diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java index 6206b09..9324e31 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java @@ -38,7 +38,6 @@ import org.ovirt.engine.core.common.businessentities.VmStatistics; import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigValues; -import org.ovirt.engine.core.common.utils.EnumUtils; import org.ovirt.engine.core.common.utils.VmDeviceCommonUtils; import org.ovirt.engine.core.common.utils.VmDeviceType; import org.ovirt.engine.core.common.vdscommands.DestroyVmVDSCommandParameters; @@ -806,7 +805,7 @@ return; } AuditLogableBase logable = new AuditLogableBase(_vds.getId()); - logable.AddCustomValue("VdsStatus", EnumUtils.ConvertToStringWithSpaces(_vds.getstatus().toString())); + logable.AddCustomValue("VdsStatus", _vds.getstatus().toString()); auditLog(logable, AuditLogType.VDS_DETECTED); } -- To view, visit http://gerrit.ovirt.org/8432 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I939be2b873812d00fe33b2d3a498f6f0a90e8ec1 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Michael Kublin <mkub...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches