Skip to content

Commit

Permalink
Use ImmutableEmptyLongIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Koval committed May 8, 2018
1 parent 8521801 commit 58f81c9
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 56 deletions.
Expand Up @@ -49,15 +49,6 @@ public class PrimitiveLongCollections
{
public static final long[] EMPTY_LONG_ARRAY = new long[0];

private static final LongIterator EMPTY = new PrimitiveLongBaseIterator()
{
@Override
protected boolean fetchNext()
{
return false;
}
};

private PrimitiveLongCollections()
{
throw new AssertionError( "no instance" );
Expand Down Expand Up @@ -232,11 +223,6 @@ public static long[] asArray( Iterator<Long> iterator )
return array;
}

public static LongIterator emptyIterator()
{
return EMPTY;
}

public static LongIterator toPrimitiveIterator( final Iterator<Long> iterator )
{
return new PrimitiveLongBaseIterator()
Expand Down
Expand Up @@ -21,6 +21,7 @@

import org.eclipse.collections.api.iterator.LongIterator;
import org.eclipse.collections.api.set.primitive.LongSet;
import org.eclipse.collections.impl.iterator.ImmutableEmptyLongIterator;
import org.eclipse.collections.impl.set.mutable.primitive.LongHashSet;
import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -117,7 +118,7 @@ public void singleWithDefaultMustAutoCloseEmptyIterator()
{
AtomicInteger counter = new AtomicInteger();
CountingPrimitiveLongIteratorResource itr = new CountingPrimitiveLongIteratorResource(
PrimitiveLongCollections.emptyIterator(), counter );
ImmutableEmptyLongIterator.INSTANCE, counter );
assertEquals( PrimitiveLongCollections.single( itr, 2 ), 2 );
assertEquals( 1, counter.get() );
}
Expand Down
Expand Up @@ -20,9 +20,9 @@
package org.neo4j.index.internal.gbptree;

import org.apache.commons.lang3.mutable.MutableLong;
import org.eclipse.collections.impl.iterator.ImmutableEmptyLongIterator;
import org.junit.Test;

import org.neo4j.collection.primitive.PrimitiveLongCollections;
import org.neo4j.io.pagecache.CursorException;
import org.neo4j.io.pagecache.PageCursor;

Expand Down Expand Up @@ -122,7 +122,7 @@ public void shouldDetectUnusedPages() throws Exception
new ConsistencyChecker<>( node, layout, stableGeneration, unstableGeneration );
try
{
cc.checkSpace( cursor, idProvider.lastId(), PrimitiveLongCollections.emptyIterator() );
cc.checkSpace( cursor, idProvider.lastId(), ImmutableEmptyLongIterator.INSTANCE );
fail( "Should have failed" );
}
catch ( RuntimeException e )
Expand Down
Expand Up @@ -21,14 +21,14 @@

import org.eclipse.collections.api.iterator.LongIterator;
import org.eclipse.collections.api.set.primitive.MutableIntSet;
import org.eclipse.collections.impl.iterator.ImmutableEmptyLongIterator;
import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet;

import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.Set;

import org.neo4j.collection.primitive.PrimitiveLongCollections;
import org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException;
import org.neo4j.kernel.impl.api.state.RelationshipChangesForNode.DiffStrategy;
import org.neo4j.kernel.impl.newapi.RelationshipDirection;
Expand Down Expand Up @@ -161,25 +161,25 @@ public boolean isPropertyRemoved( int propertyKeyId )
@Override
public LongIterator getAddedRelationships( Direction direction )
{
return PrimitiveLongCollections.emptyIterator();
return ImmutableEmptyLongIterator.INSTANCE;
}

@Override
public LongIterator getAddedRelationships( Direction direction, int[] relTypes )
{
return PrimitiveLongCollections.emptyIterator();
return ImmutableEmptyLongIterator.INSTANCE;
}

@Override
public LongIterator getAddedRelationships()
{
return PrimitiveLongCollections.emptyIterator();
return ImmutableEmptyLongIterator.INSTANCE;
}

@Override
public LongIterator getAddedRelationships( RelationshipDirection direction, int relType )
{
return PrimitiveLongCollections.emptyIterator();
return ImmutableEmptyLongIterator.INSTANCE;
}
};

Expand Down Expand Up @@ -377,27 +377,27 @@ public boolean hasRelationshipChanges()
public LongIterator getAddedRelationships( Direction direction )
{
return relationshipsAdded != null ? relationshipsAdded.getRelationships( direction ) :
PrimitiveLongCollections.emptyIterator();
ImmutableEmptyLongIterator.INSTANCE;
}

@Override
public LongIterator getAddedRelationships( Direction direction, int[] relTypes )
{
return relationshipsAdded != null ? relationshipsAdded.getRelationships( direction, relTypes ) :
PrimitiveLongCollections.emptyIterator();
ImmutableEmptyLongIterator.INSTANCE;
}

@Override
public LongIterator getAddedRelationships()
{
return relationshipsAdded != null ? relationshipsAdded.getRelationships() :
PrimitiveLongCollections.emptyIterator();
ImmutableEmptyLongIterator.INSTANCE;
}

@Override
public LongIterator getAddedRelationships( RelationshipDirection direction, int relType )
{
return relationshipsAdded != null ? relationshipsAdded.getRelationships( direction, relType ) :
PrimitiveLongCollections.emptyIterator();
ImmutableEmptyLongIterator.INSTANCE;
}
}
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.collections.api.iterator.IntIterator;
import org.eclipse.collections.api.iterator.LongIterator;
import org.eclipse.collections.api.set.primitive.MutableIntSet;
import org.eclipse.collections.impl.iterator.ImmutableEmptyLongIterator;
import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet;

import java.util.ArrayList;
Expand Down Expand Up @@ -138,7 +139,7 @@ LongIterator getPrimitiveIterator( final Iterator<Set<Long>> diff )
{
if ( !diff.hasNext() )
{
return PrimitiveLongCollections.emptyIterator();
return ImmutableEmptyLongIterator.INSTANCE;
}

return new PrimitiveLongCollections.PrimitiveLongBaseIterator()
Expand Down Expand Up @@ -531,26 +532,26 @@ public LongIterator getRelationships( RelationshipDirection direction, int type
switch ( direction )
{
case INCOMING:
return incoming != null ? primitiveIdsByType( incoming, type ) : emptyIterator();
return incoming != null ? primitiveIdsByType( incoming, type ) : ImmutableEmptyLongIterator.INSTANCE;
case OUTGOING:
return outgoing != null ? primitiveIdsByType( outgoing, type ) : emptyIterator();
return outgoing != null ? primitiveIdsByType( outgoing, type ) : ImmutableEmptyLongIterator.INSTANCE;
case LOOP:
return loops != null ? primitiveIdsByType( loops, type ) : emptyIterator();
return loops != null ? primitiveIdsByType( loops, type ) : ImmutableEmptyLongIterator.INSTANCE;
default:
throw new IllegalArgumentException( "Unknown direction: " + direction );
}
}

private LongIterator primitiveIds( Map<Integer, Set<Long>> map )
{
return map == null ? emptyIterator() :
return map == null ? ImmutableEmptyLongIterator.INSTANCE :
toPrimitiveIterator( Iterators.flatMap( Set::iterator, map.values().iterator() ) );
}

private LongIterator primitiveIdsByType( Map<Integer, Set<Long>> map, int type )
{
Set<Long> relationships = map.get( type );
return relationships == null ? emptyIterator() : toPrimitiveIterator( relationships.iterator() );
return relationships == null ? ImmutableEmptyLongIterator.INSTANCE : toPrimitiveIterator( relationships.iterator() );
}

private LongIterator getRelationships( Direction direction,
Expand All @@ -560,13 +561,13 @@ private LongIterator getRelationships( Direction direction,
{
case INCOMING:
return incoming != null || loops != null ? diffStrategy.getPrimitiveIterator(
diffs( types, incoming, loops ) ) : emptyIterator();
diffs( types, incoming, loops ) ) : ImmutableEmptyLongIterator.INSTANCE;
case OUTGOING:
return outgoing != null || loops != null ? diffStrategy.getPrimitiveIterator(
diffs( types, outgoing, loops ) ) : emptyIterator();
diffs( types, outgoing, loops ) ) : ImmutableEmptyLongIterator.INSTANCE;
case BOTH:
return outgoing != null || incoming != null || loops != null ? diffStrategy.getPrimitiveIterator(
diffs( types, outgoing, incoming, loops ) ) : emptyIterator();
diffs( types, outgoing, incoming, loops ) ) : ImmutableEmptyLongIterator.INSTANCE;
default:
throw new IllegalArgumentException( "Unknown direction: " + direction );
}
Expand Down
Expand Up @@ -20,11 +20,11 @@
package org.neo4j.kernel.impl.newapi;

import org.eclipse.collections.api.iterator.LongIterator;
import org.eclipse.collections.impl.iterator.ImmutableEmptyLongIterator;

import java.util.HashSet;
import java.util.Set;

import org.neo4j.collection.primitive.PrimitiveLongCollections;
import org.neo4j.internal.kernel.api.LabelSet;
import org.neo4j.internal.kernel.api.NodeCursor;
import org.neo4j.internal.kernel.api.NodeLabelIndexCursor;
Expand Down Expand Up @@ -60,7 +60,7 @@ public void scan( LabelScanValueIndexProgressor progressor, boolean providesLabe
{
ReadableDiffSets<Long> changes =
read.txState().nodesWithLabelChanged( label );
added = changes.augment( PrimitiveLongCollections.emptyIterator() );
added = changes.augment( ImmutableEmptyLongIterator.INSTANCE );
removed = new HashSet<>( read.txState().addedAndRemovedNodes().getRemoved() );
removed.addAll( changes.getRemoved() );
}
Expand Down
Expand Up @@ -197,7 +197,7 @@ public void close()
this.query = null;
this.values = null;
this.read = null;
this.added = emptyIterator();
this.added = ImmutableEmptyLongIterator.INSTANCE;
this.removed = LongSets.immutable.empty();

try
Expand Down Expand Up @@ -245,7 +245,7 @@ private void prefixQuery( SchemaIndexDescriptor descriptor, IndexQuery.StringPre
TransactionState txState = read.txState();
PrimitiveLongReadableDiffSets changes = txState
.indexUpdatesForRangeSeekByPrefix( descriptor, predicate.prefix() );
added = changes.augment( emptyIterator() );
added = changes.augment( ImmutableEmptyLongIterator.INSTANCE );
removed = removed( txState, changes );
}
}
Expand All @@ -262,7 +262,7 @@ private void rangeQuery( SchemaIndexDescriptor descriptor, IndexQuery.RangePredi
descriptor, valueGroup,
predicate.fromValue(), predicate.fromInclusive(),
predicate.toValue(), predicate.toInclusive() );
added = changes.augment( emptyIterator() );
added = changes.augment( ImmutableEmptyLongIterator.INSTANCE );
removed = removed( txState, changes );
}
}
Expand All @@ -274,7 +274,7 @@ private void scanQuery( SchemaIndexDescriptor descriptor )
{
TransactionState txState = read.txState();
PrimitiveLongReadableDiffSets changes = txState.indexUpdatesForScan( descriptor );
added = changes.augment( emptyIterator() );
added = changes.augment( ImmutableEmptyLongIterator.INSTANCE );
removed = removed( txState, changes );
}
}
Expand All @@ -286,7 +286,7 @@ private void suffixOrContainsQuery( SchemaIndexDescriptor descriptor, IndexQuery
{
TransactionState txState = read.txState();
PrimitiveLongReadableDiffSets changes = txState.indexUpdatesForSuffixOrContains( descriptor, query );
added = changes.augment( emptyIterator() );
added = changes.augment( ImmutableEmptyLongIterator.INSTANCE );
removed = removed( txState, changes );
}
}
Expand All @@ -300,7 +300,7 @@ private void seekQuery( SchemaIndexDescriptor descriptor, IndexQuery[] query )
TransactionState txState = read.txState();
PrimitiveLongReadableDiffSets changes = read.txState()
.indexUpdatesForSeek( descriptor, IndexQuery.asValueTuple( exactPreds ) );
added = changes.augment( emptyIterator() );
added = changes.augment( ImmutableEmptyLongIterator.INSTANCE );
removed = removed( txState, changes );
}
}
Expand Down
Expand Up @@ -20,8 +20,8 @@
package org.neo4j.kernel.impl.newapi;

import org.eclipse.collections.api.iterator.LongIterator;
import org.eclipse.collections.impl.iterator.ImmutableEmptyLongIterator;

import org.neo4j.collection.primitive.PrimitiveLongCollections;
import org.neo4j.internal.kernel.api.NodeCursor;
import org.neo4j.internal.kernel.api.RelationshipTraversalCursor;
import org.neo4j.io.pagecache.PageCursor;
Expand Down Expand Up @@ -149,7 +149,7 @@ void buffered( long nodeReference, Record record, RelationshipDirection directio
this.filterState = FilterState.fromRelationshipDirection( direction );
this.filterType = type;
init( read );
this.addedRelationships = PrimitiveLongCollections.emptyIterator();
this.addedRelationships = ImmutableEmptyLongIterator.INSTANCE;
}

/*
Expand All @@ -168,7 +168,7 @@ void chain( long nodeReference, long reference, Read read )
this.originNodeReference = nodeReference;
this.next = reference;
init( read );
this.addedRelationships = PrimitiveLongCollections.emptyIterator();
this.addedRelationships = ImmutableEmptyLongIterator.INSTANCE;
}

/*
Expand All @@ -184,7 +184,7 @@ void groups( long nodeReference, long groupReference, Read read )
this.originNodeReference = nodeReference;
read.relationshipGroups( nodeReference, groupReference, group );
init( read );
this.addedRelationships = PrimitiveLongCollections.emptyIterator();
this.addedRelationships = ImmutableEmptyLongIterator.INSTANCE;
}

/*
Expand All @@ -204,7 +204,7 @@ void filtered( long nodeReference, long reference, Read read, boolean filterStor
this.originNodeReference = nodeReference;
this.next = reference;
init( read );
this.addedRelationships = PrimitiveLongCollections.emptyIterator();
this.addedRelationships = ImmutableEmptyLongIterator.INSTANCE;
}

/*
Expand All @@ -220,7 +220,7 @@ void filteredTxState( long nodeReference, Read read, int filterType, Relationshi
this.originNodeReference = nodeReference;
this.next = NO_ID;
init( read );
this.addedRelationships = PrimitiveLongCollections.emptyIterator();
this.addedRelationships = ImmutableEmptyLongIterator.INSTANCE;
}

@Override
Expand Down
Expand Up @@ -20,10 +20,10 @@
package org.neo4j.unsafe.impl.batchimport.cache.idmapping;

import org.eclipse.collections.api.iterator.LongIterator;
import org.eclipse.collections.impl.iterator.ImmutableEmptyLongIterator;

import java.util.function.LongFunction;

import org.neo4j.collection.primitive.PrimitiveLongCollections;
import org.neo4j.helpers.progress.ProgressListener;
import org.neo4j.unsafe.impl.batchimport.cache.MemoryStatsVisitor;
import org.neo4j.unsafe.impl.batchimport.cache.NumberArrayFactory;
Expand Down Expand Up @@ -94,7 +94,7 @@ public MemoryStatsVisitor.Visitable memoryEstimation( long numberOfNodes )
@Override
public LongIterator leftOverDuplicateNodesIds()
{
return PrimitiveLongCollections.emptyIterator();
return ImmutableEmptyLongIterator.INSTANCE;
}
}

Expand Down
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.unsafe.impl.batchimport.cache.idmapping.string;

import org.eclipse.collections.api.iterator.LongIterator;
import org.eclipse.collections.impl.iterator.ImmutableEmptyLongIterator;

import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -886,7 +887,7 @@ public LongIterator leftOverDuplicateNodesIds()
{
if ( numberOfCollisions == 0 )
{
return PrimitiveLongCollections.emptyIterator();
return ImmutableEmptyLongIterator.INSTANCE;
}

// Scans duplicate marks in tracker cache. There is no bit left in dataCache to store this bit so we use
Expand Down
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.kernel.impl.api.index;

import org.eclipse.collections.api.iterator.LongIterator;
import org.eclipse.collections.impl.iterator.ImmutableEmptyLongIterator;
import org.junit.Test;
import org.mockito.Mockito;

Expand All @@ -41,7 +42,7 @@ public class NodeUpdatesIteratorTest
public void iterateOverEmptyNodeIds()
{
IndexStoreView storeView = Mockito.mock( IndexStoreView.class );
LongIterator emptyIterator = PrimitiveLongCollections.emptyIterator();
LongIterator emptyIterator = ImmutableEmptyLongIterator.INSTANCE;
NodeUpdatesIterator nodeUpdatesIterator = new NodeUpdatesIterator( storeView, emptyIterator );
assertFalse( nodeUpdatesIterator.hasNext() );
}
Expand Down

0 comments on commit 58f81c9

Please sign in to comment.