List of usage examples for java.util Collections singleton
public static <T> Set<T> singleton(T o)
From source file:com.ctc.storefront.controllers.pages.ConfigureController.java
@RequestMapping(method = RequestMethod.GET) public String productDetail(@PathVariable("productCode") final String productCode, final Model model, final HttpServletRequest request, final HttpServletResponse response) throws CMSItemNotFoundException, UnsupportedEncodingException { String redirectTo = ""; final ProductData productData = productFacade.getProductForCodeAndOptions(productCode, Collections.singleton(ProductOption.GALLERY)); if (productData.getConfigurable()) { final List<ConfigurationInfoData> configurations = productFacade .getConfiguratorSettingsForCode(productData.getCode()); if (!configurations.isEmpty()) { redirectTo = configurations.get(0).getConfiguratorType().toString(); }//from w w w .j a v a2 s . c o m } final String redirection = checkRequestUrl(request, response, productDataUrlResolver.resolve(productData)); if (StringUtils.isNotEmpty(redirection)) { return redirection + "/configuratorPage/" + redirectTo; } return FORWARD_PREFIX + "/404"; }
From source file:example.springdata.mongodb.security.PersonRepositoryIntegrationTest.java
@Test public void adminCallingShouldReturnAllUsers() throws Exception { UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(admin, "x", Collections.singleton(new SimpleGrantedAuthority("ROLE_ADMIN"))); SecurityContextHolder.getContext().setAuthentication(auth); List<Person> persons = repository.findAllForCurrentUserById(); assertThat(persons, hasSize(4));//from w w w .j av a 2 s. c om assertThat(persons, containsInAnyOrder(admin, dave, carter, oliver)); }
From source file:com.cloudera.nav.sdk.client.writer.MetadataWriter.java
public void writeRelation(Relation relation) { writeRelations(Collections.singleton(relation)); }
From source file:ai.grakn.graql.internal.analytics.ConnectedComponentVertexProgram.java
@Override public Set<String> getElementComputeKeys() { return Collections.singleton(clusterLabel); }
From source file:io.logspace.system.SolrClientResource.java
@Override protected void before() throws Throwable { this.httpClient = HttpClients.custom().disableAutomaticRetries() .setDefaultRequestConfig(RequestConfig.custom().setConnectionRequestTimeout(TIMEOUT) .setConnectTimeout(TIMEOUT).setSocketTimeout(TIMEOUT).build()) .setDefaultHeaders(Collections.singleton(new BasicHeader("Accept", APPLICATION_JSON.getMimeType()))) .build();/*www .j av a 2 s . c o m*/ }
From source file:com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil.java
public static AnalysisScope makeScope(String[] files, SingleClassLoaderFactory loaders, Language language) throws IOException { CAstAnalysisScope result = new CAstAnalysisScope(files, loaders, Collections.singleton(language)); return result; }
From source file:Main.java
/** * Copies the given {@link Set} into a new {@link Set}.<br> * //from w w w. j ava 2 s.c om * * @param <T> * the type of the entries of the set * @param data * the given set * @return If the given set was empty, a {@link Collections#emptySet()} is * returned<br> * If the given set contained only one element, a * {@link Collections#singleton(Object)}, containing said element, * is returned <br> * If the given set contained more than one element, a * {@link Collections#unmodifiableSet(Set)}, containing the * elements of the given set, is returned. */ public static <T> Set<T> copy(Set<T> data) { final int size = data.size(); switch (size) { case 0: return Collections.emptySet(); case 1: return Collections.singleton(data.iterator().next()); default: return Collections.unmodifiableSet(new HashSet<T>(data)); } }
From source file:com.cloudera.oryx.app.als.FeatureVectorsTest.java
@Test public void testRetainRecent() { FeatureVectors fv = new FeatureVectors(); fv.setVector("foo", new float[] { 1.0f }); fv.retainRecentAndIDs(Collections.singleton("foo")); assertEquals(1, fv.size());//from w ww .ja v a 2 s.com fv.retainRecentAndIDs(Collections.singleton("bar")); assertEquals(0, fv.size()); }
From source file:org.labkey.nashorn.NashornModule.java
@NotNull @Override//from w w w .java 2 s . co m public Set<? extends ModuleResourceLoader> getResourceLoaders() { return Collections.singleton(new NashornResourceLoader()); }
From source file:com.devicehive.handler.command.CommandSubscribeIntegrationTest.java
@Test public void shouldSubscribeToDeviceCommands() throws Exception { String device1 = randomUUID().toString(); String device2 = randomUUID().toString(); String subscriber1 = randomUUID().toString(); String subscriber2 = randomUUID().toString(); String subscriber3 = randomUUID().toString(); CommandSubscribeRequest sr1 = new CommandSubscribeRequest(subscriber1, device1, null, null); Request r1 = Request.newBuilder().withBody(sr1).withSingleReply(false).build(); TestCallback c1 = new TestCallback(); client.call(r1, c1);//www.j a v a 2 s .c o m CommandSubscribeRequest sr2 = new CommandSubscribeRequest(subscriber1, device2, Collections.singleton("increase_temperature"), null); Request r2 = Request.newBuilder().withBody(sr2).withSingleReply(false).build(); TestCallback c2 = new TestCallback(); client.call(r2, c2); CommandSubscribeRequest sr3 = new CommandSubscribeRequest(subscriber2, device2, null, null); Request r3 = Request.newBuilder().withBody(sr3).withSingleReply(false).build(); TestCallback c3 = new TestCallback(); client.call(r3, c3); CommandSubscribeRequest sr4 = new CommandSubscribeRequest(subscriber2, device1, Collections.singleton("toggle_lights"), null); Request r4 = Request.newBuilder().withBody(sr4).withSingleReply(false).build(); TestCallback c4 = new TestCallback(); client.call(r4, c4); CommandSubscribeRequest sr5 = new CommandSubscribeRequest(subscriber3, randomUUID().toString(), null, null); Request r5 = Request.newBuilder().withBody(sr5).withSingleReply(false).build(); TestCallback c5 = new TestCallback(); client.call(r5, c5); //wait for subscribers to subscribe Stream.of(c1.subscribeFuture, c2.subscribeFuture, c3.subscribeFuture, c4.subscribeFuture, c5.subscribeFuture).forEach(CompletableFuture::join); //devices send commands List<CompletableFuture<Response>> futures = Stream.of(device1, device2).flatMap(device -> { List<CompletableFuture<Response>> list = Stream.of("increase_temperature", "toggle_lights") .map(name -> { DeviceCommand command = new DeviceCommand(); command.setId(0); command.setCommand(name); command.setDeviceGuid(device); CommandInsertRequest event = new CommandInsertRequest(command); 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 for commands to be delivered futures.forEach(CompletableFuture::join); assertThat(c1.commands, hasSize(2)); c1.commands.forEach(event -> { assertNotNull(event.getCommand()); assertEquals(event.getCommand().getDeviceGuid(), device1); assertEquals(event.getCommand().getId(), Long.valueOf(0)); }); Set<String> names = c1.commands.stream().map(n -> n.getCommand().getCommand()).collect(Collectors.toSet()); assertThat(names, containsInAnyOrder("increase_temperature", "toggle_lights")); assertThat(c2.commands, hasSize(1)); CommandEvent e = c2.commands.stream().findFirst().get(); assertNotNull(e.getCommand()); assertEquals(e.getCommand().getDeviceGuid(), device2); assertEquals(e.getCommand().getId(), Long.valueOf(0)); assertEquals(e.getCommand().getCommand(), "increase_temperature"); assertThat(c3.commands, hasSize(2)); c3.commands.forEach(event -> { assertNotNull(event.getCommand()); assertEquals(event.getCommand().getDeviceGuid(), device2); assertEquals(event.getCommand().getId(), Long.valueOf(0)); }); names = c3.commands.stream().map(n -> n.getCommand().getCommand()).collect(Collectors.toSet()); assertThat(names, containsInAnyOrder("increase_temperature", "toggle_lights")); assertThat(c4.commands, hasSize(1)); e = c4.commands.stream().findFirst().get(); assertNotNull(e.getCommand()); assertEquals(e.getCommand().getDeviceGuid(), device1); assertEquals(e.getCommand().getId(), Long.valueOf(0)); assertEquals(e.getCommand().getCommand(), "toggle_lights"); assertThat(c5.commands, is(empty())); }