Example usage for java.util LinkedHashMap put

List of usage examples for java.util LinkedHashMap put

Introduction

In this page you can find the example usage for java.util LinkedHashMap put.

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:Main.java

public static Map<String, Object> map(final String key, final Object value) {
    LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
    map.put(key, value);
    return map;//from  ww w.  j  a  v  a  2 s.c  om
}

From source file:Main.java

public static <KEY, VALUE> LinkedHashMap<KEY, VALUE> newLinkedHashMap(KEY key, VALUE value) {
    final LinkedHashMap<KEY, VALUE> map = newLinkedHashMapSized(1);
    map.put(key, value);
    return map;//  www  .j ava 2 s  .  co  m
}

From source file:Main.java

public static <KEY, VALUE> LinkedHashMap<KEY, VALUE> newLinkedHashMap(KEY key1, VALUE value1, KEY key2,
        VALUE value2) {/*  w  w  w  .jav a2s  .  c  o m*/
    final LinkedHashMap<KEY, VALUE> map = newLinkedHashMapSized(2);
    map.put(key1, value1);
    map.put(key2, value2);
    return map;
}

From source file:Main.java

/**
 * Given a stream, and a function for creating default values, constructs a map from keys to elements of
 * type T built using the producer./*from   w w  w .  j  a  va  2  s . com*/
 * @param keyStream  The stream of keys for the map
 * @param valuesSupplier  The function that produces default values for the map
 * @param <T>  The type of the keys of the map
 * @param <U>  The type of the values of the map
 */
public static <T, U> LinkedHashMap<T, U> buildMap(Stream<T> keyStream, Supplier<U> valuesSupplier) {
    LinkedHashMap<T, U> map = new LinkedHashMap<>();
    keyStream.forEach(key -> map.put(key, valuesSupplier.get()));
    return map;
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.clustering.entropy.MatrixExperiments.java

public static <K, V extends Comparable<? super V>> LinkedHashMap<K, V> sortByValue(Map<K, V> map) {
    List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet());
    Collections.sort(list, new Comparator<Map.Entry<K, V>>() {
        @Override/*from   ww  w  . ja v  a 2  s  . c o  m*/
        public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) {
            return (o1.getValue()).compareTo(o2.getValue());
        }
    });

    LinkedHashMap<K, V> result = new LinkedHashMap<>();
    for (Map.Entry<K, V> entry : list) {
        result.put(entry.getKey(), entry.getValue());
    }
    return result;
}

From source file:net.sf.zekr.engine.theme.Theme.java

/**
 * Save a ThemeData configuration file.//  w  w w .  ja v a 2 s .com
 * 
 * @param td theme data object to be stored to the disk
 * @throws IOException
 */
public static void save(ThemeData td) throws IOException {
    OutputStreamWriter osw = new OutputStreamWriter(
            new FileOutputStream(Naming.getThemePropsDir() + "/" + td.fileName));
    LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
    map.put("name", td.name);
    map.put("author", td.author);
    map.put("version", td.version);
    map.putAll(td.props);
    ConfigUtils.write(new MapConfiguration(map), osw);
    // ConfigurationUtils.dump(new MapConfiguration(map), new PrintWriter(osw));
    IOUtils.closeQuietly(osw);
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <Key, Value> Map<Key, Value> map(Object... args) {
    LinkedHashMap<Key, Value> result = new LinkedHashMap<Key, Value>();
    for (int i = 0; i < args.length; i += 2) {
        result.put((Key) args[i], (Value) args[i + 1]);
    }/*from  w w  w.j a v  a  2  s  .c  o  m*/
    return result;
}

From source file:Main.java

public static <K, V extends Comparable<? super V>> LinkedHashMap<K, V> sortMapByValue(Map<K, V> map,
        final boolean descending) {
    List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>(map.entrySet());
    Collections.sort(list, new Comparator<Map.Entry<K, V>>() {

        public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) {
            int comp = (o1.getValue()).compareTo(o2.getValue());

            if (descending) {
                comp = comp * (-1);//from   w ww.ja  v  a  2 s .co  m
            }

            return comp;
        }
    });

    LinkedHashMap<K, V> result = new LinkedHashMap<K, V>();
    for (Map.Entry<K, V> entry : list) {
        result.put(entry.getKey(), entry.getValue());
    }
    return result;
}

From source file:com.github.horrorho.inflatabledonkey.args.OptionsFactory.java

public static Map<Option, Property> options() {
    LinkedHashMap<Option, Property> options = new LinkedHashMap<>();

    options.put(Option.builder("d").longOpt("device").desc("Device, default: 0 = first device.").argName("int")
            .hasArg().build(), Property.SELECT_DEVICE_INDEX);

    options.put(Option.builder("s").longOpt("snapshot").desc("Snapshot, default: 0 = first snapshot.")
            .argName("int").hasArg().build(), Property.SELECT_SNAPSHOT_INDEX);

    options.put(Option.builder().longOpt("extension").desc("File extension filter, case insensitive.")
            .argName("string").hasArg().build(), Property.FILTER_EXTENSION);

    options.put(Option.builder().longOpt("domain").desc("Domain filter, case insensitive.").argName("string")
            .hasArg().build(), Property.FILTER_DOMAIN);

    options.put(Option.builder("o").longOpt("folder").desc("Output folder.").argName("string").hasArg().build(),
            Property.OUTPUT_FOLDER);/*from  ww  w. j  a  v a  2s  .  c o  m*/

    options.put(new Option(null, "snapshots", false, "List device/ snapshot information and exit."),
            Property.PRINT_SNAPSHOTS);

    options.put(
            new Option(null, "domains", false, "List domains/ file count for the selected snapshot and exit."),
            Property.PRINT_DOMAIN_LIST);

    options.put(new Option(null, "token", false, "Display dsPrsID:mmeAuthToken and exit."),
            Property.ARGS_TOKEN);

    options.put(new Option(null, "help", false, "Display this help and exit."), Property.ARGS_HELP);

    return options;
}

From source file:Main.java

@SuppressWarnings("unchecked")
static public LinkedHashMap invertOrdering(LinkedHashMap passedMap) {
    LinkedHashMap result = new LinkedHashMap();
    Object[] keys = passedMap.keySet().toArray();
    for (int i = keys.length - 1; i >= 0; i--)
        result.put(keys[i], passedMap.get(keys[i]));
    return result;
}