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:gemlite.shell.commands.admin.Monitor.java

@SuppressWarnings({ "unchecked", "rawtypes" })
@CliCommand(value = "list services", help = "list services")
public String services() {
    Set<ObjectInstance> names = jmxSrv.listMBeans();
    List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
    if (names == null)
        return "no services";
    Object[] a = names.toArray();
    //???// w ww  .j av a2  s.  com
    Arrays.sort(a, (Comparator) new Comparator<ObjectInstance>() {
        @Override
        public int compare(ObjectInstance o1, ObjectInstance o2) {
            return (o1.getObjectName().toString()).compareTo(o2.getObjectName().toString());
        }
    });

    if (LogUtil.getCoreLog().isDebugEnabled())
        LogUtil.getCoreLog().debug("get names size:{} values:{}", names.size(), names.toString());

    //?service?
    for (int i = 0; i < a.length; i++) {
        ObjectInstance oi = (ObjectInstance) a[i];
        // service?,???
        HashMap<String, Object> service = new HashMap<String, Object>();
        service.put(oi.getObjectName().toString(), service);
        service.put("serviceName", service);
        try {
            Map<String, Object> map = jmxSrv.getAttributesValues(oi.getObjectName().toString());
            if (map.size() <= 0) {
                map.put("serviceName", oi.getObjectName().toString());
                LogUtil.getCoreLog().warn("jmxSrv.getAttributesValues is null ,ObjectName {}",
                        oi.getObjectName().toString());
                result.add(map);
            } else {
                result.add(map);
            }
        } catch (Exception e) {
            LogUtil.getCoreLog().error("jmxSrv.getAttributesValues is null ,ObjectName {},error:{}",
                    oi.getObjectName().toString(), e);
        }
    }

    LinkedHashMap<String, HashMap<String, Object>> rs = (LinkedHashMap<String, HashMap<String, Object>>) get(
            CommandMeta.LIST_SERVICES);
    if (rs == null)
        rs = new LinkedHashMap<String, HashMap<String, Object>>();
    for (Map<String, Object> map : result) {
        // ?
        HashMap<String, Object> service = rs.get(map.get("serviceName"));
        if (service == null) {
            service = new HashMap<String, Object>();
        }
        service.putAll(map);

        // ?
        rs.put((String) map.get("serviceName"), service);
    }

    // ws??
    put(CommandMeta.LIST_SERVICES, rs);
    if (!result.isEmpty())
        return result.toString();
    return "no services";
}

From source file:com.b44t.messenger.NotificationsController.java

@SuppressLint("InlinedApi")
private void showExtraNotifications(NotificationCompat.Builder notificationBuilder, boolean notifyAboutLast) {
    // TODO: support Android wear by calling this function above from showOrUpdateNotification
    if (Build.VERSION.SDK_INT < 18) {
        return;//from w w w. j  a  va  2s.  c o m
    }

    ArrayList<Long> sortedDialogs = new ArrayList<>();
    HashMap<Long, ArrayList<MessageObject>> messagesByDialogs = new HashMap<>();
    for (int a = 0; a < pushMessages.size(); a++) {
        MessageObject messageObject = pushMessages.get(a);
        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> oldIdsWear = new HashMap<>();
    oldIdsWear.putAll(wearNotificationsIds);
    wearNotificationsIds.clear();

    HashMap<Long, Integer> oldIdsAuto = new HashMap<>();
    oldIdsAuto.putAll(autoNotificationsIds);
    autoNotificationsIds.clear();

    for (int b = 0; b < sortedDialogs.size(); b++) {
        long dialog_id = sortedDialogs.get(b);
        ArrayList<MessageObject> messageObjects = messagesByDialogs.get(dialog_id);
        int max_id = messageObjects.get(0).getId();
        int max_date = messageObjects.get(0).messageOwner.date;
        TLRPC.Chat chat = null;
        TLRPC.User user = null;
        String name;
        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;
            //}
        }
        TLRPC.FileLocation photoPath = null;
        if (AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) {
            name = mContext.getString(R.string.AppName);
        } else {
            if (chat != null) {
                name = chat.title;
            } else {
                name = UserObject.getUserName(user);
            }
            /*if (chat != null) {
            if (chat.photo != null && chat.photo.photo_small != null && chat.photo.photo_small.volume_id != 0 && chat.photo.photo_small.local_id != 0) {
                photoPath = chat.photo.photo_small;
            }
            } else {
            if (user.photo != null && user.photo.photo_small != null && user.photo.photo_small.volume_id != 0 && user.photo.photo_small.local_id != 0) {
                photoPath = user.photo.photo_small;
            }
            }*/
        }

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

        Integer notificationIdAuto = oldIdsAuto.get(dialog_id);
        if (notificationIdAuto == null) {
            notificationIdAuto = autoNotificationId++;
        } else {
            oldIdsAuto.remove(dialog_id);
        }

        NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder(
                name).setLatestTimestamp((long) max_date * 1000);

        Intent msgHeardIntent = new Intent();
        msgHeardIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
        msgHeardIntent.setAction("com.b44t.messenger.ACTION_MESSAGE_HEARD");
        msgHeardIntent.putExtra("dialog_id", dialog_id);
        msgHeardIntent.putExtra("max_id", max_id);
        PendingIntent msgHeardPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext,
                notificationIdAuto, msgHeardIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        unreadConvBuilder.setReadPendingIntent(msgHeardPendingIntent);

        NotificationCompat.Action wearReplyAction = null;

        if (/*!ChatObject.isChannel(chat) &&*/ !AndroidUtilities.needShowPasscode(false)
                && !UserConfig.isWaitingForPasscodeEnter) {
            Intent msgReplyIntent = new Intent();
            msgReplyIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
            msgReplyIntent.setAction("com.b44t.messenger.ACTION_MESSAGE_REPLY");
            msgReplyIntent.putExtra("dialog_id", dialog_id);
            msgReplyIntent.putExtra("max_id", max_id);
            PendingIntent msgReplyPendingIntent = PendingIntent.getBroadcast(
                    ApplicationLoader.applicationContext, notificationIdAuto, msgReplyIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            RemoteInput remoteInputAuto = new RemoteInput.Builder(NotificationsController.EXTRA_VOICE_REPLY)
                    .setLabel(mContext.getString(R.string.Reply)).build();
            unreadConvBuilder.setReplyAction(msgReplyPendingIntent, remoteInputAuto);

            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,
                    notificationIdWear, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            RemoteInput remoteInputWear = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
                    .setLabel(mContext.getString(R.string.Reply)).build();
            String replyToString;
            if (chat != null) {
                replyToString = String.format(mContext.getString(R.string.ReplyToGroup), name);
            } else {
                replyToString = String.format(mContext.getString(R.string.ReplyToContact), name);
            }
            wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon, replyToString,
                    replyPendingIntent).addRemoteInput(remoteInputWear).build();
        }

        String text = "";
        for (int a = messageObjects.size() - 1; a >= 0; a--) {
            MessageObject messageObject = messageObjects.get(a);
            String message = getStringForMessage(messageObject, ADD_GROUP | ADD_USER);
            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;

            unreadConvBuilder.addMessage(message);
        }

        Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
        intent.setAction("com.b44t.messenger.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.WearableExtender wearableExtender = new NotificationCompat.WearableExtender();
        if (wearReplyAction != null) {
            wearableExtender.addAction(wearReplyAction);
        }

        NotificationCompat.Builder builder = new NotificationCompat.Builder(
                ApplicationLoader.applicationContext).setContentTitle(name)
                        .setSmallIcon(R.drawable.notification).setGroup("messages").setContentText(text)
                        .setAutoCancel(true).setColor(Theme.ACTION_BAR_COLOR).setGroupSummary(false)
                        .setContentIntent(contentIntent).extend(wearableExtender)
                        .extend(new NotificationCompat.CarExtender()
                                .setUnreadConversation(unreadConvBuilder.build()))
                        .setCategory(NotificationCompat.CATEGORY_MESSAGE);
        /*if (photoPath != null) {
        BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50");
        if (img != null) {
            builder.setLargeIcon(img.getBitmap());
        }
        }*/

        notificationManager.notify(notificationIdWear, builder.build());
        wearNotificationsIds.put(dialog_id, notificationIdWear);
    }

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

From source file:org.mycore.common.xml.MCRURIResolver.java

private HashMap<String, URIResolver> getResolverMapping() {
    final Map<String, URIResolver> extResolverMapping = EXT_RESOLVER.getURIResolverMapping();
    extResolverMapping.putAll(new MCRModuleResolverProvider().getURIResolverMapping());
    // set Map to final size with loadfactor: full
    HashMap<String, URIResolver> supportedSchemes = new HashMap<String, URIResolver>(
            10 + extResolverMapping.size(), 1);
    // don't let interal mapping be overwritten
    supportedSchemes.putAll(extResolverMapping);
    supportedSchemes.put("webapp", new MCRWebAppResolver());
    supportedSchemes.put("ifs", new MCRIFSResolver());
    supportedSchemes.put("mcrfile", new MCRMCRFileResolver());
    supportedSchemes.put("mcrobject", new MCRObjectResolver());
    supportedSchemes.put("session", new MCRSessionResolver());
    supportedSchemes.put("access", new MCRACLResolver());
    supportedSchemes.put("resource", new MCRResourceResolver());
    supportedSchemes.put("localclass", new MCRLocalClassResolver());
    supportedSchemes.put("classification", new MCRClassificationResolver());
    supportedSchemes.put("buildxml", new MCRBuildXMLResolver());
    supportedSchemes.put("catchEx", new MCRExceptionAsXMLResolver());
    supportedSchemes.put("notnull", new MCRNotNullResolver());
    supportedSchemes.put("xslStyle", new MCRXslStyleResolver());
    supportedSchemes.put("xslTransform", new MCRLayoutTransformerResolver());
    supportedSchemes.put("xslInclude", new MCRXslIncludeResolver());
    supportedSchemes.put("xslImport", new MCRXslImportResolver());
    supportedSchemes.put("versioninfo", new MCRVersionInfoResolver());
    supportedSchemes.put("deletedMcrObject", new MCRDeletedObjectResolver());
    supportedSchemes.put("fileMeta", new MCRFileMetadataResolver());
    supportedSchemes.put("basket", new org.mycore.frontend.basket.MCRBasketResolver());
    supportedSchemes.put("language", new org.mycore.datamodel.language.MCRLanguageResolver());
    supportedSchemes.put("chooseTemplate", new MCRChooseTemplateResolver());
    supportedSchemes.put("redirect", new MCRRedirectResolver());
    supportedSchemes.put("data", new MCRDataURLResolver());
    MCRRESTResolver restResolver = new MCRRESTResolver();
    supportedSchemes.put("http", restResolver);
    supportedSchemes.put("https", restResolver);
    supportedSchemes.put("file", new MCRFileResolver());
    return supportedSchemes;
}

From source file:org.telegraph.messenger.NotificationsController.java

@SuppressLint("InlinedApi")
public void showExtraNotifications(NotificationCompat.Builder notificationBuilder, boolean notifyAboutLast) {
    if (Build.VERSION.SDK_INT < 18) {
        return;//from  w  w  w  .j ava  2s  . com
    }

    ArrayList<Long> sortedDialogs = new ArrayList<>();
    HashMap<Long, ArrayList<MessageObject>> messagesByDialogs = new HashMap<>();
    for (int a = 0; a < pushMessages.size(); a++) {
        MessageObject messageObject = pushMessages.get(a);
        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> oldIdsWear = new HashMap<>();
    oldIdsWear.putAll(wearNotificationsIds);
    wearNotificationsIds.clear();

    HashMap<Long, Integer> oldIdsAuto = new HashMap<>();
    oldIdsAuto.putAll(autoNotificationsIds);
    autoNotificationsIds.clear();

    for (int b = 0; b < sortedDialogs.size(); b++) {
        long dialog_id = sortedDialogs.get(b);
        ArrayList<MessageObject> messageObjects = messagesByDialogs.get(dialog_id);
        int max_id = messageObjects.get(0).getId();
        int max_date = messageObjects.get(0).messageOwner.date;
        TLRPC.Chat chat = null;
        TLRPC.User user = null;
        String name;
        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 = UserObject.getUserName(user);
        }

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

        Integer notificationIdAuto = oldIdsAuto.get(dialog_id);
        if (notificationIdAuto == null) {
            notificationIdAuto = autoNotificationId++;
        } else {
            oldIdsAuto.remove(dialog_id);
        }

        NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder(
                name).setLatestTimestamp((long) max_date * 1000);

        Intent msgHeardIntent = new Intent();
        msgHeardIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
        msgHeardIntent.setAction("org.telegraph.messenger.ACTION_MESSAGE_HEARD");
        msgHeardIntent.putExtra("dialog_id", dialog_id);
        msgHeardIntent.putExtra("max_id", max_id);
        PendingIntent msgHeardPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext,
                notificationIdAuto, msgHeardIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        unreadConvBuilder.setReadPendingIntent(msgHeardPendingIntent);

        NotificationCompat.Action wearReplyAction = null;

        if (!ChatObject.isChannel(chat)) {
            Intent msgReplyIntent = new Intent();
            msgReplyIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
            msgReplyIntent.setAction("org.telegraph.messenger.ACTION_MESSAGE_REPLY");
            msgReplyIntent.putExtra("dialog_id", dialog_id);
            msgReplyIntent.putExtra("max_id", max_id);
            PendingIntent msgReplyPendingIntent = PendingIntent.getBroadcast(
                    ApplicationLoader.applicationContext, notificationIdAuto, msgReplyIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            RemoteInput remoteInputAuto = new RemoteInput.Builder(NotificationsController.EXTRA_VOICE_REPLY)
                    .setLabel(LocaleController.getString("Reply", R.string.Reply)).build();
            unreadConvBuilder.setReplyAction(msgReplyPendingIntent, remoteInputAuto);

            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,
                    notificationIdWear, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            RemoteInput remoteInputWear = 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);
            }
            wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon, replyToString,
                    replyPendingIntent).addRemoteInput(remoteInputWear).build();
        }

        String text = "";
        for (int a = messageObjects.size() - 1; a >= 0; a--) {
            MessageObject messageObject = messageObjects.get(a);
            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;

            unreadConvBuilder.addMessage(message);
        }

        TLRPC.FileLocation photoPath = null;
        if (chat != null) {
            if (chat.photo != null && chat.photo.photo_small != null && chat.photo.photo_small.volume_id != 0
                    && chat.photo.photo_small.local_id != 0) {
                photoPath = chat.photo.photo_small;
            }
        } else {
            if (user.photo != null && user.photo.photo_small != null && user.photo.photo_small.volume_id != 0
                    && user.photo.photo_small.local_id != 0) {
                photoPath = user.photo.photo_small;
            }
        }

        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.WearableExtender wearableExtender = new NotificationCompat.WearableExtender();
        if (wearReplyAction != null) {
            wearableExtender.addAction(wearReplyAction);
        }

        NotificationCompat.Builder builder = new NotificationCompat.Builder(
                ApplicationLoader.applicationContext).setContentTitle(name)
                        .setSmallIcon(R.drawable.notification).setGroup("messages").setContentText(text)
                        .setColor(0xff2ca5e0).setGroupSummary(false).setContentIntent(contentIntent)
                        .extend(wearableExtender)
                        .extend(new NotificationCompat.CarExtender()
                                .setUnreadConversation(unreadConvBuilder.build()))
                        .setCategory(NotificationCompat.CATEGORY_MESSAGE);
        if (photoPath != null) {
            BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50");
            if (img != null) {
                builder.setLargeIcon(img.getBitmap());
            }
        }

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

        notificationManager.notify(notificationIdWear, builder.build());
        wearNotificationsIds.put(dialog_id, notificationIdWear);
    }

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

From source file:com.google.gwt.emultest.java.util.HashMapTest.java

/**
 * Test method for 'java.util.HashMap.size()'.
 *///from w w w .  j a  va  2  s  .  c o m
public void testSize() {
    HashMap<String, String> hashMap = new HashMap<String, String>();
    checkEmptyHashMapAssumptions(hashMap);

    // Test size behavior on put
    assertEquals(hashMap.size(), SIZE_ZERO);
    hashMap.put(KEY_1, VALUE_1);
    assertEquals(hashMap.size(), SIZE_ONE);
    hashMap.put(KEY_2, VALUE_2);
    assertEquals(hashMap.size(), SIZE_TWO);
    hashMap.put(KEY_3, VALUE_3);
    assertEquals(hashMap.size(), SIZE_THREE);

    // Test size behavior on remove
    hashMap.remove(KEY_1);
    assertEquals(hashMap.size(), SIZE_TWO);
    hashMap.remove(KEY_2);
    assertEquals(hashMap.size(), SIZE_ONE);
    hashMap.remove(KEY_3);
    assertEquals(hashMap.size(), SIZE_ZERO);

    // Test size behavior on putAll
    hashMap.put(KEY_1, VALUE_1);
    hashMap.put(KEY_2, VALUE_2);
    hashMap.put(KEY_3, VALUE_3);
    HashMap<String, String> srcMap = new HashMap<String, String>(hashMap);
    hashMap.putAll(srcMap);
    assertEquals(hashMap.size(), SIZE_THREE);

    // Test size behavior on clear
    hashMap.clear();
    assertEquals(hashMap.size(), SIZE_ZERO);
}

From source file:pltag.corpus.ConnectionPathCalculator.java

/**
 * Calculates which prediction trees need to be generated from the set of connectionNodes.
 * And combines prediction trees if possible.
 * // w w w  . j ava  2 s. com
 * @param currentLeafNumber
 * @param lexicon 
 * @return
 */
@SuppressWarnings("unchecked") // cast to Collection<String>
private List<PredictionStringTree> generatePredictionTrees(int currentLeafNumber, List<StringTree> lexicon) {//, String leaf) {
                                                                                                             //if (currentLeafNumber.equals("6"))
                                                                                                             //System.out.print("");
    MultiValueMap predictionTreeNodeMap = findNodesWithGreaterLeafnumbers(currentLeafNumber);
    ArrayList<PredictionStringTree> localPredictedTrees = new ArrayList<PredictionStringTree>();
    int sourcetreeno = 0;
    ArrayList<PredictionStringTree> unhelpfulpredtrees = new ArrayList<PredictionStringTree>();
    HashMap<Integer, Integer> translations = new HashMap<Integer, Integer>();
    //System.out.println("prediction tree to connect leaf " + currentLeafNumber + " number of pred trees needed: "+ predictionTreeNodeMap.size());
    //System.out.println("nodes needed: "+predictionTreeNodeMap);
    for (Integer predictionTreeOrigin : (Collection<Integer>) predictionTreeNodeMap.keySet()) {
        ElementaryStringTree originalStringTree = (ElementaryStringTree) sentenceWordLex[predictionTreeOrigin];
        //            ElementaryStringTree originalStringTree = (ElementaryStringTree) sentenceWordLex[Integer.parseInt(predictionTreeOrigin)];
        if (originalStringTree == null) {
            continue;
        }
        originalStringTree.makeLexiconEntry();
        if (originalStringTree.categories[originalStringTree.root] != null)
        //            if (originalStringTree.categories[Integer.parseInt(originalStringTree.root)] != null)
        {
            translations.putAll(originalStringTree.removeUnaryNodes(originalStringTree.root));
        } else {
            translations.putAll(originalStringTree.removeUnaryNodes(originalStringTree.coordanchor));
        }
        if (originalStringTree.getAnchor() == Integer.MIN_VALUE
                && originalStringTree.treeString.startsWith("*"))
        //            if (originalStringTree.getAnchor().equals("") && originalStringTree.treeString.startsWith("*"))
        {
            continue;
        }
        Collection<Integer> cn = predictionTreeNodeMap.getCollection(predictionTreeOrigin);
        PredictionStringTree predictionTree = buildPredictionTree(originalStringTree, cn, currentLeafNumber);
        //            PredictionStringTree predictionTree = buildPredictionTree(originalStringTree, cn, Integer.parseInt(currentLeafNumber));
        predictionTree.cutTail(cn);
        if (predictionTree.hasUsefulNodes(cn, translations)) {
            predictionTree = buildPredictionTree(originalStringTree, cn, currentLeafNumber);
            //                predictionTree = buildPredictionTree(originalStringTree, cn, Integer.parseInt(currentLeafNumber));
            sourcetreeno++;
            //System.out.println(predictionTree.print());
            ArrayList<PredictionStringTree> newlist = new ArrayList<PredictionStringTree>();
            ArrayList<PredictionStringTree> removelist = new ArrayList<PredictionStringTree>();
            // combine prediction trees (trees can always be combined! I think.)
            for (PredictionStringTree otherTree : localPredictedTrees) {
                PredictionStringTree ct = combinePredTrees(predictionTree, otherTree,
                        predictionTreeNodeMap.values(), translations);//.copyPred();
                if (ct != null) {
                    removelist.add(otherTree);
                    removelist.add(predictionTree);
                    newlist.remove(predictionTree);
                    newlist.add(ct);
                    predictionTree = ct;
                }
            }
            if (predictionTree.isAuxtree()) {
                localPredictedTrees.add(predictionTree);
            } else {
                localPredictedTrees.add(0, predictionTree);
            }
            localPredictedTrees.removeAll(removelist);
            //            might add too much here.
            for (PredictionStringTree npt : newlist) {
                if (predictionTree.isAuxtree()) {
                    localPredictedTrees.add(npt);
                } else {
                    localPredictedTrees.add(0, npt);
                }
            }
        } else {
            predictionTree = buildPredictionTree(originalStringTree, cn, currentLeafNumber);
            //                predictionTree = buildPredictionTree(originalStringTree, cn, Integer.parseInt(currentLeafNumber));
            unhelpfulpredtrees.add(predictionTree);
        }
    }
    if (localPredictedTrees.isEmpty() & unhelpfulpredtrees.size() > 0) {
        PredictionStringTree first = null;
        int min = Integer.MAX_VALUE;
        //         String others = "";
        for (PredictionStringTree pt : unhelpfulpredtrees) {
            if (pt.isAuxtree()) {
                continue;
            }
            int anchorpos = pt.getAnchorList().get(0);
            //                int anchorpos = Integer.parseInt(pt.getAnchorList().get(0));
            if (anchorpos < min) {
                min = anchorpos;
                if (first != null)
                //            others += " @ "+first.toString();
                {
                    first = pt;
                }
            }
            //      else{ 
            //         if (first !=null)
            //         others += " @ "+first.toString();
            //      }
        }
        if (first != null) {
            //      System.out.println(first+"\t"+others);
            localPredictedTrees.add(first);
        }
    } //*/
    if (localPredictedTrees.size() > 1) {
        PredictionStringTree predictionTree = localPredictedTrees.get(0);
        ArrayList<PredictionStringTree> newlist = new ArrayList<PredictionStringTree>();
        ArrayList<PredictionStringTree> removelist = new ArrayList<PredictionStringTree>();
        for (int i = 1; i < localPredictedTrees.size(); i++) {
            PredictionStringTree otherTree = localPredictedTrees.get(i);
            PredictionStringTree ct = combinePredTrees(predictionTree, otherTree,
                    predictionTreeNodeMap.values(), translations);//.copyPred();
            if (ct != null) {
                removelist.add(otherTree);
                removelist.add(predictionTree);
                newlist.remove(predictionTree);
                newlist.add(ct);
                predictionTree = ct;
            }
        }
        if (predictionTree.isAuxtree()) {
            localPredictedTrees.add(predictionTree);
        } else {
            localPredictedTrees.add(0, predictionTree);
        }
        localPredictedTrees.removeAll(removelist);
        //            might add too much here.
        for (PredictionStringTree npt : newlist) {
            if (predictionTree.isAuxtree()) {
                localPredictedTrees.add(npt);
            } else {
                localPredictedTrees.add(0, npt);
            }
        }
    }
    for (PredictionStringTree pst : localPredictedTrees) {
        pst.cutTail(predictionTreeNodeMap.values());
    }

    if (localPredictedTrees.size() > 1) {
        LogInfo.error("unaccounted case! combination of prediction trees; number of trees: " + sourcetreeno
                + " to connect leaf " + currentLeafNumber);
    }
    //        noOfSources.put(sourcetreeno + "", noOfSources.get(sourcetreeno + "").intValue() + 1);
    noOfSources.put(sourcetreeno, noOfSources.get(sourcetreeno) + 1);
    return localPredictedTrees;
}

From source file:it.eng.spagobi.commons.presentation.tags.ListTag.java

/**
 * Builds Table list columns, reading all request information.
 * /*  w  w w  .  j ava 2 s .c  o  m*/
 * @throws JspException If any Exception occurs.
 */

protected void makeColumns() throws JspException {

    SourceBean captionSB = (SourceBean) _layout.getAttribute("CAPTIONS");
    List captions = captionSB.getContainedSourceBeanAttributes();
    int numCaps = captions.size();
    String columnFilter = (String) _serviceRequest.getAttribute("columnFilter");
    String typeFilter = (String) _serviceRequest.getAttribute("typeFilter");
    String typeValueFilter = (String) _serviceRequest.getAttribute("typeValueFilter");
    String valueFilter = (String) _serviceRequest.getAttribute("valueFilter");

    _htmlStream.append("<TABLE class='list' style='width:100%;margin-top:1px'>\n");
    _htmlStream.append("   <TR>\n");

    for (int i = 0; i < _columns.size(); i++) {
        String nameColumn = (String) ((SourceBean) _columns.elementAt(i)).getAttribute("NAME");
        String labelColumnCode = (String) ((SourceBean) _columns.elementAt(i)).getAttribute("LABEL");
        String labelColumn = "";
        if (labelColumnCode != null)
            labelColumn = msgBuilder.getMessage(labelColumnCode, _bundle, httpRequest);
        else
            labelColumn = nameColumn;
        // if an horizontal-align is specified it is considered, otherwise the defualt is align='left'
        String align = (String) ((SourceBean) _columns.elementAt(i)).getAttribute("horizontal-align");
        String orderButtons = (String) ((SourceBean) _columns.elementAt(i)).getAttribute("order_buttons");
        boolean hideOrderButtons = false;
        if (orderButtons != null && orderButtons.equalsIgnoreCase("false"))
            hideOrderButtons = true;

        if (align == null || align.trim().equals(""))
            align = "left";
        //defines order url for dynamic ordering

        HashMap orderParamsMap = new HashMap();
        orderParamsMap.putAll(_providerUrlMap);
        orderParamsMap.put("FIELD_ORDER", nameColumn);
        orderParamsMap.put("TYPE_ORDER", " ASC");
        if (columnFilter != null && typeFilter != null && typeValueFilter != null) {
            orderParamsMap.put("columnFilter", columnFilter);
            orderParamsMap.put("typeFilter", typeFilter);
            orderParamsMap.put("typeValueFilter", typeValueFilter);
            orderParamsMap.put("valueFilter", valueFilter);
        }
        String orderUrlAsc = createUrl(orderParamsMap);
        orderUrlAsc = StringEscapeUtils.escapeHtml(orderUrlAsc);

        orderParamsMap.remove("TYPE_ORDER");
        orderParamsMap.put("TYPE_ORDER", " DESC");

        List _makeTitleButton = (List) _titleButton.elementAt(i);

        //orderParamsMap.put("MESSAGEDET",SpagoBIConstants.MESSAGE_ORDER_JOB_LIST);

        String orderUrlDesc = createUrl(orderParamsMap);
        orderUrlDesc = StringEscapeUtils.escapeHtml(orderUrlDesc);

        _htmlStream.append("<TD class='portlet-section-header' style='vertical-align:middle;text-align:" + align
                + ";'  >");
        _htmlStream.append(labelColumn);
        if (!hideOrderButtons) {
            if (!nameColumn.equalsIgnoreCase("INSTANCES")) {
                _htmlStream.append("   <A href=\"" + orderUrlAsc + "\">\n");
                _htmlStream.append("      <img  src='"
                        + urlBuilder.getResourceLinkByTheme(httpRequest, "/img/commons/ArrowUp.gif", currTheme)
                        + "'/>\n");
                _htmlStream.append("   </A>\n");
                _htmlStream.append("   <A href=\"" + orderUrlDesc + "\">\n");
                _htmlStream.append("      <img  src='" + urlBuilder.getResourceLinkByTheme(httpRequest,
                        "/img/commons/ArrowDown.gif", currTheme) + "'/>\n");
                _htmlStream.append("   </A>\n");
            }
        }

        if (_makeTitleButton.size() > 0) {

            _htmlStream.append(makeTitleButton(_makeTitleButton) + "\n");

        }

        _htmlStream.append("</TD>\n");
    }
    for (int i = 0; i < numCaps; i++) {
        _htmlStream.append("<TD class='portlet-section-header' style='text-align:center'>&nbsp;</TD>\n");
    }
    _htmlStream.append("</TR>\n");
}

From source file:org.mindswap.swoop.renderer.entity.NLVisitor.java

private void reconcileNegativeThingNodes(NLNode node) {
    HashMap links = node.getLinks();
    NLLink isNotALink = new NLLink("", NLVisitor.LINK_COMPLEMENT);

    // first: gather all the is-a links
    NLLink nonThingLink = null;//  www  . ja  v a2  s .  c om
    NLLink thingLink = null;
    boolean thingFound = false;
    Set isaLinks = new HashSet();
    for (Iterator iter = links.keySet().iterator(); iter.hasNext();) {
        NLLink link = (NLLink) iter.next();
        NLNode target = (NLNode) links.get(link);

        //System.out.println( "LINK: " + link.keyword + " (" + link.linkType + "), TARGET: " + target.keyword );

        if (link.equals(isNotALink)) {
            isaLinks.add(link);

            if (target.getKeyword().equals("Thing") || target.getKeyword().equals("thing")) {
                //System.out.println( "thing found" );
                thingFound = true;
                thingLink = link;
            } else {
                nonThingLink = link;
            }
        }
    }

    //System.out.println( "NEG-ISA's: " + isaLinks.size() + " " + thingFound);

    if (thingFound) {
        if (isaLinks.size() == 0) {
            // this should never happen 
        } else if (isaLinks.size() == 1) {
            // there is only one node and it is a thing node, so we can safely pull its links up
            NLNode thingNode = (NLNode) links.get(thingLink);

            HashMap tLinks = thingNode.getLinks();
            node.links.putAll(tLinks);
            links.remove(thingLink);
        } else {
            NLNode thingNode = (NLNode) links.get(thingLink);
            NLNode nonThingNode = (NLNode) links.get(nonThingLink);

            HashMap tLinks = thingNode.getLinks();
            HashMap ntLinks = nonThingNode.getLinks();
            ntLinks.putAll(tLinks);
            links.remove(thingLink);
        }
    }

    // Recurse
    for (Iterator iter = links.keySet().iterator(); iter.hasNext();) {
        NLLink link = (NLLink) iter.next();
        NLNode target = (NLNode) links.get(link);

        //System.out.println( "NEW LINK: " + link.keyword + " (" + link.linkType + "), TARGET: " + target.keyword );

        reconcileNegativeThingNodes(target);
    }
}

From source file:org.telegram.messenger.NotificationsController.java

@SuppressLint("InlinedApi")
private void showExtraNotifications(NotificationCompat.Builder notificationBuilder, boolean notifyAboutLast) {
    if (Build.VERSION.SDK_INT < 18) {
        return;/*ww w.j av  a2s.  com*/
    }

    ArrayList<Long> sortedDialogs = new ArrayList<>();
    HashMap<Long, ArrayList<MessageObject>> messagesByDialogs = new HashMap<>();
    for (int a = 0; a < pushMessages.size(); a++) {
        MessageObject messageObject = pushMessages.get(a);
        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> oldIdsWear = new HashMap<>();
    oldIdsWear.putAll(wearNotificationsIds);
    wearNotificationsIds.clear();

    HashMap<Long, Integer> oldIdsAuto = new HashMap<>();
    oldIdsAuto.putAll(autoNotificationsIds);
    autoNotificationsIds.clear();

    for (int b = 0; b < sortedDialogs.size(); b++) {
        long dialog_id = sortedDialogs.get(b);
        ArrayList<MessageObject> messageObjects = messagesByDialogs.get(dialog_id);
        int max_id = messageObjects.get(0).getId();
        int max_date = messageObjects.get(0).messageOwner.date;
        TLRPC.Chat chat = null;
        TLRPC.User user = null;
        String name;
        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 = UserObject.getUserName(user);
        }

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

        Integer notificationIdAuto = oldIdsAuto.get(dialog_id);
        if (notificationIdAuto == null) {
            notificationIdAuto = autoNotificationId++;
        } else {
            oldIdsAuto.remove(dialog_id);
        }

        NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder(
                name).setLatestTimestamp((long) max_date * 1000);

        Intent msgHeardIntent = new Intent();
        msgHeardIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
        msgHeardIntent.setAction("org.telegram.messenger.ACTION_MESSAGE_HEARD");
        msgHeardIntent.putExtra("dialog_id", dialog_id);
        msgHeardIntent.putExtra("max_id", max_id);
        PendingIntent msgHeardPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext,
                notificationIdAuto, msgHeardIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        unreadConvBuilder.setReadPendingIntent(msgHeardPendingIntent);

        NotificationCompat.Action wearReplyAction = null;

        if (!ChatObject.isChannel(chat)) {
            Intent msgReplyIntent = new Intent();
            msgReplyIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
            msgReplyIntent.setAction("org.telegram.messenger.ACTION_MESSAGE_REPLY");
            msgReplyIntent.putExtra("dialog_id", dialog_id);
            msgReplyIntent.putExtra("max_id", max_id);
            PendingIntent msgReplyPendingIntent = PendingIntent.getBroadcast(
                    ApplicationLoader.applicationContext, notificationIdAuto, msgReplyIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            RemoteInput remoteInputAuto = new RemoteInput.Builder(NotificationsController.EXTRA_VOICE_REPLY)
                    .setLabel(LocaleController.getString("Reply", R.string.Reply)).build();
            unreadConvBuilder.setReplyAction(msgReplyPendingIntent, remoteInputAuto);

            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,
                    notificationIdWear, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            RemoteInput remoteInputWear = 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);
            }
            wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon, replyToString,
                    replyPendingIntent).addRemoteInput(remoteInputWear).build();
        }

        String text = "";
        for (int a = messageObjects.size() - 1; a >= 0; a--) {
            MessageObject messageObject = messageObjects.get(a);
            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;

            unreadConvBuilder.addMessage(message);
        }

        TLRPC.FileLocation photoPath = null;
        if (chat != null) {
            if (chat.photo != null && chat.photo.photo_small != null && chat.photo.photo_small.volume_id != 0
                    && chat.photo.photo_small.local_id != 0) {
                photoPath = chat.photo.photo_small;
            }
        } else {
            if (user.photo != null && user.photo.photo_small != null && user.photo.photo_small.volume_id != 0
                    && user.photo.photo_small.local_id != 0) {
                photoPath = user.photo.photo_small;
            }
        }

        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.WearableExtender wearableExtender = new NotificationCompat.WearableExtender();
        if (wearReplyAction != null) {
            wearableExtender.addAction(wearReplyAction);
        }

        NotificationCompat.Builder builder = new NotificationCompat.Builder(
                ApplicationLoader.applicationContext).setContentTitle(name)
                        .setSmallIcon(R.drawable.notification).setGroup("messages").setContentText(text)
                        .setColor(0xff2ca5e0).setGroupSummary(false).setContentIntent(contentIntent)
                        .extend(wearableExtender)
                        .extend(new NotificationCompat.CarExtender()
                                .setUnreadConversation(unreadConvBuilder.build()))
                        .setCategory(NotificationCompat.CATEGORY_MESSAGE);
        if (photoPath != null) {
            BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50");
            if (img != null) {
                builder.setLargeIcon(img.getBitmap());
            }
        }

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

        notificationManager.notify(notificationIdWear, builder.build());
        wearNotificationsIds.put(dialog_id, notificationIdWear);
    }

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

From source file:org.mindswap.swoop.renderer.entity.NLVisitor.java

private void reconcileThingNodes(NLNode node) {
    HashMap links = node.getLinks();
    Set keys = links.keySet();/*from w  ww  .  j  a v a 2s  . c  o  m*/
    NLLink isaLink = new NLLink("", NLVisitor.LINK_SUBCLASS);

    // first: gather all the is-a links
    NLLink nonThingLink = null;
    NLLink thingLink = null;
    boolean thingFound = false;
    Set isaLinks = new HashSet();
    for (Iterator iter = new HashSet(keys).iterator(); iter.hasNext();) {
        // cycle through each link
        NLLink link = (NLLink) iter.next();
        NLNode target = (NLNode) links.get(link);

        System.out.println("LINK: " + link.keyword + " (" + link.linkType + "), TARGET: " + target.keyword);

        if (link.equals(isaLink)) {
            isaLinks.add(link);

            if (target.getKeyword().equals("Thing") || target.getKeyword().equals("thing")) {
                System.out.println("thing found");
                thingFound = true;
                thingLink = link;
            } else {
                nonThingLink = link;
            }
        }
    }

    System.out.println("ISA's: " + isaLinks.size() + " " + thingFound);

    if (thingFound) {
        if (isaLinks.size() == 0) {
            // this should never happen 
        } else if (isaLinks.size() == 1) {
            // there is only one node and it is a thing node, so we can safely pull its links up
            NLNode thingNode = (NLNode) links.get(thingLink);

            HashMap tLinks = thingNode.getLinks();
            node.links.putAll(tLinks);
            links.remove(thingLink);
        } else {
            NLNode thingNode = (NLNode) links.get(thingLink);
            NLNode nonThingNode = (NLNode) links.get(nonThingLink);

            HashMap tLinks = thingNode.getLinks();
            HashMap ntLinks = nonThingNode.getLinks();
            ntLinks.putAll(tLinks);
            links.remove(thingLink);
        }
    }

    // Recurse
    keys = links.keySet();
    for (Iterator iter = keys.iterator(); iter.hasNext();) {
        NLLink link = (NLLink) iter.next();
        NLNode target = (NLNode) links.get(link);

        System.out.println("NEW LINK: " + link.keyword + " (" + link.linkType + "), TARGET: " + target.keyword);

        reconcileThingNodes(target);
    }
}