From 391cdbb43529ec1ec6971be70a3fdd7bc2b8789d Mon Sep 17 00:00:00 2001 From: ayyoob Date: Tue, 25 Oct 2016 14:01:51 +0530 Subject: [PATCH] avoided lazy initialization --- .../mgt/iot/output/adapter/ui/UIEventAdapter.java | 2 +- .../adapter/ui/util/WebSocketSessionRequest.java | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/UIEventAdapter.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/UIEventAdapter.java index 807396aac..35e24a55b 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/UIEventAdapter.java +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/UIEventAdapter.java @@ -360,7 +360,7 @@ public class UIEventAdapter implements OutputEventAdapter { // fetch the queryString Key:Value pair map of the given session. Map queryParamValuePairs = webSocketSessionUtil.getQueryParamValuePairs(); - if (queryParamValuePairs != null) { + if (queryParamValuePairs != null && !queryParamValuePairs.isEmpty()) { // fetch the different attribute values received as part of the current event. Object[] eventMetaData = event.getMetaData(); Object[] eventCorrelationData = event.getCorrelationData(); diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/util/WebSocketSessionRequest.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/util/WebSocketSessionRequest.java index 822028089..8ef11036f 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/util/WebSocketSessionRequest.java +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/util/WebSocketSessionRequest.java @@ -1,17 +1,17 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. - * you may obtain a copy of the License at + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -35,7 +35,7 @@ public class WebSocketSessionRequest { private static final String QUERY_STRING_SEPERATOR = "&"; private static final String QUERY_KEY_VALUE_SEPERATOR = "="; - private Map queryParamValuePairs = null; + private Map queryParamValuePairs = new HashMap<>(); private Session session; public WebSocketSessionRequest(Session session) { @@ -65,9 +65,6 @@ public class WebSocketSessionRequest { log.warn("Invalid query string [" + queryString + "] passed in."); break; } - if (queryParamValuePairs == null) { - queryParamValuePairs = new HashMap<>(); - } queryParamValuePairs.put(thisQueryParamPair[0], thisQueryParamPair[1]); } }