List of usage examples for java.util Optional orElse
public T orElse(T other)
From source file:org.opensingular.form.wicket.mapper.MoneyMapper.java
private Integer getInteiroMaximo(IModel<? extends SInstance> model) { Optional<Integer> inteiroMaximo = Optional .ofNullable(model.getObject().getAttributeValue(SPackageBasic.ATR_INTEGER_MAX_LENGTH)); return inteiroMaximo.orElse(DEFAULT_INTEGER_DIGITS); }
From source file:org.opensingular.form.wicket.mapper.MoneyMapper.java
private Integer getDecimalMaximo(IModel<? extends SInstance> model) { Optional<Integer> decimalMaximo = Optional .ofNullable(model.getObject().getAttributeValue(SPackageBasic.ATR_FRACTIONAL_MAX_LENGTH)); return decimalMaximo.orElse(DEFAULT_DIGITS); }
From source file:ch.ralscha.extdirectspring.provider.RemoteProviderOptional.java
@ExtDirectMethod(group = "optional") public String method19(@CookieValue Optional<String> stringCookie) { return stringCookie.orElse(null); }
From source file:org.apache.metron.parsers.bolt.ParserBolt.java
@SuppressWarnings("unchecked") @Override//from w w w . ja v a 2s . c o m public void execute(Tuple tuple) { byte[] originalMessage = (byte[]) messageGetStrategy.get(tuple); SensorParserConfig sensorParserConfig = getSensorParserConfig(); try { //we want to ack the tuple in the situation where we have are not doing a bulk write //otherwise we want to defer to the writerComponent who will ack on bulk commit. boolean ackTuple = !writer.handleAck(); int numWritten = 0; if (sensorParserConfig != null) { List<FieldValidator> fieldValidations = getConfigurations().getFieldValidations(); Optional<List<JSONObject>> messages = parser.parseOptional(originalMessage); for (JSONObject message : messages.orElse(Collections.emptyList())) { message.put(Constants.SENSOR_TYPE, getSensorType()); for (FieldTransformer handler : sensorParserConfig.getFieldTransformations()) { if (handler != null) { handler.transformAndUpdate(message, sensorParserConfig.getParserConfig(), stellarContext); } } if (!message.containsKey(Constants.GUID)) { message.put(Constants.GUID, UUID.randomUUID().toString()); } if (parser.validate(message) && (filter == null || filter.emitTuple(message, stellarContext))) { numWritten++; List<FieldValidator> failedValidators = getFailedValidators(message, fieldValidations); if (failedValidators.size() > 0) { MetronError error = new MetronError().withErrorType(Constants.ErrorType.PARSER_INVALID) .withSensorType(getSensorType()).addRawMessage(message); Set<String> errorFields = failedValidators.stream() .flatMap(fieldValidator -> fieldValidator.getInput().stream()) .collect(Collectors.toSet()); if (!errorFields.isEmpty()) { error.withErrorFields(errorFields); } ErrorUtils.handleError(collector, error); } else { writer.write(getSensorType(), tuple, message, getConfigurations(), messageGetStrategy); } } } } //if we are supposed to ack the tuple OR if we've never passed this tuple to the bulk writer //(meaning that none of the messages are valid either globally or locally) //then we want to handle the ack ourselves. if (ackTuple || numWritten == 0) { collector.ack(tuple); } } catch (Throwable ex) { MetronError error = new MetronError().withErrorType(Constants.ErrorType.PARSER_ERROR).withThrowable(ex) .withSensorType(getSensorType()).addRawMessage(originalMessage); ErrorUtils.handleError(collector, error); collector.ack(tuple); } }
From source file:io.github.carlomicieli.footballdb.starter.pages.TableTests.java
@Test public void shouldReturnRowValuesFromTable() { Table table3x3 = newTable3x3();//from ww w.j a v a2 s . com Optional<Table.Row> firstRow = table3x3.row(1); assertThat(firstRow).isPresent(); assertThat(firstRow.orElse(null).toString()).isEqualTo("Row(one, two, three)"); assertThat(table3x3.rowValues(4)).isNotPresent(); assertThat(table3x3.rowValues(999)).isNotPresent(); }
From source file:org.jbb.security.impl.lockout.DefaultMemberLockoutService.java
@Override public Optional<MemberLock> getMemberActiveLock(Long memberId) { Validate.notNull(memberId, MEMBER_VALIDATION_MESSAGE); // for refreshing, maybe lock can be removed for now? ifMemberHasActiveLock(memberId);//from w w w . j a va 2 s . c o m Optional<MemberLockEntity> lockOptional = lockRepository.findByMemberIdAndActiveTrue(memberId); return Optional.ofNullable(lockOptional.orElse(null)).map(memberLockDomainTranslator::toModel); }
From source file:org.openlmis.fulfillment.service.ExporterBuilder.java
/** * Copy data from the given order line item to the instance that implement * {@link OrderLineItem.Exporter} interface. *///from w ww . j a v a 2s . c om public void export(OrderLineItem item, OrderLineItem.Exporter exporter, List<OrderableDto> orderables) { exporter.setId(item.getId()); Optional<OrderableDto> orderableOptional = orderables.stream() .filter(orderable -> orderable.getId().equals(item.getOrderableId())).findAny(); OrderableDto orderableDto = orderableOptional.orElse(getIfPresent(products, item.getOrderableId())); exporter.setOrderable(orderableDto); exporter.setOrderedQuantity(item.getOrderedQuantity()); if (orderableDto != null) { exporter.setTotalDispensingUnits(item.getOrderedQuantity() * orderableDto.getNetContent()); } }
From source file:tech.beshu.ror.integration.JwtAuthTests.java
private int test(Optional<String> token, Optional<String> headerName, boolean withBearer) throws Exception { RestClient rc = container.getClient(); HttpGet req = new HttpGet(rc.from("/_cat/indices")); token.ifPresent(t -> req.addHeader(headerName.orElse("Authorization"), (withBearer ? "Bearer " : "") + t)); HttpResponse resp = rc.execute(req); return resp.getStatusLine().getStatusCode(); }
From source file:ch.ralscha.extdirectspring.provider.RemoteProviderOptional.java
@ExtDirectMethod(group = "optional") public String method18(@CookieValue(value = "nameOfTheCookie") Optional<String> aStr) { return aStr.orElse("default"); }
From source file:org.openmhealth.shim.withings.mapper.WithingsBodyMeasureDataPointMapper.java
@Override public List<DataPoint<T>> asDataPoints(List<JsonNode> responseNodes) { checkNotNull(responseNodes);//from w w w . j a v a 2 s.c o m checkNotNull(responseNodes.size() == 1, "A single response node is allowed per call."); JsonNode responseNodeBody = asRequiredNode(responseNodes.get(0), BODY_NODE_PROPERTY); List<DataPoint<T>> dataPoints = Lists.newArrayList(); for (JsonNode measureGroupNode : asRequiredNode(responseNodeBody, "measuregrps")) { if (isGoal(measureGroupNode)) { continue; } if (isOwnerAmbiguous(measureGroupNode)) { logger.warn( "The following Withings measure group is being ignored because its owner is ambiguous.\n{}", measureGroupNode); continue; } JsonNode measuresNode = asRequiredNode(measureGroupNode, "measures"); Measure.Builder<T, ?> measureBuilder = newMeasureBuilder(measuresNode).orElse(null); if (measureBuilder == null) { continue; } Optional<Long> dateTimeInEpochSeconds = asOptionalLong(measureGroupNode, "date"); if (dateTimeInEpochSeconds.isPresent()) { Instant dateTimeInstant = Instant.ofEpochSecond(dateTimeInEpochSeconds.get()); measureBuilder.setEffectiveTimeFrame(OffsetDateTime.ofInstant(dateTimeInstant, UTC)); } Optional<String> userComment = asOptionalString(measureGroupNode, "comment"); if (userComment.isPresent()) { measureBuilder.setUserNotes(userComment.get()); } T measure = measureBuilder.build(); Optional<Long> externalId = asOptionalLong(measureGroupNode, "grpid"); dataPoints.add(newDataPoint(measure, externalId.orElse(null), isSensed(measureGroupNode), null)); } return dataPoints; }