Skip to content

Commit

Permalink
Remove custom LongFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegrohmann committed Dec 10, 2015
1 parent 26242c7 commit b6c12ef
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 123 deletions.

This file was deleted.

Expand Up @@ -23,11 +23,11 @@
import java.net.URL;
import java.util.Collections;
import java.util.Map;
import java.util.function.LongFunction;
import java.util.function.Supplier;

import org.neo4j.collection.primitive.PrimitiveLongCollections;
import org.neo4j.collection.primitive.PrimitiveLongIterator;
import org.neo4j.function.LongFunction;
import org.neo4j.graphdb.ConstraintViolationException;
import org.neo4j.graphdb.DependencyResolver;
import org.neo4j.graphdb.Label;
Expand Down Expand Up @@ -354,43 +354,33 @@ private void checkAvailability()
public ResourceIterable<Node> getAllNodes()
{
threadToTransactionBridge.assertInUnterminatedTransaction();
return new ResourceIterable<Node>()
{
@Override
public ResourceIterator<Node> iterator()
{
Statement statement = threadToTransactionBridge.get();
return map2nodes( statement.readOperations().nodesGetAll(), statement );
}
return () -> {
Statement statement = threadToTransactionBridge.get();
return map2nodes( statement.readOperations().nodesGetAll(), statement );
};
}

@Override
public ResourceIterable<Relationship> getAllRelationships()
{
threadToTransactionBridge.assertInUnterminatedTransaction();
return new ResourceIterable<Relationship>()
{
@Override
public ResourceIterator<Relationship> iterator()
return () -> {
final Statement statement = threadToTransactionBridge.get();
final PrimitiveLongIterator ids = statement.readOperations().relationshipsGetAll();
return new PrefetchingResourceIterator<Relationship>()
{
final Statement statement = threadToTransactionBridge.get();
final PrimitiveLongIterator ids = statement.readOperations().relationshipsGetAll();
return new PrefetchingResourceIterator<Relationship>()
@Override
public void close()
{
@Override
public void close()
{
statement.close();
}
statement.close();
}

@Override
protected Relationship fetchNextOrNull()
{
return ids.hasNext() ? nodeManager.newRelationshipProxy( ids.next() ) : null;
}
};
}
@Override
protected Relationship fetchNextOrNull()
{
return ids.hasNext() ? nodeManager.newRelationshipProxy( ids.next() ) : null;
}
};
};
}

Expand Down Expand Up @@ -480,14 +470,7 @@ public ResourceIterator<Node> findNodes( final Label myLabel )
public ResourceIterable<Node> findNodesByLabelAndProperty( final Label myLabel, final String key,
final Object value )
{
return new ResourceIterable<Node>()
{
@Override
public ResourceIterator<Node> iterator()
{
return nodesByLabelAndProperty( myLabel, key, value );
}
};
return () -> nodesByLabelAndProperty( myLabel, key, value );
}

private ResourceIterator<Node> nodesByLabelAndProperty( Label myLabel, String key, Object value )
Expand Down Expand Up @@ -562,26 +545,14 @@ private ResourceIterator<Node> allNodesWithLabel( final Label myLabel )
}

final PrimitiveLongIterator nodeIds = statement.readOperations().nodesGetForLabel( labelId );
return ResourceClosingIterator.newResourceIterator( statement, map( new LongFunction<Node>()
{
@Override
public Node apply( long nodeId )
{
return nodeManager.newNodeProxyById( nodeId );
}
}, nodeIds ) );
return ResourceClosingIterator.newResourceIterator( statement, map(
(LongFunction<Node>) nodeId -> nodeManager.newNodeProxyById( nodeId ), nodeIds ) );
}

private ResourceIterator<Node> map2nodes( PrimitiveLongIterator input, Statement statement )
{
return ResourceClosingIterator.newResourceIterator( statement, map( new LongFunction<Node>()
{
@Override
public Node apply( long id )
{
return nodeManager.newNodeProxyById( id );
}
}, input ) );
return ResourceClosingIterator.newResourceIterator( statement, map(
(LongFunction<Node>) id -> nodeManager.newNodeProxyById( id ), input ) );
}

@Override
Expand Down
Expand Up @@ -31,9 +31,9 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.LongFunction;

import org.neo4j.collection.primitive.PrimitiveLongCollections;
import org.neo4j.function.LongFunction;
import org.neo4j.graphdb.ConstraintViolationException;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.NotFoundException;
Expand Down Expand Up @@ -150,7 +150,6 @@
import org.neo4j.logging.NullLog;

import static java.lang.Boolean.parseBoolean;

import static org.neo4j.collection.primitive.PrimitiveLongCollections.map;
import static org.neo4j.graphdb.Label.label;
import static org.neo4j.helpers.collection.IteratorUtil.first;
Expand Down Expand Up @@ -300,14 +299,7 @@ public Label apply( long from )
schemaCache = new SchemaCache( new StandardConstraintSemantics(), schemaStore );

Dependencies deps = new Dependencies();
deps.satisfyDependencies( fileSystem, config, logService, new NeoStoresSupplier()
{
@Override
public NeoStores get()
{
return neoStores;
}
} );
deps.satisfyDependencies( fileSystem, config, logService, (NeoStoresSupplier) () -> neoStores );

KernelContext kernelContext = new KernelContext()
{
Expand Down Expand Up @@ -542,36 +534,31 @@ private void repopulateAllIndexes() throws IOException, IndexCapacityExceededExc
populators[i].create();
}

Visitor<NodePropertyUpdate, IOException> propertyUpdateVisitor = new Visitor<NodePropertyUpdate, IOException>()
{
@Override
public boolean visit( NodePropertyUpdate update ) throws IOException
Visitor<NodePropertyUpdate, IOException> propertyUpdateVisitor = update -> {
// Do a lookup from which property has changed to a list of indexes worried about that property.
int propertyKeyInQuestion = update.getPropertyKeyId();
for ( int i = 0; i < propertyKeyIds.length; i++ )
{
// Do a lookup from which property has changed to a list of indexes worried about that property.
int propertyKeyInQuestion = update.getPropertyKeyId();
for ( int i = 0; i < propertyKeyIds.length; i++ )
if ( propertyKeyIds[i] == propertyKeyInQuestion )
{
if ( propertyKeyIds[i] == propertyKeyInQuestion )
if ( update.forLabel( labelIds[i] ) )
{
if ( update.forLabel( labelIds[i] ) )
try
{
populators[i].add( update.getNodeId(), update.getValueAfter() );
}
catch ( IndexEntryConflictException conflict )
{
throw conflict.notAllowed( rules[i].getLabel(), rules[i].getPropertyKey() );
}
catch ( IndexCapacityExceededException e )
{
try
{
populators[i].add( update.getNodeId(), update.getValueAfter() );
}
catch ( IndexEntryConflictException conflict )
{
throw conflict.notAllowed( rules[i].getLabel(), rules[i].getPropertyKey() );
}
catch ( IndexCapacityExceededException e )
{
throw new UnderlyingStorageException( e );
}
throw new UnderlyingStorageException( e );
}
}
}
return true;
}
return true;
};

InitialNodeLabelCreationVisitor labelUpdateVisitor = new InitialNodeLabelCreationVisitor();
Expand Down
Expand Up @@ -22,6 +22,7 @@
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.function.LongFunction;
import java.util.function.LongPredicate;

import org.neo4j.collection.primitive.base.Empty;
Expand Down Expand Up @@ -705,8 +706,7 @@ public static PrimitiveLongSet setOf( long... values )
return set;
}

public static <T> Iterator<T> map( final org.neo4j.function.LongFunction<T> mapFunction,
final PrimitiveLongIterator source )
public static <T> Iterator<T> map( final LongFunction<T> mapFunction, final PrimitiveLongIterator source )
{
return new Iterator<T>()
{
Expand Down

0 comments on commit b6c12ef

Please sign in to comment.