Example usage for java.util LinkedHashMap putAll

List of usage examples for java.util LinkedHashMap putAll

Introduction

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

Prototype

void putAll(Map<? extends K, ? extends V> m);

Source Link

Document

Copies all of the mappings from the specified map to this map (optional operation).

Usage

From source file:Main.java

/**
 * Given two maps with disjoint key sets, merges them and returns the merged map.
 *
 * @param map1  The first map to merge/*  www .ja  v  a 2  s .c  o  m*/
 * @param map2  The second map to merge
 * @param <T>  The key type of the maps
 * @param <U>  The value type of the maps
 *
 * @return  A new map that is the merger of the two parameters
 */
public static <T, U> LinkedHashMap<T, U> mergeMaps(Map<T, U> map1, Map<T, U> map2) {
    LinkedHashMap<T, U> newMap = new LinkedHashMap<>(map1);
    newMap.putAll(map2);
    return newMap;
}

From source file:org.mule.util.JarUtils.java

public static void appendJarFileEntries(File jarFile, LinkedHashMap entries) throws Exception {
    if (entries != null) {
        LinkedHashMap combinedEntries = readJarFileEntries(jarFile);
        combinedEntries.putAll(entries);
        File tmpJarFile = File.createTempFile(jarFile.getName(), null);
        createJarFileEntries(tmpJarFile, combinedEntries);
        jarFile.delete();/*ww w .  ja  va2 s.  c  o m*/
        FileUtils.renameFile(tmpJarFile, jarFile);
    }
}

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

/**
 * Save a ThemeData configuration file./*from w  w  w. j ava2  s . c o m*/
 * 
 * @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:com.github.jknack.extend.Extend.java

/**
 * Converts an object to a {@link Map}. The resulting map is the union of the bean properties and
 * all the extra properties.//w  w w. ja  va2  s  . co m
 *
 * @param source The object to extend. Required.
 * @param properties The extra property set. Required.
 * @param <T> The source type.
 * @return A new immutable map.
 */
@SuppressWarnings("unchecked")
public static <T> Map<String, Object> map(final T source, final Map<String, Object> properties) {
    notNull(source, "The source object is required.");
    notNull(properties, "The properties is required");
    final BeanMap beanMap = BeanMap.create(source);
    return new AbstractMap<String, Object>() {
        @Override
        public Object put(final String key, final Object value) {
            return null;
        }

        @Override
        public Object get(final Object key) {
            Object value = properties.get(key);
            return value == null ? beanMap.get(key) : value;
        }

        @Override
        public Set<Entry<String, Object>> entrySet() {
            LinkedHashMap<String, Object> mergedProperties = new LinkedHashMap<String, Object>(beanMap);
            mergedProperties.putAll(properties);
            return mergedProperties.entrySet();
        }
    };
}

From source file:org.loklak.geo.GeoNames.java

/**
 * Create sequences of words from a word token list. The sequence has also normalized (lowercased) names and original Text.
 * The creates sequences is a full set of all sequence combinations which are possible from the given tokens.
 * The text sequences are then reverse-sorted by the length of the combines text sequence. The result is a hashtable
 * where the key is the hash of the lowercase text sequence and the value is the original text without lowercase.
 * This allows a rapid matching with stored word sequences using the hash of the sequence
 * @param text/*from w  w  w . ja  v a  2 s  .com*/
 * @param maxlength the maximum sequence length, counts number of words
 * @return an ordered hashtable where the order is the reverse length of the sequence, the key is the hash of the lowercase string sequence and the value is the original word sequence
 */
public static LinkedHashMap<Integer, String> mix(final ArrayList<Map.Entry<String, String>> text,
        final int maxlength) {
    Map<Integer, Map<Integer, String>> a = new TreeMap<>(); // must be a TreeMap provide order on reverse word count
    for (int i = 0; i < text.size(); i++) {
        for (int x = 1; x <= Math.min(text.size() - i, maxlength); x++) {
            StringBuilder o = new StringBuilder(10 * x);
            StringBuilder l = new StringBuilder(10 * x);
            for (int j = 0; j < x; j++) {
                Map.Entry<String, String> word = text.get(i + j);
                if (j != 0) {
                    l.append(' ');
                    o.append(' ');
                }
                l.append(word.getKey());
                o.append(word.getValue());
            }
            Map<Integer, String> m = a.get(-x);
            if (m == null) {
                m = new HashMap<>();
                a.put(-x, m);
            }
            m.put(l.toString().hashCode(), o.toString());
        }
    }

    // now order the maps by the number of words
    LinkedHashMap<Integer, String> r = new LinkedHashMap<>();
    for (Map<Integer, String> m : a.values())
        r.putAll(m);
    return r;
}

From source file:Main.java

public static <K, V> void putAt(LinkedHashMap<K, V> map, K key, V value, int pos) {
    Iterator<Entry<K, V>> ei = map.entrySet().iterator();
    LinkedHashMap<K, V> pre = new LinkedHashMap<>();
    LinkedHashMap<K, V> post = new LinkedHashMap<>();

    for (int i = 0; i < pos; i++) {
        if (!ei.hasNext())
            break;
        Entry<K, V> tmpE = ei.next();
        pre.put(tmpE.getKey(), tmpE.getValue());
    }/*from   w  ww. j a  v  a  2 s  .c o m*/
    // skip element at pos
    if (ei.hasNext())
        ei.next();
    while (ei.hasNext()) {
        Entry<K, V> tmpE = ei.next();
        post.put(tmpE.getKey(), tmpE.getValue());
    }

    map.clear();
    map.putAll(pre);
    map.put(key, value);
    map.putAll(post);
}

From source file:com.espertech.esper.epl.spec.PatternStreamSpecRaw.java

private static StreamTypeService getStreamTypeService(String engineURI, String statementId,
        EventAdapterService eventAdapterService, Map<String, Pair<EventType, String>> taggedEventTypes,
        Map<String, Pair<EventType, String>> arrayEventTypes, Deque<Integer> subexpressionIdStack,
        String objectType) {//w  w  w  . j a va 2 s  .  c o  m
    LinkedHashMap<String, Pair<EventType, String>> filterTypes = new LinkedHashMap<String, Pair<EventType, String>>();
    filterTypes.putAll(taggedEventTypes);

    // handle array tags (match-until clause)
    if (arrayEventTypes != null) {
        String patternSubexEventType = getPatternSubexEventType(statementId, objectType, subexpressionIdStack);
        EventType arrayTagCompositeEventType = eventAdapterService
                .createSemiAnonymousMapType(patternSubexEventType, new HashMap(), arrayEventTypes, false);
        for (Map.Entry<String, Pair<EventType, String>> entry : arrayEventTypes.entrySet()) {
            String tag = entry.getKey();
            if (!filterTypes.containsKey(tag)) {
                Pair<EventType, String> pair = new Pair<EventType, String>(arrayTagCompositeEventType, tag);
                filterTypes.put(tag, pair);
            }
        }
    }

    return new StreamTypeServiceImpl(filterTypes, engineURI, true, false);
}

From source file:odoo.controls.OSelectionField.java

public static List<ODataRow> getRecordItems(OModel model, OColumn column, Bundle formData) {
    List<ODataRow> items = new ArrayList<>();

    OModel rel_model = model.createInstance(column.getType());
    StringBuilder whr = new StringBuilder();
    List<Object> args_list = new ArrayList<>();

    LinkedHashMap<String, OColumn.ColumnDomain> domains = new LinkedHashMap<>();
    domains.putAll(column.getDomains());
    if (column.hasDomainFilterColumn()) {
        domains.putAll(column.getDomainFilterParser(model).getDomain(formData));
    }/*from  w  ww.j  ava 2s.co m*/
    for (String key : domains.keySet()) {
        OColumn.ColumnDomain domain = domains.get(key);
        if (domain.getConditionalOperator() != null) {
            whr.append(domain.getConditionalOperator());
        } else {
            whr.append(" ");
            whr.append(domain.getColumn());
            whr.append(" ");
            whr.append(domain.getOperator());
            whr.append(" ? ");
            args_list.add(domain.getValue() + "");
        }
    }
    String where = null;
    String[] args = null;
    if (args_list.size() > 0) {
        where = whr.toString();
        args = args_list.toArray(new String[args_list.size()]);
    }
    List<ODataRow> rows = rel_model.select(new String[] { rel_model.getDefaultNameColumn() }, where, args,
            rel_model.getDefaultNameColumn());
    ODataRow row = new ODataRow();
    row.put(OColumn.ROW_ID, -1);
    row.put(rel_model.getDefaultNameColumn(), "No " + column.getLabel() + " selected");
    items.add(row);
    items.addAll(rows);
    return items;
}

From source file:AndroidUninstallStock.java

public static LinkedHashMap<String, String> getApkFromPattern(LinkedHashMap<String, String> apklist,
        LinkedList<AusInfo> section, boolean globalexclude) {
    LinkedHashMap<String, String> res = new LinkedHashMap<String, String>();
    if (globalexclude) {
        res.putAll(apklist);
    }/* w  w w .  jav a  2  s.  c o  m*/
    for (AusInfo info : section) {
        System.out.println("* " + info.apk.get("name"));
        if (!globalexclude) {
            LinkedHashMap<String, String> inc = new LinkedHashMap<String, String>();
            for (HashMap<String, String> pattern : info.include) {
                inc.putAll(_getListFromPattern(apklist, pattern, info, "include: ", false));
            }
            for (HashMap<String, String> pattern : info.exclude) {
                if (getBoolean(pattern.get("global"))) {
                    continue;
                }
                for (Map.Entry<String, String> exc : _getListFromPattern(inc, pattern, info, "exclude: ", false)
                        .entrySet()) {
                    inc.remove(exc.getKey());
                }
            }
            res.putAll(inc);
        } else {
            for (HashMap<String, String> pattern : info.exclude) {
                if (!getBoolean(pattern.get("global"))) {
                    continue;
                }
                for (Map.Entry<String, String> exc : _getListFromPattern(res, pattern, info, "exclude: ", false)
                        .entrySet()) {
                    res.remove(exc.getKey());
                }
            }
        }
    }
    return res;
}

From source file:AndroidUninstallStock.java

public static LinkedHashMap<String, String> getLibFromPatternInclude(String adb, LinkedList<String> liblist,
        LinkedHashMap<String, String> apklist, LinkedList<AusInfo> section, String sectionname,
        boolean scanlibs) throws IOException {
    LinkedHashMap<String, String> libinclude = new LinkedHashMap<String, String>();
    if (scanlibs) {
        System.out.println();//from   w w  w . j  a va2s. co m
        System.out.println("Include libraries from packages (" + sectionname + "):");
        libinclude = getLibFromPackage(adb, liblist, apklist);
    }

    System.out.println();
    System.out.println("Include libraries from section (" + sectionname + "):");
    LinkedHashMap<String, String> maplist = new LinkedHashMap<String, String>();
    for (String path : liblist) {
        maplist.put(path, "");
    }
    for (AusInfo info : section) {
        System.out.println("* " + info.apk.get("name"));
        LinkedHashMap<String, String> inc = new LinkedHashMap<String, String>();
        for (HashMap<String, String> pattern : info.include) {
            inc.putAll(_getListFromPattern(maplist, pattern, info, "include: ", true));
        }
        for (HashMap<String, String> pattern : info.exclude) {
            if (getBoolean(pattern.get("global"))) {
                continue;
            }
            for (Map.Entry<String, String> exc : _getListFromPattern(inc, pattern, info, "exclude: ", true)
                    .entrySet()) {
                inc.remove(exc.getKey());
            }
        }
        libinclude.putAll(inc);
    }

    return libinclude;
}