Example usage for org.apache.commons.collections.map MultiValueMap get

List of usage examples for org.apache.commons.collections.map MultiValueMap get

Introduction

In this page you can find the example usage for org.apache.commons.collections.map MultiValueMap get.

Prototype

public Object get(Object key) 

Source Link

Usage

From source file:com.nextep.datadesigner.impl.Observable.java

/**
 * Dumps the listeners registration difference between the specified snapshot and the current
 * snaphsot.//from ww  w .  j  a  v a 2 s .c om
 * 
 * @param snapshot old snapshot
 */
@SuppressWarnings("unchecked")
public static void dumpSnapshotDelta(Object snapshot) {
    MultiValueMap initial = (MultiValueMap) snapshot;
    MultiValueMap current = (MultiValueMap) getSnapshot();
    log.debug(">>>> DUMPING OBSERVABLE SNAPSHOT DIFFERENCE <<<<");
    log.debug("Initial listeners: " + initial.totalSize());
    log.debug("Current listeners: " + current.totalSize());
    boolean showWarning = (initial.totalSize() != current.totalSize());
    // Removing all identical listener registrations
    for (Object o : initial.keySet()) {
        Collection<IEventListener> listeners = (Collection<IEventListener>) initial.get(o);
        for (IEventListener l : listeners) {
            current.remove(o, l);
        }
    }
    // Our current map now only contains differences, we dump it
    log.debug("Residual listeners: " + current.totalSize());
    for (Object o : current.keySet()) {
        String name = NameHelper.getQualifiedName(o);

        log.debug("- Observable <" + name + "> has:");
        Collection<IEventListener> listeners = (Collection<IEventListener>) current.get(o);
        for (IEventListener l : listeners) {
            log.debug("    * Listener <" + l.toString() + "> of class [" + l.getClass().getName() + "]");
        }
    }
    if (showWarning) {
        log.warn("Some listeners have not been released");
    }
    log.debug(">>>> DUMPING ENDS <<<<");
}

From source file:net.landora.animeinfo.notifications.NotificationViewer.java

public void loadNotifications() {
    List<AnimeNotification> notifications = AnimeDBA.getOutstandAnimeNotifications();

    Set<AnimeStub> animes = new HashSet<AnimeStub>();
    for (AnimeNotification notification : notifications) {
        animes.add(notification.getFile().getEpisode().getAnime());
    }//from   w  w w .j av a 2  s . co  m

    List<AnimeStub> sortedAnime = new ArrayList<AnimeStub>(animes);
    Collections.sort(sortedAnime, UIUtils.LEXICAL_SORTER);

    notificationsNode.removeAllChildren();

    for (AnimeStub anime : sortedAnime) {
        DefaultMutableTreeNode animeNode = new DefaultMutableTreeNode(anime);

        MultiValueMap map = new MultiValueMap();
        for (AnimeNotification notificaton : notifications) {
            if (notificaton.getFile().getEpisode().getAnime().equals(anime)) {
                map.put(notificaton.getFile().getEpisode(), notificaton);
            }
        }
        List<AnimeEpisode> episodes = new ArrayList<AnimeEpisode>(map.keySet());
        Collections.sort(episodes, UIUtils.LEXICAL_SORTER);

        for (AnimeEpisode episode : episodes) {
            DefaultMutableTreeNode episodeNode = new DefaultMutableTreeNode(episode);
            List<AnimeNotification> list = (List<AnimeNotification>) map.get(episode);
            Collections.sort(list, UIUtils.LEXICAL_SORTER);
            for (AnimeNotification notification : list) {
                episodeNode.add(new DefaultMutableTreeNode(notification, false));
            }
            animeNode.add(episodeNode);
        }
        notificationsNode.add(animeNode);
    }

    treeModel.nodeStructureChanged(notificationsNode);
}

From source file:com.nextep.designer.synch.ui.services.impl.SynchronizationUIService.java

@SuppressWarnings("unchecked")
private void selectProposal(IComparisonItem item, ComparedElement selection, boolean recurseDependentElements,
        MultiValueMap reverseDependencyMap) {
    if (item == null || item.getDifferenceType() == DifferenceType.EQUALS)
        return;//from   w  ww  . jav a2  s  .c  o  m
    final IReferenceable toSelectItem = selection.get(item);
    if (item.getMergeInfo().getMergeProposal() == toSelectItem) {
        return;
    }
    item.getMergeInfo().setMergeProposal(toSelectItem);
    for (IComparisonItem subItem : item.getSubItems()) {
        if (subItem.getDifferenceType() != DifferenceType.EQUALS) {
            selectProposal(subItem, selection, false);
        }
    }

    if (recurseDependentElements) {
        // When we unselect an element, we recursively unselect any element
        // which depend on it
        if (selection.isTarget()) {
            Collection<IReferencer> dependentRefs = (Collection<IReferencer>) reverseDependencyMap
                    .get(item.getReference());
            if (dependentRefs != null) {
                for (IReferencer r : dependentRefs) {
                    if (r instanceof IReferenceable) {
                        final IComparisonItem dependentItem = lastResult
                                .getComparisonItemFor(((IReferenceable) r).getReference());
                        selectProposal(dependentItem, selection, true);
                    }
                }
            }
        }
        // When we select an element, we recursively select elements whose
        // current element is
        // depending
        if (selection.isSource()) {
            if (item.getSource() instanceof IReferencer) {
                final IReferencer referencer = (IReferencer) item.getSource();
                Collection<IReference> dependencies = referencer.getReferenceDependencies();
                for (IReference d : dependencies) {
                    final IComparisonItem dependentItem = lastResult.getComparisonItemFor(d);
                    if (dependentItem != null
                            && dependentItem.getMergeInfo().getMergeProposal() != dependentItem.getSource()) {
                        selectProposal(dependentItem, selection, true);
                    }
                }
            }
        }
    }
    // Adjusting the dirty flag
    if (lastResult != null) {
        lastResult.setDirty(true);
    }
}

From source file:ch.algotrader.service.LookupServiceImpl.java

@SuppressWarnings("unchecked")
private Map<Date, Map<String, Object>> getNameValuePairsByDate(List<Measurement> measurements) {

    // group Measurements by date
    MultiValueMap measurementsByDate = new MultiValueMap();
    for (Measurement measurement : measurements) {
        measurementsByDate.put(measurement.getDateTime(), measurement);
    }// ww  w  .  j a v  a  2 s .  c o m

    // create a nameValuePair Map per date
    Map<Date, Map<String, Object>> nameValuePairsByDate = new HashMap<>();
    for (Date dt : (Set<Date>) measurementsByDate.keySet()) {

        Map<String, Object> nameValuePairs = new HashMap<>();
        for (Measurement measurement : (Collection<Measurement>) measurementsByDate.get(dt)) {
            nameValuePairs.put(measurement.getName(), measurement.getValue());
        }
        nameValuePairsByDate.put(dt, nameValuePairs);
    }

    return nameValuePairsByDate;
}

From source file:com.siblinks.ws.service.impl.VideoServiceImpl.java

/**
 * {@inheritDoc}/*from  ww w.  java 2  s . co m*/
 */
@RequestMapping(value = "/getVideoRecommend", method = RequestMethod.GET)
public ResponseEntity<Response> getVideoRecommend(@RequestParam final long studentId) {
    SimpleResponse response = null;
    try {
        String entityName = SibConstants.SqlMapper.SQL_VIDEO_RECOMMENDED_FOR_YOU;
        Object[] params = { studentId };
        List<Object> results = dao.readObjects(entityName, params);
        MultiValueMap multiValueMap = new MultiValueMap();
        ArrayList<Object> readObject = new ArrayList<>();
        if (results != null) {
            for (int i = 0; i < results.size(); i++) {
                Map obj = (Map) results.get(i);
                // names.add(obj.get("userid").toString());
                multiValueMap.put(obj.get("name"), obj);
            }
        }
        Object[] key = multiValueMap.keySet().toArray();
        for (int i = 0; i < multiValueMap.keySet().size(); i++) {
            readObject.add(multiValueMap.get(key[i]));
        }
        // System.out.println(multiValueMap);
        // Map<String, Object> readObject = new HashMap<>();
        // for (int i = 0; i < names.size(); i++) {
        // readObject.put(names.get(i), multiValueMap.get(names.get(i)));
        // }
        response = new SimpleResponse(SibConstants.SUCCESS, "video", "getVideoRecommend", readObject);
    } catch (Exception e) {
        e.printStackTrace();
        response = new SimpleResponse(SibConstants.FAILURE, "videos", "getVideoRecommend", e.getMessage());
    }
    return new ResponseEntity<Response>(response, HttpStatus.OK);
}

From source file:com.siblinks.ws.service.impl.VideoServiceImpl.java

/**
 *
 * @param subjectId/*from   w ww.j a v  a  2  s  .c o  m*/
 * @param userId
 * @param limit
 * @param offset
 * @return
 * @throws Exception
 */
private Map<String, Object> getVideosFactory(final String subjectId, final long userId, final String limit,
        final String offset) throws Exception {
    Map<String, Object> map = new HashMap<>();
    Object[] params = null;
    params = new Object[] { userId };

    CommonUtil cmUtils = CommonUtil.getInstance();
    Map<String, String> pageLimit = cmUtils.getOffset(limit, offset);
    Object subjectIdResult = dao.readObjects(SibConstants.SqlMapper.SQL_GET_SUBJECT_REG, params);
    List<Map<String, String>> objConvertor = (List<Map<String, String>>) subjectIdResult;
    String subjectIds = null;
    if (!CollectionUtils.isEmpty(objConvertor)) {
        for (Map<String, String> obj : objConvertor) {
            subjectIds = obj.get("defaultSubjectId");
        }

    }
    if (userId == -1) {
        // Get All Video By View If Don't Login
        if (subjectId.isEmpty() || subjectId.equals("-1")) {
            params = new Object[] { Integer.parseInt(pageLimit.get("limit")),
                    Integer.parseInt(pageLimit.get("offset")) };
            List<Object> resultDataRecommended = dao.readObjects(SibConstants.SqlMapper.SQL_GET_VIDEO_BY_VIEW,
                    params);
            List<Object> resultRecently = dao.readObjects(SibConstants.SqlMapper.SQL_GET_VIDEO_PLAYLIST_NEWEST,
                    params);
            map.put("recommended", resultDataRecommended);
            map.put("recently", resultRecently);
        } else {
            String childSubjectId = CommonUtil.getAllChildCategory("" + subjectId, getAllSubjectIdCategory());
            params = new Object[] { childSubjectId, Integer.parseInt(pageLimit.get("limit")),
                    Integer.parseInt(pageLimit.get("offset")) };
            List<Object> resultDataRecommended = dao
                    .readObjects(SibConstants.SqlMapper.SQL_GET_VIDEO_VIEW_BY_SUBJECT, params);
            map.put("recommended", resultDataRecommended);
            String clauseWhere = formatQueryGetVideoPlaylist("bySubjectNotLogin", userId, childSubjectId, limit,
                    offset);
            // params = new Object[] { childSubjectId, childSubjectId,
            // Integer.parseInt(pageLimit.get("limit")),
            // Integer.parseInt(pageLimit.get("offset")) };
            List<Object> resultRecently = dao.readObjectsWhereClause(
                    SibConstants.SqlMapper.VIDEO_PLAYLIST_NEWEST_BY_SUBJECT, clauseWhere, new Object[] {});
            map.put("recently", resultRecently);
        }
    } else if (subjectId.equals("-1")) {
        if (subjectIds != null && !StringUtils.isEmpty(subjectIds)) {
            params = new Object[] { Integer.parseInt(pageLimit.get("limit")),
                    Integer.parseInt(pageLimit.get("offset")) };
            String whereClause = "WHERE V.subjectId IN(" + subjectIds
                    + ") ORDER BY V.timeStamp DESC LIMIT ? OFFSET ?;";
            List<Object> resultDataRecommended = dao.readObjectsWhereClause(
                    SibConstants.SqlMapper.SQL_GET_VIDEO_BY_SUBJECT, whereClause, params);
            map.put("recommended", resultDataRecommended);
        } else {
            params = new Object[] { Integer.parseInt(pageLimit.get("limit")),
                    Integer.parseInt(pageLimit.get("offset")) };
            List<Object> resultDataRecommended = dao.readObjects(SibConstants.SqlMapper.SQL_GET_VIDEO_BY_VIEW,
                    params);
            map.put("recommended", resultDataRecommended);
        }

        params = new Object[] { Integer.parseInt(pageLimit.get("limit")),
                Integer.parseInt(pageLimit.get("offset")) };
        List<Object> resultRecently = dao.readObjects(SibConstants.SqlMapper.SQL_GET_VIDEO_PLAYLIST_NEWEST,
                params);
        map.put("recently", resultRecently);

        String entityName = SibConstants.SqlMapper.SQL_VIDEO_RECOMMENDED_FOR_YOU;
        params = new Object[] { userId };
        List<Object> results = dao.readObjects(entityName, params);
        MultiValueMap multiValueMap = new MultiValueMap();
        ArrayList<Object> readObject = new ArrayList<>();
        if (results != null) {
            for (int i = 0; i < results.size(); i++) {
                Map obj = (Map) results.get(i);
                multiValueMap.put(obj.get("userid"), obj);
            }
        }
        Object[] key = multiValueMap.keySet().toArray();
        for (int i = 0; i < multiValueMap.keySet().size(); i++) {
            readObject.add(multiValueMap.get(key[i]));
        }
        map.put("recommended_for_you", readObject);
    } else if (isValidatedForm(userId, subjectId)) {
        if (subjectIds != null && !StringUtils.isEmpty(subjectIds)) {
            // Check subjectId contains in subjects student registered
            // String[] subjects = subjectIds.split(",");
            // if (ArrayUtils.contains(subjects, subjectId)) {
            params = new Object[] { Integer.parseInt(pageLimit.get("limit")),
                    Integer.parseInt(pageLimit.get("offset")) };

            // Get child category by subjectId
            String childSubjectId = CommonUtil.getAllChildCategory("" + subjectId, getAllSubjectIdCategory());

            String whereClause = "WHERE V.subjectId IN (" + childSubjectId
                    + ") ORDER BY V.timeStamp DESC LIMIT ? OFFSET ?;";
            List<Object> resultDataRecommended = dao.readObjectsWhereClause(
                    SibConstants.SqlMapper.SQL_GET_VIDEO_BY_SUBJECT, whereClause, params);
            map.put("recommended", resultDataRecommended);
            params = new Object[] { userId, childSubjectId, userId, childSubjectId,
                    Integer.parseInt(pageLimit.get("limit")), Integer.parseInt(pageLimit.get("offset")) };

            String clauseWhere = formatQueryGetVideoPlaylist("bySubjectLogin", userId, childSubjectId, limit,
                    offset);
            List<Object> resultRecently = dao.readObjectsWhereClause(
                    SibConstants.SqlMapper.SQL_NEW_VIDEO_PLAYLIST_MENTOR_SUBSCRIBED_BY_SUB, clauseWhere,
                    new Object[] {});
            map.put("recently", resultRecently != null ? resultRecently : null);

            String entityName = SibConstants.SqlMapper.SQL_VIDEO_RECOMMENDED_FOR_YOU_WITH_SUB_ID;
            params = new Object[] { childSubjectId, userId };
            List<Object> results = dao.readObjects(entityName, params);
            MultiValueMap multiValueMap = new MultiValueMap();
            ArrayList<Object> readObject = new ArrayList<>();
            if (results != null) {
                for (int i = 0; i < results.size(); i++) {
                    Map obj = (Map) results.get(i);
                    multiValueMap.put(obj.get("userid"), obj);
                }
            }
            Object[] key = multiValueMap.keySet().toArray();
            for (int i = 0; i < multiValueMap.keySet().size(); i++) {
                readObject.add(multiValueMap.get(key[i]));
            }
            map.put("recommended_for_you", readObject);
            // }
            // }
        } else {
            params = new Object[] { subjectId, Integer.parseInt(pageLimit.get("limit")),
                    Integer.parseInt(pageLimit.get("offset")) };
            List<Object> resultDataRecommended = dao
                    .readObjects(SibConstants.SqlMapper.SQL_GET_VIDEO_VIEW_BY_SUBJECT, params);
            map.put("recommended", resultDataRecommended);
        }
    }

    return map;
}

From source file:org.apache.ambari.server.state.stack.StackRoleCommandOrder.java

/**
 * merge StackRoleCommandOrder content with parent
 *
 * @param parent parent StackRoleCommandOrder instance
 *//*from   www .  j  a va 2  s. com*/

public void merge(StackRoleCommandOrder parent) {

    HashMap<String, Object> mergedRoleCommandOrders = new HashMap<String, Object>();
    HashMap<String, Object> parentData = parent.getContent();

    List<String> keys = Arrays.asList(GENERAL_DEPS_KEY, GLUSTERFS_DEPS_KEY, NO_GLUSTERFS_DEPS_KEY,
            NAMENODE_HA_DEPS_KEY, RESOURCEMANAGER_HA_DEPS_KEY);

    for (String key : keys) {
        if (parentData.containsKey(key) && content.containsKey(key)) {
            Map<String, Object> result = new HashMap<String, Object>();
            Map<String, Object> parentProperties = (Map<String, Object>) parentData.get(key);
            Map<String, Object> childProperties = (Map<String, Object>) content.get(key);
            MultiValueMap childAndParentProperties = new MultiValueMap();
            childAndParentProperties.putAll(childProperties);
            childAndParentProperties.putAll(parentProperties);
            for (Object property : childAndParentProperties.keySet()) {
                List propertyValues = (List) childAndParentProperties.get(property);
                result.put((String) property, propertyValues.get(0));
            }
            mergedRoleCommandOrders.put(key, result);
        } else if (content.containsKey(key)) {
            mergedRoleCommandOrders.put(key, content.get(key));
        } else if (parentData.containsKey(key)) {
            mergedRoleCommandOrders.put(key, parentData.get(key));
        }
    }
    this.content = mergedRoleCommandOrders;
}

From source file:org.lockss.subscription.SubscriptionManager.java

/**
 * Provides the publications for which subscription decisions have not been
 * made yet./*from   w  w  w  .j  av  a2 s . c om*/
 * 
 * @return A List<SerialPublication> with the publications for which
 *         subscription decisions have not been made yet.
 * @throws DbException
 *           if any problem occurred accessing the database.
 */
public List<SerialPublication> getUndecidedPublications() throws DbException {
    final String DEBUG_HEADER = "getUndecidedPublications(): ";
    if (log.isDebug2())
        log.debug2(DEBUG_HEADER + "Starting...");

    List<SerialPublication> unsubscribedPublications = new ArrayList<SerialPublication>();

    // Get the existing subscriptions with publisher names.
    MultiValueMap subscriptionMap = mapSubscriptionsByPublisher(findAllSubscriptionsAndPublishers());

    Collection<Subscription> publisherSubscriptions = null;
    String publisherName;
    String titleName;
    SerialPublication publication;
    int publicationNumber = 1;

    // Loop through all the publishers.
    for (TdbPublisher publisher : TdbUtil.getTdb().getAllTdbPublishers().values()) {
        publisherName = publisher.getName();
        if (log.isDebug3())
            log.debug3(DEBUG_HEADER + "publisherName = " + publisherName);

        // Get the subscribed publications that belong to the publisher.
        publisherSubscriptions = (Collection<Subscription>) subscriptionMap.get(publisherName);
        if (log.isDebug3()) {
            if (publisherSubscriptions != null) {
                log.debug3(DEBUG_HEADER + "publisherSubscriptions.size() = " + publisherSubscriptions.size());
            } else {
                log.debug3(DEBUG_HEADER + "publisherSubscriptions is null.");
            }
        }

        // Loop through all the titles (subscribed or not) of the publisher.
        for (TdbTitle title : publisher.getTdbTitles()) {
            // Skip any titles that are not subscribable.
            if (!isSubscribable(title)) {
                continue;
            }

            titleName = title.getName();
            if (log.isDebug3())
                log.debug3(DEBUG_HEADER + "titleName = " + titleName);

            // Loop through all the title providers. 
            for (TdbProvider provider : title.getTdbProviders()) {
                String providerName = provider.getName();
                if (log.isDebug3())
                    log.debug3(DEBUG_HEADER + "providerName = " + providerName);

                // TODO: Replace with provider.getLid() when available.
                String providerLid = null;
                if (log.isDebug3())
                    log.debug3(DEBUG_HEADER + "providerLid = " + providerLid);

                // Check whether there is no subscription defined for this title and
                // this provider.
                if (publisherSubscriptions == null || !matchSubscriptionTitleAndProvider(publisherSubscriptions,
                        titleName, providerLid, providerName)) {
                    // Yes: Add the publication to the list of publications with no
                    // subscriptions.
                    publication = new SerialPublication();
                    publication.setPublicationNumber(publicationNumber++);
                    publication.setPublicationName(titleName);
                    publication.setProviderLid(providerLid);
                    publication.setProviderName(providerName);
                    publication.setPublisherName(publisherName);
                    publication.setPissn(title.getPrintIssn());
                    publication.setEissn(title.getEissn());
                    publication.setProprietaryIds(
                            new LinkedHashSet<String>(Arrays.asList(title.getProprietaryIds())));
                    publication.setTdbTitle(title);

                    if (log.isDebug3())
                        log.debug3(DEBUG_HEADER + "publication = " + publication);

                    unsubscribedPublications.add(normalizePublication(publication));
                }
            }
        }
    }

    if (log.isDebug3())
        log.debug3(DEBUG_HEADER + "unsubscribedPublications.size() = " + unsubscribedPublications.size());

    // Sort the publications for displaying purposes.
    Collections.sort(unsubscribedPublications, PUBLICATION_COMPARATOR);

    if (log.isDebug2())
        log.debug2(DEBUG_HEADER + "unsubscribedPublications.size() = " + unsubscribedPublications.size());
    return unsubscribedPublications;
}