List of usage examples for java.util Optional orElse
public T orElse(T other)
From source file:ca.oson.json.util.ObjectUtil.java
public static <T> T unwraponce(T obj) { if (obj != null && obj instanceof Optional) { Optional<T> opt = (Optional) obj; obj = opt.orElse(null); }//from w w w .j a v a 2 s .c om return obj; }
From source file:ca.oson.json.util.ObjectUtil.java
public static <T> T unwrap(T obj) { while (obj != null && obj instanceof Optional) { Optional<T> opt = (Optional) obj; obj = opt.orElse(null); }/*from ww w . j a v a 2s . c om*/ return obj; }
From source file:alfio.util.TemplateResource.java
public static Map<String, Object> prepareModelForConfirmationEmail(Organization organization, Event event, TicketReservation reservation, Optional<String> vat, List<Ticket> tickets, OrderSummary orderSummary, String reservationUrl, String reservationShortID, Optional<String> invoiceAddress, Optional<String> bankAccountNr, Optional<String> bankAccountOwner) { Map<String, Object> model = new HashMap<>(); model.put("organization", organization); model.put("event", event); model.put("ticketReservation", reservation); model.put("hasVat", vat.isPresent()); model.put("vatNr", vat.orElse("")); model.put("tickets", tickets); model.put("orderSummary", orderSummary); model.put("reservationUrl", reservationUrl); model.put("locale", reservation.getUserLanguage()); ZonedDateTime confirmationTimestamp = Optional.ofNullable(reservation.getConfirmationTimestamp()) .orElseGet(ZonedDateTime::now); model.put("confirmationDate", confirmationTimestamp.withZoneSameInstant(event.getZoneId())); if (reservation.getValidity() != null) { model.put("expirationDate", ZonedDateTime.ofInstant(reservation.getValidity().toInstant(), event.getZoneId())); }/*from w w w.java2 s . c o m*/ model.put("reservationShortID", reservationShortID); model.put("hasInvoiceAddress", invoiceAddress.isPresent()); invoiceAddress.ifPresent(addr -> { model.put("invoiceAddress", StringUtils.replace(addr, "\n", ", ")); model.put("invoiceAddressAsList", Arrays.asList(StringUtils.split(addr, '\n'))); }); model.put("hasBankAccountNr", bankAccountNr.isPresent()); bankAccountNr.ifPresent(nr -> { model.put("bankAccountNr", nr); }); model.put("isOfflinePayment", reservation.getStatus() == TicketReservation.TicketReservationStatus.OFFLINE_PAYMENT); model.put("paymentReason", event.getShortName() + " " + reservationShortID); model.put("hasBankAccountOnwer", bankAccountOwner.isPresent()); bankAccountOwner.ifPresent(owner -> { model.put("bankAccountOnwer", StringUtils.replace(owner, "\n", ", ")); model.put("bankAccountOnwerAsList", Arrays.asList(StringUtils.split(owner, '\n'))); }); return model; }
From source file:io.fluo.webindex.data.fluo.UriCountExport.java
@Override protected Map<RowColumn, Bytes> generateData(String pageID, Optional<UriInfo> val) { if (val.orElse(UriInfo.ZERO).equals(UriInfo.ZERO)) { return Collections.emptyMap(); }/*from w w w . j av a2s . c o m*/ UriInfo uriInfo = val.get(); Map<RowColumn, Bytes> rcMap = new HashMap<>(); Bytes linksTo = Bytes.of("" + uriInfo.linksTo); rcMap.put(new RowColumn(createTotalRow(pageID, uriInfo.linksTo), Column.EMPTY), linksTo); String domain = URL.fromPageID(pageID).getReverseDomain(); String domainRow = encodeDomainRankPageId(domain, uriInfo.linksTo, pageID); rcMap.put(new RowColumn(domainRow, new Column(Constants.RANK, "")), linksTo); rcMap.put(new RowColumn("p:" + pageID, FluoConstants.PAGE_INCOUNT_COL), linksTo); return rcMap; }
From source file:net.pkhsolutions.pecsapp.model.PageModel.java
public void setEntity(@NotNull Optional<Page> entity) { this.entity = entity.orElse(null); }
From source file:spring.travel.site.model.user.User.java
@JsonIgnore public void setAddress(Optional<Address> address) { this.a = address.orElse(null); }
From source file:org.sonarqube.shell.commands.SonarSession.java
void disconnect(Optional<String> message) { consoleOut(message.orElse("Successfully disconnected from: " + rootContext.getUri())); rootContext = null;/*w ww .j a v a 2s. c om*/ }
From source file:org.zalando.stups.stupsback.admin.domain.ThumbsUpHandler.java
@HandleBeforeCreate public void handleCreate(ThumbsUp likes) { final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null) { final Optional<Object> principal = Optional.ofNullable(authentication.getPrincipal()); likes.setUsername(principal.orElse(new String("testuser")).toString()); } else {/*from w w w . j av a 2s.c o m*/ likes.setUsername("anonymous"); } }
From source file:net.wouterdanes.docker.provider.model.PushableImage.java
public PushableImage(final String imageId, final Optional<String> nameAndTag) { notBlank(imageId, "Image id was null or empty"); notNull(nameAndTag.orElse(""), "Name and tag was null or empty"); this.imageId = imageId; this.nameAndTag = nameAndTag; }
From source file:org.openmhealth.shim.fitbit.mapper.FitbitBodyWeightDataPointMapper.java
@Override protected Optional<DataPoint<BodyWeight>> asDataPoint(JsonNode node) { MassUnitValue bodyWeight = new MassUnitValue(KILOGRAM, asRequiredDouble(node, "weight")); BodyWeight.Builder builder = new BodyWeight.Builder(bodyWeight); Optional<OffsetDateTime> dateTime = combineDateTimeAndTimezone(node); if (dateTime.isPresent()) { builder.setEffectiveTimeFrame(dateTime.get()); }/* w w w . j a v a 2 s .co m*/ Optional<Long> externalId = asOptionalLong(node, "logId"); return Optional.of(newDataPoint(builder.build(), externalId.orElse(null))); }