Arik Hadas has uploaded a new change for review. Change subject: core: minor cleanup in ObjectIdentityChecker ......................................................................
core: minor cleanup in ObjectIdentityChecker - Change the type of ObjectIdentityChecker#mPermitted from List to Set, which is more appropriate because each value in it should appear at most once (instead of verifying when adding something, that it's not there already) - Rename ObjectIdentityChecker's members such that they'll conform the standard naming convention in java (instead of starting with 'm') Change-Id: I7845cb876f0edcfd1a9c58a06ff443175295c554 Signed-off-by: Arik Hadas <[email protected]> --- M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ObjectIdentityChecker.java 1 file changed, 23 insertions(+), 23 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/37/10737/1 diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ObjectIdentityChecker.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ObjectIdentityChecker.java index 20c02d5..02b52cf 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ObjectIdentityChecker.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ObjectIdentityChecker.java @@ -2,8 +2,10 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.ovirt.engine.core.common.queries.ValueObjectMap; import org.ovirt.engine.core.common.utils.EnumUtils; @@ -14,35 +16,35 @@ import org.ovirt.engine.core.utils.log.LogFactory; public class ObjectIdentityChecker { - private IObjectDescriptorContainer mContainer; - private static Map<String, Class<?>> mAliases = + private IObjectDescriptorContainer container; + private static Map<String, Class<?>> aliases = new HashMap<String, Class<?>>(); - private static Map<Class<?>, ObjectIdentityChecker> mIdentities = + private static Map<Class<?>, ObjectIdentityChecker> identities = new HashMap<Class<?>, ObjectIdentityChecker>(); - private static Map<Class<?>, Class<?>> mStatusTypes = + private static Map<Class<?>, Class<?>> statusTypes = new HashMap<Class<?>, Class<?>>(); - private Map<Enum<?>, List<String>> mDictionary = + private Map<Enum<?>, List<String>> dictionary = new HashMap<Enum<?>, List<String>>(); - private List<String> mPermitted = new ArrayList<String>(); + private Set<String> permitted = new HashSet<String>(); public ObjectIdentityChecker(Class<?> type) { - mIdentities.put(type, this); + identities.put(type, this); } public ObjectIdentityChecker(Class<?> type, Iterable<String> aliases) { this(type); for (String alias : aliases) { - mAliases.put(alias, type); + ObjectIdentityChecker.aliases.put(alias, type); } } public ObjectIdentityChecker(Class<?> type, Iterable<String> aliases, Class<?> enumType) { this(type, aliases); - mStatusTypes.put(type, enumType); + statusTypes.put(type, enumType); } public final void setContainer(IObjectDescriptorContainer value) { - mContainer = value; + container = value; } public static boolean CanUpdateField(Object fieldContainer, String fieldName, Enum<?> status) { @@ -51,7 +53,7 @@ public static boolean CanUpdateField(String objectType, String fieldName, Enum<?> status, Object fieldContainer) { Class<?> type = null; - if ((type = mAliases.get(objectType)) != null) { + if ((type = aliases.get(objectType)) != null) { return CanUpdateField(type, fieldName, status, fieldContainer); } else { throw new RuntimeException(String.format("status type %1$s not exist", type)); @@ -61,7 +63,7 @@ public static boolean CanUpdateField(Class<?> objectType, String fieldName, Enum<?> status, Object fieldContainer) { ObjectIdentityChecker checker = null; - if ((checker = mIdentities.get(objectType)) != null) { + if ((checker = identities.get(objectType)) != null) { return checker.IsFieldUpdatable(status, fieldName, fieldContainer); } return true; @@ -70,9 +72,9 @@ @SuppressWarnings("unchecked") public static boolean CanUpdateField(String objectType, String fieldName, String status) { Class<?> type = null; - if ((type = mAliases.get(objectType)) != null) { + if ((type = aliases.get(objectType)) != null) { @SuppressWarnings("rawtypes") - final Class statusType = mStatusTypes.get(type); + final Class statusType = statusTypes.get(type); if (statusType != null) { Enum<?> currentStatus; try { @@ -92,9 +94,9 @@ public final void AddField(Enum<?> status, String fieldName) { List<String> values = null; - if (!((values = mDictionary.get(status)) != null)) { + if (!((values = dictionary.get(status)) != null)) { values = new ArrayList<String>(); - mDictionary.put(status, values); + dictionary.put(status, values); } if (!values.contains(fieldName)) { values.add(fieldName); @@ -114,9 +116,7 @@ } public final void AddPermittedField(String fieldName) { - if (!mPermitted.contains(fieldName)) { - mPermitted.add(fieldName); - } + permitted.add(fieldName); } public final void AddPermittedFields(String[] fieldNames) { @@ -126,18 +126,18 @@ } public final boolean IsFieldUpdatable(String name) { - return mPermitted.contains(name); + return permitted.contains(name); } private boolean IsFieldUpdatable(Enum<?> status, String name, Object fieldContainer) { boolean returnValue = true; if (!IsFieldUpdatable(name)) { - if (fieldContainer != null && mContainer != null - && !mContainer.CanUpdateField(fieldContainer, name, status)) { + if (fieldContainer != null && container != null + && !container.CanUpdateField(fieldContainer, name, status)) { returnValue = false; } else { List<String> values = null; - if ((values = mDictionary.get(status)) != null && values != null) { + if ((values = dictionary.get(status)) != null && values != null) { returnValue = values.contains(name); } else { returnValue = false; -- To view, visit http://gerrit.ovirt.org/10737 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7845cb876f0edcfd1a9c58a06ff443175295c554 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Arik Hadas <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
