List of usage examples for java.util Optional isPresent
public boolean isPresent()
From source file:dev.archiecortez.jfacelog.employeemanager.EmployeeManagerPresenter.java
@FXML public void newPass() throws IOException { NewPassDialog newPassDialog = new NewPassDialog(); Optional<Pair<String, String>> rslt = newPassDialog.showAndWait(); try {//from w w w.j a va 2 s. com if (rslt.isPresent()) { DTREmployee emp = (DTREmployee) employeesListView.getSelectionModel().getSelectedItem(); emp.changePassword(rslt.get().getKey(), rslt.get().getValue()); employeeDTO.updateEmployee(emp); } } catch (Exception e) { Alert a = new Alert(Alert.AlertType.ERROR); a.setTitle("Error setting password."); a.setContentText(e.getMessage()); a.showAndWait(); } }
From source file:org.obiba.mica.dataset.DatasetCacheResolver.java
@Override public Collection<? extends Cache> resolveCaches( CacheOperationInvocationContext<?> cacheOperationInvocationContext) { Collection<Cache> res = Lists.newArrayList(); Optional<Object> dataset = Arrays.stream(cacheOperationInvocationContext.getArgs()) .filter(o -> o instanceof Dataset).findFirst(); if (dataset.isPresent()) { String cacheName = "dataset-" + ((Dataset) dataset.get()).getId(); Cache datasetCache = springCacheManager.getCache(cacheName); if (datasetCache == null) { CacheConfiguration conf = cacheManager.getEhcache("dataset-variables").getCacheConfiguration() .clone();//from w w w.j a v a 2s. co m conf.setName(cacheName); cacheManager.addCache(new net.sf.ehcache.Cache(conf)); net.sf.ehcache.Cache cache = cacheManager.getCache(cacheName); cacheManager.replaceCacheWithDecoratedCache(cache, InstrumentedEhcache.instrument(metricRegistry, cache)); datasetCache = new EhCacheCache(cacheManager.getEhcache(cacheName)); } res.add(datasetCache); } return res; }
From source file:com.blackducksoftware.integration.hub.detect.detector.nuget.NugetInspectorPackager.java
public NugetParseResult createDetectCodeLocation(final File dependencyNodeFile) throws IOException { final String text = FileUtils.readFileToString(dependencyNodeFile, StandardCharsets.UTF_8); final NugetInspection nugetInspection = gson.fromJson(text, NugetInspection.class); final List<DetectCodeLocation> codeLocations = new ArrayList<>(); String projectName = ""; String projectVersion = ""; for (final NugetContainer it : nugetInspection.containers) { final Optional<NugetParseResult> possibleParseResult = createDetectCodeLocationFromNugetContainer(it); if (possibleParseResult.isPresent()) { final NugetParseResult result = possibleParseResult.get(); if (StringUtils.isNotBlank(result.projectName)) { projectName = result.projectName; projectVersion = result.projectVersion; }// www . ja v a 2 s . com codeLocations.addAll(result.codeLocations); } } return new NugetParseResult(projectName, projectVersion, codeLocations); }
From source file:com.epam.ta.reportportal.core.widget.impl.GetWidgetHandler.java
private boolean isFilterUnShared(String userName, String project, Optional<UserFilter> userFilter) { return userFilter.isPresent() && !AclUtils.isPossibleToReadResource(userFilter.get().getAcl(), userName, project); }
From source file:io.curly.artifact.service.DefaultArtifactCommand.java
@Override @Loggable/*from w w w . j ava2 s.c om*/ @HystrixCommand(ignoreExceptions = IllegalArgumentException.class) public Observable<Optional<Artifact>> save(Artifact artifact, User user) { return new ObservableResult<Optional<Artifact>>() { @Override public Optional<Artifact> invoke() { Optional<Artifact> optional = Optional.ofNullable(artifactService.save(artifact, user)); if (optional.isPresent()) { applicationEventPublisher.publishEvent(new CreatedArtifactEvent(optional.get())); } return optional; } }; }
From source file:me.dags.creativeblock.blockpack.FolderBlockPack.java
@Override public List<BlockDefinition> getDefinitions() { List<BlockDefinition> definitions = new ArrayList<>(); final File definitionsDir = FileUtil.getDir(this.getSource(), "assets", creativeBlock.domain(), "definitions"); final File texturesDir = FileUtil.getDir(this.getSource(), "assets", creativeBlock.domain(), "textures", "blocks"); Iterator<File> defIterator = FileUtils.iterateFilesAndDirs(definitionsDir, definitionsFilter(), TrueFileFilter.INSTANCE);//from w w w .j ava 2s .co m while (defIterator.hasNext()) { File file = defIterator.next(); Optional<DefinitionSerializable> optional = JsonUtil.deserialize(file, DefinitionSerializable.class); if (optional.isPresent()) { DefinitionSerializable jsonDefinition = optional.get(); jsonDefinition.tabId = getTabName(definitionsDir, file); BlockDefinition definition = BlockDefinition.from(optional.get()); definitions.add(definition); } } return definitions; }
From source file:com.teradata.logging.TestFrameworkLoggingAppender.java
private void writeToFile(String message) { Optional<PrintWriter> printWriter = getFilePrintWriterForCurrentTest(); if (printWriter.isPresent()) { printWriter.get().print(message); printWriter.get().flush();/*from w w w . j a v a2 s . c om*/ } }
From source file:com.teradata.logging.TestFrameworkLoggingAppender.java
private Optional<PrintWriter> getFilePrintWriterForCurrentTest() { Optional<String> currentTestLogFileName = getCurrentTestLogFileName(); if (currentTestLogFileName.isPresent()) { return Optional.of(getFilePrintWriter(currentTestLogFileName.get())); } else {//from w w w. j a v a2 s. c o m return Optional.empty(); } }
From source file:com.devicehive.handler.command.CommandInsertHandlerTest.java
@Test public void shouldHandleCommandInsert() throws Exception { DeviceCommand command = new DeviceCommand(); command.setId(System.currentTimeMillis()); command.setCommand("do work"); command.setDeviceGuid(UUID.randomUUID().toString()); CommandInsertRequest cir = new CommandInsertRequest(command); Response response = handler.handle(Request.newBuilder().withBody(cir).build()); assertNotNull(response);//www . j a v a 2 s . c o m assertNotNull(response.getBody()); assertTrue(response.getBody() instanceof CommandInsertResponse); CommandInsertResponse body = (CommandInsertResponse) response.getBody(); assertEquals(body.getDeviceCommand(), command); Optional<DeviceCommand> cmd = hazelcastService.find(command.getId(), command.getDeviceGuid(), DeviceCommand.class); assertTrue(cmd.isPresent()); assertEquals(cmd.get(), command); ArgumentCaptor<CommandEvent> eventCaptor = ArgumentCaptor.forClass(CommandEvent.class); verify(eventBus).publish(eventCaptor.capture()); CommandEvent event = eventCaptor.getValue(); assertEquals(event.getCommand(), command); }