List of usage examples for java.util Optional get
public T get()
From source file:com.galenframework.storage.controllers.api.PageApiController.java
private Long obtainProjectId(String projectName) { Optional<Project> project = projectRepository.findProject(projectName); if (project.isPresent()) { return project.get().getProjectId(); } else {/* www . j ava 2 s . c o m*/ throw new RuntimeException("Missing project: " + projectName); } }
From source file:io.prestosql.plugin.accumulo.AccumuloClient.java
/** * Gets a collection of Accumulo Range objects from the given Presto domain. * This maps the column constraints of the given Domain to an Accumulo Range scan. * * @param domain Domain, can be null (returns (-inf, +inf) Range) * @param serializer Instance of an {@link AccumuloRowSerializer} * @return A collection of Accumulo Range objects * @throws TableNotFoundException If the Accumulo table is not found *//*www .j ava 2s . c om*/ public static Collection<Range> getRangesFromDomain(Optional<Domain> domain, AccumuloRowSerializer serializer) throws TableNotFoundException { // if we have no predicate pushdown, use the full range if (!domain.isPresent()) { return ImmutableSet.of(new Range()); } ImmutableSet.Builder<Range> rangeBuilder = ImmutableSet.builder(); for (io.prestosql.spi.predicate.Range range : domain.get().getValues().getRanges().getOrderedRanges()) { rangeBuilder.add(getRangeFromPrestoRange(range, serializer)); } return rangeBuilder.build(); }
From source file:lumbermill.internal.StringTemplateTest.java
@Test public void testExtractSentence() { try {//ww w. j av a 2 s . co m StringTemplate t = StringTemplate.compile("Hej hopp {field}"); Event event = Codecs.BYTES.from("Hello").put("field", "value"); Optional<String> formattedString = t.format(event); assertThat(formattedString.isPresent()).isTrue(); assertThat(formattedString.get()).isEqualTo("Hej hopp value"); ObjectNode objectNode = new ObjectNode(JsonNodeFactory.instance); JsonEvent jsonEvent = new JsonEvent(objectNode); jsonEvent.put("id", "This is a test ID"); jsonEvent.put("version", "This is a test version"); StringTemplate key = StringTemplate.compile("{id}/{version}"); assertThat(key.format(jsonEvent).get()).isEqualTo("This is a test ID/This is a test version"); } catch (RuntimeException e) { e.printStackTrace(); throw e; } }
From source file:ac.simons.tweetarchive.tweets.TweetStorageService.java
@Transactional public TweetEntity store(final Status status, final String rawContent) { final Optional<TweetEntity> existingTweet = this.tweetRepository.findOne(status.getId()); if (existingTweet.isPresent()) { final TweetEntity rv = existingTweet.get(); log.warn("Tweet with status {} already existed...", rv.getId()); return rv; }/* www . j a v a 2s. c o m*/ final TweetEntity tweet = new TweetEntity(status.getId(), status.getUser().getId(), status.getUser().getScreenName(), status.getCreatedAt().toInstant().atZone(ZoneId.of("UTC")), extractContent(status), extractSource(status), rawContent); tweet.setCountryCode(Optional.ofNullable(status.getPlace()).map(Place::getCountryCode).orElse(null)); if (status.getInReplyToStatusId() != -1L && status.getInReplyToUserId() != -1L && status.getInReplyToScreenName() != null) { tweet.setInReplyTo(new InReplyTo(status.getInReplyToStatusId(), status.getInReplyToScreenName(), status.getInReplyToUserId())); } tweet.setLang(status.getLang()); tweet.setLocation(Optional.ofNullable(status.getGeoLocation()) .map(g -> new TweetEntity.Location(g.getLatitude(), g.getLongitude())).orElse(null)); // TODO Handle quoted tweets return this.tweetRepository.save(tweet); }
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();//w w w .j av a 2 s . co m } }
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);//from w w w . ja v a2s . 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); }
From source file:me.yanaga.winter.data.jpa.PersonRepositoryTest.java
@Test public void testFindOneConsumer() { Person first = new Person(); first.setName("Yanaga"); personRepository.save(first);// www . jav a 2s .c o m Optional<Person> found = personRepository.findOne(q -> q.limit(1)); assertThat(found.get()).isEqualTo(first); }
From source file:pt.ist.fenix.ui.spring.PagesAdminController.java
@RequestMapping(method = RequestMethod.POST, consumes = JSON_VALUE) public @ResponseBody String create(@PathVariable String siteId, @RequestBody String bodyJson) { PagesAdminBean bean = new PagesAdminBean(bodyJson); Site site = site(siteId);/*w ww . j av a 2 s .c o m*/ Optional<MenuItem> menuItem = service.create(site, bean.getParent(), bean.getTitle(), bean.getBody()); return service.serialize(menuItem.get(), true).toString(); }
From source file:org.thingsplode.synapse.core.Uri.java
public String getQueryParamterValue(String parameterName) { if (queryParameters == null || queryParameters.isEmpty()) { return null; }/*from w ww . j a va2 s. com*/ Optional<Parameter<String>> o = queryParameters.stream() .filter((p) -> p.getName().equalsIgnoreCase(parameterName)).findFirst(); return o.isPresent() ? o.get().getValue() : null; }
From source file:com.macrossx.wechat.impl.WechatMenuHelper.java
@Override public Optional<WechatMenu> getMenu() { try {//from w w w. j a va 2 s .c o m Optional<WechatAccessToken> token = wechatHelper.getAccessToken(); if (token.isPresent()) { WechatAccessToken accessToken = token.get(); HttpGet httpGet = new HttpGet(); httpGet.setURI( new URI(MessageFormat.format(WechatConstants.MENU_GET_URL, accessToken.getAccess_token()))); return new WechatHttpClient().send(httpGet, WechatMenu.class); } } catch (URISyntaxException e) { log.info(e.getMessage()); } return Optional.empty(); }