Subversion Repository Public Repository

litesoft

Diff Revisions 820 vs 821 for /trunk/Java/core/Anywhere/src/org/litesoft/core/typeutils/Maps.java

Diff revisions: vs.
  @@ -4,6 +4,11 @@
4 4
5 5 public class Maps
6 6 {
7 + public static <K,V> Map<K,V> newHashMap()
8 + {
9 + return new HashMap<K,V>();
10 + }
11 +
7 12 public static <K, V> Map<K, V> empty()
8 13 {
9 14 return Collections.emptyMap();
  @@ -33,4 +38,64 @@
33 38 }
34 39 return rv;
35 40 }
41 +
42 + public static Map<String, String> createHashMap( String... pKeyValuePairs )
43 + throws IllegalArgumentException
44 + {
45 + Map<String, String> zMap = newHashMap();
46 + return populate( zMap, pKeyValuePairs );
47 + }
48 +
49 + public static Map<String, String> populate( Map<String, String> pToPopulate, String... pNameValuePairs )
50 + throws IllegalArgumentException
51 + {
52 + if ( pNameValuePairs != null )
53 + {
54 + if ( (pNameValuePairs.length & 1) == 1 )
55 + {
56 + throw new IllegalArgumentException( "NameValuePairs not paired" );
57 + }
58 + for ( int i = 0; i < pNameValuePairs.length; )
59 + {
60 + String name = pNameValuePairs[i++];
61 + String value = pNameValuePairs[i++];
62 + // noinspection unchecked
63 + pToPopulate.put( name, value );
64 + }
65 + }
66 + return pToPopulate;
67 + }
68 +
69 + public static void populate( Map pToPopulate, Map pNewContents )
70 + {
71 + if ( pNewContents != null )
72 + {
73 + //noinspection unchecked
74 + pToPopulate.putAll( pNewContents );
75 + }
76 + }
77 +
78 + public static String[] getSortedKeysAsStrings( Map pMap )
79 + {
80 + String[] names = Strings.toArray( pMap.keySet().toArray() );
81 + Arrays.sort( names );
82 + return names;
83 + }
84 +
85 + public static Map<String, String> addPropertiesTo( Map<String, String> pMap, String... pProperty_NameValues )
86 + throws IllegalArgumentException
87 + {
88 + if ( Objects.isNotNullOrEmpty( pProperty_NameValues ) )
89 + {
90 + if ( (pProperty_NameValues.length & 1) != 0 )
91 + {
92 + throw new IllegalArgumentException( "Attempt to add Properties that were NOT Name/Value pairs" );
93 + }
94 + for ( int i = 0; i < pProperty_NameValues.length; i += 2 )
95 + {
96 + pMap.put( pProperty_NameValues[i], pProperty_NameValues[i + 1] );
97 + }
98 + }
99 + return pMap;
100 + }
36 101 }