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.UnitPositionScalingFunction.java

@Override
public Set<ValueRequirement> getRequirements(final FunctionCompilationContext context,
        final ComputationTarget target, final ValueRequirement desiredValue) {
    final Position position = target.getPosition();
    final Security security = position.getSecurity();
    final ValueProperties constraints = desiredValue.getConstraints().withoutAny(ValuePropertyNames.FUNCTION);
    final ValueRequirement requirement = new ValueRequirement(_requirementName, ComputationTargetType.SECURITY,
            security.getUniqueId(), constraints);
    return Collections.singleton(requirement);
}

From source file:com.vrem.util.EnumUtilsTest.java

@Test
public void testFindUsingValues() throws Exception {
    // setup//from   w ww.ja v  a 2s  . c  o m
    TestObject expected = TestObject.VALUE1;
    Set<TestObject> values = Collections.singleton(expected);
    // execute
    Set<String> actual = EnumUtils.find(values);
    // validate
    assertEquals(1, actual.size());
    assertTrue(actual.contains("" + expected.ordinal()));
}

From source file:org.openmrs.module.kenyaemr.fragment.controller.Moh257FragmentController.java

/**
 * Convenience method to get encounters from the given form
 * @param patient the patient/*from  ww  w . j  a  va  2  s  .c  o m*/
 * @param form the form
 * @return the encounters
 */
private static List<Encounter> getPatientEncounterByForm(Patient patient, Form form) {
    return Context.getEncounterService().getEncounters(patient, null, null, null, Collections.singleton(form),
            null, null, null, null, false);
}

From source file:grakn.core.graql.analytics.DegreeVertexProgram.java

@Override
public Set<VertexComputeKey> getVertexComputeKeys() {
    return Collections.singleton(VertexComputeKey.of(DEGREE, false));
}

From source file:com.datatorrent.lib.io.fs.AbstractThroughputFileInputOperatorTest.java

@Test
public void testInitialPartitioning() {
    underTest.setPartitionCount(4);// w ww .  j a  v  a2 s.  c o  m
    underTest.setPreferredMaxPendingFilesPerOperator(6);

    for (int i = 0; i < 74; i++) {
        underTest.pendingFiles.add("file-" + i);
    }

    int partitioncount = underTest.getNewPartitionCount(Collections.singleton(mockPartition), null);
    Assert.assertEquals(4, partitioncount);
}

From source file:com.devicehive.handler.notification.NotificationSubscribeInsertIntegrationTest.java

@Test
public void shouldSubscribeToDeviceNotifications() throws Exception {
    String device1 = randomUUID().toString();
    String device2 = randomUUID().toString();

    String subscriber1 = randomUUID().toString();
    String subscriber2 = randomUUID().toString();
    String subscriber3 = randomUUID().toString();

    NotificationSubscribeRequest sr1 = new NotificationSubscribeRequest(subscriber1, device1, null, null);
    Request r1 = Request.newBuilder().withBody(sr1).withSingleReply(false).build();
    TestCallback c1 = new TestCallback();
    client.call(r1, c1);/*from  w  w w . jav a 2s  .  c  o  m*/

    NotificationSubscribeRequest sr2 = new NotificationSubscribeRequest(subscriber1, device2,
            Collections.singleton("temperature"), null);
    Request r2 = Request.newBuilder().withBody(sr2).withSingleReply(false).build();
    TestCallback c2 = new TestCallback();
    client.call(r2, c2);

    NotificationSubscribeRequest sr3 = new NotificationSubscribeRequest(subscriber2, device2, null, null);
    Request r3 = Request.newBuilder().withBody(sr3).withSingleReply(false).build();
    TestCallback c3 = new TestCallback();
    client.call(r3, c3);

    NotificationSubscribeRequest sr4 = new NotificationSubscribeRequest(subscriber2, device1,
            Collections.singleton("vibration"), null);
    Request r4 = Request.newBuilder().withBody(sr4).withSingleReply(false).build();
    TestCallback c4 = new TestCallback();
    client.call(r4, c4);

    NotificationSubscribeRequest sr5 = new NotificationSubscribeRequest(subscriber3, randomUUID().toString(),
            null, null);
    Request r5 = Request.newBuilder().withBody(sr5).withSingleReply(false).build();
    TestCallback c5 = new TestCallback();
    client.call(r5, c5);

    //wait subsribers to subscribe
    Stream.of(c1.subscribeFuture, c2.subscribeFuture, c3.subscribeFuture, c4.subscribeFuture,
            c5.subscribeFuture).forEach(CompletableFuture::join);

    //devices send notifications
    List<CompletableFuture<Response>> futures = Stream.of(device1, device2).flatMap(device -> {
        List<CompletableFuture<Response>> list = Stream.of("temperature", "vibration").map(name -> {
            DeviceNotification notification = new DeviceNotification();
            notification.setId(0);
            notification.setNotification(name);
            notification.setDeviceGuid(device);
            NotificationInsertRequest event = new NotificationInsertRequest(notification);
            CompletableFuture<Response> f = new CompletableFuture<>();
            client.call(Request.newBuilder().withBody(event).build(), f::complete);
            return f;
        }).collect(Collectors.toList());
        return list.stream();
    }).collect(Collectors.toList());

    //wait notifications delivered
    futures.forEach(CompletableFuture::join);

    assertThat(c1.notifications, hasSize(2));
    c1.notifications.forEach(event -> {
        assertNotNull(event.getNotification());
        assertEquals(event.getNotification().getDeviceGuid(), device1);
        assertEquals(event.getNotification().getId(), Long.valueOf(0));
    });
    Set<String> names = c1.notifications.stream().map(n -> n.getNotification().getNotification())
            .collect(Collectors.toSet());
    assertThat(names, containsInAnyOrder("temperature", "vibration"));

    assertThat(c2.notifications, hasSize(1));
    NotificationEvent e = c2.notifications.stream().findFirst().get();
    assertNotNull(e.getNotification());
    assertEquals(e.getNotification().getDeviceGuid(), device2);
    assertEquals(e.getNotification().getId(), Long.valueOf(0));
    assertEquals(e.getNotification().getNotification(), "temperature");

    assertThat(c3.notifications, hasSize(2));
    c3.notifications.forEach(event -> {
        assertNotNull(event.getNotification());
        assertEquals(event.getNotification().getDeviceGuid(), device2);
        assertEquals(event.getNotification().getId(), Long.valueOf(0));
    });
    names = c3.notifications.stream().map(n -> n.getNotification().getNotification())
            .collect(Collectors.toSet());
    assertThat(names, containsInAnyOrder("temperature", "vibration"));

    assertThat(c4.notifications, hasSize(1));
    e = c4.notifications.stream().findFirst().get();
    assertNotNull(e.getNotification());
    assertEquals(e.getNotification().getDeviceGuid(), device1);
    assertEquals(e.getNotification().getId(), Long.valueOf(0));
    assertEquals(e.getNotification().getNotification(), "vibration");

    assertThat(c5.notifications, is(empty()));
}

From source file:com.opengamma.financial.analytics.model.bond.BondPresentValueCountryCurveFunction.java

@Override
public Set<ValueSpecification> getResults(final FunctionCompilationContext context,
        final ComputationTarget target, final Map<ValueSpecification, ValueRequirement> inputs) {
    String curveName = null;/* www .ja v  a 2  s . co  m*/
    for (ValueSpecification input : inputs.keySet()) {
        if (ValueRequirementNames.YIELD_CURVE.equals(input.getValueName())) {
            curveName = input.getProperty(ValuePropertyNames.CURVE);
            break;
        }
    }
    Validate.notNull(curveName, "curveName");
    return Collections
            .singleton(new ValueSpecification(ValueRequirementNames.PRESENT_VALUE, target.toSpecification(),
                    createValueProperties()
                            .with(ValuePropertyNames.COUNTRY, BondFunctionUtils.getCountryName(target))
                            .with(ValuePropertyNames.CURVE, curveName).get()));
}

From source file:org.gridobservatory.greencomputing.dao.MachineDao.java

@Override
public void insert(Machine machine) {
    this.insert(Collections.singleton(machine));
}

From source file:com.opengamma.financial.analytics.model.bond.BondPresentValueCurrencyCurveFunction.java

@Override
public Set<ValueSpecification> getResults(final FunctionCompilationContext context,
        final ComputationTarget target, final Map<ValueSpecification, ValueRequirement> inputs) {
    String curveName = null;/*from  w w  w  .  j  a v  a2  s.  co m*/
    for (ValueSpecification input : inputs.keySet()) {
        if (ValueRequirementNames.YIELD_CURVE.equals(input.getValueName())) {
            curveName = input.getProperty(ValuePropertyNames.CURVE);
            break;
        }
    }
    Validate.notNull(curveName, "curveName");
    return Collections
            .singleton(new ValueSpecification(ValueRequirementNames.PRESENT_VALUE, target.toSpecification(),
                    createValueProperties()
                            .with(ValuePropertyNames.CURRENCY, BondFunctionUtils.getCurrencyName(target))
                            .with(ValuePropertyNames.CURVE, curveName).get()));
}

From source file:org.cloudfoundry.identity.uaa.oauth.CheckTokenEndpointTests.java

public CheckTokenEndpointTests() {
    authentication = new OAuth2Authentication(
            new DefaultAuthorizationRequest("client", Collections.singleton("read")),
            UaaAuthenticationTestFactory.getAuthentication("12345", "olds", "olds@vmware.com"));

    SignerProvider signerProvider = new SignerProvider();
    signerProvider.setSigningKey("abc");
    signerProvider.setVerifierKey("abc");
    tokenServices.setSignerProvider(signerProvider);
    endpoint.setTokenServices(tokenServices);
    Date oneSecondAgo = new Date(System.currentTimeMillis() - 1000);
    Date thirtySecondsAhead = new Date(System.currentTimeMillis() + 30000);
    UaaUserDatabase userDatabase = new MockUaaUserDatabase("12345", "olds", "olds@vmware.com", null, null,
            oneSecondAgo, oneSecondAgo);
    tokenServices.setUserDatabase(userDatabase);

    approvalStore.addApproval(/* ww  w. j  a  va  2s  . c om*/
            new Approval("olds", "client", "read", thirtySecondsAhead, ApprovalStatus.APPROVED, oneSecondAgo));
    approvalStore.addApproval(
            new Approval("olds", "client", "write", thirtySecondsAhead, ApprovalStatus.APPROVED, oneSecondAgo));
    tokenServices.setApprovalStore(approvalStore);

    Map<String, ? extends ClientDetails> clientDetailsStore = Collections.singletonMap("client",
            new BaseClientDetails("client", "scim, cc", "read, write", "authorization_code, password",
                    "scim.read, scim.write", "http://localhost:8080/uaa"));
    clientDetailsService.setClientDetailsStore(clientDetailsStore);
    tokenServices.setClientDetailsService(clientDetailsService);

    accessToken = tokenServices.createAccessToken(authentication);
}