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:eu.europa.ec.fisheries.uvms.rules.service.bean.ExchangeRuleServiceBean.java

@Override
public boolean identificationRefExists(String refGuid, String... typeRefType) {
    Boolean faQueryIdentificationExists = false;
    try {//w  ww. ja v  a2s  .  c om
        LogRefIdByTypeExistsRequest existsRequest = new LogRefIdByTypeExistsRequest();
        for (String refType : typeRefType) {
            existsRequest.getRefTypes().add(EnumUtils.getEnum(TypeRefType.class, refType));
        }
        existsRequest.getRefTypes().removeAll(Collections.singleton(null));
        existsRequest.setRefGuid(refGuid);
        existsRequest.setMethod(ExchangeModuleMethod.LOG_REF_ID_BY_TYPE_EXISTS);
        String jaxBObjectToString = marshallJaxBObjectToString(existsRequest);
        String jmsMessageID = producer.sendDataSourceMessage(jaxBObjectToString, EXCHANGE);
        TextMessage message = consumer.getMessage(jmsMessageID, TextMessage.class);
        String text = message.getText();
        LogRefIdByTypeExistsResponse response = unMarshallMessage(text, LogRefIdByTypeExistsResponse.class);
        faQueryIdentificationExists = response.getRefGuid() != null;

    } catch (JAXBException | MessageException | JMSException e) {
        log.error(e.getMessage(), e);
    }
    return faQueryIdentificationExists;
}

From source file:info.magnolia.ui.api.app.registry.AppDescriptorRegistry.java

@Override
public void register(DefinitionProvider<AppDescriptor> provider) {
    super.register(provider);
    sendEvent(AppRegistryEventType.REGISTERED, Collections.singleton(provider.getMetadata()));
}

From source file:com.opengamma.financial.analytics.PositionOrTradeScalingFunction.java

@Override
public Set<ValueSpecification> getResults(final FunctionCompilationContext context,
        final ComputationTarget target) {
    return Collections.singleton(
            new ValueSpecification(_requirementName, target.toSpecification(), ValueProperties.all()));
}

From source file:edu.uci.ics.jung.algorithms.blockmodel.StructurallyEquivalent.java

public VertexPartition<V, E> transform(Graph<V, E> g) {
    Set<Pair<V>> vertex_pairs = getEquivalentPairs(g);

    Set<Set<V>> rv = new HashSet<Set<V>>();
    Map<V, Set<V>> intermediate = new HashMap<V, Set<V>>();
    for (Pair<V> p : vertex_pairs) {
        Set<V> res = intermediate.get(p.getFirst());
        if (res == null)
            res = intermediate.get(p.getSecond());
        if (res == null) // we haven't seen this one before
            res = new HashSet<V>();
        res.add(p.getFirst());//from   w w  w .ja  va2 s . c o  m
        res.add(p.getSecond());
        intermediate.put(p.getFirst(), res);
        intermediate.put(p.getSecond(), res);
    }
    rv.addAll(intermediate.values());

    // pick up the vertices which don't appear in intermediate; they are
    // singletons (equivalence classes of size 1)
    Collection<V> singletons = CollectionUtils.subtract(g.getVertices(), intermediate.keySet());
    for (V v : singletons) {
        Set<V> v_set = Collections.singleton(v);
        intermediate.put(v, v_set);
        rv.add(v_set);
    }

    return new VertexPartition<V, E>(g, intermediate, rv);
}

From source file:com.opengamma.financial.analytics.model.YieldCurveNodeSensitivitiesHelper.java

/**
 * @deprecated Use {@link #getInstrumentLabelledSensitivitiesForCurve(String, YieldCurveBundle, DoubleMatrix1D, InterpolatedYieldCurveSpecificationWithSecurities, ValueSpecification)}
 * instead//  ww  w  . j av a2s. co m
 * @param curve The curve
 * @param sensitivitiesForCurve The sensitivities for the curve
 * @param curveSpec The curve specification
 * @param resultSpec The resultSpecification
 * @return The computed value
 */
@Deprecated
public static Set<ComputedValue> getSensitivitiesForCurve(final YieldAndDiscountCurve curve,
        final DoubleMatrix1D sensitivitiesForCurve,
        final InterpolatedYieldCurveSpecificationWithSecurities curveSpec,
        final ValueSpecification resultSpec) {
    final int n = sensitivitiesForCurve.getNumberOfElements();
    if (!(curve instanceof YieldCurve)) {
        throw new IllegalArgumentException("Can only handle YieldCurve");
    }
    final Double[] keys = ((YieldCurve) curve).getCurve().getXData();
    final double[] values = new double[n];
    final Object[] labels = YieldCurveLabelGenerator.getLabels(curveSpec);
    DoubleLabelledMatrix1D labelledMatrix = new DoubleLabelledMatrix1D(keys, labels, values);
    for (int i = 0; i < n; i++) {
        labelledMatrix = (DoubleLabelledMatrix1D) labelledMatrix.add(keys[i], labels[i],
                sensitivitiesForCurve.getEntry(i));
    }
    return Collections.singleton(new ComputedValue(resultSpec, labelledMatrix));
}

From source file:com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil.java

public static AnalysisScope makeScope(SourceModule[] files, SingleClassLoaderFactory loaders, Language language)
        throws IOException {
    CAstAnalysisScope result = new CAstAnalysisScope(files, loaders, Collections.singleton(language));
    return result;
}

From source file:com.flipkart.flux.guice.module.AkkaModuleTest.java

@Test
public void testGetRouterConfigurations_shouldGetConcurrencyValueFromConfigFile() throws Exception {
    when(configuration.getProperty(/*  w  ww.  j a v  a 2s .c  o m*/
            "com.flipkart.flux.integration.SimpleWorkflow_simpleIntegerReturningTask.executionConcurrency"))
                    .thenReturn(5);
    when(deploymentUnit.getTaskConfiguration()).thenReturn(configuration);
    Map<String, DeploymentUnit> deploymentUnitsMap = new HashMap<String, DeploymentUnit>() {
        {
            put("DeploymentUnit1", deploymentUnit);
        }
    };
    int defaultNoOfActors = 10;

    Class simpleWorkflowClass = this.getClass().getClassLoader()
            .loadClass("com.flipkart.flux.integration.SimpleWorkflow");
    Map<String, Method> taskMethods = Collections.singletonMap(
            "com.flipkart.flux.integration.SimpleWorkflow_simpleIntegerReturningTask_com.flipkart.flux.integration.IntegerEvent_version1",
            simpleWorkflowClass.getMethod("simpleIntegerReturningTask"));
    when(deploymentUnit.getTaskMethods()).thenReturn(taskMethods);

    when(deploymentUnitManager.getAllDeploymentUnits()).thenReturn(Collections.singleton(deploymentUnit));

    assertThat(akkaModule.getRouterConfigs(deploymentUnitManager, new TaskRouterUtil(defaultNoOfActors)))
            .containsEntry("com.flipkart.flux.integration.SimpleWorkflow_simpleIntegerReturningTask", 5);
}

From source file:org.jasig.cas.web.view.Cas30ResponseView.java

@Override
protected void prepareMergedOutputModel(final Map<String, Object> model, final HttpServletRequest request,
        final HttpServletResponse response) throws Exception {

    super.prepareMergedOutputModel(model, request, response);

    final Service service = super.getServiceFrom(model);
    final RegisteredService registeredService = this.servicesManager.findServiceBy(service);

    final Map<String, Object> attributes = new HashMap<>(getPrincipalAttributesAsMultiValuedAttributes(model));
    attributes.put(CasProtocolConstants.VALIDATION_CAS_MODEL_ATTRIBUTE_NAME_AUTHENTICATION_DATE,
            Collections.singleton(getAuthenticationDate(model)));
    attributes.put(CasProtocolConstants.VALIDATION_CAS_MODEL_ATTRIBUTE_NAME_FROM_NEW_LOGIN,
            Collections.singleton(isAssertionBackedByNewLogin(model)));
    attributes.put(CasProtocolConstants.VALIDATION_REMEMBER_ME_ATTRIBUTE_NAME,
            Collections.singleton(isRememberMeAuthentication(model)));

    decideIfCredentialPasswordShouldBeReleasedAsAttribute(attributes, model, registeredService);
    decideIfProxyGrantingTicketShouldBeReleasedAsAttribute(attributes, model, registeredService);

    super.putIntoModel(model, CasProtocolConstants.VALIDATION_CAS_MODEL_ATTRIBUTE_NAME_ATTRIBUTES,
            this.casAttributeEncoder.encodeAttributes(attributes, getServiceFrom(model)));
}

From source file:io.pravega.test.integration.MultiReadersEndToEndTest.java

@Test(timeout = 30000)
public void testReadersEqualToSegments() throws Exception {
    runTest(Collections.singleton("teststream1"), 2, 2);
    runTestUsingMock(Collections.singleton("teststream1"), 2, 2);
}

From source file:com.threewks.thundr.gmail.GmailModule.java

@Override
public void configure(UpdatableInjectionContext injectionContext) {
    super.configure(injectionContext);

    // applications using this module must provide a 'host' config property (used to construct the callback URL)
    getRequiredProperty(injectionContext, "host");

    // applications using this module must provide an OAuth client id and secret
    String clientId = getRequiredProperty(injectionContext, "gmailOAuthClientId");
    String clientSecret = getRequiredProperty(injectionContext, "gmailOAuthClientSecret");

    // applications using this module must inject a DataStoreFactory and HttpTransport instance
    DataStoreFactory dataStoreFactory = getRequredDependency(injectionContext, DataStoreFactory.class);
    HttpTransport httpTransport = getRequredDependency(injectionContext, HttpTransport.class);

    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    Collection<String> scopes = Collections.singleton(GmailScopes.GMAIL_COMPOSE);

    try {//  ww  w. j  av  a2 s . c om
        GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jsonFactory,
                clientId, clientSecret, scopes).setDataStoreFactory(dataStoreFactory).build();
        injectionContext.inject(flow).named("gmailAuthorizationCodeFlow").as(GoogleAuthorizationCodeFlow.class);
    } catch (IOException e) {
        throw new ConfigurationException(e, "Couldn't initialize GoogleAuthorizationCodeFlow");
    }
}