1 /*
2 * Copyright (c) 2006-present the original author or authors.
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 package org.codehaus.gmaven.plugin.util;
17
18 import java.util.Enumeration;
19 import java.util.HashMap;
20 import java.util.Map;
21 import java.util.Properties;
22
23 import static com.google.common.base.Preconditions.checkNotNull;
24
25 /**
26 * Map helper.
27 *
28 * @since 2.1.1
29 */
30 public class Maps2
31 {
32 private Maps2() {
33 // empty
34 }
35
36 public static Map<String,String> fromProperties(final Properties properties) {
37 checkNotNull(properties);
38 Map<String,String> result = new HashMap<String, String>(properties.size());
39 Enumeration names = properties.propertyNames();
40 while (names.hasMoreElements()) {
41 String name = (String)names.nextElement();
42 result.put(name, properties.getProperty(name));
43 }
44 return result;
45 }
46 }