Example usage for java.util Collections EMPTY_MAP

List of usage examples for java.util Collections EMPTY_MAP

Introduction

In this page you can find the example usage for java.util Collections EMPTY_MAP.

Prototype

Map EMPTY_MAP

To view the source code for java.util Collections EMPTY_MAP.

Click Source Link

Document

The empty map (immutable).

Usage

From source file:org.codehaus.groovy.grails.web.sitemesh.GrailsLayoutDecoratorMapper.java

private Decorator useExistingDecorator(HttpServletRequest request, String decoratorName, String decoratorPage) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Using decorator " + decoratorPage);
    }/*from   w  ww . j  a v a  2  s .  com*/

    Decorator d = new DefaultDecorator(decoratorName, decoratorPage, request.getRequestURI(),
            Collections.EMPTY_MAP);
    decoratorMap.put(decoratorName, d);
    return d;
}

From source file:de.hybris.platform.catalog.jalo.synchronization.ItemCopyCreatorTest.java

@Ignore("can not easily write test case for nested ItemCopyCreators ")
@Test/*from   w  w  w.  j  a  va  2 s.c o  m*/
public void testExceptionDuringCreationPartOfAttributes() throws JaloPriceFactoryException {
    final Currency eur = getOrCreateCurrency("eur");
    final Unit unit = ProductManager.getInstance().createUnit("p", "piece");
    final Set<Language> languages = jaloSession.getC2LManager().getAllLanguages();
    //determine other attribute
    final CatalogVersionSyncCopyContext ctx = new CatalogVersionSyncCopyContext(syncJob, syncCronJob, worker) {
        @Override
        SynchronizationPersistenceAdapter getPersistenceAdapter() {
            return new LegacySynchronizationPersistenceAdapter(this) {
                @Override
                public void update(final Item entity, final Map.Entry<String, Object> attribute)
                        throws SynchronizationPersistenceException {
                    //if other attribute
                    if ("europe1Prices".equalsIgnoreCase(attribute.getKey())) {
                        throw new IllegalStateException(
                                "expected exception during setting partof attributes  ...");
                    }
                    super.update(entity, attribute);
                }
            };
        }

        @Override
        protected Set<Language> getTargetLanguages() {
            return languages;
        }

    };

    final Product source = ProductManager.getInstance().createProduct(PRODUCT_FAILING_ON_CREATE);

    Europe1PriceFactory.getInstance().createPriceRow(source, null, null, null, 0, eur, unit, 1, false, null,
            99.99);

    final Product target = null;

    final Collection<String> whiteList = Arrays.asList(Product.CODE, "europe1Prices"/*
                                                                                     * , Product.NAME, Product.TYPE,
                                                                                     * Product.PK
                                                                                     */);
    final Collection<String> blackList = Arrays.asList(Product.MODIFIED_TIME, Product.CREATION_TIME);

    final Map<String, Object> presets = Collections.EMPTY_MAP;
    final ItemCopyCreator copyCreator = new ItemCopyCreator(ctx, null, source, target, blackList, whiteList,
            presets);

    final Product result = copyCreator.copy();

    Assert.assertEquals(0,
            Europe1PriceFactory.getInstance()
                    .getProductPriceRows(jaloSession.getSessionContext(), result,
                            Europe1PriceFactory.getInstance().getPPG(jaloSession.getSessionContext(), result))
                    .size());
    Assert.assertNull(
            catalogManager.getProductByCatalogVersion(syncJob.getTargetVersion(), PRODUCT_FAILING_ON_CREATE));
}

From source file:org.artificer.repository.test.RelationshipQueryTest.java

@Test
public void testGenericTargetAttributeQueries() throws Exception {
    XsdDocument xsdDoc = addXsdDoc();/* w  ww  .j av a 2s. co m*/
    WsdlDocument wsdlDoc1 = addWsdlDoc();
    WsdlDocument wsdlDoc2 = addWsdlDoc();
    WsdlDocument wsdlDoc3 = addWsdlDoc();

    Map<QName, String> otherAttributes = new HashMap<QName, String>();
    otherAttributes.put(QName.valueOf("FooKey"), "FooValue");
    ArtificerModelUtils.addGenericRelationship(xsdDoc, "relWithAttr", wsdlDoc1.getUuid(), Collections.EMPTY_MAP,
            otherAttributes);
    ArtificerModelUtils.addGenericRelationship(xsdDoc, "relWithAttr", wsdlDoc2.getUuid(), Collections.EMPTY_MAP,
            otherAttributes);
    Map<QName, String> otherAttributes2 = new HashMap<QName, String>();
    otherAttributes2.put(QName.valueOf("FooKey2"), "FooValue2");
    ArtificerModelUtils.addGenericRelationship(xsdDoc, "relWithAttr2", wsdlDoc3.getUuid(),
            Collections.EMPTY_MAP, otherAttributes2);

    xsdDoc = (XsdDocument) persistenceManager.updateArtifact(xsdDoc, ArtifactType.XsdDocument());

    // add custom properties only to one of the wsdls
    Property prop = new Property();
    prop.setPropertyName("FooProperty");
    prop.setPropertyValue("FooValue");
    wsdlDoc1.getProperty().add(prop);

    wsdlDoc1 = (WsdlDocument) persistenceManager.updateArtifact(wsdlDoc1, ArtifactType.WsdlDocument());

    ArtificerQuery query = queryManager
            .createQuery("/s-ramp/xsd/XsdDocument[relWithAttr[s-ramp:getTargetAttribute(., 'FooKey')]]");
    PagedResult<ArtifactSummary> artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(1, artifactSet.getTotalSize());

    query = queryManager.createQuery(
            "/s-ramp/xsd/XsdDocument[relWithAttr[s-ramp:getTargetAttribute(., 'FooKey') = 'FooValue']]");
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(1, artifactSet.getTotalSize());

    query = queryManager
            .createQuery("/s-ramp/xsd/XsdDocument[relWithAttr[s-ramp:getTargetAttribute(., 'InvalidKey')]]");
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(0, artifactSet.getTotalSize());

    query = queryManager.createQuery(
            "/s-ramp/xsd/XsdDocument[relWithAttr[s-ramp:getTargetAttribute(., 'FooKey') = 'FooValue' and @FooProperty = 'FooValue']]");
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(1, artifactSet.getTotalSize());

    query = queryManager.createQuery(
            "/s-ramp/xsd/XsdDocument[relWithAttr[s-ramp:getTargetAttribute(., 'FooKey') = 'FooValue' and @InvalidProperty]]");
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(0, artifactSet.getTotalSize());

    query = queryManager.createQuery(
            "/s-ramp/xsd/XsdDocument[relWithAttr[s-ramp:getTargetAttribute(., 'FooKey') = 'FooValue' or @FooProperty = 'FooValue']]");
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(1, artifactSet.getTotalSize());

    query = queryManager.createQuery(
            "/s-ramp/xsd/XsdDocument[relWithAttr[s-ramp:getTargetAttribute(., 'FooKey') = 'InvalidValue' or @FooProperty = 'FooValue']]");
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(1, artifactSet.getTotalSize());

    query = queryManager.createQuery(
            "/s-ramp/xsd/XsdDocument[relWithAttr[s-ramp:getTargetAttribute(., 'FooKey') = 'InvalidValue' or @FooProperty = 'FooValue']]");
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(1, artifactSet.getTotalSize());

    query = queryManager.createQuery("/s-ramp/xsd/XsdDocument[@uuid = ?]/relWithAttr2");
    query.setString(xsdDoc.getUuid());
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(1, artifactSet.getTotalSize());

    query = queryManager.createQuery(
            "/s-ramp/xsd/XsdDocument[@uuid = ?]/relWithAttr2[s-ramp:getTargetAttribute(., 'FooKey2')]");
    query.setString(xsdDoc.getUuid());
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(1, artifactSet.getTotalSize());
    Assert.assertEquals(wsdlDoc3.getUuid(), artifactSet.getResults().get(0).getUuid());

    query = queryManager.createQuery(
            "/s-ramp/xsd/XsdDocument[@uuid = ?]/relWithAttr2[s-ramp:getTargetAttribute(., 'FooKey2') = 'FooValue2']");
    query.setString(xsdDoc.getUuid());
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(1, artifactSet.getTotalSize());
    Assert.assertEquals(wsdlDoc3.getUuid(), artifactSet.getResults().get(0).getUuid());

    query = queryManager.createQuery(
            "/s-ramp/xsd/XsdDocument[@uuid = ?]/relWithAttr2[s-ramp:getTargetAttribute(., 'InvalidKey')]");
    query.setString(xsdDoc.getUuid());
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(0, artifactSet.getTotalSize());
}

From source file:org.alfresco.web.forms.xforms.XFormsProcessor.java

private static JSONObject loadConfig() {
    final ConfigService cfgService = Application.getConfigService(FacesContext.getCurrentInstance());
    final ConfigElement xformsConfig = cfgService.getGlobalConfig().getConfigElement("wcm").getChild("xforms");
    final List<ConfigElement> widgetConfig = xformsConfig.getChildren("widget");

    class WidgetConfigElement implements Comparable<WidgetConfigElement> {
        public final String xformsType;
        public final String xmlSchemaType;
        public final String appearance;
        public final String javascriptClassName;
        private final Map<String, String> params = new HashMap<String, String>();

        public WidgetConfigElement(final String xformsType, final String xmlSchemaType, final String appearance,
                final String javascriptClassName) {
            if (xformsType == null) {
                throw new NullPointerException();
            }//from  ww w.  j ava  2s.  c o m
            this.xformsType = xformsType;
            this.xmlSchemaType = xmlSchemaType;
            this.appearance = appearance;
            this.javascriptClassName = javascriptClassName;
        }

        public void addParam(final String k, final String v) {
            this.params.put(k, v);
        }

        public Map<String, String> getParams() {
            return (this.params == null ? (Map<String, String>) Collections.EMPTY_MAP
                    : Collections.unmodifiableMap(this.params));
        }

        public int compareTo(final WidgetConfigElement other) {
            int result = this.xformsType.compareTo(other.xformsType);
            if (result != 0) {
                return result;
            }

            result = this.compareAttribute(this.xmlSchemaType, other.xmlSchemaType);
            if (result != 0) {
                return result;
            }
            result = this.compareAttribute(this.appearance, other.appearance);
            if (result != 0) {
                return result;
            }

            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("widget definitions " + this + " and " + other + " may collide");
            }
            return 0;
        }

        public String toString() {
            return (this.getClass().getName() + "{" + "xformsType: " + this.xformsType + ", xmlSchemaType: "
                    + this.xmlSchemaType + ", appearance: " + this.appearance + ", javascriptClassName: "
                    + this.javascriptClassName + ", numParams: " + this.getParams().size() + "}");
        }

        private int compareAttribute(final String s1, final String s2) {
            return (s1 != null && s2 == null ? 1
                    : (s1 == null && s2 != null ? -1 : (s1 != null && s2 != null ? s1.compareTo(s2) : 0)));
        }
    }

    final TreeSet<WidgetConfigElement> widgetConfigs = new TreeSet<WidgetConfigElement>();
    for (final ConfigElement ce : widgetConfig) {
        final WidgetConfigElement wce = new WidgetConfigElement(ce.getAttribute("xforms-type"),
                ce.getAttribute("xml-schema-type"), ce.getAttribute("appearance"),
                ce.getAttribute("javascript-class-name"));

        final List<ConfigElement> params = ce.getChildren("param");
        for (final ConfigElement p : params) {
            wce.addParam(p.getAttribute("name"), p.getValue());
        }
        widgetConfigs.add(wce);
    }
    try {
        final JSONObject result = new JSONObject();
        for (final WidgetConfigElement wce : widgetConfigs) {
            if (!result.has(wce.xformsType)) {
                result.put(wce.xformsType, new JSONObject());
            }
            final JSONObject xformsTypeObject = result.getJSONObject(wce.xformsType);
            String s = wce.xmlSchemaType == null ? "*" : wce.xmlSchemaType;
            if (!xformsTypeObject.has(s)) {
                xformsTypeObject.put(s, new JSONObject());
            }
            final JSONObject schemaTypeObject = xformsTypeObject.getJSONObject(s);
            s = wce.appearance == null ? "*" : wce.appearance;
            final JSONObject o = new JSONObject();
            schemaTypeObject.put(s, o);
            o.put("className", wce.javascriptClassName);
            if (wce.getParams().size() != 0) {
                o.put("params", new JSONObject(wce.getParams()));
            }
        }
        return result;
    } catch (JSONException jsone) {
        LOGGER.error(jsone, jsone);
        return null;
    }
}

From source file:com.baifendian.swordfish.common.utils.graph.Graph.java

/**
 * ??/*from  ww w  .  java 2  s  .  c o  m*/
 *
 * @param key    id
 * @param edges 
 * @return
 */
private synchronized Map<VK, ED> getNeighborNodeAttr(VK key, final Map<VK, Map<VK, ED>> edges) {
    final Map<VK, ED> neighborEdges = edges.get(key);

    if (neighborEdges == null) {
        return Collections.EMPTY_MAP;
    }

    return neighborEdges;
}

From source file:org.beangle.model.persist.hibernate.CriterionUtils.java

private static Map<String, Object> converToMap(String prefix, Component component, MatchMode mode) {
    if (null == component) {
        return Collections.EMPTY_MAP;
    }//from   ww w . j av  a2 s.  co  m
    Map<String, Object> datas = CollectUtils.newHashMap();
    String attr = "";
    try {
        Map<String, Object> beanMap = PropertyUtils.describe(component);
        for (Iterator<String> iter = beanMap.keySet().iterator(); iter.hasNext();) {
            attr = iter.next();
            Object value = PropertyUtils.getProperty(component, attr);
            if (value == null) {
                continue;
            } else {
                addTrivialAttr(datas, prefix + "." + attr, value, mode);
            }
        }
        return datas;

    } catch (Exception e) {
        logger.error(
                "[converToMap]:error occur in converToMap of component" + component + "with attr named " + attr,
                e);

    }
    return Collections.EMPTY_MAP;
}

From source file:com.thoughtworks.go.server.service.ElasticAgentPluginService.java

public boolean shouldAssignWork(ElasticAgentMetadata metadata, String environment,
        ElasticProfile elasticProfile, ClusterProfile clusterProfile, JobIdentifier identifier) {
    Map<String, String> clusterProfileProperties = clusterProfile != null
            ? clusterProfile.getConfigurationAsMap(true)
            : Collections.EMPTY_MAP;
    GoPluginDescriptor pluginDescriptor = pluginManager.getPluginDescriptorFor(metadata.elasticPluginId());
    Map<String, String> configuration = elasticProfile.getConfigurationAsMap(true);

    if (!StringUtils.equals(clusterProfile.getPluginId(), metadata.elasticPluginId())) {
        return false;
    }/*from w  w  w  .jav a 2s . c om*/

    return elasticAgentPluginRegistry.shouldAssignWork(pluginDescriptor, toAgentMetadata(metadata), environment,
            configuration, clusterProfileProperties, identifier);
}

From source file:com.facebook.litho.DebugComponent.java

/**
 * @return Key-value mapping of this components state.
 *///from w  w  w. jav  a  2s.co  m
public Map<String, Object> getState() {
    final InternalNode node = mNode.get();
    final Component component = node == null || node.getComponents().isEmpty() ? null
            : node.getComponents().get(mComponentIndex);
    if (component == null) {
        return Collections.EMPTY_MAP;
    }

    final ComponentLifecycle.StateContainer stateContainer = component.getStateContainer();
    if (stateContainer == null) {
        return Collections.EMPTY_MAP;
    }

    final Map<String, Object> state = new ArrayMap<>();

    for (Field field : stateContainer.getClass().getDeclaredFields()) {
        try {
            field.setAccessible(true);
            if (field.getAnnotation(State.class) != null) {
                final Object value = field.get(stateContainer);
                if (!(value instanceof ComponentLifecycle)) {
                    state.put(field.getName(), value);
                }
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    return state;
}

From source file:org.apache.jackrabbit.core.state.ChildNodeEntries.java

/**
 * Ensures that the {@link #nameMap} and {@link #entries} map are
 * modifiable./*from   ww  w . ja  v  a 2s  .  c o  m*/
 */
@SuppressWarnings("unchecked")
private void ensureModifiable() {
    if (nameMap == Collections.EMPTY_MAP) {
        nameMap = new HashMap<Name, Object>();
        entries = new LinkedMap();
    } else if (shared) {
        entries = (LinkedMap) entries.clone();
        nameMap = new HashMap<Name, Object>(nameMap);
        for (Map.Entry<Name, Object> entry : nameMap.entrySet()) {
            Object value = entry.getValue();
            if (value instanceof List<?>) {
                entry.setValue(new ArrayList<ChildNodeEntry>((List<ChildNodeEntry>) value));
            }
        }
        shared = false;
    }
}

From source file:org.apache.cayenne.wocompat.EOModelHelper.java

/**
 * Loads EOFetchSpecification information and returns it as a map.
 *///from w w  w . jav  a2 s.c  o m
protected Map loadQueryIndex(String entityName) throws Exception {
    InputStream queryIn = null;

    // catch file open exceptions since not all entities have query
    // files....
    try {
        queryIn = openQueryStream(entityName);
    } catch (IOException ioex) {
        return Collections.EMPTY_MAP;
    }

    try {
        plistParser.ReInit(queryIn);
        return (Map) plistParser.propertyList();
    } finally {
        queryIn.close();
    }
}