Skip to content

Commit

Permalink
Use helper stream methods available from neo helpers.
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Jul 19, 2018
1 parent c550c64 commit cebf756
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
import java.util.List;
import java.util.ServiceLoader;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import org.neo4j.graphdb.config.BaseSetting;
import org.neo4j.graphdb.config.SettingGroup;
import org.neo4j.helpers.collection.Iterators;

/**
* Every class which contains settings should implement this interface to allow the configuration to find the
Expand Down Expand Up @@ -99,19 +99,6 @@ default List<ConfigOptions> getConfigOptions()
*/
static List<LoadableConfig> allConfigClasses()
{
return StreamSupport.stream( ServiceLoader.load( LoadableConfig.class ).spliterator(), false )
.collect( Collectors.toList() );
}

/**
* Collects and returns settings of all known implementors.
* @return all ConfigOptions known at runtime.
*/
static List<ConfigOptions> loadAllAvailableConfigOptions()
{
return StreamSupport.stream( ServiceLoader.load( LoadableConfig.class ).spliterator(), false )
.map( LoadableConfig::getConfigOptions )
.flatMap( List::stream )
.collect( Collectors.toList() );
return Iterators.stream( ServiceLoader.load( LoadableConfig.class ).iterator() ).collect( Collectors.toList() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@
import java.util.List;
import java.util.Map;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.concurrent.TimeUnit;
import java.util.function.LongFunction;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import org.neo4j.collection.PrimitiveLongResourceIterator;
import org.neo4j.graphdb.DependencyResolver;
Expand All @@ -40,6 +38,7 @@
import org.neo4j.graphdb.index.Index;
import org.neo4j.graphdb.index.IndexManager;
import org.neo4j.graphdb.index.RelationshipIndex;
import org.neo4j.helpers.collection.Iterators;
import org.neo4j.helpers.collection.MapUtil;
import org.neo4j.helpers.collection.PrefetchingResourceIterator;
import org.neo4j.internal.kernel.api.IndexReference;
Expand Down Expand Up @@ -621,14 +620,14 @@ public Stream<BooleanResult> relationshipManualIndexRemove( @Name( "indexName" )
return Stream.of( new BooleanResult( Boolean.TRUE ) );
}

private Map<String,String> indexProviderDescriptorMap( IndexReference indexReference )
private static Map<String,String> indexProviderDescriptorMap( IndexReference indexReference )
{
return MapUtil.stringMap(
"key", indexReference.providerKey(),
"version", indexReference.providerVersion() );
}

private List<String> propertyNames( TokenNameLookup tokens, IndexReference index )
private static List<String> propertyNames( TokenNameLookup tokens, IndexReference index )
{
int[] propertyIds = index.properties();
List<String> propertyNames = new ArrayList<>( propertyIds.length );
Expand All @@ -639,7 +638,7 @@ private List<String> propertyNames( TokenNameLookup tokens, IndexReference index
return propertyNames;
}

private <T> Stream<T> toStream( NodeExplicitIndexCursor cursor, LongFunction<T> mapper )
private static <T> Stream<T> toStream( NodeExplicitIndexCursor cursor, LongFunction<T> mapper )
{
PrefetchingResourceIterator<T> it = new PrefetchingResourceIterator<T>()
{
Expand All @@ -663,13 +662,10 @@ public void close()
cursor.close();
}
};

Stream<T> stream =
StreamSupport.stream( Spliterators.spliteratorUnknownSize( it, Spliterator.ORDERED ), false );
return stream.onClose( cursor::close );
return Iterators.stream( it, Spliterator.ORDERED );
}

private <T> Stream<T> toStream( RelationshipExplicitIndexCursor cursor, LongFunction<T> mapper )
private static <T> Stream<T> toStream( RelationshipExplicitIndexCursor cursor, LongFunction<T> mapper )
{
PrefetchingResourceIterator<T> it = new PrefetchingResourceIterator<T>()
{
Expand All @@ -693,13 +689,10 @@ public void close()
cursor.close();
}
};

Stream<T> stream =
StreamSupport.stream( Spliterators.spliteratorUnknownSize( it, Spliterator.ORDERED ), false );
return stream.onClose( cursor::close );
return Iterators.stream( it, Spliterator.ORDERED );
}

private <T> Stream<T> toStream( PrimitiveLongResourceIterator iterator, LongFunction<T> mapper )
private static <T> Stream<T> toStream( PrimitiveLongResourceIterator iterator, LongFunction<T> mapper )
{
Iterator<T> it = new Iterator<T>()
{
Expand All @@ -716,15 +709,7 @@ public T next()
}
};

Stream<T> stream =
StreamSupport.stream( Spliterators.spliteratorUnknownSize( it, Spliterator.ORDERED ), false );
return stream.onClose( () ->
{
if ( iterator != null )
{
iterator.close();
}
} );
return Iterators.stream( it, Spliterator.ORDERED );
}

private Stream<WeightedNodeResult> toWeightedNodeResultStream( NodeExplicitIndexCursor cursor )
Expand Down Expand Up @@ -753,9 +738,7 @@ protected WeightedNodeResult fetchNextOrNull()
}
};

Stream<WeightedNodeResult> stream =
StreamSupport.stream( Spliterators.spliteratorUnknownSize( it, Spliterator.ORDERED ), false );
return stream.onClose( cursor::close );
return Iterators.stream( it, Spliterator.ORDERED );
}

private Stream<WeightedRelationshipResult> toWeightedRelationshipResultStream(
Expand Down Expand Up @@ -784,10 +767,7 @@ protected WeightedRelationshipResult fetchNextOrNull()
}
}
};

Stream<WeightedRelationshipResult> stream =
StreamSupport.stream( Spliterators.spliteratorUnknownSize( it, Spliterator.ORDERED ), false );
return stream.onClose( cursor::close );
return Iterators.stream( it, Spliterator.ORDERED );
}

private IndexProcedures indexProcedures()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public Stream<TransactionStatusResult> listTransactions() throws InvalidArgument
}
}

private Function<KernelTransactionHandle,List<QuerySnapshot>> getTransactionQueries()
private static Function<KernelTransactionHandle,List<QuerySnapshot>> getTransactionQueries()
{
return transactionHandle -> transactionHandle.executingQueries()
.map( ExecutingQuery::snapshot )
Expand Down Expand Up @@ -422,12 +422,12 @@ private <T> Stream<Pair<KernelTransactionHandle, T>> getActiveTransactions(
.flatMap( tx -> selector.apply( tx ).map( data -> Pair.of( tx, data ) ) );
}

private Stream<ExecutingQuery> executingQueriesWithIds( Set<Long> ids, KernelTransactionHandle txHandle )
private static Stream<ExecutingQuery> executingQueriesWithIds( Set<Long> ids, KernelTransactionHandle txHandle )
{
return txHandle.executingQueries().filter( q -> ids.contains( q.internalQueryId() ) );
}

private Stream<ExecutingQuery> executingQueriesWithId( long id, KernelTransactionHandle txHandle )
private static Stream<ExecutingQuery> executingQueriesWithId( long id, KernelTransactionHandle txHandle )
{
return txHandle.executingQueries().filter( q -> q.internalQueryId() == id );
}
Expand Down

0 comments on commit cebf756

Please sign in to comment.