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

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

Introduction

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

Prototype

public static MultiValueMap decorate(Map map, Factory collectionFactory) 

Source Link

Document

Creates a map which decorates the given map and creates the value collections using the supplied collectionFactory.

Usage

From source file:edu.harvard.med.screensaver.service.cherrypicks.CherryPickRequestPlateMapFilesBuilder.java

@SuppressWarnings("unchecked")
/**/*from  w w  w .  ja v  a2  s. c  o  m*/
 * Normally, we create 1 file per assay plate. However, in the case where an
 * assay plate is comprised of wells from library copy plates that have
 * different plate types, we need to generate a separate file for each source
 * plate type (i.e., the assay plate will be defined over multiple files).
 * @return a MultiMap that partitions the cherry picks by file,
 * ordering both the file names and cherry picks for each file.
 */
private MultiMap/*<String,SortedSet<CherryPick>>*/ buildCherryPickFiles(CherryPickRequest cherryPickRequest,
        Set<CherryPickAssayPlate> forPlates) {
    MultiMap assayPlate2SourcePlateTypes = getSourcePlateTypesForEachAssayPlate(cherryPickRequest);

    MultiMap result = MultiValueMap.decorate(new TreeMap<String, SortedSet<LabCherryPick>>(), new Factory() {
        public Object create() {
            return new TreeSet<LabCherryPick>(PlateMappingCherryPickComparator.getInstance());
        }
    });

    // HACK: transform set of CPAP into a set of IDs, for purpose of checking
    // set membership; we can't rely upon CPAP.equals(), since we're comparing
    // non-managed entities with managed entities, and therefore we do not have
    // the guarantee of instance equality for entities with the same ID
    Set<Serializable> forPlateIds = new HashSet<Serializable>(forPlates.size());
    for (CherryPickAssayPlate cpap : forPlates) {
        if (cpap.getEntityId() == null) {
            throw new IllegalArgumentException(
                    "all members of 'forPlates' must already be persisted and have a database identifier");
        }
        forPlateIds.add(cpap.getEntityId());
    }

    for (LabCherryPick cherryPick : cherryPickRequest.getLabCherryPicks()) {
        if (cherryPick.isAllocated()) {
            CherryPickAssayPlate assayPlate = cherryPick.getAssayPlate();
            if (forPlates == null || (assayPlate != null && forPlateIds.contains(assayPlate.getEntityId()))) {
                Set<PlateType> sourcePlateTypes = (Set<PlateType>) assayPlate2SourcePlateTypes
                        .get(assayPlate.getName());
                String fileName = makeFilename(cherryPick, sourcePlateTypes.size());
                result.put(fileName, cherryPick);
            }
        }
    }
    return result;
}

From source file:edu.harvard.med.screensaver.service.cherrypicks.CherryPickRequestPlateMapFilesBuilder.java

private MultiMap getSourcePlateTypesForEachAssayPlate(CherryPickRequest cherryPickRequest) {
    MultiMap assayPlateName2PlateTypes = MultiValueMap.decorate(new HashMap(), new Factory() {
        public Object create() {
            return new HashSet();
        }//from w ww .j  a  v a2  s.c o  m
    });

    for (LabCherryPick cherryPick : cherryPickRequest.getLabCherryPicks()) {
        if (cherryPick.isAllocated() && cherryPick.isMapped()) {
            assayPlateName2PlateTypes.put(cherryPick.getAssayPlate().getName(), cherryPick.getSourceCopy()
                    .findPlate(cherryPick.getSourceWell().getPlateNumber()).getPlateType());
        }
    }
    return assayPlateName2PlateTypes;
}

From source file:org.apache.cocoon.el.impl.objectmodel.ObjectModelImpl.java

public ObjectModelImpl() {
    singleValueMap = new HashMap();
    //FIXME: Not sure if this makes sense
    //super.map = UnmodifiableMap.decorate(singleValueMap);
    super.map = singleValueMap;
    localContexts = new ArrayStack();
    multiValueMap = MultiValueMap.decorate(new HashMap(), StackReversedIteration.class);
    multiValueMapForLocated = MultiValueMap.decorate(new HashMap(), StackReversedIteration.class);
}

From source file:org.jsmiparser.smi.SmiSymbolMapImpl.java

public SmiSymbolMapImpl(Class<T> symbolClass, Map<String, SmiModule> moduleMap) {
    super(MultiValueMap.decorate(new HashMap(), ArrayList.class));
    m_symbolClass = symbolClass;/*w  w w.  j a  va2s. c om*/
    m_moduleMap = moduleMap;
}

From source file:org.jsmiparser.util.multimap.GenMultiMap.java

public static <K, V> GenMultiMap<K, V> hashMap() {
    return new GenMultiMap<K, V>(MultiValueMap.decorate(new HashMap(), ArrayList.class));
}

From source file:org.jsmiparser.util.multimap.GenMultiMap.java

public static <K, V> GenMultiMap<K, V> treeMap() {
    return new GenMultiMap<K, V>(MultiValueMap.decorate(new TreeMap(), ArrayList.class));
}

From source file:org.lockss.servlet.SubscriptionManagement.java

/**
 * Maps publications by publisher./*from www  .  jav  a 2  s  .co  m*/
 * 
 * @param publications
 *          A List<SerialPublication> with the publications.
 * @return a MultiValueMap with the map in the desired format.
 */
private MultiValueMap orderPublicationsByPublisher(List<SerialPublication> publications) {
    final String DEBUG_HEADER = "orderPublicationsByPublisher(): ";
    if (log.isDebug2()) {
        if (publications != null) {
            log.debug2(DEBUG_HEADER + "publications.size() = " + publications.size());
        } else {
            log.debug2(DEBUG_HEADER + "publications is null");
        }
    }

    SerialPublication publication;
    String publisherName;
    String publicationName;

    // Initialize the resulting map.
    MultiValueMap publicationMap = MultiValueMap.decorate(new TreeMap<String, TreeSet<SerialPublication>>(),
            FactoryUtils
                    .prototypeFactory(new TreeSet<SerialPublication>(subManager.getPublicationComparator())));

    int publicationCount = 0;

    if (publications != null) {
        publicationCount = publications.size();
    }

    // Loop through all the publications.
    for (int i = 0; i < publicationCount; i++) {
        publication = publications.get(i);

        // The publisher name.
        publisherName = publication.getPublisherName();
        if (log.isDebug3())
            log.debug3(DEBUG_HEADER + "publisherName = " + publisherName);

        // Do nothing with this publication if it has no publisher.
        if (StringUtil.isNullString(publisherName)) {
            log.error("Publication '" + publication.getPublicationName()
                    + "' is unsubscribable because it has no publisher.");
            continue;
        }

        // The publication name.
        publicationName = publication.getPublicationName();
        if (log.isDebug3())
            log.debug3(DEBUG_HEADER + "publicationName = " + publicationName);

        // Initialize the unique name of the publication for display purposes.
        String uniqueName = publicationName;

        // Check whether the publication name displayed must be qualified with the
        // provider name to make it unique.
        if ((i > 0 && publicationName.equals(publications.get(i - 1).getPublicationName())
                && publisherName.equals(publications.get(i - 1).getPublisherName()))
                || (i < publicationCount - 1
                        && publicationName.equals(publications.get(i + 1).getPublicationName())
                        && publisherName.equals(publications.get(i + 1).getPublisherName()))) {
            // Yes: Create the unique name.
            if (!StringUtil.isNullString(publication.getProviderName())) {
                uniqueName += " [" + publication.getProviderName() + "]";
                if (log.isDebug3())
                    log.debug3(DEBUG_HEADER + "uniqueName = " + uniqueName);
            }
        }

        // Remember the publication unique name.
        publication.setUniqueName(uniqueName);

        // Add the publication to this publisher set of publications.
        publicationMap.put(publisherName, publication);
    }

    if (log.isDebug2())
        log.debug2(DEBUG_HEADER + "Done.");
    return publicationMap;
}

From source file:org.lockss.servlet.SubscriptionManagement.java

/**
 * Maps subscriptions by publisher.// w w w . j a v  a 2 s.co m
 * 
 * @param subscriptions
 *          A Collection<Subscription> with the subscriptions.
 * @return a MultiValueMap with the map in the desired format.
 */
private MultiValueMap orderSubscriptionsByPublisher(List<Subscription> subscriptions) {
    final String DEBUG_HEADER = "orderSubscriptionsByPublisher(): ";
    if (log.isDebug2()) {
        if (subscriptions != null) {
            log.debug2(DEBUG_HEADER + "subscriptions.size() = " + subscriptions.size());
        } else {
            log.debug2(DEBUG_HEADER + "subscriptions is null");
        }
    }

    Subscription subscription;
    SerialPublication publication;
    String publisherName;
    String publicationName;

    // Initialize the resulting map.
    MultiValueMap subscriptionMap = MultiValueMap.decorate(new TreeMap<String, TreeSet<Subscription>>(),
            FactoryUtils.prototypeFactory(
                    new TreeSet<Subscription>(subManager.getSubscriptionByPublicationComparator())));

    int subscriptionCount = 0;

    if (subscriptions != null) {
        subscriptionCount = subscriptions.size();
    }

    // Loop through all the subscriptions.
    for (int i = 0; i < subscriptionCount; i++) {
        subscription = subscriptions.get(i);

        // The publication.
        publication = subscription.getPublication();

        // The publisher name.
        publisherName = publication.getPublisherName();
        if (log.isDebug3())
            log.debug3(DEBUG_HEADER + "publisherName = " + publisherName);

        // Do nothing with this subscription if it has no publisher.
        if (StringUtil.isNullString(publisherName)) {
            log.error("Publication '" + publication.getPublicationName()
                    + "' is unsubscribable because it has no publisher.");
            continue;
        }

        // The publication name.
        publicationName = publication.getPublicationName();
        if (log.isDebug3())
            log.debug3(DEBUG_HEADER + "publicationName = " + publicationName);

        // Initialize the unique name of the publication for display purposes.
        String uniqueName = publicationName;

        // Check whether the publication name displayed must be qualified with the
        // provider name to make it unique.
        if ((i > 0 && publicationName.equals(subscriptions.get(i - 1).getPublication().getPublicationName())
                && publisherName.equals(subscriptions.get(i - 1).getPublication().getPublisherName()))
                || (i < subscriptionCount - 1
                        && publicationName
                                .equals(subscriptions.get(i + 1).getPublication().getPublicationName())
                        && publisherName
                                .equals(subscriptions.get(i + 1).getPublication().getPublisherName()))) {
            // Yes: Create the unique name.
            if (!StringUtil.isNullString(publication.getProviderName())) {
                uniqueName += " [" + publication.getProviderName() + "]";
                if (log.isDebug3())
                    log.debug3(DEBUG_HEADER + "uniqueName = " + uniqueName);
            }
        }

        // Remember the publication unique name.
        publication.setUniqueName(uniqueName);

        // Add the subscription to this publisher set of subscriptions.
        subscriptionMap.put(publisherName, subscription);
    }

    if (log.isDebug2())
        log.debug2(DEBUG_HEADER + "Done.");
    return subscriptionMap;
}

From source file:org.opencms.gwt.CmsVfsService.java

/**
 * @see org.opencms.gwt.shared.rpc.I_CmsVfsService#getBrokenLinks(java.lang.String)
 */// w  w w . j  a v a 2s  .co m
public CmsDeleteResourceBean getBrokenLinks(String sitePath) throws CmsRpcException {

    try {
        CmsResource entryResource = getCmsObject().readResource(sitePath, CmsResourceFilter.IGNORE_EXPIRATION);
        CmsDeleteResourceBean result = null;

        CmsListInfoBean info = null;
        List<CmsBrokenLinkBean> brokenLinks = null;

        CmsObject cms = getCmsObject();
        String resourceSitePath = cms.getSitePath(entryResource);

        try {
            ensureSession();

            List<CmsResource> descendants = new ArrayList<CmsResource>();
            HashSet<CmsUUID> deleteIds = new HashSet<CmsUUID>();

            descendants.add(entryResource);
            if (entryResource.isFolder()) {
                descendants.addAll(cms.readResources(resourceSitePath, CmsResourceFilter.IGNORE_EXPIRATION));
            }
            for (CmsResource deleteRes : descendants) {
                deleteIds.add(deleteRes.getStructureId());
            }
            MultiValueMap linkMap = MultiValueMap.decorate(new HashMap<Object, Object>(),
                    FactoryUtils.instantiateFactory(HashSet.class));
            for (CmsResource resource : descendants) {
                List<CmsResource> linkSources = getLinkSources(cms, resource, deleteIds);
                for (CmsResource source : linkSources) {
                    linkMap.put(resource, source);
                }
            }

            brokenLinks = getBrokenLinkBeans(linkMap);
            info = getPageInfo(entryResource);

            result = new CmsDeleteResourceBean(resourceSitePath, info, brokenLinks);

        } catch (Throwable e) {
            error(e);
        }
        return result;
    } catch (CmsException e) {
        error(e);
        return null; // will never be reached 
    }
}

From source file:org.springsource.ide.eclipse.boot.maven.analyzer.graph.DirectedGraph.java

public MultiValueMap createEdgeStore() {
    return MultiValueMap.decorate(new HashMap(), HashSet.class);
}