Skip to content

Commit

Permalink
Use of ifPresent/map etc. for some operations on Optionals
Browse files Browse the repository at this point in the history
  • Loading branch information
gartens committed Dec 5, 2023
1 parent ba54b2c commit fb49c61
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ public class PolyCatalog extends Catalog implements PolySerializable {
private final AtomicBoolean dirty = new AtomicBoolean( false );

@Getter
PropertyChangeListener changeListener = evt -> {
dirty.set( true );
};
PropertyChangeListener changeListener = evt -> dirty.set( true );


public PolyCatalog() {
Expand Down Expand Up @@ -183,9 +181,7 @@ private void addNamespaceIfNecessary( AllocationEntity entity ) {

// re-add physical namespace, we could check first, but not necessary

if ( getStoreSnapshot( entity.adapterId ).isPresent() ) {
getStoreSnapshot( entity.adapterId ).get().addNamespace( entity.namespaceId, adapter.getCurrentNamespace() );
}
getStoreSnapshot( entity.adapterId ).ifPresent( e -> e.addNamespace( entity.namespaceId, adapter.getCurrentNamespace() ) );

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ private QueryInterfaceManager( TransactionManager transactionManager, Authentica


public QueryInterface getQueryInterface( String uniqueName ) {
uniqueName = uniqueName.toLowerCase();
return interfaceByName.get( uniqueName );
return interfaceByName.get( uniqueName.toLowerCase() );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ protected AbstractAlgOptPlanner( AlgOptCostFactory costFactory, Context context
this.context = context;

Optional<CancelFlag> oCancelFlag = context.unwrap( CancelFlag.class );
this.cancelFlag = oCancelFlag.isPresent()
? oCancelFlag.get().atomicBoolean
: new AtomicBoolean();
this.cancelFlag = oCancelFlag.map( c -> c.atomicBoolean ).orElseGet( AtomicBoolean::new );

// Add abstract {@link AlgNode} classes. No RelNodes will ever be registered with these types, but some operands may use them.
classes.add( AlgNode.class );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class PolyTimeStamp extends PolyTemporal {

public static final DateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );

public Long milliSinceEpoch; // normalized to utz
public Long milliSinceEpoch; // normalized to UTC


public PolyTimeStamp( Long milliSinceEpoch ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,10 @@ protected Map<Long, List<AllocationColumn>> selectPlacementOld( LogicalTable tab
AllocationPlacement longestPlacement = catalog.getSnapshot().alloc().getPlacement( adapterIdWithMostPlacements, table.id ).orElseThrow();
for ( LogicalColumn column : logicalColumns ) {
Optional<AllocationColumn> optionalColumn = catalog.getSnapshot().alloc().getColumn( longestPlacement.id, column.id );
if ( optionalColumn.isPresent() ) {
placementList.add( optionalColumn.get() );
} else {
missingColumns.add( column );
}
optionalColumn.ifPresentOrElse(
placementList::add,
() -> missingColumns.add( column )
);
}

Map<Long, List<AllocationColumn>> placementToColumns = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,8 @@ public Result setOpToSql( SqlSetOperator operator, AlgNode alg ) {
for ( Ord<AlgNode> input : Ord.zip( alg.getInputs() ) ) {
final Result result = visitChild( input.i, input.e );
if ( node == null ) {
if ( input.getValue().unwrap( JdbcScan.class ).isPresent() ) {
node = result.asSelect( input.getValue().unwrap( JdbcScan.class ).get().getEntity().getNodeList() );
} else {
node = result.asSelect();
}
node = input.getValue().unwrap( JdbcScan.class ).map( i -> result.asSelect( i.getEntity().getNodeList() ) )
.orElse( result.asSelect() );
} else {
if ( input.getValue().unwrap( JdbcScan.class ).isPresent() ) {
node = (SqlNode) operator.createCall( POS, node, result.asSelect( input.getValue().unwrap( JdbcScan.class ).get().getEntity().getNodeList() ) );
Expand Down

0 comments on commit fb49c61

Please sign in to comment.