Example usage for org.apache.commons.collections Transformer Transformer

List of usage examples for org.apache.commons.collections Transformer Transformer

Introduction

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

Prototype

Transformer

Source Link

Usage

From source file:org.opencms.jsp.util.CmsDynamicFunctionBeanWrapper.java

/**
 * Gets the lazy map for accessing the various function formats.<p>
 *
 * @return a map which allows access to the various function formats
 *///ww  w. ja  v  a 2s  .c o m
public Object getFormatFor() {

    Transformer mapFunction = new Transformer() {

        public Object transform(Object param) {

            if (m_functionBean == null) {
                return new CmsDynamicFunctionFormatWrapper(m_cms, null);
            }
            int width = -1;
            String type = null;
            boolean isWidth = false;
            if (param instanceof Long) {
                width = (int) ((Long) param).longValue();
                isWidth = true;
            } else if (param instanceof Integer) {
                width = ((Integer) param).intValue();
                isWidth = true;
            } else {
                type = param.toString();
            }
            Format format;
            if (isWidth) {
                format = m_functionBean.getFormatForContainer(m_cms, "", width);
            } else {
                format = m_functionBean.getFormatForContainer(m_cms, type, -1);
            }
            CmsDynamicFunctionFormatWrapper wrapper = new CmsDynamicFunctionFormatWrapper(m_cms, format);
            return wrapper;
        }
    };
    return CmsCollectionsGenericWrapper.createLazyMap(mapFunction);
}

From source file:org.opencms.jsp.util.CmsJspCategoryAccessBean.java

/**
 * Returns a map from a category path to the wrapper of all the sub-categories of the category with the path given as key.
 *
 * @return a map from a category path to all sub-categories of the path's category.
 *///from w w  w  . j a va 2  s . c  om
public Map<String, CmsJspCategoryAccessBean> getSubCategories() {

    if (m_subCategories == null) {
        m_subCategories = CmsCollectionsGenericWrapper.createLazyMap(new Transformer() {

            @SuppressWarnings("synthetic-access")
            public Object transform(Object pathPrefix) {

                return new CmsJspCategoryAccessBean(m_categories, (String) pathPrefix);
            }

        });
    }
    return m_subCategories;
}

From source file:org.opencms.xml.containerpage.CmsContainerBean.java

/**
 * Returns a lazy initialized map that describes if a certain element if part of this container.<p>
 * /*from  w w  w  .j a  v  a 2s .  c  o  m*/
 * @return a lazy initialized map that describes if a certain element if part of this container
 */
public Map<CmsUUID, Boolean> getContainsElement() {

    if (m_containsElement == null) {
        m_containsElement = CmsCollectionsGenericWrapper.createLazyMap(new Transformer() {

            public Object transform(Object input) {

                return Boolean.valueOf(containsElement((CmsUUID) input));
            }
        });
    }
    return m_containsElement;
}

From source file:org.openconcerto.openoffice.ODSingleXMLDocument.java

/**
 * Detach the children of elem whose names already exist in the body.
 * /*from ww  w .j av a 2 s  .com*/
 * @param elem the elem to be trimmed.
 * @throws JDOMException if an error occurs.
 */
protected final void detachDuplicate(Element elem) throws JDOMException {
    final String singularName = elem.getName().substring(0, elem.getName().length() - 1);
    final List thisNames = getXPath("./text:" + singularName + "s/text:" + singularName + "/@text:name")
            .selectNodes(getChild("body"));
    org.apache.commons.collections.CollectionUtils.transform(thisNames, new Transformer() {
        public Object transform(Object obj) {
            return ((Attribute) obj).getValue();
        }
    });

    final Iterator iter = elem.getChildren().iterator();
    while (iter.hasNext()) {
        final Element decl = (Element) iter.next();
        if (thisNames.contains(decl.getAttributeValue("name", getVersion().getTEXT()))) {
            // on retire les dj existant
            iter.remove();
        }
    }
}

From source file:org.openconcerto.openoffice.ODSingleXMLDocument.java

private List<String> mergeUnique(ODXMLDocument doc, String topElem, String elemToMerge, String attrFQName,
        ElementTransformer addTransf) throws JDOMException {
    List<String> added = new ArrayList<String>();
    Element thisParent = this.getChild(topElem, true);

    XPath xp = this.getXPath("./" + elemToMerge + "/@" + attrFQName);

    // les styles de ce document
    List thisElemNames = xp.selectNodes(thisParent);
    // on transforme la liste d'attributs en liste de String
    org.apache.commons.collections.CollectionUtils.transform(thisElemNames, new Transformer() {
        public Object transform(Object obj) {
            return ((Attribute) obj).getValue();
        }//w  ww. ja  v  a 2 s.co m
    });

    // pour chaque style de l'autre document
    Iterator otherElemNames = xp.selectNodes(doc.getChild(topElem)).iterator();
    while (otherElemNames.hasNext()) {
        Attribute attr = (Attribute) otherElemNames.next();
        // on l'ajoute si non dj dedans
        if (!thisElemNames.contains(attr.getValue())) {
            thisParent.addContent(addTransf.transform((Element) attr.getParent().clone()));
            added.add(attr.getValue());
        }
    }

    return added;
}

From source file:org.openconcerto.sql.model.SQLResultSet.java

public SQLResultSet(ResultSet delegate) {
    this.delegate = delegate;
    this.helper = new ResultSetFullnameHelper(this);
    this.indexes = LazyMap.decorate(new HashMap(), new Transformer() {
        public Object transform(Object input) {
            final String colName = (String) input;
            try {
                return new Integer(doFindColumn(colName));
            } catch (SQLException e) {
                return e;
            }/*from www.j av a 2s. co  m*/
        }
    });
}

From source file:org.openengsb.core.services.internal.deployer.connector.ConnectorFile.java

private ImmutableMap<String, String> getFilteredEntries(Map<String, String> propertyMap, final String prefix) {
    @SuppressWarnings("unchecked")
    Map<String, String> transformedMap = MapUtils.transformedMap(new HashMap<String, String>(),
            new Transformer() {
                @Override//from   www  . j  a v  a 2s .  co m
                public Object transform(Object input) {
                    return ((String) input).replaceFirst(prefix + ".", "");
                }
            }, null);
    Map<String, String> filterEntries = Maps.filterEntries(propertyMap,
            new Predicate<Map.Entry<String, String>>() {
                @Override
                public boolean apply(Entry<String, String> input) {
                    return input.getKey().startsWith(prefix + ".");
                }
            });
    transformedMap.putAll(filterEntries);
    return ImmutableMap.copyOf(transformedMap);
}

From source file:org.openlmis.core.dto.FacilityFeedDTO.java

@SuppressWarnings("unchecked")
public FacilityFeedDTO(Facility facility, Facility parentFacility) {
    this.facility = facility;
    this.facilityType = facility.getFacilityType().getName();
    this.geographicZone = facility.getGeographicZone().getName();
    this.operatedBy = (facility.getOperatedBy() != null) ? facility.getOperatedBy().getText() : null;
    this.parentFacility = parentFacility != null ? parentFacility.getCode() : null;
    this.programsSupported = (List<String>) collect(facility.getSupportedPrograms(), new Transformer() {
        @Override//  w  w  w .  j a v  a  2s.  c  o  m
        public Object transform(Object o) {
            return ((ProgramSupported) o).getProgram().getCode();
        }
    });
}

From source file:org.openlmis.distribution.dto.DistributionRefrigeratorsDTO.java

public DistributionRefrigerators transform() {
    List<RefrigeratorReading> refrigeratorReadings = new ArrayList<>();
    final Long createdBy = this.createdBy;
    final Long modifiedBy = this.modifiedBy;
    if (readings != null) {
        refrigeratorReadings = (List) collect(readings, new Transformer() {
            @Override/*  w w w  . ja  v  a 2s .c o  m*/
            public Object transform(Object o) {
                RefrigeratorReadingDTO readingDTO = (RefrigeratorReadingDTO) o;
                readingDTO.setCreatedBy(createdBy);
                readingDTO.setModifiedBy(modifiedBy);
                RefrigeratorReading reading = readingDTO.transform();
                return reading;
            }
        });
    }

    return new DistributionRefrigerators(refrigeratorReadings);
}

From source file:org.openlmis.distribution.service.FacilityDistributionService.java

private List<RefrigeratorReading> getRefrigeratorReadings(final Long facilityId,
        List<Refrigerator> refrigerators) {
    return (List<RefrigeratorReading>) collect(select(refrigerators, new Predicate() {
        @Override//from   w ww . ja  v  a  2  s  .co  m
        public boolean evaluate(Object o) {
            return ((Refrigerator) o).getFacilityId().equals(facilityId);
        }
    }), new Transformer() {
        @Override
        public Object transform(Object o) {
            return new RefrigeratorReading((Refrigerator) o);
        }
    });
}