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

@Override
public Set<ValueRequirement> getRequirements(final FunctionCompilationContext context,
        final ComputationTarget target, final ValueRequirement desiredValue) {
    final HistoricalTimeSeriesResolver resolver = OpenGammaCompilationContext
            .getHistoricalTimeSeriesResolver(context);
    final String fieldName = s_marketDataRequirementNamesMap.get(_requirementName);
    final HistoricalTimeSeriesResolutionResult timeSeries = resolver
            .resolve(target.getSecurity().getExternalIdBundle(), null, null, null, fieldName, null);
    if (timeSeries == null) {
        return null;
    }/*from  w w  w. j  av  a 2  s. co m*/
    // TODO - Can we do something more efficient than getting the whole series?
    return Collections.singleton(HistoricalTimeSeriesFunctionUtils.createHTSRequirement(timeSeries, fieldName,
            null, true, DateConstraint.VALUATION_TIME.minus(Period.ofDays(1)), true));
}

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

@Test
public void testTokenRetrievalWithUserAuthorities() throws Exception {
    body.put("user_authorities", Collections.singleton("uaa.user"));
    OAuth2Authentication result = services.loadAuthentication("FOO");
    assertNotNull(result);//from  w ww .jav  a2s.  com
    assertEquals("[uaa.user]", result.getUserAuthentication().getAuthorities().toString());
}

From source file:com.spotify.reaper.unit.service.SegmentRunnerTest.java

@Test
public void timeoutTest() throws InterruptedException, ReaperException, ExecutionException {
    final AppContext context = new AppContext();
    context.storage = new MemoryStorage();
    RepairUnit cf = context.storage/* w ww . ja va 2 s .c om*/
            .addRepairUnit(new RepairUnit.Builder("reaper", "reaper", Sets.newHashSet("reaper")));
    RepairRun run = context.storage.addRepairRun(
            new RepairRun.Builder("reaper", cf.getId(), DateTime.now(), 0.5, 1, RepairParallelism.PARALLEL));
    context.storage.addRepairSegments(Collections.singleton(
            new RepairSegment.Builder(run.getId(), new RingRange(BigInteger.ONE, BigInteger.ZERO), cf.getId())),
            run.getId());
    final long segmentId = context.storage.getNextFreeSegment(run.getId()).get().getId();

    final ExecutorService executor = Executors.newSingleThreadExecutor();
    final MutableObject<Future<?>> future = new MutableObject<>();

    context.jmxConnectionFactory = new JmxConnectionFactory() {
        @Override
        public JmxProxy connect(final Optional<RepairStatusHandler> handler, String host) {
            JmxProxy jmx = mock(JmxProxy.class);
            when(jmx.getClusterName()).thenReturn("reaper");
            when(jmx.isConnectionAlive()).thenReturn(true);
            when(jmx.tokenRangeToEndpoint(anyString(), any(RingRange.class)))
                    .thenReturn(Lists.newArrayList(""));
            when(jmx.triggerRepair(any(BigInteger.class), any(BigInteger.class), anyString(),
                    Matchers.<RepairParallelism>any(), Sets.newHashSet(anyString())))
                            .then(new Answer<Integer>() {
                                @Override
                                public Integer answer(InvocationOnMock invocation) {
                                    assertEquals(RepairSegment.State.NOT_STARTED,
                                            context.storage.getRepairSegment(segmentId).get().getState());
                                    future.setValue(executor.submit(new Thread() {
                                        @Override
                                        public void run() {
                                            handler.get().handle(1, ActiveRepairService.Status.STARTED,
                                                    "Repair command 1 has started");
                                            assertEquals(RepairSegment.State.RUNNING, context.storage
                                                    .getRepairSegment(segmentId).get().getState());
                                        }
                                    }));
                                    return 1;
                                }
                            });

            return jmx;
        }
    };
    RepairRunner rr = mock(RepairRunner.class);
    RepairUnit ru = mock(RepairUnit.class);
    SegmentRunner sr = new SegmentRunner(context, segmentId, Collections.singleton(""), 100, 0.5,
            RepairParallelism.PARALLEL, "reaper", ru, rr);
    sr.run();

    future.getValue().get();
    executor.shutdown();

    assertEquals(RepairSegment.State.NOT_STARTED, context.storage.getRepairSegment(segmentId).get().getState());
    assertEquals(1, context.storage.getRepairSegment(segmentId).get().getFailCount());
}

From source file:com.hp.autonomy.searchcomponents.hod.search.fields.HodSearchResultDeserializer.java

@Override
public HodSearchResult deserialize(final JsonParser jsonParser,
        final DeserializationContext deserializationContext) throws IOException {
    final FieldsInfo fieldsInfo = configService.getConfig().getFieldsInfo();
    final Map<String, FieldInfo<?>> fieldConfig = fieldsInfo.getFieldConfigByName();

    final JsonNode node = jsonParser.getCodec().readTree(jsonParser);

    final Map<String, FieldInfo<?>> fieldMap = new HashMap<>(fieldConfig.size());
    for (final FieldInfo<?> fieldInfo : fieldConfig.values()) {
        for (final String name : fieldInfo.getNames()) {
            final String[] stringValues = parseAsStringArray(node, name);

            if (ArrayUtils.isNotEmpty(stringValues)) {
                final List<Object> values = new ArrayList<>(stringValues.length);
                for (final String stringValue : stringValues) {
                    final Object value = fieldInfo.getType().parseValue(fieldInfo.getType().getType(),
                            stringValue);
                    values.add(value);/*from   w  w  w.  ja v a  2s .  c  om*/
                }

                fieldMap.put(fieldInfo.getId(), new FieldInfo<>(fieldInfo.getId(), Collections.singleton(name),
                        fieldInfo.getType(), values));
            }
        }
    }

    return new HodSearchResult.Builder().setReference(parseAsString(node, "reference"))
            .setIndex(parseAsString(node, "index")).setTitle(parseAsString(node, "title"))
            .setSummary(parseAsString(node, "summary")).setWeight(parseAsDouble(node, "weight"))
            .setFieldMap(fieldMap).setDate(parseAsDateFromArray(node, "date"))
            .setPromotionCategory(parsePromotionCategory(node, "promotion")).build();
}

From source file:be.ordina.msdashboard.graph.RedisServiceTest.java

@Test
public void deleteAllNodes() {
    Set<String> keys = Collections.singleton("nodeId");

    doReturn(keys).when(redisTemplate).keys("*");

    redisService.deleteAllNodes();//from w ww  .  j  a  va 2  s . co  m

    verify(redisTemplate).keys("*");
    verify(redisTemplate).delete(keys);
}

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

public void unregister(String name) {
    DefinitionProvider<AppDescriptor> toRemove = getProvider(name);
    getRegistryMap().remove(toRemove.getMetadata());
    sendEvent(AppRegistryEventType.UNREGISTERED, Collections.singleton(toRemove.getMetadata()));
}

From source file:com.photobox.gradle.androidpublisher.AndroidPublisherHelper.java

private static Credential authorizeWithServiceAccount(String serviceAccountEmail, File serviceAccountKeyFile)
        throws GeneralSecurityException, IOException {
    log.info(String.format("Authorizing using Service Account: %s", serviceAccountEmail));

    // Build service account credential.
    log.info("Using service key file: " + serviceAccountKeyFile.getAbsolutePath());
    GoogleCredential credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
            .setJsonFactory(JSON_FACTORY).setServiceAccountId(serviceAccountEmail)
            .setServiceAccountScopes(Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER))
            .setServiceAccountPrivateKeyFromP12File(serviceAccountKeyFile).build();
    return credential;
}

From source file:edu.cornell.mannlib.vitro.webapp.modelaccess.adapters.NamedDefaultModelMaker.java

@Override
public ExtendedIterator<String> listModels() {
    return super.listModels().andThen(Collections.singleton(this.defaultModelUri).iterator());
}

From source file:com.espertech.esper.epl.join.table.PropertyIndexedEventTableUnique.java

/**
 * Returns the set of events that have the same property value as the given event.
 * @param keys to compare against/*from   ww w .  j  a  va 2 s  .  com*/
 * @return set of events with property value, or null if none found (never returns zero-sized set)
 */
@Override
public Set<EventBean> lookup(Object[] keys) {
    MultiKeyUntyped key = new MultiKeyUntyped(keys);
    EventBean event = propertyIndex.get(key);
    if (event != null) {
        return Collections.singleton(event);
    }
    return null;
}

From source file:net.solarnetwork.node.job.DatumDataSourceManagedLoggerJob.java

private void executeForDatumDataSource(JobExecutionContext jobContext) {
    if (log.isDebugEnabled()) {
        log.debug("Collecting [{}] from [{}]", datumDataSource.getDatumType().getSimpleName(), datumDataSource);
    }//from ww  w . java 2  s. c  om
    T datum = datumDataSource.readCurrentDatum();
    if (datum != null) {
        persistDatum(Collections.singleton(datum));
    } else {
        log.info("No data returned from [{}]", datumDataSource);
    }
}