List of usage examples for java.util Optional get
public T get()
From source file:com.teradata.tempto.internal.configuration.ConfigurationVariableResolver.java
private Pair<String, Object> resolveConfigurationEntry(Configuration configuration, String prefix, StrSubstitutor strSubstitutor) { Optional<Object> optionalValue = configuration.get(prefix); if (optionalValue.isPresent()) { Object value = optionalValue.get(); if (value instanceof String) { return Pair.of(prefix, strSubstitutor.replace(value)); } else {/*from w w w . jav a 2 s. c o m*/ return Pair.of(prefix, value); } } else { return Pair.of(prefix, resolveVariables(configuration.getSubconfiguration(prefix), strSubstitutor)); } }
From source file:ddf.security.impl.SubjectIdentityImpl.java
/** * Get a subject's unique identifier. 1. If the configured unique identifier if present 2. Email * address if present 3. Username not, user name is returned. * * @param subject//from ww w . j av a 2 s .com * @return subject unique identifier */ @Override public String getUniqueIdentifier(Subject subject) { Optional<String> owner = getSubjectAttribute(subject).stream().findFirst(); if (owner.isPresent()) { return owner.get(); } String identifier = SubjectUtils.getEmailAddress(subject); if (StringUtils.isNotBlank(identifier)) { return identifier; } return SubjectUtils.getName(subject); }
From source file:bg.vitkinov.edu.services.JokeCategoryService.java
@RequestMapping(value = "/search/{name}", method = RequestMethod.GET) public ResponseEntity<?> getCategoryByName(@PathVariable String name) { Optional<Category> category = repository.findByName(name); return category.isPresent() ? new ResponseEntity<>(category.get(), HttpStatus.OK) : new ResponseEntity<>(HttpStatus.NOT_FOUND); }
From source file:it.polimi.diceH2020.launcher.service.Validator.java
public boolean validatePrivateCloudParameters(Path pathToFile) { Optional<PrivateCloudParameters> sol = objectFromPath(pathToFile, PrivateCloudParameters.class); return (sol.isPresent() && sol.get().validate()); }
From source file:io.dfox.junit.example.NoteRepositoryTest.java
@Test public void testSaveFind() throws IOException { final String name = "test-note"; final String contents = "This is my note"; assertFalse(repository.getNote(name).isPresent()); try (InputStream contentsStream = IOUtils.toInputStream(contents)) { repository.saveNote(name, contentsStream); }//from w w w .j a v a2s . c o m Optional<InputStream> note = repository.getNote(name); assertTrue(note.isPresent()); try (InputStream stream = note.get()) { String savedContents = IOUtils.toString(stream); Assert.assertEquals(contents, savedContents); } }
From source file:org.springsource.restbucks.payment.CreditCardRepositoryIntegrationTest.java
@Test public void createsCreditCard() { CreditCard creditCard = repository.save(createCreditCard()); Optional<CreditCard> result = repository.findByNumber(creditCard.getNumber()); assertThat(result.isPresent(), is(true)); assertThat(result.get(), is(creditCard)); }
From source file:keywhiz.auth.cookie.CookieAuthenticator.java
@Override public Optional<User> authenticate(Cookie cookie) { User user = null;//w ww . java2 s. c o m if (cookie != null) { Optional<UserCookieData> cookieData = getUserCookieData(cookie); if (cookieData.isPresent()) { user = cookieData.get().getUser(); } } return Optional.ofNullable(user); }
From source file:it.polimi.diceH2020.launcher.service.Validator.java
public boolean validatePublicCloudParameters(Path pathToFile) { Optional<PublicCloudParametersMap> sol = objectFromPath(pathToFile, PublicCloudParametersMap.class); return (sol.isPresent() && sol.get().validate()); }
From source file:mc.feature.ast.ASTTest.java
@Test public void testFileNameInSourcePosition() { String grammarToTest = "src/test/resources/mc/grammar/SimpleGrammarWithConcept.mc4"; Path model = Paths.get(new File(grammarToTest).getAbsolutePath()); MontiCoreScript mc = new MontiCoreScript(); Optional<ASTMCGrammar> ast = mc.parseGrammar(model); assertTrue(ast.isPresent());//from w ww . ja va 2s.co m ASTMCGrammar clonedAst = ast.get().deepClone(); assertTrue(clonedAst.get_SourcePositionStart().getFileName().isPresent()); assertEquals("SimpleGrammarWithConcept.mc4", FilenameUtils.getName(clonedAst.get_SourcePositionStart().getFileName().get())); }
From source file:org.openwms.tms.redirection.TargetRedirector.java
/** * The implementation has to vote for a certain vote on particular rules that are implemented by the voter. * * @param vote The vote to vote for//from ww w . j ava2 s . c om * @throws DeniedException is thrown when the voter cannot vote for the action */ @Override public void voteFor(RedirectVote vote) throws DeniedException { Optional<T> optionalTarget = resolveTarget(vote); if (optionalTarget.isPresent()) { if (isTargetAvailable(optionalTarget.get())) { assignTarget(vote); vote.complete(); } else { String msg = translator.translate(TMSMessageCodes.TARGET_BLOCKED_MSG, vote.getTarget(), vote.getTransportOrder().getPersistentKey()); vote.addMessage(new Message.Builder().withMessage(msg) .withMessageNo(TMSMessageCodes.TARGET_BLOCKED_MSG).build()); LOGGER.debug(msg); } } }