/** * Returns the equivalent {@code java.util.Optional} value to this optional. * * <p>Unfortunately, the method reference {@code Optional::toJavaUtil} will not work, because it * could refer to either the static or instance version of this method. Write out the lambda * expression {@code o -> o.toJavaUtil()} instead. * * @since 21.0 */ public java.util.Optional<T> toJavaUtil() { return java.util.Optional.ofNullable(orNull()); }
@Override public Object handleValidatedValue(final Optional<?> optional) { return optional.orNull(); }
/** * Convert a Guava {@link com.google.common.base.Optional} to an {@link Optional}. * * @param guavaOptional The Guava {@link com.google.common.base.Optional} * @return An equivalent {@link Optional} */ public static <T> Optional<T> fromGuavaOptional(final com.google.common.base.Optional<T> guavaOptional) { return Optional.ofNullable(guavaOptional.orNull()); }
@Override public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException { statement.setObject(position, value.orNull()); } }
@Override public Object apply(Optional<?> optional) { return optional.orNull(); } };
/** @since 18.0 */ // @Override on JDK8 public <A extends Annotation> @Nullable A getDeclaredAnnotation(Class<A> annotationType) { checkNotNull(annotationType); return FluentIterable.from(annotations).filter(annotationType).first().orNull(); }
/** @since 18.0 */ // @Override on JDK8 @NullableDecl public <A extends Annotation> A getDeclaredAnnotation(Class<A> annotationType) { checkNotNull(annotationType); return FluentIterable.from(annotations).filter(annotationType).first().orNull(); }
@Override protected boolean isRowNumberCondition(final List<SelectItem> items, final String columnLabel) { Optional<String> rowNumberAlias = Optional.absent(); for (SelectItem each : items) { if (each.getAlias().isPresent() && "rownum".equalsIgnoreCase(each.getExpression())) { rowNumberAlias = each.getAlias(); break; } } return "rownum".equalsIgnoreCase(columnLabel) || columnLabel.equalsIgnoreCase(rowNumberAlias.orNull()); }
@Override public Optional<ByteSource> streamTaskLog(String taskid, long offset) throws IOException { final TaskRunner runner = taskMaster.getTaskRunner().orNull(); if (runner instanceof TaskLogStreamer) { return ((TaskLogStreamer) runner).streamTaskLog(taskid, offset); } else { return Optional.absent(); } } }
@Override protected boolean isRowNumberCondition(final List<SelectItem> items, final String columnLabel) { Optional<String> rowNumberAlias = Optional.absent(); for (SelectItem each : items) { if (each.getAlias().isPresent() && "ROW_NUMBER".equalsIgnoreCase(each.getExpression())) { rowNumberAlias = each.getAlias(); break; } } return columnLabel.equalsIgnoreCase(rowNumberAlias.orNull()); }
@Override public Optional<ColumnDefinitionSegment> extract(final ParserRuleContext ancestorNode) { Optional<ParserRuleContext> columnNameNode = ExtractorUtils.findFirstChildNode(ancestorNode, RuleName.COLUMN_NAME); if (!columnNameNode.isPresent()) { return Optional.absent(); } Optional<ParserRuleContext> dataTypeNode = ExtractorUtils.findFirstChildNode(ancestorNode, RuleName.DATA_TYPE); Optional<String> dataTypeText = dataTypeNode.isPresent() ? Optional.of(dataTypeNode.get().getChild(0).getText()) : Optional.<String>absent(); boolean isPrimaryKey = ExtractorUtils.findFirstChildNode(ancestorNode, RuleName.PRIMARY_KEY).isPresent(); return Optional.of(new ColumnDefinitionSegment(columnNameNode.get().getText(), dataTypeText.orNull(), isPrimaryKey)); } }
public void testOrNull_absent() { assertNull(Optional.absent().orNull()); }
public void testOrNull_present() { assertEquals("a", Optional.of("a").orNull()); }
public Optional<Set<Interval>> getSegmentGranularIntervals() { return Optional.fromNullable( (Set<Interval>) schema.getDataSchema() .getGranularitySpec() .bucketIntervals() .orNull() ); }
@Override public String get(final String key) { final RangeRequest request = RangeRequest.newBuilder().setKey(ByteString.copyFromUtf8(key)).build(); return etcdRetryEngine.execute(new Callable<String>() { @Override public String call() throws InterruptedException, ExecutionException, TimeoutException { RangeResponse response = kvStub.range(request).get(config.getOperationTimeoutMilliseconds(), TimeUnit.MILLISECONDS); return response.getKvsCount() > 0 ? response.getKvs(0).getValue().toStringUtf8() : null; } }).orNull(); }
/** The key reference combination to use, or all if unset. */ Optional<ReferenceType> keys() { return Optional.ofNullable(Enums.getIfPresent(ReferenceType.class, System.getProperty("keys", "").toUpperCase()).orNull()); }
private void fillStarSelectItemSegment(final StarSelectItemSegment selectItemSegment, final SelectStatement selectStatement) { selectStatement.setContainStar(true); Optional<String> owner = selectItemSegment.getOwner(); selectStatement.getItems().add(new StarSelectItem(owner.orNull())); if (!owner.isPresent()) { return; } Optional<Table> table = selectStatement.getTables().find(owner.get()); if (table.isPresent() && !table.get().getAlias().isPresent()) { selectStatement.addSQLToken(new TableToken(selectItemSegment.getStartIndex(), 0, SQLUtil.getExactlyValue(owner.get()), SQLUtil.getLeftDelimiter(owner.get()), SQLUtil.getRightDelimiter(owner.get()))); } }
private ExpressionSegment extractPropertyExpressionSegment(final ParserRuleContext expressionNode) { ParserRuleContext columnNode = (ParserRuleContext) expressionNode.getChild(0); Optional<ColumnSegment> columnSegment = new ColumnSegmentExtractor().extract(columnNode); Preconditions.checkState(columnSegment.isPresent()); return new PropertyExpressionSegment(columnSegment.get().getName(), columnSegment.get().getOwner().orNull(), columnNode.getStart().getStartIndex(), columnNode.getStop().getStopIndex()); }
private String getTableName(final ShardingRule shardingRule, final Tables tables, final ConditionSegment conditionSegment) { Collection<String> shardingLogicTableNames = shardingRule.getShardingLogicTableNames(tables.getTableNames()); if (tables.isSingleTable() || tables.isSameTable() || 1 == shardingLogicTableNames.size() || shardingRule.isAllBindingTables(shardingLogicTableNames)) { return tables.getSingleTableName(); } Optional<Table> table = tables.find(conditionSegment.getColumn().getOwner().orNull()); return table.isPresent() ? table.get().getName() : ""; }