Example usage for java.util Collections singletonMap

List of usage examples for java.util Collections singletonMap

Introduction

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

Prototype

public static <K, V> Map<K, V> singletonMap(K key, V value) 

Source Link

Document

Returns an immutable map, mapping only the specified key to the specified value.

Usage

From source file:de.whs.poodle.Utils.java

public Map<String, Object> simpleMessage(String messageCode, Object[] messageArgs) {
    Locale locale = LocaleContextHolder.getLocale();
    String message = messageSource.getMessage(messageCode, messageArgs, locale);

    return Collections.singletonMap("message", message);
}

From source file:org.elasticsearch.xpack.ml.integration.MlBasicMultiNodeIT.java

public void testMiniFarequote() throws Exception {
    String jobId = "mini-farequote-job";
    createFarequoteJob(jobId);/*from   w  w  w.j  a  v  a 2  s  .c om*/

    Response response = client().performRequest("post",
            MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId + "/_open");
    assertEquals(200, response.getStatusLine().getStatusCode());
    assertEquals(Collections.singletonMap("opened", true), responseEntityToMap(response));

    String postData = "{\"airline\":\"AAL\",\"responsetime\":\"132.2046\",\"sourcetype\":\"farequote\",\"time\":\"1403481600\"}\n"
            + "{\"airline\":\"JZA\",\"responsetime\":\"990.4628\",\"sourcetype\":\"farequote\",\"time\":\"1403481700\"}";
    response = client().performRequest("post",
            MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId + "/_data", Collections.emptyMap(),
            new StringEntity(postData,
                    randomFrom(ContentType.APPLICATION_JSON, ContentType.create("application/x-ndjson"))));
    assertEquals(202, response.getStatusLine().getStatusCode());
    Map<String, Object> responseBody = responseEntityToMap(response);
    assertEquals(2, responseBody.get("processed_record_count"));
    assertEquals(4, responseBody.get("processed_field_count"));
    assertEquals(177, responseBody.get("input_bytes"));
    assertEquals(6, responseBody.get("input_field_count"));
    assertEquals(0, responseBody.get("invalid_date_count"));
    assertEquals(0, responseBody.get("missing_field_count"));
    assertEquals(0, responseBody.get("out_of_order_timestamp_count"));
    assertEquals(0, responseBody.get("bucket_count"));
    assertEquals(1403481600000L, responseBody.get("earliest_record_timestamp"));
    assertEquals(1403481700000L, responseBody.get("latest_record_timestamp"));

    response = client().performRequest("post",
            MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId + "/_flush");
    assertEquals(200, response.getStatusLine().getStatusCode());
    assertFlushResponse(response, true, 1403481600000L);

    response = client().performRequest("post",
            MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId + "/_close",
            Collections.singletonMap("timeout", "20s"));
    assertEquals(200, response.getStatusLine().getStatusCode());
    assertEquals(Collections.singletonMap("closed", true), responseEntityToMap(response));

    response = client().performRequest("get",
            MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId + "/_stats");
    assertEquals(200, response.getStatusLine().getStatusCode());
    @SuppressWarnings("unchecked")
    Map<String, Object> dataCountsDoc = (Map<String, Object>) ((Map) ((List) responseEntityToMap(response)
            .get("jobs")).get(0)).get("data_counts");
    assertEquals(2, dataCountsDoc.get("processed_record_count"));
    assertEquals(4, dataCountsDoc.get("processed_field_count"));
    assertEquals(177, dataCountsDoc.get("input_bytes"));
    assertEquals(6, dataCountsDoc.get("input_field_count"));
    assertEquals(0, dataCountsDoc.get("invalid_date_count"));
    assertEquals(0, dataCountsDoc.get("missing_field_count"));
    assertEquals(0, dataCountsDoc.get("out_of_order_timestamp_count"));
    assertEquals(0, dataCountsDoc.get("bucket_count"));
    assertEquals(1403481600000L, dataCountsDoc.get("earliest_record_timestamp"));
    assertEquals(1403481700000L, dataCountsDoc.get("latest_record_timestamp"));

    response = client().performRequest("delete", MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId);
    assertEquals(200, response.getStatusLine().getStatusCode());
}

From source file:com.arpnetworking.tsdcore.sinks.DataDogSink.java

/**
 * {@inheritDoc}/*from   w  w  w.  j a v  a  2 s  . c  o m*/
 */
@Override
protected Collection<byte[]> serialize(final PeriodicData periodicData) {
    final String period = periodicData.getPeriod().toString(ISOPeriodFormat.standard());
    final long timestamp = (periodicData.getStart().getMillis()
            + periodicData.getPeriod().toStandardDuration().getMillis()) / 1000;

    final List<Datum> dataDogData = Lists.newArrayList();
    for (final AggregatedData datum : periodicData.getData()) {
        if (!datum.isSpecified()) {
            continue;
        }

        dataDogData.add(new Datum(
                period + "_" + datum.getFQDSN().getMetric() + "_" + datum.getFQDSN().getStatistic().getName(),
                timestamp, (float) datum.getValue().getValue(), periodicData.getDimensions().get("host"),
                createTags(periodicData, datum)));
    }

    final String dataDogDataAsJson;
    try {
        dataDogDataAsJson = OBJECT_MAPPER.writeValueAsString(Collections.singletonMap("series", dataDogData));
    } catch (final JsonProcessingException e) {
        LOGGER.error().setMessage("Serialization error").addData("periodicData", periodicData).setThrowable(e)
                .log();
        return Collections.emptyList();
    }
    return Collections.singletonList(dataDogDataAsJson.getBytes(Charsets.UTF_8));
}

From source file:ch.cyberduck.core.spectra.SpectraReadFeatureTest.java

@Test(expected = NotfoundException.class)
public void testReadNotFound() throws Exception {
    final Host host = new Host(new SpectraProtocol() {
        @Override/*from   w w w. ja  v a 2 s .c o m*/
        public Scheme getScheme() {
            return Scheme.http;
        }
    }, System.getProperties().getProperty("spectra.hostname"),
            Integer.valueOf(System.getProperties().getProperty("spectra.port")),
            new Credentials(System.getProperties().getProperty("spectra.user"),
                    System.getProperties().getProperty("spectra.key")));
    final SpectraSession session = new SpectraSession(host, new DisabledX509TrustManager(),
            new DefaultX509KeyManager());
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final TransferStatus status = new TransferStatus();
    final Path container = new Path("cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path test = new Path(container, "nosuchname", EnumSet.of(Path.Type.file));
    new SpectraBulkService(session).pre(Transfer.Type.download, Collections.singletonMap(test, status),
            new DisabledConnectionCallback());
    new SpectraReadFeature(session).read(test, status, new DisabledConnectionCallback());
}

From source file:com.amazonaws.sample.entitlement.rs.JaxRsEntitlementService.java

/**
 * Request entitlements for a user/*from   w ww .ja va  2s . c o  m*/
 * @param authorization string that is associated to the identity of a user
 * @return Applications
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response requestSubscriptions(@HeaderParam("Authorization") String authorization) {
    try {
        Item user = entitlementService.getUserFromAuthorization(authorization);
        String response = entitlementService.getSubscriptions(user);
        return response(Status.OK, response);
    } catch (AuthorizationException e) {
        String authenticateHeader = e.getAuthenticateHeader();

        if (authenticateHeader == null) {
            return response(Status.UNAUTHORIZED, e.getMessage());
        } else {
            return response(Status.UNAUTHORIZED, e.getMessage(),
                    Collections.singletonMap("WWW-Authenticate", authenticateHeader));
        }
    } catch (ApplicationBadStateException e) {
        return response(Status.CONFLICT, e.getMessage());
    }
}

From source file:uk.org.taverna.platform.LocalExecutionIT.java

public void testLocalExecution() throws Exception {
    setup();//from   w w w.  j a v a  2  s  .co m

    WorkflowBundle workflowBundle = loadWorkflow("/t2flow/in-out.t2flow");
    Workflow workflow = workflowBundle.getMainWorkflow();
    Profile profile = workflowBundle.getMainProfile();
    for (ExecutionEnvironment executionEnvironment : executionEnvironments) {
        Map<String, Data> inputs = Collections.singletonMap("in", dataService.create("test-input"));

        String executionId = executionService.createExecution(executionEnvironment, workflowBundle, workflow,
                profile, inputs);
        WorkflowReport report = executionService.getWorkflowReport(executionId);
        assertEquals(State.CREATED, report.getState());
        executionService.start(executionId);

        Map<String, Data> results = report.getOutputs();
        assertNotNull(results);
        waitForResults(results, report, "out");

        Object result = results.get("out").getValue();
        assertEquals("test-input", result);
        assertEquals(State.COMPLETED, report.getState());
        System.out.println(report);
    }
}

From source file:com.yahoo.glimmer.web.QueryController.java

@RequestMapping(value = "/dataSetList", method = RequestMethod.GET)
public Map<String, ?> getDataSetList(@RequestParam(required = false) String callback) {
    return Collections.singletonMap(OBJECT_KEY, indexMap.keySet());
}

From source file:org.jboss.as.test.integration.logging.syslog.SyslogHandlerTestCase.java

@BeforeClass
public static void deploy() throws Exception {
    deploy(createDeployment(Collections.singletonMap("Logging-Profile", "syslog-profile")), DEPLOYMENT_NAME);
}

From source file:org.fede.calculator.web.MvcConfig.java

@Bean
public ContentNegotiatingViewResolver cnResolver() {
    ContentNegotiatingViewResolver bean = new ContentNegotiatingViewResolver();
    bean.setOrder(0);//from  w  w  w.j ava 2 s  .  co  m
    bean.setContentNegotiationManager(new ContentNegotiationManager(new PathExtensionContentNegotiationStrategy(
            Collections.singletonMap("json", MediaType.APPLICATION_JSON))));

    MappingJackson2JsonView jacksonView = new MappingJackson2JsonView();
    jacksonView.setExtractValueFromSingleKeyModel(true);

    bean.setDefaultViews(Arrays.asList(new View[] { jacksonView }));
    return bean;
}

From source file:com.yoncabt.ebr.executor.ReportTask.java

@Override
public void run() {
    if (status == Status.CANCEL) {
        return;/*from   ww  w  . j a  v  a  2 s .  co m*/
    }
    status = Status.RUN;
    logManager.info(request.getUuid() + " balad");
    synchronized (this) {
        started = System.currentTimeMillis();
    }
    response = new ReportResponse();
    response.setUuid(request.getUuid());
    try {
        //FIXME support for sql
        JasperReport jr = new JasperReport();
        ReportDefinition definition = jr.loadDefinition(JasperReport.getReportFile(request.getReport()));
        if (StringUtils.isEmpty(request.getDatasourceName())) {
            request.setDatasourceName(definition.getDataSource());
        }
        if (StringUtils.isEmpty(request.getDatasourceName())) {
            request.setDatasourceName("default");
        }
        connection = dataSourceManager.get(request.getDatasourceName(), request.getUser(), "EBR",
                request.getReport());
        jasperReports.exportTo(request, ReportOutputFormat.valueOf(request.getExtension()), connection,
                definition);
        byte[] bytes = reportLogger.getReportData(request.getUuid());
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        baos.write(bytes, 0, bytes.length);
        if (!StringUtils.isBlank(request.getEmail()) && mailSender.isConfigured()) {
            mailSender.send(request.getEmail(), "Raporunuz ektedir", Collections
                    .singletonMap(request.getUuid() + "." + request.getExtension(), baos.toByteArray()));
        }
        logManager.info(request.getUuid() + " bitti");
        status = Status.FINISH;
    } catch (Exception ex) {
        status = Status.EXCEPTION;
        logManager.error(request.getUuid() + " hata", ex);
        synchronized (this) {
            exception = new ReportException(ex);
        }
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
    synchronized (this) {
        ended = System.currentTimeMillis();
    }
}