List of usage examples for java.util Set stream
default Stream<E> stream()
From source file:nu.yona.server.device.service.DeviceServiceTestConfiguration.java
@Test public void getDeviceAnonymized_byId_tryGetNonExistingId_exception() { expectedException.expect(DeviceServiceException.class); expectedException.expect(hasMessageId("error.device.not.found.anonymized.id")); // Add devices String deviceName1 = "First"; OperatingSystem operatingSystem1 = OperatingSystem.ANDROID; addDeviceToRichard(0, deviceName1, operatingSystem1); String deviceName2 = "Second"; OperatingSystem operatingSystem2 = OperatingSystem.IOS; addDeviceToRichard(1, deviceName2, operatingSystem2); // Verify two devices are present Set<UserDevice> devices = richard.getDevices(); assertThat(devices.stream().map(UserDevice::getName).collect(Collectors.toSet()), containsInAnyOrder(deviceName1, deviceName2)); // Try to get the anonymized ID for a nonexisting ID service.getDeviceAnonymized(createRichardAnonymizedDto(), UUID.randomUUID()); }
From source file:nu.yona.server.device.service.DeviceServiceTestConfiguration.java
@Test public void getDeviceAnonymized_byIndex_firstDevice_correctDevice() { // Add devices String deviceName1 = "First"; OperatingSystem operatingSystem1 = OperatingSystem.ANDROID; UserDevice device1 = addDeviceToRichard(0, deviceName1, operatingSystem1); String deviceName2 = "Second"; OperatingSystem operatingSystem2 = OperatingSystem.IOS; addDeviceToRichard(1, deviceName2, operatingSystem2); // Verify two devices are present Set<UserDevice> devices = richard.getDevices(); assertThat(devices.stream().map(UserDevice::getName).collect(Collectors.toSet()), containsInAnyOrder(deviceName1, deviceName2)); // Get the anonymized device for the first index DeviceAnonymizedDto deviceAnonymized = service.getDeviceAnonymized(createRichardAnonymizedDto(), 0); // Assert success assertThat(deviceAnonymized.getId(), equalTo(userDeviceRepository.getOne(device1.getId()).getDeviceAnonymizedId())); }
From source file:nu.yona.server.device.service.DeviceServiceTestConfiguration.java
@Test public void getDeviceAnonymized_byIndex_secondDevice_correctDevice() { // Add devices String deviceName1 = "First"; OperatingSystem operatingSystem1 = OperatingSystem.ANDROID; addDeviceToRichard(0, deviceName1, operatingSystem1); String deviceName2 = "Second"; OperatingSystem operatingSystem2 = OperatingSystem.IOS; UserDevice device2 = addDeviceToRichard(1, deviceName2, operatingSystem2); // Verify two devices are present Set<UserDevice> devices = richard.getDevices(); assertThat(devices.stream().map(UserDevice::getName).collect(Collectors.toSet()), containsInAnyOrder(deviceName1, deviceName2)); // Get the anonymized device for the second index DeviceAnonymizedDto deviceAnonymized = service.getDeviceAnonymized(createRichardAnonymizedDto(), 1); // Assert success assertThat(deviceAnonymized.getId(), equalTo(userDeviceRepository.getOne(device2.getId()).getDeviceAnonymizedId())); }
From source file:nu.yona.server.device.service.DeviceServiceTestConfiguration.java
@Test public void getDeviceAnonymized_byIndex_defaultDevice_correctDevice() { // Add devices String deviceName1 = "First"; OperatingSystem operatingSystem1 = OperatingSystem.ANDROID; UserDevice device1 = addDeviceToRichard(0, deviceName1, operatingSystem1); String deviceName2 = "Second"; OperatingSystem operatingSystem2 = OperatingSystem.IOS; addDeviceToRichard(1, deviceName2, operatingSystem2); // Verify two devices are present Set<UserDevice> devices = richard.getDevices(); assertThat(devices.stream().map(UserDevice::getName).collect(Collectors.toSet()), containsInAnyOrder(deviceName1, deviceName2)); // Get the anonymized device for a negative index, implies fall back to default device DeviceAnonymizedDto deviceAnonymized = service.getDeviceAnonymized(createRichardAnonymizedDto(), -1); // Assert success assertThat(deviceAnonymized.getId(), equalTo(userDeviceRepository.getOne(device1.getId()).getDeviceAnonymizedId())); }
From source file:nu.yona.server.device.service.DeviceServiceTestConfiguration.java
@Test public void getDeviceAnonymizedId_byId_firstDevice_correctDevice() { // Add devices String deviceName1 = "First"; OperatingSystem operatingSystem1 = OperatingSystem.ANDROID; UserDevice device1 = addDeviceToRichard(0, deviceName1, operatingSystem1); String deviceName2 = "Second"; OperatingSystem operatingSystem2 = OperatingSystem.IOS; addDeviceToRichard(1, deviceName2, operatingSystem2); // Verify two devices are present Set<UserDevice> devices = richard.getDevices(); assertThat(devices.stream().map(UserDevice::getName).collect(Collectors.toSet()), containsInAnyOrder(deviceName1, deviceName2)); // Get the anonymized ID for the first device ID UUID deviceAnonymizedId = service.getDeviceAnonymizedId(createRichardUserDto(), device1.getId()); // Assert success assertThat(deviceAnonymizedId,//from w w w . j a v a 2 s. com equalTo(userDeviceRepository.getOne(device1.getId()).getDeviceAnonymizedId())); }
From source file:nu.yona.server.device.service.DeviceServiceTestConfiguration.java
@Test public void getDeviceAnonymizedId_byId_secondDevice_correctDevice() { // Add devices String deviceName1 = "First"; OperatingSystem operatingSystem1 = OperatingSystem.ANDROID; addDeviceToRichard(0, deviceName1, operatingSystem1); String deviceName2 = "Second"; OperatingSystem operatingSystem2 = OperatingSystem.IOS; UserDevice device2 = addDeviceToRichard(1, deviceName2, operatingSystem2); // Verify two devices are present Set<UserDevice> devices = richard.getDevices(); assertThat(devices.stream().map(UserDevice::getName).collect(Collectors.toSet()), containsInAnyOrder(deviceName1, deviceName2)); // Get the anonymized ID for the second device ID UUID deviceAnonymizedId = service.getDeviceAnonymizedId(createRichardUserDto(), device2.getId()); // Assert success assertThat(deviceAnonymizedId,/* w ww. j a va 2 s .c o m*/ equalTo(userDeviceRepository.getOne(device2.getId()).getDeviceAnonymizedId())); }
From source file:com.ejisto.event.listener.SessionRecorderManager.java
private void tryToSave(final String contextPath) { final Set<CollectedData> data = RECORDED_DATA.replace(contextPath, new HashSet<>()); if (CollectionUtils.isEmpty(data)) { log.debug("Nothing to save, exiting"); return;//from w w w . j a v a 2s .co m } String name; do { name = showInputDialog(null, getMessage("session.record.save.as"), new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(new Date())); } while (StringUtils.isEmpty(name) && !GuiUtils.showWarning(null, getMessage("warning.message"))); if (StringUtils.isNotEmpty(name)) { final CollectedData collectedData; if (data.size() > 1) { final Stream<CollectedData> stream = data.stream(); CollectedData aggregated = CollectedData.empty(stream.findFirst().get().getRequestURI(), contextPath); collectedData = stream.reduce(aggregated, CollectedData::join); } else { collectedData = data.iterator().next(); } collectedDataRepository.saveRecordedSession(name, collectedData); eventManager.publishEvent( new SessionRecorded(this, name, getMessage("session.recorded.status.message", name))); } }
From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.KubernetesV2SearchProvider.java
private List<Map<String, Object>> getMatches(String query, List<String> types, Map<String, String> filters) { String matchQuery = String.format("*%s*", query.toLowerCase()); Set<String> typeSet = new HashSet<>(types); // We add k8s versions of Spinnaker types here to ensure that (for example) replica sets are returned when server groups are requested. typeSet.addAll(types.stream().map(t -> { try {//from w w w .j a v a 2s .c om return KubernetesSpinnakerKindMap.SpinnakerKind.fromString(t); } catch (IllegalArgumentException e) { return null; } }).filter(Objects::nonNull).map(kindMap::translateSpinnakerKind).flatMap(Collection::stream) .map(KubernetesKind::toString).collect(Collectors.toSet())); // Remove caches that we can't search typeSet.retainAll(allCaches); // Search caches directly List<Map<String, Object>> results = typeSet.stream() .map(type -> cacheUtils.getAllKeysMatchingPattern(type, matchQuery)).flatMap(Collection::stream) .map(this::convertKeyToMap).filter(Objects::nonNull).collect(Collectors.toList()); // Search 'logical' caches (clusters, apps) for indirect matches Map<String, List<String>> keyToAllLogicalKeys = getKeysRelatedToLogicalMatches(matchQuery); results.addAll(keyToAllLogicalKeys.entrySet().stream().map(kv -> { Map<String, Object> result = convertKeyToMap(kv.getKey()); if (result == null) { return null; } kv.getValue().stream().map(Keys::parseKey).filter(Optional::isPresent).map(Optional::get) .filter(LogicalKey.class::isInstance).map(k -> (LogicalKey) k) .forEach(k -> result.put(k.getLogicalKind().singular(), k.getName())); return result; }).collect(Collectors.toList())); results = results.stream().filter(r -> typeSet.contains(r.get("type")) || typeSet.contains(r.get("group"))) .collect(Collectors.toList()); return results; }
From source file:nu.yona.server.device.service.DeviceServiceTestConfiguration.java
@Test public void getDeviceAnonymized_byId_firstDevice_correctDevice() { // Add devices String deviceName1 = "First"; OperatingSystem operatingSystem1 = OperatingSystem.ANDROID; UserDevice device1 = addDeviceToRichard(0, deviceName1, operatingSystem1); UUID deviceAnonymizedId1 = device1.getDeviceAnonymizedId(); String deviceName2 = "Second"; OperatingSystem operatingSystem2 = OperatingSystem.IOS; addDeviceToRichard(1, deviceName2, operatingSystem2); // Verify two devices are present Set<UserDevice> devices = richard.getDevices(); assertThat(devices.stream().map(UserDevice::getName).collect(Collectors.toSet()), containsInAnyOrder(deviceName1, deviceName2)); // Get the anonymized device for the first ID DeviceAnonymizedDto deviceAnonymized = service.getDeviceAnonymized(createRichardAnonymizedDto(), deviceAnonymizedId1);/*from ww w. j ava 2s . c o m*/ // Assert success assertThat(deviceAnonymized.getId(), equalTo(userDeviceRepository.getOne(device1.getId()).getDeviceAnonymizedId())); }
From source file:nu.yona.server.device.service.DeviceServiceTestConfiguration.java
@Test public void getDeviceAnonymized_byId_secondDevice_correctDevice() { // Add devices String deviceName1 = "First"; OperatingSystem operatingSystem1 = OperatingSystem.ANDROID; addDeviceToRichard(0, deviceName1, operatingSystem1); String deviceName2 = "Second"; OperatingSystem operatingSystem2 = OperatingSystem.IOS; UserDevice device2 = addDeviceToRichard(1, deviceName2, operatingSystem2); UUID deviceAnonymizedId2 = device2.getDeviceAnonymizedId(); // Verify two devices are present Set<UserDevice> devices = richard.getDevices(); assertThat(devices.stream().map(UserDevice::getName).collect(Collectors.toSet()), containsInAnyOrder(deviceName1, deviceName2)); // Get the anonymized device for the second ID DeviceAnonymizedDto deviceAnonymized = service.getDeviceAnonymized(createRichardAnonymizedDto(), deviceAnonymizedId2);//from w w w. ja v a 2 s . c o m // Assert success assertThat(deviceAnonymized.getId(), equalTo(userDeviceRepository.getOne(device2.getId()).getDeviceAnonymizedId())); }