Here you can find the source of toMap(Properties properties)
properties
into a Map.
Parameter | Description |
---|---|
properties | a parameter |
public static Map<String, String> toMap(Properties properties)
//package com.java2s; /******************************************************************************* * Copyright (c) 2009, 2010 Cloudsmith Inc. and others. * 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:/*ww w . j a v a 2 s .c om*/ * Cloudsmith Inc. - initial API and implementation *******************************************************************************/ import java.util.*; public class Main { /** * Copies all elements from <code>properties</code> into a Map. The returned map might be unmodifiable * @param properties * @return The map containing all elements */ public static Map<String, String> toMap(Properties properties) { if (properties == null || properties.isEmpty()) return emptyMap(); Map<String, String> props = new HashMap<String, String>(properties.size()); putAll(properties, props); return props; } /** * The emptyMap() method was introduced in Java 1.5 so we need this here to be able to * down compile to 1.4. * @param <K> The type of the map keys * @param <V> The type of the map values * @return An empty set */ @SuppressWarnings("unchecked") public static <K, V> Map<K, V> emptyMap() { return Collections.EMPTY_MAP; } /** * Copies all elements from <code>properties</code> into the given <code>result</code>. * @param properties * @param result */ public static void putAll(Properties properties, Map<String, String> result) { for (Enumeration<Object> keys = properties.keys(); keys.hasMoreElements();) { String key = (String) keys.nextElement(); result.put(key, properties.getProperty(key)); } } }