List of usage examples for java.util Collections singletonList
public static <T> List<T> singletonList(T o)
From source file:org.cloudfoundry.identity.uaa.login.LinkedMaskingMultiValueMapTests.java
@Test public void set() { map.set("key", "value1"); map.set("key", "value2"); assertEquals(1, map.size());//from w w w . j a v a 2 s .c o m assertEquals(Collections.singletonList("value2"), map.get("key")); }
From source file:com.example.dlp.Redact.java
private static void redactString(String string, String replacement, Likelihood minLikelihood, List<InfoType> infoTypes) throws Exception { // [START dlp_redact_string] // Instantiate the DLP client try (DlpServiceClient dlpClient = DlpServiceClient.create()) { // The minimum likelihood required before returning a match // eg.minLikelihood = LIKELIHOOD_VERY_LIKELY; InspectConfig inspectConfig = InspectConfig.newBuilder().addAllInfoTypes(infoTypes) .setMinLikelihood(minLikelihood).build(); ContentItem contentItem = ContentItem.newBuilder().setType("text/plain") .setData(ByteString.copyFrom(string.getBytes())).build(); List<ReplaceConfig> replaceConfigs = new ArrayList<>(); if (infoTypes.isEmpty()) { // replace all detected sensitive elements with replacement string replaceConfigs.add(ReplaceConfig.newBuilder().setReplaceWith(replacement).build()); } else {/*from ww w . ja v a2s.co m*/ // Replace select info types with chosen replacement string for (InfoType infoType : infoTypes) { replaceConfigs.add( ReplaceConfig.newBuilder().setInfoType(infoType).setReplaceWith(replacement).build()); } } RedactContentResponse contentResponse = dlpClient.redactContent(inspectConfig, Collections.singletonList(contentItem), replaceConfigs); for (ContentItem responseItem : contentResponse.getItemsList()) { // print out string with redacted content System.out.println(responseItem.getData().toStringUtf8()); } } // [END dlp_redact_string] }
From source file:fi.hsl.parkandride.core.domain.prediction.AbstractPredictorTest.java
public void insertUtilization(DateTime timestamp, int spacesAvailable) { Utilization u = new Utilization(); u.facilityId = utilizationKey.facilityId; u.capacityType = utilizationKey.capacityType; u.usage = utilizationKey.usage;/*from ww w .jav a 2s .c o m*/ u.timestamp = timestamp; u.spacesAvailable = spacesAvailable; utilizationRepository.insertUtilizations(Collections.singletonList(u)); if (!latestInsertedUtilization.isPresent() || latestInsertedUtilization.get().timestamp.isBefore(timestamp)) { latestInsertedUtilization = Optional.of(u); } }
From source file:io.pivotal.strepsirrhini.chaosloris.web.ChaosResourceAssemblerTest.java
@Test public void toResource() { Application application = new Application(UUID.randomUUID()); application.setId(-1L);//from w w w . j av a2 s .c o m Schedule schedule = new Schedule("0 0 * * * *", "hourly"); schedule.setId(-2L); Chaos chaos = new Chaos(application, 0.2, schedule); chaos.setId(-3L); Event event = new Event(chaos, Instant.EPOCH, Collections.emptyList(), Integer.MIN_VALUE); event.setId(-4L); when(this.eventRepository.findByChaos(chaos)).thenReturn(Collections.singletonList(event)); ChaosResourceAssembler.ChaosResource resource = this.resourceAssembler.toResource(chaos); assertThat(resource.getContent()).isSameAs(chaos); assertThat(resource.getLinks()).hasSize(4); assertThat(resource.getLink("application")).isNotNull(); assertThat(resource.getLink("event")).isNotNull(); assertThat(resource.getLink("schedule")).isNotNull(); }
From source file:PDFBuilderTest.java
@Test public void createPDF() throws Exception { Employee employee = new Employee(); employee.setFirstName("John"); employee.setLastName("Smith"); pdfBuilder.setEmployee(employee);/*w ww.j av a 2 s. c o m*/ User issuer = new User(); issuer.setFirstName("Peter"); issuer.setLastName("Cruz"); pdfBuilder.setIssuer(issuer); Asset asset = new Asset(); DeviceBrand db = new DeviceBrand("HP"); DeviceType dt = new DeviceType("Laptop"); DeviceModel dm = new DeviceModel(dt, db, "840 G1"); asset.setDeviceModel(dm); asset.setSerialNumber("32179879"); asset.setInventoryNumber("A000402"); pdfBuilder.setAssets(Collections.singletonList(asset)); pdfBuilder.setDate(LocalDate.now()); String file = pdfBuilder.createPDF(); System.out.println("file: " + file); assertTrue(Files.exists(Paths.get(file))); }
From source file:org.bozzo.ipplan.web.assembler.AddressPlanResourceAssemblerTest.java
@Test public void toResources_with_singleton_array_should_return_a_singleton_array() { AddressPlan plan = new AddressPlan(); plan.setId(1L);/* w w w . j av a 2s . c o m*/ plan.setDescription("Test description"); plan.setInfraId(1); plan.setLastModifed(new Date()); plan.setName("test"); List<AddressPlanResource> resources = this.assembler.toResources(Collections.singletonList(plan)); Assert.assertNotNull(resources); Assert.assertEquals(1, resources.size()); Assert.assertTrue(ResourceSupport.class.isAssignableFrom(resources.get(0).getClass())); }
From source file:io.opentracing.contrib.elasticsearch5.TracingTest.java
@BeforeClass public static void startElasticsearch() throws Exception { Settings settings = Settings.builder().put("path.home", ES_WORKING_DIR) .put("path.data", ES_WORKING_DIR + "/data").put("path.logs", ES_WORKING_DIR + "/logs") .put("transport.type", "netty4").put("http.type", "netty4").put("cluster.name", clusterName) .put("http.port", HTTP_PORT).put("transport.tcp.port", HTTP_TRANSPORT_PORT) .put("network.host", "127.0.0.1").build(); Collection plugins = Collections.singletonList(Netty4Plugin.class); node = new PluginConfigurableNode(settings, plugins); node.start();//from ww w. j av a 2 s . c om }
From source file:com.octo.mbo.domain.ApproachingMatcher.java
/** * Sort the list of keys according to their distance with the reference key * @param keysOfSlides List of keys//from ww w. j a v a2 s . c o m * @param key A reference key that will be compared to each String * @return A map whose index are the distances and values a list of keys for the corresponding distance. */ public SortedMap<Integer, Set<String>> sortByDistanceWithKey(Collection<String> keysOfSlides, String key) { assert keysOfSlides != null; assert key != null; SortedMap<Integer, Set<String>> keysSortedByDistance = new TreeMap<>(); for (String slideKey : keysOfSlides) { int distK2k = levenshteinDistance.apply(normalize(key), normalize(slideKey)); if (keysSortedByDistance.containsKey(distK2k)) { keysSortedByDistance.get(distK2k).add(slideKey); } else { keysSortedByDistance.put(distK2k, new HashSet<>((Collections.singletonList(slideKey)))); } } log.trace("Sort by least distance to '{}' after normalization : {}", key, keysSortedByDistance); return keysSortedByDistance; }
From source file:de.hybris.platform.acceleratorstorefrontcommons.controllers.util.GlobalMessages.java
public static void addFlashMessage(final RedirectAttributes model, final String messageHolder, final String messageKey, final Object[] attributes) { final GlobalMessage message = new GlobalMessage(); message.setCode(messageKey);/*from ww w. j a v a 2 s. c om*/ message.setAttributes(attributes != null ? Arrays.asList(attributes) : Collections.emptyList()); final Map<String, ?> flashModelMap = model.getFlashAttributes(); if (flashModelMap.containsKey(messageHolder)) { final List<GlobalMessage> messages = new ArrayList<>( (List<GlobalMessage>) flashModelMap.get(messageHolder)); messages.add(message); model.addFlashAttribute(messageHolder, messages); } else { model.addFlashAttribute(messageHolder, Collections.singletonList(message)); } }
From source file:com.cloudera.cdk.morphline.json.ExtractJsonPathsBuilder.java
@Override public Collection<String> getNames() { return Collections.singletonList("extractJsonPaths"); }