Example usage for java.util Collections singleton

List of usage examples for java.util Collections singleton

Introduction

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

Prototype

public static <T> Set<T> singleton(T o) 

Source Link

Document

Returns an immutable set containing only the specified object.

Usage

From source file:org.excalibur.discovery.service.p2p.DiscoveryServiceImpl.java

@Override
public void registerResource(ResourceDetails resource) throws Exception {
    checkNotNull(resource);/*from  w w  w .jav a 2 s  .co m*/
    this.registerResources(resource.getName(), Collections.singleton(resource));
}

From source file:ca.uhn.fhir.rest.server.interceptor.ExceptionHandlingInterceptor.java

public Object handleException(RequestDetails theRequestDetails, BaseServerResponseException theException)
        throws ServletException, IOException {
    IRestfulResponse response = theRequestDetails.getResponse();

    FhirContext ctx = theRequestDetails.getServer().getFhirContext();

    IBaseOperationOutcome oo = theException.getOperationOutcome();
    if (oo == null) {
        oo = createOperationOutcome(theException, ctx);
    }// w  w  w  . j  av a 2 s  .  c  om

    int statusCode = theException.getStatusCode();

    // Add headers associated with the specific error code
    if (theException.hasResponseHeaders()) {
        Map<String, List<String>> additional = theException.getResponseHeaders();
        for (Entry<String, List<String>> next : additional.entrySet()) {
            if (isNotBlank(next.getKey()) && next.getValue() != null) {
                String nextKey = next.getKey();
                for (String nextValue : next.getValue()) {
                    response.addHeader(nextKey, nextValue);
                }
            }
        }
    }

    String statusMessage = null;
    if (theException instanceof UnclassifiedServerFailureException) {
        String sm = theException.getMessage();
        if (isNotBlank(sm) && sm.indexOf('\n') == -1) {
            statusMessage = sm;
        }
    }

    return response.streamResponseAsResource(oo, true, Collections.singleton(SummaryEnum.FALSE), statusCode,
            statusMessage, false, false);

}

From source file:de.hybris.platform.maintenance.CleanupCronJobIntegrationTest.java

@Before
public void setup() {
    final ItemObjectResolver modelResolver = Registry.getApplicationContext().getBean("modelResolver",
            ItemObjectResolver.class);

    //the performable with all the needed services
    gmjp = new GenericMaintenanceJobPerformable();
    gmjp.setModelService(modelService);/*from   ww w.  j  a  v a  2s  .co  m*/
    gmjp.setFlexibleSearchService(flexibleSearchService);
    gmjp.setSessionService(sessionService);
    gmjp.setModelResolver(modelResolver);

    //the testsubject with the default values
    cuCJmi = new CleanupCronJobStrategy();
    cuCJmi.setModelService(modelService);
    cuCJmi.setTypeService(typeService);
    cuCJmi.setResult(Collections.singleton(CronJobResult.SUCCESS));
    cuCJmi.setStatus(Collections.singleton(CronJobStatus.FINISHED));
    cuCJmi.setExcludedCronJobCodes(Collections.EMPTY_SET);

    gmjp.setMaintenanceCleanupStrategy(cuCJmi);
    assertEquals("MaintenanceCleanupJob", gmjp.getType());

    final MaintenanceCleanupJobModel slayerJob = modelService.create(MaintenanceCleanupJobModel.class);
    slayerJob.setCode("cleanupCronJobsPerformable");
    slayerJob.setSpringId("cleanupCronJobsPerformable");

    modelService.save(slayerJob);
}

From source file:com.nesscomputing.cache.NamespacedCache.java

/**
 * Single key fetch.  Returns null if no entry exists
 * @see NessCache#get(String, java.util.Collection)
 *///from   ww w.ja  v  a  2 s .c  om
@CheckForNull
public byte[] get(String key) {
    return cache.get(namespace, Collections.singleton(key)).get(key);
}

From source file:com.opengamma.engine.test.MockFunction.java

public void addResult(ComputedValue result) {
    addResults(Collections.singleton(result));
}

From source file:org.jboss.spring.factory.NamedXmlApplicationContext.java

private void initializeNames(Resource resource) {
    try {/*from  ww  w . j  a v  a 2  s .co  m*/
        XPath xPath = XPathFactory.newInstance().newXPath();
        xPath.setNamespaceContext(new NamespaceContext() {
            @Override
            public String getNamespaceURI(String prefix) {
                return "http://www.springframework.org/schema/beans";
            }

            @Override
            public String getPrefix(String namespaceURI) {
                return "beans";
            }

            @Override
            public Iterator getPrefixes(String namespaceURI) {
                return Collections.singleton("beans").iterator();
            }
        });
        String expression = "/beans:beans/beans:description";
        InputSource inputSource = new InputSource(resource.getInputStream());
        String description = xPath.evaluate(expression, inputSource);
        if (description != null) {
            Matcher bfm = Pattern.compile(Constants.BEAN_FACTORY_ELEMENT).matcher(description);
            if (bfm.find()) {
                this.name = bfm.group(1);
            }
            Matcher pbfm = Pattern.compile(Constants.PARENT_BEAN_FACTORY_ELEMENT).matcher(description);
            if (pbfm.find()) {
                String parentName = pbfm.group(1);
                try {
                    this.getBeanFactory()
                            .setParentBeanFactory((BeanFactory) Util.lookup(parentName, BeanFactory.class));
                } catch (Exception e) {
                    throw new BeanDefinitionStoreException(
                            "Failure during parent bean factory JNDI lookup: " + parentName, e);
                }
            }
        }
        if (this.name == null || "".equals(StringUtils.trimAllWhitespace(this.name))) {
            this.name = this.defaultName;
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:ch.rasc.wampspring.user.UserEventMessenger.java

/**
 * Send an {@link EventMessage} to every client that is currently subscribed to the
 * provided topicURI except the one provided with the excludeUser parameter.
 *
 * @param topicURI the name of the topic
 * @param event the payload of the {@link EventMessage}
 * @param user the user that will be excluded
 *//*  www .j a v  a 2 s .co  m*/
public void sendToAllExceptUser(String topicURI, Object event, String excludeUser) {
    sendToAllExceptUsers(topicURI, event, Collections.singleton(excludeUser));
}

From source file:me.smoe.adar.utils.cam.o.mapping.CAMatcher.java

private Map<Long, Integer> matcherCA(String cases, Type type, boolean needParticiple) throws Exception {
    List<CAMCasesScore> casesScores = new ArrayList<>();
    for (String word : needParticiple ? SentenceAnalyzer.analyzer(cases) : Collections.singleton(cases)) {
        casesScores.addAll(findByTypeAndWord(type.getValue(), word));
    }/*from  w w  w.  ja v a 2s .c  o  m*/

    Map<Long, Integer> caScoreMapping = new HashMap<>();
    for (CAMCasesScore casesScore : casesScores) {
        Long ca = casesScore.getCa();
        Integer score = casesScore.getScore();

        if (caScoreMapping.containsKey(ca)) {
            score = calcCumulateScore(caScoreMapping.get(ca), score);
        }

        caScoreMapping.put(ca, score);
    }

    return caScoreMapping;
}

From source file:com.xtructure.xutil.coll.UTestMapBuilder.java

public void putAllTransformBehavesAsExpected() {
    MapBuilder<String, String> mb = new MapBuilder<String, String>();
    assertThat("", //
            mb.newInstance(), isEmpty());
    MapBuilder<String, String> got = mb.putAll(IdentityTransform.<String>getInstance(),
            Collections.singleton("one"));
    assertThat("", //
            got, isSameAs(mb));//ww w  .  j a v  a2 s .c o  m
    assertThat("", //
            mb.newInstance(), hasSize(1), containsKey("one"), containsValue("one"));
}

From source file:com.github.achatain.nopasswordauthentication.utils.FakeHttpServletRequest.java

public Enumeration<Locale> getLocales() {
    return Collections.enumeration(Collections.singleton(Locale.US));
}