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:com.opengamma.financial.analytics.model.equity.varianceswap.EquityForwardFromSpotAndYieldCurveFunction.java

@Override
public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs,
        final ComputationTarget target, final Set<ValueRequirement> desiredValues) {
    final ValueRequirement desiredValue = Iterables.getOnlyElement(desiredValues);
    final String curveName = desiredValue.getConstraint(ValuePropertyNames.CURVE);
    final String curveCalculationConfig = desiredValue
            .getConstraint(ValuePropertyNames.CURVE_CALCULATION_CONFIG);
    // 1. Get the expiry _time_ from the trade
    final EquityVarianceSwapSecurity security = (EquityVarianceSwapSecurity) target.getSecurity();
    final double expiry = TimeCalculator.getTimeBetween(ZonedDateTime.now(executionContext.getValuationClock()),
            security.getLastObservationDate());

    // 2. Get the discount curve and spot value
    final Object discountObject = inputs
            .getValue(getDiscountRequirement(security, curveName, curveCalculationConfig));
    if (discountObject == null) {
        throw new OpenGammaRuntimeException("Could not get Discount Curve");
    }//ww w .  ja  v a2 s.c  o m
    final YieldAndDiscountCurve discountCurve = (YieldAndDiscountCurve) discountObject;

    final Object spotObject = inputs.getValue(getSpotRequirement(security));
    if (spotObject == null) {
        throw new OpenGammaRuntimeException("Could not get Underlying's Spot value");
    }
    final double spot = (Double) spotObject;

    // 3. Compute the forward
    final double discountFactor = discountCurve.getDiscountFactor(expiry);
    Validate.isTrue(discountFactor != 0,
            "The discount curve has returned a zero value for a discount bond. Check rates.");
    final double forward = spot / discountFactor;

    final ValueSpecification valueSpec = getValueSpecification(target.toSpecification(), security);
    return Collections.singleton(new ComputedValue(valueSpec, forward));
}

From source file:org.alfresco.bm.test.Test.java

/**
 * @param testDAO               data persistence
 * @param logService            logging//from  w  w w . ja  v a 2s . c o  m
 * @param release               the software release name of this test
 * @param schema                the property schema version
 * @param description           the test description
 * @param contextPath           the context under which the application was launched
 * @param defaults              provider of all the test defaults
 */
public Test(MongoTestDAO testDAO, LogService logService, String release, Integer schema, String description,
        String contextPath, TestDefaults defaults) {
    this.testDAO = testDAO;
    this.logService = logService;
    this.release = release;
    this.schema = schema;
    this.description = description;
    this.contextPath = contextPath;
    this.defaults = defaults;
    this.systemCapabilities = Collections.singleton(CAPABILITY_JAVA6);
    this.refreshRegistrationTask = new TestDriverPingTask();
    this.testRunPingTask = new TestRunPingTask();

    // This will only be valid if driver registration succeeds
    this.driverId = null;
}

From source file:org.apereo.services.persondir.support.rule.StringFormatAttributeRule.java

@Override
public Set<IPersonAttributes> evaluate(final Map<String, List<Object>> userInfo) {

    // Assertions.
    if (userInfo == null) {
        final String msg = "Argument 'userInfo' cannot be null.";
        throw new IllegalArgumentException(msg);
    }/*from www.  j a va 2  s .co  m*/
    if (!appliesTo(userInfo)) {
        final String msg = "May not evaluate.  This rule does not apply.";
        throw new IllegalArgumentException(msg);
    }

    final Object[] args = new Object[formatArguments.size()];
    for (int i = 0; i < formatArguments.size(); i++) {
        final String key = formatArguments.get(i);
        final List<Object> values = userInfo.get(key);
        args[i] = values.isEmpty() ? null : values.get(0);
    }

    final String outputAttributeValue = String.format(this.formatString, args);

    final Map<String, List<Object>> rslt = new HashMap<>();
    rslt.put(this.outputAttribute, Arrays.asList(new Object[] { outputAttributeValue }));

    final String username = this.usernameAttributeProvider.getUsernameFromQuery(userInfo);
    final IPersonAttributes person = new NamedPersonImpl(username, rslt);
    return Collections.singleton(person);

}

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

@Test
public void testGetRouterConfigurations_shouldUseDefaultConcurrentValue() throws Exception {
    when(deploymentUnit.getTaskConfiguration()).thenReturn(configuration);
    Map<String, DeploymentUnit> deploymentUnitsMap = new HashMap<String, DeploymentUnit>() {
        {/*from   www .j  ava 2  s. c om*/
            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",
                    defaultNoOfActors);
}

From source file:com._4dconcept.springframework.data.marklogic.repository.config.MarklogicRepositoryConfigurationExtension.java

@Override
protected Collection<Class<?>> getIdentifyingTypes() {
    return Collections.singleton(MarklogicRepository.class);
}

From source file:be.makercafe.apps.makerbench.editors.XMLEditor.java

private StyleSpans<Collection<String>> computeHighlighting(String text) {
    Matcher matcher = XML_TAG.matcher(text);
    int lastKwEnd = 0;
    StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
    while (matcher.find()) {
        spansBuilder.add(Collections.emptyList(), matcher.start() - lastKwEnd);
        if (matcher.group("COMMENT") != null) {
            spansBuilder.add(Collections.singleton("comment"), matcher.end() - matcher.start());
        } else {/*from   w  w w.  j  a v  a 2  s . co  m*/
            if (matcher.group("ELEMENT") != null) {
                String attributesText = matcher.group(GROUP_ATTRIBUTES_SECTION);
                spansBuilder.add(Collections.singleton("tagmark"),
                        matcher.end(GROUP_OPEN_BRACKET) - matcher.start(GROUP_OPEN_BRACKET));
                spansBuilder.add(Collections.singleton("anytag"),
                        matcher.end(GROUP_ELEMENT_NAME) - matcher.end(GROUP_OPEN_BRACKET));
                if (!attributesText.isEmpty()) {
                    lastKwEnd = 0;
                    Matcher amatcher = ATTRIBUTES.matcher(attributesText);
                    while (amatcher.find()) {
                        spansBuilder.add(Collections.emptyList(), amatcher.start() - lastKwEnd);
                        spansBuilder.add(Collections.singleton("attribute"),
                                amatcher.end(GROUP_ATTRIBUTE_NAME) - amatcher.start(GROUP_ATTRIBUTE_NAME));
                        spansBuilder.add(Collections.singleton("tagmark"),
                                amatcher.end(GROUP_EQUAL_SYMBOL) - amatcher.end(GROUP_ATTRIBUTE_NAME));
                        spansBuilder.add(Collections.singleton("avalue"),
                                amatcher.end(GROUP_ATTRIBUTE_VALUE) - amatcher.end(GROUP_EQUAL_SYMBOL));
                        lastKwEnd = amatcher.end();
                    }
                    if (attributesText.length() > lastKwEnd)
                        spansBuilder.add(Collections.emptyList(), attributesText.length() - lastKwEnd);
                }
                lastKwEnd = matcher.end(GROUP_ATTRIBUTES_SECTION);
                spansBuilder.add(Collections.singleton("tagmark"),
                        matcher.end(GROUP_CLOSE_BRACKET) - lastKwEnd);
            }
        }
        lastKwEnd = matcher.end();
    }
    spansBuilder.add(Collections.emptyList(), text.length() - lastKwEnd);
    return spansBuilder.create();
}

From source file:com.github.mjdetullio.jenkins.plugins.multibranch.SyncBranchesTrigger.java

/**
 * {@inheritDoc}/*from   www .j a v  a  2s . c o  m*/
 */
@Override
public Collection<? extends Action> getProjectActions() {
    return Collections.singleton(new SyncBranchesAction());
}

From source file:com.netflix.nicobar.core.module.ScriptModuleLoaderTest.java

@Test
public void testLoadArchive() throws Exception {
    Path jarPath = CoreTestResourceUtil.getResourceAsPath(TEST_MODULE_SPEC_JAR);

    ScriptArchive scriptArchive = new JarScriptArchive.Builder(jarPath).build();
    when(MOCK_COMPILER.shouldCompile(Mockito.eq(scriptArchive))).thenReturn(true);
    when(MOCK_COMPILER.compile(Mockito.eq(scriptArchive), Mockito.any(JBossModuleClassLoader.class),
            Mockito.any(Path.class))).thenReturn(Collections.<Class<?>>emptySet());
    ScriptModuleLoader moduleLoader = new ScriptModuleLoader.Builder()
            .addPluginSpec(new ScriptCompilerPluginSpec.Builder(TestCompilerPlugin.PLUGIN_ID)
                    .withPluginClassName(MockScriptCompilerPlugin.class.getName()).build())
            .build();/*from www .  ja va 2  s  .  co m*/
    moduleLoader.updateScriptArchives(Collections.singleton(scriptArchive));

    ModuleId moduleId = scriptArchive.getModuleSpec().getModuleId();
    ScriptModule scriptModule = moduleLoader.getScriptModule(moduleId);

    assertNotNull(scriptModule);
    assertEquals(scriptModule.getModuleId(), moduleId);
    JBossModuleClassLoader moduleClassLoader = scriptModule.getModuleClassLoader();
    for (String entryName : scriptArchive.getArchiveEntryNames()) {
        URL resourceUrl = moduleClassLoader.findResource(entryName, true);
        assertNotNull(resourceUrl, "couldn't find entry in the classloader: " + entryName);
    }
    verify(MOCK_COMPILER).shouldCompile(Mockito.eq(scriptArchive));
    verify(MOCK_COMPILER).compile(Mockito.eq(scriptArchive), Mockito.any(JBossModuleClassLoader.class),
            Mockito.any(Path.class));
    verifyNoMoreInteractions(MOCK_COMPILER);
}

From source file:com.netflix.nicobar.groovy2.plugin.Groovy2PluginTest.java

@Test
public void testLoadSimpleScript() throws Exception {
    ScriptModuleLoader moduleLoader = createGroovyModuleLoader().build();
    // create a new script archive consisting of HellowWorld.groovy and add it the loader.
    // Declares a dependency on the Groovy2RuntimeModule.
    Path scriptRootPath = GroovyTestResourceUtil.findRootPathForScript(TestScript.HELLO_WORLD);
    ScriptArchive scriptArchive = new PathScriptArchive.Builder(scriptRootPath).setRecurseRoot(false)
            .addFile(TestScript.HELLO_WORLD.getScriptPath())
            .setModuleSpec(createGroovyModuleSpec(TestScript.HELLO_WORLD.getModuleId()).build()).build();
    moduleLoader.updateScriptArchives(Collections.singleton(scriptArchive));

    // locate the class file in the module and execute it
    ScriptModule scriptModule = moduleLoader.getScriptModule(TestScript.HELLO_WORLD.getModuleId());
    Class<?> clazz = findClassByName(scriptModule, TestScript.HELLO_WORLD);
    assertGetMessage(clazz, "Hello, World!");
}

From source file:com.manydesigns.portofino.oauth.OAuthHelper.java

public OAuthHelper(ActionBeanContext actionBeanContext, String tokenServerUrl, String authorizationServerUrl,
        String scope, String clientId, String clientSecret) {
    this(actionBeanContext, tokenServerUrl, authorizationServerUrl, Collections.singleton(scope), clientId,
            clientSecret);//from   w w  w  .  j av a  2 s  .  co m
}