/** * Map initialiser, takes an array of Strings alternately key and value * * @param m a Map to insert the values into, already allocated. * @param alternatingkv array of key/value pairs to insert into the Map */ public static void mapInitialiser( Map<String, String> m, String[] alternatingkv ) { if ( ( alternatingkv.length & 1 ) != 0 ) { throw new IllegalArgumentException( "Initialiser array must have an even number of items." ); } for ( int i = 0; i < alternatingkv.length; i += 2 ) { final String key = alternatingkv[ i ]; final String value = alternatingkv[ i + 1 ]; m.put( key, value ); } } /** * Map initialiser, takes an array of keys and matching array of values * * @param m a Map to insert the values into, already allocated. * @param keys array of keys * @param values array of values matching keys */ public static void mapInitialiser( Map<String, String> m, String[] keys, String[] values ) { if ( keys.length != values.length ) { throw new IllegalArgumentException( "Initialiser mast have equals numbers of keys and values." ); } for ( int i = 0; i < keys.length; i++ ) { m.put( keys[ i ], values[ i ] ); } }