Skip to content

Commit

Permalink
Use Optional.isEmpty() method
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed May 18, 2020
1 parent 7ff3ace commit 6d9d47e
Show file tree
Hide file tree
Showing 281 changed files with 559 additions and 559 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private static void validateLocalityGroups(ConnectorTableMetadata meta)
{
// Validate any configured locality groups
Optional<Map<String, Set<String>>> groups = AccumuloTableProperties.getLocalityGroups(meta.getProperties());
if (!groups.isPresent()) {
if (groups.isEmpty()) {
return;
}

Expand Down Expand Up @@ -336,7 +336,7 @@ private static List<AccumuloColumnHandle> getColumnHandles(ConnectorTableMetadat
private void setLocalityGroups(Map<String, Object> tableProperties, AccumuloTable table)
{
Optional<Map<String, Set<String>>> groups = AccumuloTableProperties.getLocalityGroups(tableProperties);
if (!groups.isPresent()) {
if (groups.isEmpty()) {
LOG.debug("No locality groups to set");
return;
}
Expand Down Expand Up @@ -896,7 +896,7 @@ public static Collection<Range> getRangesFromDomain(Optional<Domain> domain, Acc
throws TableNotFoundException
{
// if we have no predicate pushdown, use the full range
if (!domain.isPresent()) {
if (domain.isEmpty()) {
return ImmutableSet.of(new Range());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ private ConnectorTableMetadata getTableMetadata(SchemaTableName tableName)
private List<SchemaTableName> listTables(ConnectorSession session, SchemaTablePrefix prefix)
{
// List all tables if schema or table is null
if (!prefix.getTable().isPresent()) {
if (prefix.getTable().isEmpty()) {
return listTables(session, prefix.getSchema());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private boolean getRangesWithMetrics(
}

Optional<Entry<Long, AccumuloColumnConstraint>> entry = cardinalities.entries().stream().findFirst();
if (!entry.isPresent()) {
if (entry.isEmpty()) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public AccumuloPageSink(
.map(AccumuloColumnHandle::getOrdinal)
.findAny();

if (!ordinal.isPresent()) {
if (ordinal.isEmpty()) {
throw new PrestoException(FUNCTION_IMPLEMENTATION_ERROR, "Row ID ordinal not found");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public ConnectorTableMetadata getTableMetadata(ConnectorSession session, Connect
@Override
public List<SchemaTableName> listTables(ConnectorSession session, Optional<String> schemaName)
{
if (!schemaName.isPresent()) {
if (schemaName.isEmpty()) {
return Stream.of(AtopTable.values())
.map(table -> new SchemaTableName(environment, table.getName()))
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public List<JdbcColumnHandle> getColumns(ConnectorSession session, JdbcTableHand
.setComment(comment)
.build());
}
if (!columnMapping.isPresent()) {
if (columnMapping.isEmpty()) {
UnsupportedTypeHandling unsupportedTypeHandling = getUnsupportedTypeHandling(session);
verify(unsupportedTypeHandling == IGNORE, "Unsupported type handling is set to %s, but toPrestoType() returned empty", unsupportedTypeHandling);
}
Expand Down Expand Up @@ -865,7 +865,7 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type)

protected Function<String, String> tryApplyLimit(OptionalLong limit)
{
if (!limit.isPresent()) {
if (limit.isEmpty()) {
return Function.identity();
}
return limitFunction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public Optional<JdbcTableHandle> getTableHandle(JdbcIdentity identity, SchemaTab
return cachedTableHandle;
}
Optional<JdbcTableHandle> tableHandle = delegate.getTableHandle(identity, schemaTableName);
if (!tableHandle.isPresent() || cacheMissing) {
if (tableHandle.isEmpty() || cacheMissing) {
tableHandleCache.put(key, tableHandle);
}
return tableHandle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public JdbcPageSink(ConnectorSession session, JdbcOutputTableHandle handle, Jdbc

columnTypes = handle.getColumnTypes();

if (!handle.getJdbcColumnTypes().isPresent()) {
if (handle.getJdbcColumnTypes().isEmpty()) {
columnWriters = columnTypes.stream()
.map(type -> {
WriteMapping writeMapping = jdbcClient.toWriteMapping(session, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public ClientSessionProperty(Optional<String> catalog, String name, String value

private static void verifyProperty(Optional<String> catalog, String name, String value)
{
checkArgument(!catalog.isPresent() || !catalog.get().isEmpty(), "Invalid session property: %s.%s:%s", catalog, name, value);
checkArgument(catalog.isEmpty() || !catalog.get().isEmpty(), "Invalid session property: %s.%s:%s", catalog, name, value);
checkArgument(!name.isEmpty(), "Session property name is empty");

CharsetEncoder charsetEncoder = US_ASCII.newEncoder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public boolean isCredentialsConfigurationValid()
return false;
}
// if no credentials were supplied, let's check if we can create the default ones
if (!credentialsKey.isPresent() && !credentialsFile.isPresent()) {
if (credentialsKey.isEmpty() && credentialsFile.isEmpty()) {
try {
GoogleCredentials.getApplicationDefault();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSess

private List<SchemaTableName> listTables(ConnectorSession session, SchemaTablePrefix prefix)
{
if (!prefix.getTable().isPresent()) {
if (prefix.getTable().isEmpty()) {
return listTables(session, prefix.getSchema());
}
SchemaTableName tableName = prefix.toSchemaTableName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public ConnectorTableMetadata getTableMetadata(ConnectorSession session, Connect
public List<SchemaTableName> listTables(ConnectorSession session, Optional<String> schemaName)
{
return tables.values().stream()
.filter(table -> !schemaName.isPresent() || table.getSchemaName().equals(schemaName.get()))
.filter(table -> schemaName.isEmpty() || table.getSchemaName().equals(schemaName.get()))
.map(BlackHoleTableHandle::toSchemaTableName)
.collect(toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private static Optional<SSLContext> buildSslContext(
Optional<File> truststorePath,
Optional<String> truststorePassword)
{
if (!keystorePath.isPresent() && !truststorePath.isPresent()) {
if (keystorePath.isEmpty() && truststorePath.isEmpty()) {
return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSess

private List<SchemaTableName> listTables(ConnectorSession session, SchemaTablePrefix prefix)
{
if (!prefix.getTable().isPresent()) {
if (prefix.getTable().isEmpty()) {
return listTables(session, prefix.getSchema());
}
return ImmutableList.of(prefix.toSchemaTableName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ private static void checkColumnNames(List<ColumnMetadata> columns)
private Optional<CassandraColumnHandle> buildColumnHandle(AbstractTableMetadata tableMetadata, ColumnMetadata columnMeta, boolean partitionKey, boolean clusteringKey, int ordinalPosition, boolean hidden)
{
Optional<CassandraType> cassandraType = toCassandraType(columnMeta.getType().getName());
if (!cassandraType.isPresent()) {
if (cassandraType.isEmpty()) {
log.debug("Unsupported column type: %s", columnMeta.getType().getName());
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public List<TokenSplit> getSplits(String keyspace, String table, Optional<Long>
List<String> endpoints = getEndpoints(keyspace, tokenRange);
checkState(!endpoints.isEmpty(), "endpoints is empty for token range: %s", tokenRange);

if (!tokenRing.isPresent()) {
if (tokenRing.isEmpty()) {
checkState(!tokenRange.isWrappedAround(), "all token ranges must be unwrapped at this step");
splits.add(createSplit(tokenRange, endpoints));
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ public boolean isSupportedPartitionKey()

public static boolean isFullySupported(DataType dataType)
{
if (!toCassandraType(dataType.getName()).isPresent()) {
if (toCassandraType(dataType.getName()).isEmpty()) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private static Optional<SSLContext> buildSslContext(
Optional<File> trustStorePath,
Optional<String> trustStorePassword)
{
if (!keyStorePath.isPresent() && !trustStorePath.isPresent()) {
if (keyStorePath.isEmpty() && trustStorePath.isEmpty()) {
return Optional.empty();
}

Expand Down Expand Up @@ -383,7 +383,7 @@ public List<Shard> getSearchShards(String index)

SearchShardsResponse.Shard chosen;
ElasticsearchNode node;
if (!candidate.isPresent()) {
if (candidate.isEmpty()) {
// pick an arbitrary shard with and assign to an arbitrary node
chosen = shardGroup.stream()
.min(this::shardPreference)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private ConnectorTableMetadata getTableMetadata(SchemaTableName tableName)

private List<SchemaTableName> listTables(ConnectorSession session, SchemaTablePrefix prefix)
{
if (!prefix.getTable().isPresent()) {
if (prefix.getTable().isEmpty()) {
return listTables(session, prefix.getSchema());
}
return ImmutableList.of(prefix.toSchemaTableName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public Node(
this.right = requireNonNull(right, "right is null");
if (leafId.isPresent()) {
checkArgument(leafId.getAsInt() >= 0, "leafId must be >= 0");
checkArgument(!left.isPresent(), "Leaf node cannot have left child");
checkArgument(!right.isPresent(), "Leaf node cannot have right child");
checkArgument(left.isEmpty(), "Leaf node cannot have left child");
checkArgument(right.isEmpty(), "Leaf node cannot have right child");
}
else {
checkArgument(left.isPresent(), "Intermediate node must have left child");
Expand Down Expand Up @@ -292,12 +292,12 @@ private static Node buildKdbTreeNode(int maxItemsPerNode, int level, Rectangle e
// Split over longer side
boolean splitVertically = extent.getWidth() >= extent.getHeight();
Optional<SplitResult<Node>> splitResult = trySplit(splitVertically ? BY_X : BY_Y, maxItemsPerNode, level, extent, items, leafIdAllocator);
if (!splitResult.isPresent()) {
if (splitResult.isEmpty()) {
// Try spitting by the other side
splitResult = trySplit(splitVertically ? BY_Y : BY_X, maxItemsPerNode, level, extent, items, leafIdAllocator);
}

if (!splitResult.isPresent()) {
if (splitResult.isEmpty()) {
return newLeaf(extent, leafIdAllocator.next());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public List<List<Object>> readAllValues(String tableName)
{
try {
Optional<String> sheetExpression = tableSheetMappingCache.getUnchecked(tableName);
if (!sheetExpression.isPresent()) {
if (sheetExpression.isEmpty()) {
throw new PrestoException(SHEETS_UNKNOWN_TABLE_ERROR, "Sheet expression not found for table " + tableName);
}
return sheetDataCache.getUnchecked(sheetExpression.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public SheetsTableHandle getTableHandle(ConnectorSession session, SchemaTableNam
}

Optional<SheetsTable> table = sheetsClient.getTable(tableName.getTableName());
if (!table.isPresent()) {
if (table.isEmpty()) {
return null;
}

Expand All @@ -82,7 +82,7 @@ public SheetsTableHandle getTableHandle(ConnectorSession session, SchemaTableNam
public ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle table)
{
Optional<ConnectorTableMetadata> connectorTableMetadata = getTableMetadata(((SheetsTableHandle) table).toSchemaTableName());
if (!connectorTableMetadata.isPresent()) {
if (connectorTableMetadata.isEmpty()) {
throw new PrestoException(SHEETS_UNKNOWN_TABLE_ERROR, "Metadata not found for table " + ((SheetsTableHandle) table).getTableName());
}
return connectorTableMetadata.get();
Expand All @@ -93,7 +93,7 @@ public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, Conn
{
SheetsTableHandle sheetsTableHandle = (SheetsTableHandle) tableHandle;
Optional<SheetsTable> table = sheetsClient.getTable(sheetsTableHandle.getTableName());
if (!table.isPresent()) {
if (table.isEmpty()) {
throw new TableNotFoundException(sheetsTableHandle.toSchemaTableName());
}

Expand Down Expand Up @@ -136,7 +136,7 @@ private Optional<ConnectorTableMetadata> getTableMetadata(SchemaTableName tableN
@Override
public List<SchemaTableName> listTables(ConnectorSession session, Optional<String> schemaName)
{
if (!schemaName.isPresent()) {
if (schemaName.isEmpty()) {
throw new PrestoException(SHEETS_UNKNOWN_SCHEMA_ERROR, "Schema not present - " + schemaName);
}
if (schemaName.get().equalsIgnoreCase("information_schema")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public ConnectorSplitSource getSplits(
Optional<SheetsTable> table = sheetsClient.getTable(tableHandle.getTableName());

// this can happen if table is removed during a query
if (!table.isPresent()) {
if (table.isEmpty()) {
throw new TableNotFoundException(tableHandle.toSchemaTableName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ private static List<Path> getTargetPathsFromSymlink(FileSystem fileSystem, Path

private static List<HivePartitionKey> getPartitionKeys(Table table, Optional<Partition> partition)
{
if (!partition.isPresent()) {
if (partition.isEmpty()) {
return ImmutableList.of();
}
ImmutableList.Builder<HivePartitionKey> partitionKeys = ImmutableList.builder();
Expand All @@ -668,7 +668,7 @@ private static List<HivePartitionKey> getPartitionKeys(Table table, Optional<Par

private static Properties getPartitionSchema(Table table, Optional<Partition> partition)
{
if (!partition.isPresent()) {
if (partition.isEmpty()) {
return getHiveSchema(table);
}
return getHiveSchema(partition.get(), table);
Expand All @@ -686,8 +686,8 @@ public static Optional<BucketSplitInfo> createBucketSplitInfo(Optional<HiveBucke
requireNonNull(bucketHandle, "bucketHandle is null");
requireNonNull(bucketFilter, "buckets is null");

if (!bucketHandle.isPresent()) {
checkArgument(!bucketFilter.isPresent(), "bucketHandle must be present if bucketFilter is present");
if (bucketHandle.isEmpty()) {
checkArgument(bucketFilter.isEmpty(), "bucketHandle must be present if bucketFilter is present");
return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public ColumnType getColumnType()

public boolean isBaseColumn()
{
return !hiveColumnProjectionInfo.isPresent();
return hiveColumnProjectionInfo.isEmpty();
}

@Override
Expand Down
Loading

0 comments on commit 6d9d47e

Please sign in to comment.