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:edu.internet2.middleware.psp.shibboleth.ChangeLogDataConnector.java

/**
 * If the change log entry is an attribute value assignment, return (a) the 'name' of the group or stem that the
 * attribute value was assigned to or (b) the 'memberSubjectId' of the member that the attribute value was assigned
 * to as well as (c) an attribute representing the value assignment. Otherwise, return an empty map.
 * // w ww .j a  va  2 s .  co  m
 * @param changeLogEntry the change log entry
 * @return (a) the 'name' of the group or stem that the attribute value was assigned to or (b) the 'memberSubjectId'
 *         of the member that the attribute value was assigned to as well as (c) an attribute representing the value
 *         assignment or null
 */
protected Map<String, BaseAttribute> buildAttributeFrameworkAttributes(ChangeLogEntry changeLogEntry) {

    ChangeLogType changeLogType = changeLogEntry.getChangeLogType();

    // return attributes if this is an attribute assign value change log entry
    if (!changeLogType.getChangeLogCategory().equals("attributeAssignValue")) {
        return Collections.EMPTY_MAP;
    }

    // get the attribute assign id
    String attributeAssignId = changeLogEntry.retrieveValueForLabel("attributeAssignId");
    if (attributeAssignId == null) {
        return Collections.EMPTY_MAP;
    }

    // get the attribute assignment
    AttributeAssign attributeAssign = AttributeAssignFinder.findById(attributeAssignId, false);
    if (attributeAssign == null) {
        return Collections.EMPTY_MAP;
    }

    // the attributes to return
    Map<String, BaseAttribute> attributes = new LinkedHashMap<String, BaseAttribute>();

    // return an attribute with name attributeDefNameName and value
    String attributeDefNameName = changeLogEntry.retrieveValueForLabel("attributeDefNameName");
    String value = changeLogEntry.retrieveValueForLabel("value");
    if (attributeDefNameName != null && value != null) {
        BasicAttribute<String> attribute = new BasicAttribute<String>();
        attribute.setId(attributeDefNameName);
        attribute.getValues().add(value);
        attributes.put(attribute.getId(), attribute);
    }

    // return an attributeAssignType attribute
    AttributeAssignType attributeAssignType = attributeAssign.getAttributeAssignType();
    if (attributeAssignType != null) {
        BasicAttribute<String> attribute = new BasicAttribute<String>();
        attribute.setId("attributeAssignType");
        attribute.getValues().add(attributeAssign.getAttributeAssignType().getName());
        attributes.put(attribute.getId(), attribute);
    }

    // if the attribute was assigned to a group, return the group name
    if (attributeAssign.getAttributeAssignType() == AttributeAssignType.group) {
        Group group = attributeAssign.getOwnerGroup();
        if (group != null) {
            BasicAttribute<String> attribute = new BasicAttribute<String>();
            attribute.setId("name");
            attribute.getValues().add(group.getName());
            attributes.put(attribute.getId(), attribute);
        }
    }

    // if the attribute was assigned to a stem, return the stem name
    if (attributeAssign.getAttributeAssignType() == AttributeAssignType.stem) {
        Stem stem = attributeAssign.getOwnerStem();
        if (stem != null) {
            BasicAttribute<String> attribute = new BasicAttribute<String>();
            attribute.setId("name");
            attribute.getValues().add(stem.getName());
            attributes.put(attribute.getId(), attribute);
        }
    }

    // if the attribute was assigned to a member, return the member subject id
    if (attributeAssign.getAttributeAssignType() == AttributeAssignType.member) {
        Member member = attributeAssign.getOwnerMember();
        if (member != null) {
            BasicAttribute<String> attribute = new BasicAttribute<String>();
            attribute.setId("memberSubjectId");
            attribute.getValues().add(member.getSubjectId());
            attributes.put(attribute.getId(), attribute);
        }
    }

    return attributes;
}

From source file:com.codebullets.sagalib.processing.SagaExecutionTaskTest.java

/**
 * <pre>/*from  w w w  .  j  av a 2  s . co m*/
 * Given => Parent execution context is provided
 * When  => task runs
 * Then  => Parent context set as part of execution context.
 * </pre>
 */
@Test
public void run_parentContextProvided_contextHasParentContext() {
    // given
    CurrentExecutionContext context = new SagaExecutionContext();
    ExecutionContext parentContext = mock(ExecutionContext.class);

    SagaEnvironment env = SagaEnvironment.create(timeoutManager, storage, createContextProvider(context),
            Sets.newHashSet(module), Sets.newHashSet(interceptor), instanceResolver);
    sut = new SagaExecutionTask(env, invoker, theMessage, Collections.EMPTY_MAP, parentContext);

    // when
    sut.run();

    // then
    assertThat("Expected header value to be part of context.", context.parentContext(),
            sameInstance(parentContext));
}

From source file:com.oneops.inductor.InductorTest.java

@Test
public void testWoExecutorConfigWithCloudCloudServiceEnvVarOverriding() {
    CmsWorkOrderSimple wo = gson.fromJson(remoteWo, CmsWorkOrderSimple.class);
    HashMap<String, String> m = new HashMap<>();
    m.put("rubygems", "compute_proxy");
    m.put("rubygemsbkp", "compute_proxy_backup");
    wo.getPayLoad().get(MANAGED_VIA).get(0).addCiAttribute("proxy_map", gson.toJson(m));
    wo.setServices(Collections.EMPTY_MAP);
    Config cfg = new Config();
    cfg.setCircuitDir("/opt/oneops/inductor/packer");
    cfg.setIpAttribute("public_ip");
    cfg.setEnv("");
    cfg.init();/*from   www .j  av a  2 s .co  m*/
    WorkOrderExecutor executor = new WorkOrderExecutor(cfg, mock(Semaphore.class));
    final String vars = executor.getProxyEnvVars(wo);

    assertTrue(vars.equals(
            "rubygems_proxy=compute_proxy rubygemsbkp_proxy=compute_proxy_backup ruby_proxy= DATACENTER_proxy=dal misc_proxy=http://repos.org/mirrored-assets/apache.mirrors.pair.com/ class=user pack=circuit-oneops-1"));
}

From source file:de.betterform.xml.config.DefaultConfig.java

/**
 * Returns the specified configuration value in a String.
 * //from  ww  w.  j  ava2  s  .c o m
 * @param configContext
 *            the context holding the configuration.
 * @param path
 *            the context relative path to the section.
 * @param nameAttribute
 *            the name of the attribute to load from
 * @return the specified configuration value in a String
 * @throws Exception
 *             if any error occured during configuration loading.
 */
private String load(NodeInfo configContext, String path, String nameAttribute) throws Exception {
    String value;

    Element element = (Element) XPathUtil
            .getAsNode(XPathCache.getInstance().evaluate(configContext, path, Collections.EMPTY_MAP, null), 1);
    value = element.getAttribute(nameAttribute);

    return value;
}

From source file:org.apache.sling.servlets.post.impl.operations.StreamingUploadOperationTest.java

@Test
public void testParts() throws RepositoryException, UnsupportedEncodingException {
    List<Modification> changes = new ArrayList<Modification>();
    PostResponse response = new AbstractPostResponse() {
        @Override/*from   ww  w  .  jav a2s .  c om*/
        protected void doSend(HttpServletResponse response) throws IOException {

        }

        @Override
        public void onChange(String type, String... arguments) {

        }

        @Override
        public String getPath() {
            return "/test/upload/location";
        }
    };

    List<Part> partsList = new ArrayList<Part>();
    partsList.add(new MockPart("test1.txt@Length", null, null, 0,
            new ByteArrayInputStream("8".getBytes("UTF-8")), Collections.EMPTY_MAP));
    partsList.add(new MockPart("test1.txt@Offset", null, null, 0,
            new ByteArrayInputStream("0".getBytes("UTF-8")), Collections.EMPTY_MAP));
    partsList.add(new MockPart("test1.txt", "text/plain", "test1bad.txt", 4,
            new ByteArrayInputStream("test".getBytes("UTF-8")), mapOf("Content-Length", "4")));
    partsList.add(new MockPart("test1.txt@Offset", null, null, 0,
            new ByteArrayInputStream("4".getBytes("UTF-8")), Collections.EMPTY_MAP));
    partsList.add(new MockPart("test1.txt", "text/plain", "test1bad.txt", 4,
            new ByteArrayInputStream("part".getBytes("UTF-8")), mapOf("Content-Length", "4")));
    partsList.add(new MockPart("*", "text/plain2", "test2.txt", 8,
            new ByteArrayInputStream("test1234".getBytes("UTF-8")), Collections.EMPTY_MAP));
    partsList.add(new MockPart("badformfield2", null, null, 0,
            new ByteArrayInputStream("testbadformfield2".getBytes("UTF-8")), Collections.EMPTY_MAP));
    final Iterator<Part> partsIterator = partsList.iterator();
    final Map<String, Resource> repository = new HashMap<String, Resource>();
    final ResourceResolver resourceResolver = new MockResourceResolver() {
        @Override
        public Resource getResource(String path) {

            Resource resource = repository.get(path);

            if (resource == null) {
                if ("/test/upload/location".equals(path)) {
                    resource = new MockRealResource(this, path, "sling:Folder");
                    repository.put(path, resource);
                    LOG.debug("Created {} ", path);

                }
            }
            LOG.debug("Resource {} is {} {}", path, resource, ResourceUtil.isSyntheticResource(resource));
            return resource;
        }

        @Override
        public Iterable<Resource> getChildren(Resource resource) {

            List<Resource> children = new ArrayList<Resource>();
            for (Map.Entry<String, Resource> e : repository.entrySet()) {
                if (isChild(resource.getPath(), e.getKey())) {
                    children.add(e.getValue());
                }
            }
            return children;
        }

        private boolean isChild(String path, String key) {
            if (key.length() > path.length() && key.startsWith(path)) {
                return !key.substring(path.length() + 1).contains("/");
            }
            return false;
        }

        @Override
        public Iterator<Resource> listChildren(Resource parent) {
            return getChildren(parent).iterator();
        }

        @Override
        public void delete(Resource resource) throws PersistenceException {

        }

        @Override
        public Resource create(Resource resource, String s, Map<String, Object> map)
                throws PersistenceException {
            Resource childResource = resource.getChild(s);
            if (childResource != null) {
                throw new IllegalArgumentException("Child " + s + " already exists ");
            }
            String resourceType = (String) map.get("sling:resourceType");
            if (resourceType == null) {
                resourceType = (String) map.get("jcr:primaryType");
            }
            if (resourceType == null) {
                LOG.warn("Resource type null for {} {} ", resource, resource.getPath() + "/" + s);
            }
            Resource newResource = new MockRealResource(this, resource.getPath() + "/" + s, resourceType, map);
            repository.put(newResource.getPath(), newResource);
            LOG.debug("Created Resource {} ", newResource.getPath());
            return newResource;
        }

        @Override
        public void revert() {

        }

        @Override
        public void commit() throws PersistenceException {
            LOG.debug("Committing");
            for (Map.Entry<String, Resource> e : repository.entrySet()) {
                LOG.debug("Committing {} ", e.getKey());
                Resource r = e.getValue();
                ModifiableValueMap vm = r.adaptTo(ModifiableValueMap.class);
                for (Map.Entry<String, Object> me : vm.entrySet()) {
                    if (me.getValue() instanceof InputStream) {
                        try {
                            String value = IOUtils.toString((InputStream) me.getValue());
                            LOG.debug("Converted {} {}  ", me.getKey(), value);
                            vm.put(me.getKey(), value);

                        } catch (IOException e1) {
                            throw new PersistenceException("Failed to commit input stream", e1);
                        }
                    }
                }
                LOG.debug("Converted {} ", vm);
            }
            LOG.debug("Comittted {} ", repository);

        }

        @Override
        public boolean hasChanges() {
            return false;
        }
    };

    SlingHttpServletRequest request = new MockSlingHttpServlet3Request(null, null, null, null, null) {
        @Override
        public Object getAttribute(String name) {
            if ("request-parts-iterator".equals(name)) {
                return partsIterator;
            }
            return super.getAttribute(name);
        }

        @Override
        public ResourceResolver getResourceResolver() {
            return resourceResolver;
        }
    };
    streamedUplodOperation.doRun(request, response, changes);

    {
        Resource r = repository.get("/test/upload/location/test1.txt");
        Assert.assertNotNull(r);
        ValueMap m = r.adaptTo(ValueMap.class);
        Assert.assertNotNull(m);

        Assert.assertEquals("nt:file", m.get("jcr:primaryType"));

    }
    {
        Resource r = repository.get("/test/upload/location/test1.txt/jcr:content");
        Assert.assertNotNull(r);
        ValueMap m = r.adaptTo(ValueMap.class);
        Assert.assertNotNull(m);

        Assert.assertEquals("nt:resource", m.get("jcr:primaryType"));
        Assert.assertTrue(m.get("jcr:lastModified") instanceof Calendar);
        Assert.assertEquals("text/plain", m.get("jcr:mimeType"));
        Assert.assertEquals("testpart", m.get("jcr:data"));

    }
    {
        Resource r = repository.get("/test/upload/location/test2.txt");
        Assert.assertNotNull(r);
        ValueMap m = r.adaptTo(ValueMap.class);
        Assert.assertNotNull(m);

        Assert.assertEquals("nt:file", m.get("jcr:primaryType"));

    }
    {
        Resource r = repository.get("/test/upload/location/test2.txt/jcr:content");
        Assert.assertNotNull(r);
        ValueMap m = r.adaptTo(ValueMap.class);
        Assert.assertNotNull(m);

        Assert.assertEquals("nt:resource", m.get("jcr:primaryType"));
        Assert.assertTrue(m.get("jcr:lastModified") instanceof Calendar);
        Assert.assertEquals("text/plain2", m.get("jcr:mimeType"));
        Assert.assertEquals("test1234", m.get("jcr:data"));
    }

}

From source file:org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.java

/**
 * Validates the given model.//from   w  ww  .  j a  v  a2  s  .  co  m
 *
 * There are two "layers" of validation
 * <ol>
 * <li>
 * errors when loading the resource. Usually these are syntax violations which irritate the parser. They will be
 * returned as a String.
 * <li>
 * all kinds of other errors (i.e. violations of validation checks) will only be logged, but not included in the
 * return value.
 * </ol>
 * <p>
 * Validation will be done on a separate resource, in order to keep the original one intact in case its content
 * needs to be removed because of syntactical errors.
 *
 * @param name
 * @param inputStream
 * @return error messages as a String if any syntactical error were found, <code>null</code> otherwise
 * @throws IOException if there was an error with the given {@link InputStream}, loading the resource from there
 */
private String validateModel(String name, InputStream inputStream) throws IOException {
    // use another resource for validation in order to keep the original one for emergency-removal in case of errors
    Resource resource = resourceSet.createResource(URI.createURI("tmp_" + name));
    try {
        resource.load(inputStream, Collections.EMPTY_MAP);
        StringBuilder criticalErrors = new StringBuilder();
        List<String> warnings = new LinkedList<>();

        if (resource != null && !resource.getContents().isEmpty()) {
            // Check for syntactical errors
            for (Diagnostic diagnostic : resource.getErrors()) {
                criticalErrors.append(MessageFormat.format("[{0},{1}]: {2}\n", diagnostic.getLine(),
                        diagnostic.getColumn(), diagnostic.getMessage()));
            }
            if (criticalErrors.length() > 0) {
                return criticalErrors.toString();
            }

            // Check for validation errors, but log them only
            org.eclipse.emf.common.util.Diagnostic diagnostic = Diagnostician.INSTANCE
                    .validate(resource.getContents().get(0));
            for (org.eclipse.emf.common.util.Diagnostic d : diagnostic.getChildren()) {
                warnings.add(d.getMessage());
            }
            if (warnings.size() > 0) {
                logger.info("Validation issues found in configuration model '{}', using it anyway:\n{}", name,
                        StringUtils.join(warnings, "\n"));
            }
        }
    } finally {
        resourceSet.getResources().remove(resource);
    }
    return null;
}

From source file:org.codehaus.groovy.grails.web.pages.GroovyPageMetaInfo.java

@SuppressWarnings("rawtypes")
public void setJspTags(Map jspTags) {
    this.jspTags = jspTags != null ? jspTags : Collections.EMPTY_MAP;
}

From source file:eu.openanalytics.rsb.RestJobsITCase.java

@Test
public void submitValidZipJob() throws Exception {
    final String applicationName = newTestApplicationName();
    @SuppressWarnings("unchecked")
    final Document resultDoc = doTestSubmitZipJob(applicationName, getTestData("r-job-sample.zip"),
            Collections.EMPTY_MAP);
    final String resultUri = getResultUri(resultDoc);
    ponderRetrieveAndValidateZipResult(resultUri);
}

From source file:org.codehaus.groovy.grails.plugins.couchdb.domain.CouchDomainClass.java

public Map getAssociationMap() {
    return Collections.EMPTY_MAP;
}

From source file:org.hyperic.hq.measurement.server.session.AvailabilityDataDAO.java

/**
 * @return {@link Map} of {@link Integer} to ({@link TreeSet} of
 *         {@link AvailabilityDataRLE}).
 *         <p>/*from   w  w w .  j a va 2 s.c o  m*/
 *         The {@link Map} key of {@link Integer} == {@link Measurement}
 *         .getId().
 *         <p>
 *         The {@link TreeSet}'s comparator sorts by
 *         {@link AvailabilityDataRLE}.getStartime().
 */
@SuppressWarnings("unchecked")
Map<Integer, TreeSet<AvailabilityDataRLE>> getHistoricalAvailMap(Integer[] mids, final long after,
        final boolean descending) {
    if (mids.length <= 0) {
        return Collections.EMPTY_MAP;
    }
    final Comparator<AvailabilityDataRLE> comparator = new Comparator<AvailabilityDataRLE>() {
        public int compare(AvailabilityDataRLE lhs, AvailabilityDataRLE rhs) {
            Long lhsStart = new Long(lhs.getStartime());
            Long rhsStart = new Long(rhs.getStartime());
            if (descending) {
                return rhsStart.compareTo(lhsStart);
            }
            return lhsStart.compareTo(rhsStart);
        }
    };
    StringBuilder sql = new StringBuilder().append("FROM AvailabilityDataRLE rle")
            .append(" WHERE rle.availabilityDataId.measurement in (:mids)");
    if (after > 0) {
        sql.append(" AND rle.endtime >= :endtime");
    }
    Query query = getSession().createQuery(sql.toString()).setParameterList("mids", mids, new IntegerType());
    if (after > 0) {
        query.setLong("endtime", after);
    }
    List<AvailabilityDataRLE> list = query.list();
    Map<Integer, TreeSet<AvailabilityDataRLE>> rtn = new HashMap<Integer, TreeSet<AvailabilityDataRLE>>(
            list.size());
    TreeSet<AvailabilityDataRLE> tmp;
    for (AvailabilityDataRLE rle : list) {
        Integer mId = rle.getMeasurement().getId();
        if (null == (tmp = rtn.get(mId))) {
            tmp = new TreeSet<AvailabilityDataRLE>(comparator);
            rtn.put(rle.getMeasurement().getId(), tmp);
        }
        tmp.add(rle);
    }
    for (int i = 0; i < mids.length; i++) {
        if (!rtn.containsKey(mids[i])) {
            rtn.put(mids[i], new TreeSet<AvailabilityDataRLE>(comparator));
        }
    }
    return rtn;
}