Example usage for org.apache.commons.collections MapUtils lazyMap

List of usage examples for org.apache.commons.collections MapUtils lazyMap

Introduction

In this page you can find the example usage for org.apache.commons.collections MapUtils lazyMap.

Prototype

public static Map lazyMap(Map map, Transformer transformerFactory) 

Source Link

Document

Returns a "lazy" map whose values will be created on demand.

Usage

From source file:info.magnolia.cms.gui.controlx.impl.RenderKitImpl.java

/**
 * Init the layzy map. //from   ww w . ja  va2  s  .co m
 */
public RenderKitImpl() {
    renderers = MapUtils.lazyMap(new HashMap(), new Factory() {
        public Object create() {
            return new TemplatedRenderer();
        }
    });
}

From source file:org.codice.ddf.catalog.ui.config.ConfigurationApplication.java

public void setTypeNameMapping(String[] mappings) {
    if (mappings != null) {
        typeNameMapping = MapUtils.lazyMap(new TreeMap(), NEW_SET_FACTORY);

        for (String mappingValue : mappings) {
            // workaround for KARAF-1701
            for (String mapping : StringUtils.split(mappingValue, ",")) {
                String[] nameAndType = StringUtils.split(mapping, "=");
                if (nameAndType.length == 2) {
                    String displayName = StringUtils.strip(nameAndType[0]);
                    String type = StringUtils.strip(nameAndType[1]);
                    if (StringUtils.isNotBlank(displayName) && StringUtils.isNotBlank(type)) {
                        typeNameMapping.get(displayName).add(type);
                    }//  w  ww.j  av  a 2 s  .  c  o m
                } else {
                    LOGGER.info("Invalid type display name mapping format {}", mapping);
                }
            }
        }
    }
}

From source file:org.objectstyle.cayenne.access.util.SelectObserver.java

/**
 * Organizes a list of objects in a map keyed by the source related object for
 * the "incoming" relationship.//w w w  .  j  a v  a2s . c  om
 * 
 * @since 1.1
 */
static Map partitionBySource(ObjRelationship incoming, List prefetchedObjects) {
    Class sourceObjectClass = ((ObjEntity) incoming.getSourceEntity())
            .getJavaClass(Configuration.getResourceLoader());
    ObjRelationship reverseRelationship = incoming.getReverseRelationship();

    // Might be used later on... obtain and cast only once
    DbRelationship dbRelationship = (DbRelationship) incoming.getDbRelationships().get(0);

    Factory listFactory = new Factory() {
        public Object create() {
            return new ArrayList();
        }
    };

    Map toManyLists = MapUtils.lazyMap(new HashMap(), listFactory);
    Iterator destIterator = prefetchedObjects.iterator();
    while (destIterator.hasNext()) {
        DataObject destinationObject = (DataObject) destIterator.next();
        DataObject sourceObject = null;
        if (reverseRelationship != null) {
            sourceObject = (DataObject) destinationObject.readProperty(reverseRelationship.getName());
        } else {
            // Reverse relationship doesn't exist... match objects manually
            DataContext context = destinationObject.getDataContext();
            ObjectStore objectStore = context.getObjectStore();

            Map sourcePk = dbRelationship.srcPkSnapshotWithTargetSnapshot(
                    objectStore.getSnapshot(destinationObject.getObjectId(), context));

            // if object does not exist yet, don't create it
            // the reason for its absense is likely due to the absent intermediate prefetch
            sourceObject = objectStore.getObject(new ObjectId(sourceObjectClass, sourcePk));
        }

        // don't attach to hollow objects
        if (sourceObject != null && sourceObject.getPersistenceState() != PersistenceState.HOLLOW) {
            List relatedObjects = (List) toManyLists.get(sourceObject);
            relatedObjects.add(destinationObject);
        }
    }

    return toManyLists;
}