diff options
Diffstat (limited to 'sdnr/wt/devicemanager/provider/src/main')
2 files changed, 29 insertions, 22 deletions
diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/aaiconnector/impl/URLParamEncoder.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/aaiconnector/impl/URLParamEncoder.java index 2e8b44fd7..4decc24d7 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/aaiconnector/impl/URLParamEncoder.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/aaiconnector/impl/URLParamEncoder.java @@ -19,13 +19,16 @@ package org.onap.ccsdk.features.sdnr.wt.devicemanager.aaiconnector.impl; class URLParamEncoder { + private URLParamEncoder() { + } + + private static final String UNSAFE_CHARSET = " %$&+,/:;=?@<>#%"; + public static String encode(String input) { StringBuilder resultStr = new StringBuilder(); for (char ch : input.toCharArray()) { if (isUnsafe(ch)) { - resultStr.append('%'); - resultStr.append(toHex(ch / 16)); - resultStr.append(toHex(ch % 16)); + resultStr.append(escape(ch)); } else { resultStr.append(ch); } @@ -33,14 +36,18 @@ class URLParamEncoder { return resultStr.toString(); } - private static char toHex(int ch) { - return (char) (ch < 10 ? '0' + ch : 'A' + ch - 10); - } - private static boolean isUnsafe(char ch) { - if (ch > 128 || ch < 0) { + if (ch > 128) { return true; } - return " %$&+,/:;=?@<>#%".indexOf(ch) >= 0; + return UNSAFE_CHARSET.indexOf(ch) >= 0; + } + + private static String escape(char ch){ + return String.format("%c%c%c", '%', toHex(ch / 16), toHex(ch % 16)); + } + + private static char toHex(int ch) { + return (char) (ch < 10 ? '0' + ch : 'A' + ch - 10); } } diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/netconf/container/AllPm.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/netconf/container/AllPm.java index 196493cde..5c7cd03bd 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/netconf/container/AllPm.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/base/netconf/container/AllPm.java @@ -1,4 +1,4 @@ -/******************************************************************************* +/** * ============LICENSE_START======================================================================== * ONAP : ccsdk feature sdnr wt * ================================================================================================= @@ -6,28 +6,28 @@ * ================================================================================================= * Licensed 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 - * + * <p> * http://www.apache.org/licenses/LICENSE-2.0 - * + * <p> * 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 specific language governing permissions and limitations under * the License. * ============LICENSE_END========================================================================== - ******************************************************************************/ + */ /** * */ package org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container; -import java.util.ArrayList; -import java.util.List; import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.database.types.EsHistoricalPerformance15Minutes; import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.database.types.EsHistoricalPerformance24Hours; -public class AllPm { +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; - private final static AllPm EMPTY = new AllPm(); +public class AllPm { private final List<EsHistoricalPerformance15Minutes> pm15 = new ArrayList<>(); private final List<EsHistoricalPerformance24Hours> pm24 = new ArrayList<>(); @@ -41,19 +41,19 @@ public class AllPm { } public List<EsHistoricalPerformance15Minutes> getPm15() { - return pm15; + return Collections.unmodifiableList(pm15); } public List<EsHistoricalPerformance24Hours> getPm24() { - return pm24; + return Collections.unmodifiableList(pm24); } - public Object size() { - return pm15.size()+pm24.size(); + public int size() { + return pm15.size() + pm24.size(); } public static AllPm getEmpty() { - return EMPTY; + return new AllPm(); } } |