List of usage examples for java.util Collections singletonMap
public static <K, V> Map<K, V> singletonMap(K key, V value)
From source file:com.as.sagma.ControladorServicios.java
@RequestMapping(value = "/servicio-usuarios", method = RequestMethod.GET, headers = { "Accept=application/json" }) public @ResponseBody String generarUsuario() throws Exception { Map<String, ArrayList<Usuario2>> singletonMap = Collections.singletonMap("Usuarios", GeneradorDeUsuarios.generarUsuario()); ObjectMapper mapper = new ObjectMapper(); return mapper.writeValueAsString(singletonMap); }
From source file:sample.jersey.RestEndpoint.java
@GET @Path("add") @Produces(MediaType.APPLICATION_JSON)/*from w w w . ja v a 2 s . com*/ public Response add(@QueryParam("a") int a, @QueryParam("b") int b) { Integer integerA = 0; Integer integerB = 0; try { integerA = Integer.valueOf(a); integerB = Integer.valueOf(b); } catch (NumberFormatException e) { return Response.status(Response.Status.BAD_REQUEST) .entity(Collections.singletonMap("errorMessage", "query params a & b should be integers")) .build(); } return Response.ok(Collections.singletonMap("sum", integerA + integerB)).build(); }
From source file:com.github.rholder.gradle.dependency.DependencyConversionUtil.java
/** * Use the Gradle Tooling API to extract dependency information on the * given path, returning the root node of the dependency graph. * * @param projectPath the path to the target project to load * @param toolingLogger instance to use for Gradle tooling log messages *//* www . j a v a 2 s. c om*/ public static Map<String, GradleNode> loadProjectDependenciesFromModel(String projectPath, final ToolingLogger toolingLogger) { if (projectPath == null) { return Collections.singletonMap("root", new GradleNode("No Gradle project directory selected...")); } ProjectConnection connection = GradleConnector.newConnector().forProjectDirectory(new File(projectPath)) .connect(); Map<String, GradleNode> dependencyMap = Maps.newHashMap(); AcumenTreeModel atm; try { @SuppressWarnings("unchecked") BuildActionExecuter<AcumenTreeModel> action = connection.action(new AcumenModelAction()); action.addProgressListener(new ProgressListener() { public void statusChanged(ProgressEvent event) { toolingLogger.log(event.getDescription()); } }); // TODO this needs to be cached // extract from classpath File initAcumenFile = File.createTempFile("init-acumen", ".gradle"); initAcumenFile.deleteOnExit(); // use a custom plugin, if this value is set File extractedJarFile; String devGradleAcumen = System.getProperty("gradle.view.debug.acumen.jar"); if (devGradleAcumen == null) { extractedJarFile = File.createTempFile("gradle-acumen", ".jar"); extractedJarFile.deleteOnExit(); dumpFromClasspath("/gradle-acumen-0.2.0.jar", extractedJarFile); } else { extractedJarFile = new File(devGradleAcumen); } acumenTemplateFromClasspath(extractedJarFile, initAcumenFile); action.withArguments("--init-script", initAcumenFile.getAbsolutePath()); File jdkHome = getJdkHome(); if (jdkHome != null) { toolingLogger.log("Using Gradle JAVA_HOME=" + jdkHome); action.setJavaHome(jdkHome); } atm = action.run(); GradleNode rootNode = convertToGradleNode(atm); dependencyMap.put("root", rootNode); } catch (Exception e) { toolingLogger.log(ExceptionUtils.getFullStackTrace(e)); throw new RuntimeException(e); } finally { connection.close(); } return dependencyMap; }
From source file:org.spring.data.gemfire.app.main.InitializerPeerCacheApp.java
@Override protected ConfigurableApplicationContext initApplicationContext(final String... args) { new SpringContextBootstrappingInitializer().init(PropertyUtils.createProperties( Collections.singletonMap(SpringContextBootstrappingInitializer.CONTEXT_CONFIG_LOCATIONS_PARAMETER, StringUtils.arrayToCommaDelimitedString(getConfigurationFile(args))))); return SpringContextBootstrappingInitializer.getApplicationContext(); }
From source file:gov.nih.nci.cabig.ctms.web.tabs.DefaultTabConfigurerTest.java
private RootBeanDefinition createTestBeanDef(int id) { return new RootBeanDefinition(TestBean.class, new MutablePropertyValues(Collections.singletonMap("id", id))); }
From source file:io.fabric8.maven.enricher.fabric8.GrafanaLinkEnricher.java
@Override public Map<String, String> getAnnotations(Kind kind) { if (kind.isController()) { String url = findGrafanaLink(); return url != null ? Collections.singletonMap(Fabric8Annotations.METRICS_PATH.value(), url) : null; } else {//from ww w . ja v a 2s.c o m return null; } }
From source file:com.logsniffer.reader.grok.GrokTest.java
@Test public void testSingleSimplePattern() throws GrokException { GroksRegistry r = new GroksRegistry(); r.registerPatternBlocks(Collections.singletonMap("base", new String[] { "USERNAME [a-zA-Z0-9_-]+" })); assertEquals(1, r.getGroks().size()); assertNotNull(r.getGroks().get("USERNAME")); assertEquals(0, r.getGroks().get("USERNAME").getGroupNames().size()); assertEquals(true, r.getGroks().get("USERNAME").matcher("mbok").matches()); assertEquals(false, r.getGroks().get("USERNAME").matcher("mbok!").matches()); }
From source file:io.fabric8.maven.enricher.fabric8.DocLinkEnricher.java
@Override public Map<String, String> getAnnotations(Kind kind) { if (kind.isController()) { String url = findDocumentationUrl(); return url != null ? Collections.singletonMap(Fabric8Annotations.DOCS_URL.value(), url) : null; } else {/*from ww w. j a v a 2s . c om*/ return null; } }
From source file:com.codecrate.shard.ui.event.commandbus.SpecificApplicationEventActionCommandExecutor.java
protected void onSpecificApplicationEvent(ApplicationEvent event) { LOG.info("Executing specific action command due to application event " + event); delegate.execute(Collections.singletonMap("event", event)); }
From source file:io.spring.initializr.web.mapper.DependencyMetadataJsonMapperTests.java
@Test public void mapDependency() throws Exception { Dependency d = Dependency.withId("foo", "org.foo", "foo"); d.setRepository("my-repo"); d.setBom("my-bom"); Repository repository = new Repository(); repository.setName("foo-repo"); repository.setUrl(new URL("http://example.com/foo")); BillOfMaterials bom = BillOfMaterials.create("org.foo", "foo-bom", "1.0.0.RELEASE"); DependencyMetadata metadata = new DependencyMetadata(Version.parse("1.2.0.RELEASE"), Collections.singletonMap(d.getId(), d), Collections.singletonMap("repo-id", repository), Collections.singletonMap("bom-id", bom)); JSONObject content = new JSONObject(mapper.write(metadata)); assertEquals("my-bom", content.getJSONObject("dependencies").getJSONObject("foo").getString("bom")); assertEquals("my-repo", content.getJSONObject("dependencies").getJSONObject("foo").getString("repository")); assertEquals("foo-repo", content.getJSONObject("repositories").getJSONObject("repo-id").getString("name")); assertEquals("foo-bom", content.getJSONObject("boms").getJSONObject("bom-id").getString("artifactId")); assertEquals("1.0.0.RELEASE", content.getJSONObject("boms").getJSONObject("bom-id").getString("version")); }