Example usage for org.apache.commons.collections FactoryUtils prototypeFactory

List of usage examples for org.apache.commons.collections FactoryUtils prototypeFactory

Introduction

In this page you can find the example usage for org.apache.commons.collections FactoryUtils prototypeFactory.

Prototype

public static Factory prototypeFactory(Object prototype) 

Source Link

Document

Creates a Factory that will return a clone of the same prototype object each time the factory is used.

Usage

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

/**
 * Maps publications by publisher.// ww  w  .  j a  va2 s  .  com
 * 
 * @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;
}