List of usage examples for java.util Optional isPresent
public boolean isPresent()
From source file:com.dickthedeployer.dick.web.service.GroupService.java
private void validateIfNameAvailable(GroupModel groupModel) throws NameTakenException { Optional<Namespace> namespace = namespaceDao.findByName(groupModel.getName()); if (namespace.isPresent()) { throw new NameTakenException(); }/* w ww.j a v a2 s . c o m*/ }
From source file:it.unibo.alchemist.model.implementations.conditions.BiomolPresentInEnv.java
private double getTotalQuantity() { double quantityInEnvNodes = 0; if (!getEnviromentNodesSurrounding().isEmpty()) { quantityInEnvNodes = getEnviromentNodesSurrounding().stream().parallel() .mapToDouble(n -> n.getConcentration(getBiomolecule())).sum(); }/* w w w .ja va2s.co m*/ double quantityInLayers = 0; final Optional<Layer<Double>> layer = environment.getLayer(getBiomolecule()); if (layer.isPresent()) { quantityInLayers = layer.get().getValue(environment.getPosition(getNode())); } return quantityInEnvNodes + quantityInLayers; }
From source file:com.ebay.logstorm.server.services.impl.PipelineEntityServiceImpl.java
@Override public PipelineEntity getPipelineByIdOrThrow(String uuid) throws Exception { Optional<PipelineEntity> entity = getPipelineByUuid(uuid); if (entity.isPresent()) { return entity.get(); } else {// w ww. ja va 2 s .c o m throw new PipelineException("Pipeline [uuid='" + uuid + "'] not found"); } }
From source file:com.teradata.benchto.driver.execution.ExecutionDriver.java
private void runOptionalMacros(Optional<List<String>> macros, String kind) { if (macros.isPresent()) { LOG.info("Running {} macros: {}", kind, macros.get()); macroService.runBenchmarkMacros(macros.get()); }//from ww w. j a v a2s.c om }
From source file:com.blackducksoftware.integration.hub.detect.detector.bitbake.GraphParserTransformer.java
public DependencyGraph transform(final GraphParser graphParser, final String targetArchitecture) { final Map<String, GraphNode> nodes = graphParser.getNodes(); final Map<String, GraphEdge> edges = graphParser.getEdges(); final LazyExternalIdDependencyGraphBuilder graphBuilder = new LazyExternalIdDependencyGraphBuilder(); for (final GraphNode graphNode : nodes.values()) { final String name = getNameFromNode(graphNode); final DependencyId dependencyId = new NameDependencyId(name); final Optional<String> version = getVersionFromNode(graphNode); if (version.isPresent()) { final ExternalId externalId = new ExternalId(Forge.YOCTO); externalId.name = name;/*from w ww.jav a 2s .c o m*/ externalId.version = version.get(); externalId.architecture = targetArchitecture; graphBuilder.setDependencyInfo(dependencyId, name, version.get(), externalId); } graphBuilder.addChildToRoot(dependencyId); } for (final GraphEdge graphEdge : edges.values()) { final DependencyId node1 = new NameDependencyId(getNameFromNode(graphEdge.getNode1())); final DependencyId node2 = new NameDependencyId(getNameFromNode(graphEdge.getNode2())); graphBuilder.addParentWithChild(node1, node2); } return graphBuilder.build(); }
From source file:mtsar.processors.task.InverseCountAllocatorTest.java
@Test public void testUnequalAllocation() { when(countDAO.getCountsSQL(anyString())).thenReturn(Arrays.asList(Pair.of(1, 1), Pair.of(2, 0))); final TaskAllocator allocator = new InverseCountAllocator(stage, dbi, taskDAO, answerDAO); final Optional<TaskAllocation> optional = allocator.allocate(worker); assertThat(optional.isPresent()).isTrue(); final TaskAllocation allocation = optional.get(); assertThat(allocation.getTask().get().getId()).isEqualTo(2); assertThat(allocation.getTaskRemaining()).isEqualTo(2); assertThat(allocation.getTaskCount()).isEqualTo(2); }
From source file:mtsar.processors.task.InverseCountAllocatorTest.java
@Test public void testEqualAllocation() { when(countDAO.getCountsSQL(anyString())).thenReturn(Arrays.asList(Pair.of(1, 0), Pair.of(2, 0))); final TaskAllocator allocator = new InverseCountAllocator(stage, dbi, taskDAO, answerDAO); final Optional<TaskAllocation> optional = allocator.allocate(worker); assertThat(optional.isPresent()).isTrue(); final TaskAllocation allocation = optional.get(); assertThat(allocation.getTask().get().getId()).isBetween(1, 2); assertThat(allocation.getTaskRemaining()).isEqualTo(2); assertThat(allocation.getTaskCount()).isEqualTo(2); }
From source file:io.dfox.junit.http.example.ExampleTest.java
private void assertNoteExists(final String notePath) throws IOException { JsonNode notesFixture = getTestData("notes.json"); JsonNode noteFixture = notesFixture.path(notePath); String name = noteFixture.path("name").asText(); String expectedContents = noteFixture.path("contents").asText(); Optional<InputStream> note = repository.getNote(name); assertTrue(note.isPresent()); try (InputStream stream = note.get()) { String contents = IOUtils.toString(stream); assertEquals(expectedContents, contents); }// w w w. j a va 2 s. c o m }
From source file:com.github.jrh3k5.habitat4j.rest.CachingAccessTokenProvider.java
@Override public AccessToken getAccessToken() { final Optional<AccessToken> currentAccessToken = getCurrentAccessToken(); if (!currentAccessToken.isPresent() || needsRefresh(currentAccessToken.get())) { return getNewAccessToken(); }/*from ww w .ja v a 2 s . c o m*/ return currentAccessToken.get(); }
From source file:com.properned.application.LocaleListCell.java
private MenuItem getDeleteMenu(Locale locale) { MenuItem deleteMenu = new MenuItem(MessageReader.getInstance().getMessage("action.deleteMessageKey")); deleteMenu.setOnAction(new EventHandler<ActionEvent>() { @Override//from w w w .ja va2s.c om public void handle(ActionEvent event) { logger.info("Clic on delete button for locale '" + locale.toString() + "'"); String fileName = properties.getMapPropertiesFileByLocale().get(locale).getAbsolutePath(); Alert alert = new Alert(AlertType.CONFIRMATION); alert.setTitle(MessageReader.getInstance().getMessage("manageLocale.confirmDelete.title")); alert.setHeaderText(MessageReader.getInstance().getMessage("manageLocale.confirmDelete.header")); alert.setContentText( MessageReader.getInstance().getMessage("manageLocale.confirmDelete.content", fileName)); Optional<ButtonType> result = alert.showAndWait(); if (result.isPresent() && result.get() == ButtonType.OK) { logger.info("User say OK to the confirm"); properties.deleteLocale(locale); // Reload list controller.initializeList(); } } }); if (properties.getMapPropertiesByLocale().keySet().size() <= 1) { // We can delete only if there is more than the current locale deleteMenu.setDisable(true); } return deleteMenu; }