| /** |
| * Copyright (c) 2011, 2015 - Bernhard Edler (Wien), Loetz GmbH&Co.KG (Heidelberg) |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Bernhard Edler - Initial implementation |
| */ |
| package org.eclipse.osbp.runtime.common.util; |
| |
| import java.util.Arrays; |
| import java.util.Dictionary; |
| import java.util.Enumeration; |
| import java.util.HashMap; |
| import java.util.Hashtable; |
| import java.util.Properties; |
| |
| // TODO: Auto-generated Javadoc |
| /** |
| * The Class OSGiUtil. |
| */ |
| @SuppressWarnings("all") |
| public class OSGiUtil { |
| |
| /** |
| * Convert hash map to dictionary. |
| * |
| * @param input |
| * the input |
| * @return the dictionary |
| */ |
| public static Dictionary<String, Object> convertHashMapToDictionary( |
| HashMap<?, ?> input) { |
| Dictionary<String, Object> dict = new Hashtable<String, Object>(); |
| for (Object key : input.keySet()) { |
| dict.put(key.toString(), input.get(key)); |
| } |
| return dict; |
| } |
| |
| /** |
| * Convert hash map to properties. |
| * |
| * @param input |
| * the input |
| * @return the properties |
| */ |
| public static Properties convertHashMapToProperties(HashMap<?, ?> input) { |
| Properties props = new Properties(); |
| for (Object key : input.keySet()) { |
| props.put(key, input.get(key)); |
| } |
| return props; |
| } |
| |
| /** |
| * Convert dictionary to hash map. |
| * |
| * @param input |
| * the input |
| * @return the hash map |
| */ |
| public static HashMap<String, String> convertDictionaryToHashMap( |
| Dictionary<?, ?> input) { |
| HashMap<String, String> map = new HashMap<String, String>(); |
| Enumeration<String> iter = (Enumeration<String>) input.keys(); |
| while (iter.hasMoreElements()) { |
| String key = (String) iter.nextElement(); |
| map.put(key, input.get(key).toString()); |
| } |
| return map; |
| } |
| |
| /** |
| * Convert dictionary to properties. |
| * |
| * @param input |
| * the input |
| * @return the properties |
| */ |
| public static Properties convertDictionaryToProperties( |
| Dictionary<?, ?> input) { |
| Properties props = new Properties(); |
| Enumeration<String> iter = (Enumeration<String>) input.keys(); |
| while (iter.hasMoreElements()) { |
| String key = (String) iter.nextElement(); |
| props.setProperty(key, input.get(key).toString()); |
| } |
| return props; |
| } |
| |
| /** |
| * Gets the enum values. |
| * |
| * @param e |
| * the e |
| * @return the enum values |
| */ |
| public static String[] getEnumValues(Class<? extends Enum<?>> e) { |
| return Arrays.toString(e.getEnumConstants()).replaceAll("^.|.$", "") |
| .split(", "); |
| } |
| |
| /** |
| * Filter properties. |
| * |
| * @param properties |
| * the properties |
| * @param keySet |
| * the key set |
| * @return the hash map |
| */ |
| public static HashMap<String, String> filterProperties( |
| HashMap<String, String> properties, String[] keySet) { |
| for (String key : properties.keySet()) { |
| if (!Arrays.asList(keySet).contains(key)) { |
| properties.remove(key); |
| } |
| } |
| return properties; |
| }; |
| |
| /** |
| * Filter properties. |
| * |
| * @param properties |
| * the properties |
| * @param keySet |
| * the key set |
| * @return the properties |
| */ |
| public static Properties filterProperties(Properties properties, |
| String[] keySet) { |
| Enumeration<Object> iter = (Enumeration<Object>) properties.keys(); |
| while (iter.hasMoreElements()) { |
| String key = (String) iter.nextElement(); |
| if (!Arrays.asList(keySet).contains(key)) { |
| properties.remove(key); |
| } |
| } |
| return properties; |
| }; |
| } |