Example usage for java.util Collections singletonList

List of usage examples for java.util Collections singletonList

Introduction

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

Prototype

public static <T> List<T> singletonList(T o) 

Source Link

Document

Returns an immutable list containing only the specified object.

Usage

From source file:be.agiv.security.client.ClientProxySelector.java

@Override
public List<Proxy> select(URI uri) {
    LOG.debug("select for: " + uri);
    String hostname = uri.getHost();
    Proxy proxy = this.proxies.get(hostname);
    if (null != proxy) {
        LOG.debug("using proxy: " + proxy);
        return Collections.singletonList(proxy);
    }//from ww w .j  a v a 2 s.c o  m
    if (null != this.defaultProxySelector) {
        return this.defaultProxySelector.select(uri);
    }
    return Collections.singletonList(Proxy.NO_PROXY);
}

From source file:tds.assessment.services.impl.AssessmentServiceImplIntegrationTests.java

@Test
public void shouldReturnCachedAssessment() {
    final String clientName = "SBAC_PT";
    Assessment assessment = new Assessment();
    assessment.setKey("theKey");
    Segment fixedFormSegment = new Segment(assessment.getKey(), Algorithm.FIXED_FORM);
    assessment.setSegments(Collections.singletonList(fixedFormSegment));

    when(assessmentQueryRepository.findAssessmentByKey(clientName, assessment.getKey()))
            .thenReturn(Optional.of(assessment));
    Optional<Assessment> maybeAssessment1 = service.findAssessment(clientName, assessment.getKey());
    // Get the cached value - only a single repo call should result from the two service calls
    Optional<Assessment> maybeAssessment2 = service.findAssessment(clientName, assessment.getKey());
    verify(assessmentQueryRepository, times(1)).findAssessmentByKey(clientName, assessment.getKey());

    assertThat(maybeAssessment1).isEqualTo(maybeAssessment2);
}

From source file:com.orange.cepheus.mockiotagent.AdminController.java

@RequestMapping(value = "/registerRoom", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity registerRoom() throws URISyntaxException, ExecutionException, InterruptedException {
    RegisterContext registerContext = new RegisterContext();
    ContextRegistration registration = new ContextRegistration();
    registration.setProvidingApplication(new URI(providingApplication));
    EntityId entityId = new EntityId("Room*", "Room", true);
    registration.setEntityIdList(Collections.singletonList(entityId));
    List<ContextRegistrationAttribute> attributeList = new ArrayList<>();
    ContextRegistrationAttribute tempAttribute = new ContextRegistrationAttribute("temperature", false);
    tempAttribute.setType("double");
    attributeList.add(tempAttribute);/*from   w  ww.jav a  2s . c o m*/
    ContextRegistrationAttribute floorAttribute = new ContextRegistrationAttribute("floor", false);
    floorAttribute.setType("string");
    attributeList.add(floorAttribute);
    ContextRegistrationAttribute shutterAttribute = new ContextRegistrationAttribute("shutter", false);
    shutterAttribute.setType("string");
    attributeList.add(shutterAttribute);
    registration.setContextRegistrationAttributeList(attributeList);
    registerContext.setContextRegistrationList(Collections.singletonList(registration));
    registerContext.setDuration("PT10M");
    RegisterContextResponse registerContextResponse = ngsiClient
            .registerContext(cepheusBroker, null, registerContext).get();
    logger.info("RegisterContextResponse of type {} received from {}: RegistrationId {}", "Shutter",
            cepheusBroker, registerContextResponse.getRegistrationId());

    return new ResponseEntity<>(HttpStatus.OK);
}

From source file:com.cloudera.cdk.morphline.twitter.ReadJsonTestTweetsBuilder.java

@Override
public Collection<String> getNames() {
    return Collections.singletonList("readJsonTestTweets");
}

From source file:org.rapidpm.microservice.optionals.service.ServiceWrapper.java

private static void writeRestPortToFile() {
    String restPort = System.getProperty(MainUndertow.REST_PORT_PROPERTY, MainUndertow.DEFAULT_REST_PORT + "");
    try {//from   w  ww. j  a v  a  2s. c om
        Files.write(MICROSERVICE_REST_FILE, Collections.singletonList(restPort));
    } catch (IOException e) {
        LOGGER.warning("Can not write to File " + MICROSERVICE_REST_FILE
                + "check permissions and restart the service");
        exitHandler.exit(1);
    }

}

From source file:de.hybris.platform.order.interceptors.AbstractOrderPrepareInterceptorTest.java

@Before
public void init() throws JaloSystemException {
    MockitoAnnotations.initMocks(this);

    interceptor = new DefaultAbstractOrderPrepareInterceptor();
    interceptor.setKeyGenerator(mockKeyGenerator);

    order = new OrderModel();
    order.setCalculated(Boolean.TRUE);
    entry = new OrderEntryModel();
    entry.setCalculated(Boolean.TRUE);
    order.setEntries(Collections.singletonList(entry));
    order.setCode("123");
}

From source file:com.michellemay.mappings.MappingsFactoryTest.java

@Test(expected = IllegalArgumentException.class)
public void testCreateEmptyMapping() throws Exception {
    MappingConfig config = new MappingConfig();
    new MappingsFactory(Collections.singletonList(config));
}

From source file:com.stackify.metric.impl.MetricSenderTest.java

/**
 * testSend// w w w. j a  v a2s.  com
 * @throws Exception 
 */
@Test
public void testSend() throws Exception {
    ApiConfiguration apiConfig = Mockito.mock(ApiConfiguration.class);

    ObjectMapper objectMapper = new ObjectMapper();

    MetricMonitorService monitorService = Mockito.mock(MetricMonitorService.class);
    Mockito.when(monitorService.getMonitorId(Mockito.any(MetricIdentity.class))).thenReturn(14);

    HttpClient httpClient = PowerMockito.mock(HttpClient.class);
    PowerMockito.whenNew(HttpClient.class).withAnyArguments().thenReturn(httpClient);
    PowerMockito.when(httpClient.post(Mockito.anyString(), (byte[]) Mockito.any())).thenReturn("");

    MetricSender sender = new MetricSender(apiConfig, objectMapper, monitorService);

    MetricIdentity identity = new MetricIdentity("category", "name", MetricMonitorType.GAUGE);
    MetricAggregate aggregate = MetricAggregate.fromMetricIdentity(identity, System.currentTimeMillis());

    sender.send(Collections.singletonList(aggregate));

    Mockito.verify(httpClient).post(Mockito.anyString(), Mockito.any(byte[].class));
}

From source file:com.linecorp.armeria.server.http.jetty.JettyServiceTest.java

static WebAppContext newWebAppContext() throws MalformedURLException {
    final WebAppContext handler = new WebAppContext();
    handler.setContextPath("/");
    handler.setBaseResource(Resource.newClassPathResource("/tomcat_service"));
    handler.setClassLoader(new URLClassLoader(
            new URL[] {
                    Resource.newClassPathResource("/tomcat_service/WEB-INF/lib/hello.jar").getURI().toURL() },
            JettyService.class.getClassLoader()));

    handler.addBean(new ServletContainerInitializersStarter(handler), true);
    handler.setAttribute("org.eclipse.jetty.containerInitializers",
            Collections.singletonList(new ContainerInitializer(new JettyJasperInitializer(), null)));
    return handler;
}

From source file:Main.java

/**
 * Splits a collection into several collections. (Particularly useful for limitations of database
 * around the "in" clause)/*ww w  .j a  v a  2 s  .  co m*/
 *
 * @param collection
 * @param collectionSizeMax
 * @return
 */
@SuppressWarnings("unchecked")
public static <T> Collection<Collection<T>> split(final Collection<T> collection, final int collectionSizeMax) {
    Collection<Collection<T>> result = null;

    try {
        if (isNotEmpty(collection)) {
            if (collectionSizeMax > 0 && collection.size() > collectionSizeMax) {

                // Guessing the result size and initializing the result
                int size = (collection.size() / collectionSizeMax);
                if ((collection.size() % collectionSizeMax) != 0) {
                    size++;
                }
                result = new ArrayList<Collection<T>>(size);

                // Browsing the collection
                Collection<T> curLot = null;
                for (final T element : collection) {

                    // If necessary, initializing a lot
                    if (curLot == null || curLot.size() >= collectionSizeMax) {
                        curLot = new ArrayList<T>(collectionSizeMax);

                        // Adding the new lot
                        result.add(curLot);
                    }

                    // Adding an element into the current lot
                    curLot.add(element);
                }
            } else {
                result = Collections.singletonList(collection);
            }
        }
    } catch (final Exception e) {
        throw new RuntimeException(e);
    } finally {
        if (result == null) {
            result = new ArrayList<Collection<T>>();
        }
    }

    // Retour du resultat
    return result;
}