Martin Mucha has uploaded a new change for review. Change subject: core: refactor: extracted uninteressant hashmap manipulation to separate method ......................................................................
core: refactor: extracted uninteressant hashmap manipulation to separate method • obtaining list for given key and initializing it if it's null was separated into own method, since it's not interessant code worsening readability • added check for nicName nullity; it should not happen. If it happens, there's a bug in our code(about which we're immediately informed). Change-Id: I1bbeebec517e7ac3e9897003447d5a6290792201 Signed-off-by: Martin Mucha <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkAttachmentsValidator.java 1 file changed, 17 insertions(+), 6 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/46/36146/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkAttachmentsValidator.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkAttachmentsValidator.java index 2e50c20..78c6ae5 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkAttachmentsValidator.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkAttachmentsValidator.java @@ -51,17 +51,28 @@ private Map<String, List<NetworkType>> createNicNameToNetworkTypesMap() { Map<String, List<NetworkType>> nicNameToNetworkTypes = new HashMap<>(); for (NetworkAttachment attachment : attachmentsToConfigure) { - String nicName = attachment.getNicName(); - if (!nicNameToNetworkTypes.containsKey(nicName)) { - nicNameToNetworkTypes.put(nicName, new ArrayList<NetworkType>()); - } - Network networkToConfigure = networkMap.get(attachment.getNetworkId()); - nicNameToNetworkTypes.get(nicName).add(determineNetworkType(networkToConfigure)); + NetworkType networkType = determineNetworkType(networkToConfigure); + getNetworkTypesList(nicNameToNetworkTypes, attachment.getNicName()).add(networkType); } return nicNameToNetworkTypes; } + private List<NetworkType> getNetworkTypesList(Map<String, List<NetworkType>> nicNameToNetworkTypes, String nicName) { + + if (nicName == null) { + throw new IllegalArgumentException("nic name cannot be null"); + } + + List<NetworkType> result = nicNameToNetworkTypes.get(nicName); + if (result == null) { + result = new ArrayList<>(); + nicNameToNetworkTypes.put(nicName, result); + } + + return result; + } + //TODO MM: move to Network? private NetworkType determineNetworkType(Network network) { return NetworkUtils.isVlan(network) -- To view, visit http://gerrit.ovirt.org/36146 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1bbeebec517e7ac3e9897003447d5a6290792201 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Martin Mucha <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
