2 * Copyright 2015 Samsung Electronics All Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package oic.simulator.serviceprovider.utils;
19 import java.util.ArrayList;
20 import java.util.Iterator;
21 import java.util.List;
25 * This class has common utility methods.
27 public class Utility {
29 public static String uriToDisplayName(String uri) {
32 String tokens[] = uri.split(Constants.FORWARD_SLASH);
33 if (null != tokens && tokens.length > 2) {
34 result = tokens[tokens.length - 3] + Constants.UNDERSCORE
35 + tokens[tokens.length - 1];
41 public static String fileNameToDisplay(String fileName) {
42 if (null == fileName || fileName.length() < 1) {
45 // Remove the RAML file standard prefix
46 int len = Constants.RAML_FILE_PREFIX.length();
48 if (fileName.startsWith(Constants.RAML_FILE_PREFIX)) {
49 fileName = fileName.substring(len);
53 // Removing the file extension
54 int index = fileName.lastIndexOf('.');
55 fileName = fileName.substring(0, index);
59 public static String displayToFileName(String displayName) {
60 if (null == displayName || displayName.length() < 1) {
65 fileName = Constants.RAML_FILE_PREFIX + displayName;
67 // Adding the file extension
68 fileName = fileName + Constants.RAML_FILE_EXTENSION;
73 public static String getAutomationStatus(boolean status) {
75 return Constants.ENABLED;
77 return Constants.DISABLED;
81 public static String getAutomationString(boolean status) {
83 return Constants.ENABLE;
85 return Constants.DISABLE;
89 public static boolean getAutomationBoolean(String status) {
91 if (status.equals(Constants.ENABLE)) {
98 public static int getUpdateIntervalFromString(String value) {
99 int result = Constants.DEFAULT_AUTOMATION_INTERVAL;
102 result = Integer.parseInt(value);
103 } catch (NumberFormatException nfe) {
105 .println("Getting UpdateInterval from string failed!");
111 public static List<String> convertSetToList(Set<String> typeSet) {
112 if (null == typeSet) {
115 List<String> list = new ArrayList<String>();
116 Iterator<String> typeItr = typeSet.iterator();
117 while (typeItr.hasNext()) {
118 list.add(typeItr.next());