Example usage for java.util HashMap putAll

List of usage examples for java.util HashMap putAll

Introduction

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

Prototype

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

Source Link

Document

Copies all of the mappings from the specified map to this map.

Usage

From source file:me.cpwc.nibblegram.android.NotificationsController.java

public void showWearNotifications(boolean notifyAboutLast) {
    if (Build.VERSION.SDK_INT < 19) {
        return;//from   w  w w  .  j av a 2  s  .c  om
    }
    ArrayList<Long> sortedDialogs = new ArrayList<Long>();
    HashMap<Long, ArrayList<MessageObject>> messagesByDialogs = new HashMap<Long, ArrayList<MessageObject>>();
    for (MessageObject messageObject : pushMessages) {
        long dialog_id = messageObject.getDialogId();
        if ((int) dialog_id == 0) {
            continue;
        }

        ArrayList<MessageObject> arrayList = messagesByDialogs.get(dialog_id);
        if (arrayList == null) {
            arrayList = new ArrayList<MessageObject>();
            messagesByDialogs.put(dialog_id, arrayList);
            sortedDialogs.add(0, dialog_id);
        }
        arrayList.add(messageObject);
    }

    HashMap<Long, Integer> oldIds = new HashMap<Long, Integer>();
    oldIds.putAll(wearNoticationsIds);
    wearNoticationsIds.clear();

    for (long dialog_id : sortedDialogs) {
        ArrayList<MessageObject> messageObjects = messagesByDialogs.get(dialog_id);
        int max_id = messageObjects.get(0).messageOwner.id;
        TLRPC.Chat chat = null;
        TLRPC.User user = null;
        String name = null;
        if (dialog_id > 0) {
            user = MessagesController.getInstance().getUser((int) dialog_id);
            if (user == null) {
                continue;
            }
        } else {
            chat = MessagesController.getInstance().getChat(-(int) dialog_id);
            if (chat == null) {
                continue;
            }
        }
        if (chat != null) {
            name = chat.title;
        } else {
            name = ContactsController.formatName(user.first_name, user.last_name);
        }

        Integer notificationId = oldIds.get(dialog_id);
        if (notificationId == null) {
            notificationId = wearNotificationId++;
        } else {
            oldIds.remove(dialog_id);
        }

        Intent replyIntent = new Intent(ApplicationLoader.applicationContext, WearReplyReceiver.class);
        replyIntent.putExtra("dialog_id", dialog_id);
        replyIntent.putExtra("max_id", max_id);
        PendingIntent replyPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext,
                notificationId, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
                .setLabel(LocaleController.getString("Reply", R.string.Reply)).build();
        String replyToString;
        if (chat != null) {
            replyToString = LocaleController.formatString("ReplyToGroup", R.string.ReplyToGroup, name);
        } else {
            replyToString = LocaleController.formatString("ReplyToUser", R.string.ReplyToUser, name);
        }
        NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon,
                replyToString, replyPendingIntent).addRemoteInput(remoteInput).build();

        String text = "";
        for (MessageObject messageObject : messageObjects) {
            String message = getStringForMessage(messageObject, false);
            if (message == null) {
                continue;
            }
            if (chat != null) {
                message = message.replace(" @ " + name, "");
            } else {
                message = message.replace(name + ": ", "").replace(name + " ", "");
            }
            if (text.length() > 0) {
                text += "\n\n";
            }
            text += message;
        }

        Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
        intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE);
        intent.setFlags(32768);
        if (chat != null) {
            intent.putExtra("chatId", chat.id);
        } else if (user != null) {
            intent.putExtra("userId", user.id);
        }
        PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent,
                PendingIntent.FLAG_ONE_SHOT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(
                ApplicationLoader.applicationContext).setContentTitle(name)
                        .setSmallIcon(R.drawable.notification).setGroup("messages").setContentText(text)
                        .setGroupSummary(false).setContentIntent(contentIntent)
                        .extend(new NotificationCompat.WearableExtender().addAction(action))
                        .setCategory(NotificationCompat.CATEGORY_MESSAGE);

        if (chat == null && user != null && user.phone != null && user.phone.length() > 0) {
            builder.addPerson("tel:+" + user.phone);
        }

        notificationManager.notify(notificationId, builder.build());
        wearNoticationsIds.put(dialog_id, notificationId);
    }

    for (HashMap.Entry<Long, Integer> entry : oldIds.entrySet()) {
        notificationManager.cancel(entry.getValue());
    }
}

From source file:org.kuali.kfs.module.tem.document.web.struts.TravelFormBase.java

protected Map<String, ExtraButton> createPaymentExtraButtonMap() {
    final HashMap<String, ExtraButton> result = new HashMap<String, ExtraButton>();
    result.putAll(createDVExtraButtonMap());
    return result;
}

From source file:de.fabianonline.telegram_backup.exporter.HTMLExporter.java

public void export(UserManager user) {
    try {//from w  ww . j  a  va2  s .  co  m
        Database db = new Database(user, null);

        // Create base dir
        logger.debug("Creating base dir");
        String base = user.getFileBase() + "files" + File.separatorChar;
        new File(base).mkdirs();
        new File(base + "dialogs").mkdirs();

        logger.debug("Fetching dialogs");
        LinkedList<Database.Dialog> dialogs = db.getListOfDialogsForExport();
        logger.trace("Got {} dialogs", dialogs.size());
        logger.debug("Fetching chats");
        LinkedList<Database.Chat> chats = db.getListOfChatsForExport();
        logger.trace("Got {} chats", chats.size());

        logger.debug("Generating index.html");
        HashMap<String, Object> scope = new HashMap<String, Object>();
        scope.put("user", user);
        scope.put("dialogs", dialogs);
        scope.put("chats", chats);

        // Collect stats data
        scope.put("count.chats", chats.size());
        scope.put("count.dialogs", dialogs.size());

        int count_messages_chats = 0;
        int count_messages_dialogs = 0;
        for (Database.Chat c : chats)
            count_messages_chats += c.count;
        for (Database.Dialog d : dialogs)
            count_messages_dialogs += d.count;

        scope.put("count.messages", count_messages_chats + count_messages_dialogs);
        scope.put("count.messages.chats", count_messages_chats);
        scope.put("count.messages.dialogs", count_messages_dialogs);

        scope.put("count.messages.from_me", db.getMessagesFromUserCount());

        scope.put("heatmap_data", intArrayToString(db.getMessageTimesMatrix()));

        scope.putAll(db.getMessageAuthorsWithCount());
        scope.putAll(db.getMessageTypesWithCount());
        scope.putAll(db.getMessageMediaTypesWithCount());

        MustacheFactory mf = new DefaultMustacheFactory();
        Mustache mustache = mf.compile("templates/html/index.mustache");
        OutputStreamWriter w = getWriter(base + "index.html");
        mustache.execute(w, scope);
        w.close();

        mustache = mf.compile("templates/html/chat.mustache");

        int i = 0;
        logger.debug("Generating {} dialog pages", dialogs.size());
        for (Database.Dialog d : dialogs) {
            i++;
            logger.trace("Dialog {}/{}: {}", i, dialogs.size(), Utils.anonymize("" + d.id));
            LinkedList<HashMap<String, Object>> messages = db.getMessagesForExport(d);
            scope.clear();
            scope.put("user", user);
            scope.put("dialog", d);
            scope.put("messages", messages);

            scope.putAll(db.getMessageAuthorsWithCount(d));
            scope.put("heatmap_data", intArrayToString(db.getMessageTimesMatrix(d)));
            scope.putAll(db.getMessageTypesWithCount(d));
            scope.putAll(db.getMessageMediaTypesWithCount(d));

            w = getWriter(base + "dialogs" + File.separatorChar + "user_" + d.id + ".html");
            mustache.execute(w, scope);
            w.close();
        }

        i = 0;
        logger.debug("Generating {} chat pages", chats.size());
        for (Database.Chat c : chats) {
            i++;
            logger.trace("Chat {}/{}: {}", i, chats.size(), Utils.anonymize("" + c.id));
            LinkedList<HashMap<String, Object>> messages = db.getMessagesForExport(c);
            scope.clear();
            scope.put("user", user);
            scope.put("chat", c);
            scope.put("messages", messages);

            scope.putAll(db.getMessageAuthorsWithCount(c));
            scope.put("heatmap_data", intArrayToString(db.getMessageTimesMatrix(c)));
            scope.putAll(db.getMessageTypesWithCount(c));
            scope.putAll(db.getMessageMediaTypesWithCount(c));

            w = getWriter(base + "dialogs" + File.separatorChar + "chat_" + c.id + ".html");
            mustache.execute(w, scope);
            w.close();
        }

        logger.debug("Generating additional files");
        // Copy CSS
        URL cssFile = getClass().getResource("/templates/html/style.css");
        File dest = new File(base + "style.css");
        FileUtils.copyURLToFile(cssFile, dest);
        logger.debug("Done exporting.");
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException("Exception above!");
    }
}

From source file:org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.java

private HashMap<CacheCompoundKey, GluuInumMap> getAllInumServerEntries(
        HashMap<CacheCompoundKey, GluuInumMap> primaryKeyAttrValueInumMap,
        HashMap<CacheCompoundKey, GluuInumMap> addedPrimaryKeyAttrValueInumMap) {
    HashMap<CacheCompoundKey, GluuInumMap> result = new HashMap<CacheCompoundKey, GluuInumMap>();

    result.putAll(primaryKeyAttrValueInumMap);
    result.putAll(addedPrimaryKeyAttrValueInumMap);

    return result;
}

From source file:mx.org.cedn.avisosconagua.engine.processors.Init.java

/**
 * Updates selected areas in the google map displayed in the web form.
 * @param nuevo new advice properties//from w ww  .  j a v a2  s  . co m
 * @param anterior previous advice properties
 */
private void procesaAreas(HashMap<String, String> nuevo, BasicDBObject anterior) {
    if (null != anterior) {
        HashMap<String, String> cambios = new HashMap<>();
        for (String key : nuevo.keySet()) {
            if (key.startsWith("area-")) {
                String states = "states" + key.substring(4);
                String municipalities = "municipalities" + key.substring(4);
                if (null == nuevo.get(states) || null == nuevo.get(municipalities)) {
                    if (((String) nuevo.get(key)).equals(anterior.get(key))) {
                        if (null != anterior.get(states)) {
                            cambios.put(states, (String) anterior.get(states));
                        }
                        if (null != anterior.get(municipalities)) {
                            cambios.put(municipalities, (String) anterior.get(municipalities));
                        }
                    }
                }

            }
        }
        if (!cambios.isEmpty()) {
            nuevo.putAll(cambios);
        }
    }
}

From source file:au.org.ands.vocabs.toolkit.provider.transform.GetMetadataTransformProvider.java

/**
 * Parse the files harvested from PoolParty and extract the
 * metadata.//from  w  ww. j av a 2 s  .  co m
 * @param pPprojectId The PoolParty project id.
 * @return The results of the metadata extraction.
 */
public final HashMap<String, Object> extractMetadata(final String pPprojectId) {
    Path dir = Paths.get(ToolkitFileUtils.getMetadataOutputPath(pPprojectId));
    HashMap<String, Object> results = new HashMap<String, Object>();
    ConceptHandler conceptHandler = new ConceptHandler();
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
        for (Path entry : stream) {
            conceptHandler.setSource(entry.getFileName().toString());
            RDFFormat format = Rio.getParserFormatForFileName(entry.toString());
            RDFParser rdfParser = Rio.createParser(format);
            rdfParser.setRDFHandler(conceptHandler);
            FileInputStream is = new FileInputStream(entry.toString());
            logger.debug("Reading RDF:" + entry.toString());
            rdfParser.parse(is, entry.toString());
        }
    } catch (DirectoryIteratorException | IOException | RDFParseException | RDFHandlerException ex) {
        results.put(TaskStatus.EXCEPTION, "Exception in extractMetadata while Parsing RDF");
        logger.error("Exception in extractMetadata while Parsing RDF:", ex);
        return results;
    }
    results.putAll(conceptHandler.getMetadata());
    results.put("concept_count", Integer.toString(conceptHandler.getCountedConcepts()));
    return results;
}

From source file:org.nuxeo.ecm.platform.query.api.AbstractPageProvider.java

/**
 * Default (dummy) implementation that should be overridden by PageProvider actually dealing with Aggregates
 *
 * @param eventProps/*w ww .  jav  a  2  s . c o  m*/
 * @since 7.4
 */
protected void incorporateAggregates(Map<String, Serializable> eventProps) {

    List<AggregateDefinition> ags = getDefinition().getAggregates();
    if (ags != null) {
        ArrayList<HashMap<String, Serializable>> aggregates = new ArrayList<HashMap<String, Serializable>>();
        for (AggregateDefinition ag : ags) {
            HashMap<String, Serializable> agData = new HashMap<String, Serializable>();
            agData.put("type", ag.getType());
            agData.put("id", ag.getId());
            agData.put("field", ag.getDocumentField());
            agData.putAll(ag.getProperties());
            ArrayList<HashMap<String, Serializable>> rangesData = new ArrayList<HashMap<String, Serializable>>();
            if (ag.getDateRanges() != null) {
                for (AggregateRangeDateDefinition range : ag.getDateRanges()) {
                    HashMap<String, Serializable> rangeData = new HashMap<String, Serializable>();
                    rangeData.put("from", range.getFromAsString());
                    rangeData.put("to", range.getToAsString());
                    rangesData.add(rangeData);
                }
                for (AggregateRangeDefinition range : ag.getRanges()) {
                    HashMap<String, Serializable> rangeData = new HashMap<String, Serializable>();
                    rangeData.put("from-dbl", range.getFrom());
                    rangeData.put("to-dbl", range.getTo());
                    rangesData.add(rangeData);
                }
            }
            agData.put("ranges", rangesData);
            aggregates.add(agData);
        }
        eventProps.put("aggregates", aggregates);
    }

}

From source file:com.negaheno.android.NotificationsController.java

public void showWearNotifications(boolean notifyAboutLast) {
    if (Build.VERSION.SDK_INT < 19) {
        return;/*from   w ww.  j  a v a 2 s  .co m*/
    }
    ArrayList<Long> sortedDialogs = new ArrayList<>();
    HashMap<Long, ArrayList<MessageObject>> messagesByDialogs = new HashMap<>();
    for (MessageObject messageObject : pushMessages) {
        long dialog_id = messageObject.getDialogId();
        if ((int) dialog_id == 0) {
            continue;
        }

        ArrayList<MessageObject> arrayList = messagesByDialogs.get(dialog_id);
        if (arrayList == null) {
            arrayList = new ArrayList<>();
            messagesByDialogs.put(dialog_id, arrayList);
            sortedDialogs.add(0, dialog_id);
        }
        arrayList.add(messageObject);
    }

    HashMap<Long, Integer> oldIds = new HashMap<>();
    oldIds.putAll(wearNoticationsIds);
    wearNoticationsIds.clear();

    for (long dialog_id : sortedDialogs) {
        ArrayList<MessageObject> messageObjects = messagesByDialogs.get(dialog_id);
        int max_id = messageObjects.get(0).messageOwner.id;
        TLRPC.Chat chat = null;
        TLRPC.User user = null;
        String name = null;
        if (dialog_id > 0) {
            user = MessagesController.getInstance().getUser((int) dialog_id);
            if (user == null) {
                continue;
            }
        } else {
            chat = MessagesController.getInstance().getChat(-(int) dialog_id);
            if (chat == null) {
                continue;
            }
        }
        if (chat != null) {
            name = chat.title;
        } else {
            name = ContactsController.formatName(user.first_name, user.last_name);
        }

        Integer notificationId = oldIds.get(dialog_id);
        if (notificationId == null) {
            notificationId = wearNotificationId++;
        } else {
            oldIds.remove(dialog_id);
        }

        Intent replyIntent = new Intent(ApplicationLoader.applicationContext, WearReplyReceiver.class);
        replyIntent.putExtra("dialog_id", dialog_id);
        replyIntent.putExtra("max_id", max_id);
        PendingIntent replyPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext,
                notificationId, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
                .setLabel(LocaleController.getString("Reply", R.string.Reply)).build();
        String replyToString;
        if (chat != null) {
            replyToString = LocaleController.formatString("ReplyToGroup", R.string.ReplyToGroup, name);
        } else {
            replyToString = LocaleController.formatString("ReplyToUser", R.string.ReplyToUser, name);
        }
        NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon,
                replyToString, replyPendingIntent).addRemoteInput(remoteInput).build();

        String text = "";
        for (MessageObject messageObject : messageObjects) {
            String message = getStringForMessage(messageObject, false);
            if (message == null) {
                continue;
            }
            if (chat != null) {
                message = message.replace(" @ " + name, "");
            } else {
                message = message.replace(name + ": ", "").replace(name + " ", "");
            }
            if (text.length() > 0) {
                text += "\n\n";
            }
            text += message;
        }

        Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
        intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE);
        intent.setFlags(32768);
        if (chat != null) {
            intent.putExtra("chatId", chat.id);
        } else if (user != null) {
            intent.putExtra("userId", user.id);
        }
        PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent,
                PendingIntent.FLAG_ONE_SHOT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(
                ApplicationLoader.applicationContext).setContentTitle(name)
                        .setSmallIcon(R.drawable.notification).setGroup("messages").setContentText(text)
                        .setGroupSummary(false).setContentIntent(contentIntent)
                        .extend(new NotificationCompat.WearableExtender().addAction(action))
                        .setCategory(NotificationCompat.CATEGORY_MESSAGE);

        if (chat == null && user != null && user.phone != null && user.phone.length() > 0) {
            builder.addPerson("tel:+" + user.phone);
        }

        notificationManager.notify(notificationId, builder.build());
        wearNoticationsIds.put(dialog_id, notificationId);
    }

    for (HashMap.Entry<Long, Integer> entry : oldIds.entrySet()) {
        notificationManager.cancel(entry.getValue());
    }
}