diff --git a/community/collections/src/main/java/org/neo4j/collection/PrimitiveIntCollections.java b/community/collections/src/main/java/org/neo4j/collection/PrimitiveIntCollections.java deleted file mode 100644 index e3e0792c970e..000000000000 --- a/community/collections/src/main/java/org/neo4j/collection/PrimitiveIntCollections.java +++ /dev/null @@ -1,356 +0,0 @@ -/* - * Copyright (c) 2002-2018 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.collection; - -import org.eclipse.collections.api.iterator.IntIterator; -import org.eclipse.collections.api.set.primitive.IntSet; -import org.eclipse.collections.api.set.primitive.MutableIntSet; -import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.Set; -import java.util.function.IntConsumer; -import java.util.function.IntFunction; -import java.util.function.IntPredicate; -import java.util.function.LongToIntFunction; - -/** - * Basic and common primitive int collection utils and manipulations. - * - * @see PrimitiveLongCollections - */ -public class PrimitiveIntCollections -{ - private PrimitiveIntCollections() - { - } - - /** - * Base iterator for simpler implementations of {@link IntIterator}s. - */ - public abstract static class PrimitiveIntBaseIterator implements IntIterator - { - private boolean hasNextDecided; - private boolean hasNext; - private int next; - - @Override - public boolean hasNext() - { - if ( !hasNextDecided ) - { - hasNext = fetchNext(); - hasNextDecided = true; - } - return hasNext; - } - - @Override - public int next() - { - if ( !hasNext() ) - { - throw new NoSuchElementException( "No more elements in " + this ); - } - hasNextDecided = false; - return next; - } - - /** - * Fetches the next item in this iterator. Returns whether or not a next item was found. If a next - * item was found, that value must have been set inside the implementation of this method - * using {@link #next(int)}. - */ - protected abstract boolean fetchNext(); - - /** - * Called from inside an implementation of {@link #fetchNext()} if a next item was found. - * This method returns {@code true} so that it can be used in short-hand conditionals - * (TODO what are they called?), like: - *
-         * @Override
-         * protected boolean fetchNext()
-         * {
-         *     return source.hasNext() ? next( source.next() ) : false;
-         * }
-         * 
- * @param nextItem the next item found. - */ - protected boolean next( int nextItem ) - { - next = nextItem; - hasNext = true; - return true; - } - } - - public static IntIterator iterator( final int... items ) - { - return new PrimitiveIntBaseIterator() - { - private int index = -1; - - @Override - protected boolean fetchNext() - { - return ++index < items.length && next( items[index] ); - } - }; - } - - // Concating - public static IntIterator concat( Iterator iterators ) - { - return new PrimitiveIntConcatingIterator( iterators ); - } - - public static class PrimitiveIntConcatingIterator extends PrimitiveIntBaseIterator - { - private final Iterator iterators; - private IntIterator currentIterator; - - public PrimitiveIntConcatingIterator( Iterator iterators ) - { - this.iterators = iterators; - } - - @Override - protected boolean fetchNext() - { - if ( currentIterator == null || !currentIterator.hasNext() ) - { - while ( iterators.hasNext() ) - { - currentIterator = iterators.next(); - if ( currentIterator.hasNext() ) - { - break; - } - } - } - return (currentIterator != null && currentIterator.hasNext()) && next( currentIterator.next() ); - } - - protected final IntIterator currentIterator() - { - return currentIterator; - } - } - - public static IntIterator filter( IntIterator source, final IntPredicate filter ) - { - return new PrimitiveIntFilteringIterator( source ) - { - @Override - public boolean test( int item ) - { - return filter.test( item ); - } - }; - } - - public static IntIterator deduplicate( IntIterator source ) - { - return new PrimitiveIntFilteringIterator( source ) - { - private final IntHashSet visited = new IntHashSet(); - - @Override - public boolean test( int testItem ) - { - return visited.add( testItem ); - } - }; - } - - public abstract static class PrimitiveIntFilteringIterator extends PrimitiveIntBaseIterator implements IntPredicate - { - private final IntIterator source; - - public PrimitiveIntFilteringIterator( IntIterator source ) - { - this.source = source; - } - - @Override - protected boolean fetchNext() - { - while ( source.hasNext() ) - { - int testItem = source.next(); - if ( test( testItem ) ) - { - return next( testItem ); - } - } - return false; - } - - @Override - public abstract boolean test( int testItem ); - } - - public static IntSet asSet( IntIterator iterator ) - { - final MutableIntSet set = new IntHashSet(); - while ( iterator.hasNext() ) - { - int next = iterator.next(); - if ( !set.add( next ) ) - { - throw new IllegalStateException( "Duplicate " + next + " from " + iterator ); - } - } - return set; - } - - public static IntIterator toPrimitiveIterator( final Iterator iterator ) - { - return new PrimitiveIntBaseIterator() - { - @Override - protected boolean fetchNext() - { - if ( iterator.hasNext() ) - { - Integer nextValue = iterator.next(); - if ( null == nextValue ) - { - throw new IllegalArgumentException( "Cannot convert null Integer to primitive int" ); - } - return next( nextValue.intValue() ); - } - return false; - } - }; - } - - public static void consume( IntIterator source, IntConsumer consumer ) - { - while ( source.hasNext() ) - { - consumer.accept( source.next() ); - } - } - - public static MutableIntSet asSet( long[] values, LongToIntFunction converter ) - { - MutableIntSet set = new IntHashSet( values.length ); - for ( long value : values ) - { - set.add( converter.applyAsInt( value ) ); - } - return set; - } - - public static boolean contains( int[] values, int candidate ) - { - for ( int value : values ) - { - if ( value == candidate ) - { - return true; - } - } - return false; - } - - /** - * Pulls all items from the {@code iterator} and puts them into a {@link List}, boxing each int. - * - * @param iterator {@link IntIterator} to pull values from. - * @return a {@link List} containing all items. - */ - public static List toList( IntIterator iterator ) - { - List out = new ArrayList<>(); - while ( iterator.hasNext() ) - { - out.add( iterator.next() ); - } - return out; - } - - /** - * Pulls all items from the {@code iterator} and puts them into a {@link Set}, boxing each int. - * Any duplicate value will throw {@link IllegalStateException}. - * - * @param iterator {@link IntIterator} to pull values from. - * @return a {@link Set} containing all items. - * @throws IllegalStateException for the first encountered duplicate. - */ - public static Set toSet( IntIterator iterator ) - { - return mapToSet( iterator, Integer::new ); - } - - public static Set mapToSet( IntIterator iterator, IntFunction map ) - { - Set set = new HashSet<>(); - while ( iterator.hasNext() ) - { - addUnique( set, map.apply( iterator.next() ) ); - } - return set; - } - - private static > void addUnique( C collection, T item ) - { - if ( !collection.add( item ) ) - { - throw new IllegalStateException( "Encountered an already added item:" + item + - " when adding items uniquely to a collection:" + collection ); - } - } - - /** - * Deduplicates values in the {@code values} array. - * - * @param values sorted array of int values. - * @return the provided array if no duplicates were found, otherwise a new shorter array w/o duplicates. - */ - public static int[] deduplicate( int[] values ) - { - int unique = 0; - for ( int i = 0; i < values.length; i++ ) - { - int value = values[i]; - for ( int j = 0; j < unique; j++ ) - { - if ( value == values[j] ) - { - value = -1; // signal that this value is not unique - break; // we will not find more than one conflict - } - } - if ( value != -1 ) - { // this has to be done outside the inner loop, otherwise we'd never accept a single one... - values[unique++] = values[i]; - } - } - return unique < values.length ? Arrays.copyOf( values, unique ) : values; - } -} diff --git a/community/collections/src/main/java/org/neo4j/collection/PrimitiveLongCollections.java b/community/collections/src/main/java/org/neo4j/collection/PrimitiveLongCollections.java index 280d53b69241..dca487ece476 100644 --- a/community/collections/src/main/java/org/neo4j/collection/PrimitiveLongCollections.java +++ b/community/collections/src/main/java/org/neo4j/collection/PrimitiveLongCollections.java @@ -39,12 +39,9 @@ import org.neo4j.graphdb.Resource; import static java.util.Arrays.copyOf; -import static org.neo4j.collection.PrimitiveCommons.closeSafely; /** * Basic and common primitive int collection utils and manipulations. - * - * @see PrimitiveIntCollections */ public class PrimitiveLongCollections { @@ -52,7 +49,7 @@ public class PrimitiveLongCollections private PrimitiveLongCollections() { - throw new AssertionError( "no instance" ); + // nop } public static LongIterator iterator( final long... items ) @@ -92,49 +89,12 @@ public boolean test( long item ) }; } - public static PrimitiveLongResourceIterator filter( PrimitiveLongResourceIterator source, final LongPredicate filter ) - { - return new PrimitiveLongResourceFilteringIterator( source ) - { - @Override - public boolean test( long item ) - { - return filter.test( item ); - } - }; - } - // Range public static LongIterator range( long start, long end ) { return new PrimitiveLongRangeIterator( start, end ); } - public static long single( LongIterator iterator, long defaultItem ) - { - try - { - if ( !iterator.hasNext() ) - { - closeSafely( iterator ); - return defaultItem; - } - long item = iterator.next(); - if ( iterator.hasNext() ) - { - throw new NoSuchElementException( "More than one item in " + iterator + ", first:" + item + - ", second:" + iterator.next() ); - } - closeSafely( iterator ); - return item; - } - catch ( NoSuchElementException exception ) - { - closeSafely( iterator, exception ); - throw exception; - } - } - /** * Returns the index of the given item in the iterator(zero-based). If no items in {@code iterator} * equals {@code item} {@code -1} is returned. @@ -528,24 +488,6 @@ protected boolean fetchNext() public abstract boolean test( long testItem ); } - public abstract static class PrimitiveLongResourceFilteringIterator extends PrimitiveLongFilteringIterator - implements PrimitiveLongResourceIterator - { - PrimitiveLongResourceFilteringIterator( LongIterator source ) - { - super( source ); - } - - @Override - public void close() - { - if ( source instanceof Resource ) - { - ((Resource) source).close(); - } - } - } - public static class PrimitiveLongRangeIterator extends PrimitiveLongBaseIterator { private long current; diff --git a/community/collections/src/main/java/org/neo4j/collection/PrimitiveLongResourceCollections.java b/community/collections/src/main/java/org/neo4j/collection/PrimitiveLongResourceCollections.java index 8226af193548..f17637cd6852 100644 --- a/community/collections/src/main/java/org/neo4j/collection/PrimitiveLongResourceCollections.java +++ b/community/collections/src/main/java/org/neo4j/collection/PrimitiveLongResourceCollections.java @@ -19,10 +19,7 @@ */ package org.neo4j.collection; -import org.eclipse.collections.api.iterator.LongIterator; - import java.util.Arrays; -import java.util.function.LongPredicate; import org.neo4j.graphdb.Resource; import org.neo4j.graphdb.ResourceUtils; @@ -60,18 +57,6 @@ public static PrimitiveLongResourceIterator concat( Iterable value % 2 == 0; // ITERATOR @@ -53,26 +51,6 @@ void simpleIterator() // FILTER - @Test - void filterItems() - { - // Given - CountingResource resource = new CountingResource(); - PrimitiveLongResourceIterator iterator = PrimitiveLongResourceCollections.iterator( resource, 1, 2, 3, 4 ); - - // When - PrimitiveLongResourceIterator filtered = PrimitiveLongResourceCollections.filter( iterator, EVEN ); - - // Then - assertContent( filtered, 2, 4 ); - - // When - filtered.close(); - - // Then - assertEquals( 1, resource.closeCount(), "exactly one call to close" ); - } - // CONCAT @Test diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/MultipleIndexPopulator.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/MultipleIndexPopulator.java index 1339b40a4423..971b2821a7ed 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/MultipleIndexPopulator.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/MultipleIndexPopulator.java @@ -52,7 +52,7 @@ import org.neo4j.util.FeatureToggles; import static java.lang.String.format; -import static org.neo4j.collection.PrimitiveIntCollections.contains; +import static org.eclipse.collections.impl.utility.ArrayIterate.contains; import static org.neo4j.kernel.impl.api.index.IndexPopulationFailure.failure; /** diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexBase.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexBase.java index e8db28c60ef7..8665482beda6 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexBase.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexBase.java @@ -22,12 +22,13 @@ import java.lang.reflect.Array; import java.util.Arrays; -import org.neo4j.collection.PrimitiveIntCollections; import org.neo4j.function.ThrowingConsumer; import org.neo4j.function.ThrowingFunction; import org.neo4j.helpers.Exceptions; import org.neo4j.kernel.api.index.IndexProvider; +import static org.eclipse.collections.impl.utility.ArrayIterate.contains; + /** * Acting as a simplifier for the multiplexing that is going in inside a fusion index. A fusion index consists of multiple parts, * each handling one or more value groups. Each instance, be it a reader, populator or accessor should extend this class @@ -157,7 +158,7 @@ static void validateSelectorInstances( Object[] instances, int... aliveIndex ) { for ( int i = 0; i < instances.length; i++ ) { - boolean expected = PrimitiveIntCollections.contains( aliveIndex, i ); + boolean expected = contains( aliveIndex, i ); boolean actual = instances[i] != IndexProvider.EMPTY; if ( expected != actual ) { diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/BatchInserterImpl.java b/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/BatchInserterImpl.java index 66ed24d60548..5e30a2f861eb 100644 --- a/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/BatchInserterImpl.java +++ b/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/BatchInserterImpl.java @@ -34,7 +34,6 @@ import java.util.Map.Entry; import java.util.function.LongFunction; -import org.neo4j.collection.PrimitiveIntCollections; import org.neo4j.collection.PrimitiveLongCollections; import org.neo4j.graphdb.ConstraintViolationException; import org.neo4j.graphdb.Label; @@ -166,6 +165,7 @@ import static java.lang.Boolean.parseBoolean; import static java.util.Collections.emptyIterator; +import static org.eclipse.collections.impl.utility.ArrayIterate.contains; import static org.neo4j.collection.PrimitiveLongCollections.map; import static org.neo4j.graphdb.Label.label; import static org.neo4j.graphdb.factory.GraphDatabaseSettings.logs_directory; @@ -535,7 +535,7 @@ private void repopulateAllIndexes() throws IOException, IndexEntryConflictExcept try ( InitialNodeLabelCreationVisitor labelUpdateVisitor = new InitialNodeLabelCreationVisitor() ) { StoreScan storeScan = indexStoreView.visitNodes( labelIds, - propertyKeyId -> PrimitiveIntCollections.contains( propertyKeyIds, propertyKeyId ), + propertyKeyId -> contains( propertyKeyIds, propertyKeyId ), propertyUpdateVisitor, labelUpdateVisitor, true ); storeScan.run(); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/api/index/SimpleIndexPopulatorCompatibility.java b/community/kernel/src/test/java/org/neo4j/kernel/api/index/SimpleIndexPopulatorCompatibility.java index 3fc66099c2e0..e29e549cf9bd 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/api/index/SimpleIndexPopulatorCompatibility.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/api/index/SimpleIndexPopulatorCompatibility.java @@ -49,12 +49,11 @@ import static java.util.Collections.singletonList; import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; -import static org.neo4j.collection.PrimitiveLongCollections.single; import static org.neo4j.helpers.collection.Iterators.asSet; import static org.neo4j.internal.kernel.api.InternalIndexState.FAILED; -import static org.neo4j.kernel.api.StatementConstants.NO_SUCH_NODE; import static org.neo4j.kernel.api.index.IndexEntryUpdate.add; @Ignore( "Not a test. This is a compatibility suite that provides test cases for verifying" + @@ -202,7 +201,8 @@ public void shouldPopulateAndUpdate() throws Exception { NodeValueIterator nodes = new NodeValueIterator(); reader.query( nodes, IndexOrder.NONE, IndexQuery.exact( propertyKeyId, entry.value ) ); - assertEquals( entry.nodeId, single( nodes, NO_SUCH_NODE ) ); + assertEquals( entry.nodeId, nodes.next() ); + assertFalse( nodes.hasNext() ); } } } @@ -231,7 +231,8 @@ private void assertHasAllValues( List values ) throws IOException, { NodeValueIterator nodes = new NodeValueIterator(); reader.query( nodes, IndexOrder.NONE, IndexQuery.exact( propertyKeyId, entry.value ) ); - assertEquals( entry.nodeId, single( nodes, NO_SUCH_NODE ) ); + assertEquals( entry.nodeId, nodes.next() ); + assertFalse( nodes.hasNext() ); } } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorageLayerRelTypesAndDegreeTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorageLayerRelTypesAndDegreeTest.java index 415ce08d098c..72656baa88dd 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorageLayerRelTypesAndDegreeTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorageLayerRelTypesAndDegreeTest.java @@ -54,7 +54,6 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; -import static org.neo4j.collection.PrimitiveIntCollections.mapToSet; import static org.neo4j.helpers.collection.Iterators.asSet; import static org.neo4j.kernel.impl.api.store.TestRelType.IN; import static org.neo4j.kernel.impl.api.store.TestRelType.LOOP; @@ -377,7 +376,7 @@ private void testRelationshipTypesForDenseNode( LongConsumer nodeChanger, Set relTypes( StoreSingleNodeCursor cursor ) { - return mapToSet( disk.relationshipTypes( disk.newStatement(), cursor.get() ).intIterator(), this::relTypeForId ); + return disk.relationshipTypes( disk.newStatement(), cursor.get() ).collect( this::relTypeForId ).toSet(); } private void testDegreesForDenseNodeWithPartiallyDeletedRelGroupChain( TestRelType... typesToDelete ) diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/command/IndexWorkSyncTransactionApplicationStressIT.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/command/IndexWorkSyncTransactionApplicationStressIT.java index a5508e6ac8b4..8f3350edc3d1 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/command/IndexWorkSyncTransactionApplicationStressIT.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/command/IndexWorkSyncTransactionApplicationStressIT.java @@ -29,7 +29,6 @@ import java.util.Collection; import java.util.concurrent.atomic.AtomicBoolean; -import org.neo4j.collection.PrimitiveLongCollections; import org.neo4j.helpers.collection.Visitor; import org.neo4j.internal.kernel.api.IndexQuery; import org.neo4j.internal.kernel.api.InternalIndexState; @@ -63,6 +62,7 @@ import static java.util.Collections.singletonList; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.neo4j.helpers.TimeUtil.parseTimeMillis; import static org.neo4j.kernel.impl.transaction.command.Commands.createIndexRule; import static org.neo4j.kernel.impl.transaction.command.Commands.transactionRepresentation; @@ -221,8 +221,8 @@ private void verifyIndex( TransactionToApply tx ) throws Exception Value propertyValue = propertyValue( id, base + i ); IndexQuery.ExactPredicate query = IndexQuery.exact( descriptor.getPropertyId(), propertyValue ); LongIterator hits = reader.query( query ); - assertEquals( "Index doesn't contain " + visitor.nodeId + " " + propertyValue, - visitor.nodeId, PrimitiveLongCollections.single( hits, -1 ) ); + assertEquals( "Index doesn't contain " + visitor.nodeId + " " + propertyValue, visitor.nodeId, hits.next() ); + assertFalse( hits.hasNext() ); tx = tx.next(); } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/util/collection/SimpleBitSetTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/util/collection/SimpleBitSetTest.java index 0083066b95ea..306fde0ff80b 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/util/collection/SimpleBitSetTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/util/collection/SimpleBitSetTest.java @@ -19,13 +19,12 @@ */ package org.neo4j.kernel.impl.util.collection; +import org.eclipse.collections.api.iterator.IntIterator; +import org.eclipse.collections.api.list.primitive.MutableIntList; +import org.eclipse.collections.impl.factory.primitive.IntLists; +import org.eclipse.collections.impl.list.mutable.primitive.IntArrayList; import org.junit.Test; -import java.util.List; - -import org.neo4j.collection.PrimitiveIntCollections; - -import static java.util.Arrays.asList; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; @@ -158,10 +157,15 @@ public void shouldAllowIterating() set.put( 78 ); // When - List found = PrimitiveIntCollections.toList( set.iterator() ); + IntIterator iterator = set.iterator(); + MutableIntList found = new IntArrayList(); + while ( iterator.hasNext() ) + { + found.add( iterator.next() ); + } // Then - assertThat( found, equalTo( asList( 4, 7, 63, 78 ) )); + assertThat( found, equalTo( IntLists.immutable.of( 4, 7, 63, 78 ) ) ); } @Test diff --git a/community/lucene-index/src/main/java/org/neo4j/index/impl/lucene/explicit/LuceneBatchInserterIndex.java b/community/lucene-index/src/main/java/org/neo4j/index/impl/lucene/explicit/LuceneBatchInserterIndex.java index 89f943535d3c..3a204ae44fee 100644 --- a/community/lucene-index/src/main/java/org/neo4j/index/impl/lucene/explicit/LuceneBatchInserterIndex.java +++ b/community/lucene-index/src/main/java/org/neo4j/index/impl/lucene/explicit/LuceneBatchInserterIndex.java @@ -40,8 +40,8 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.NoSuchElementException; -import org.neo4j.collection.PrimitiveLongCollections; import org.neo4j.graphdb.ResourceIterator; import org.neo4j.graphdb.index.IndexHits; import org.neo4j.helpers.collection.LruCache; @@ -53,6 +53,8 @@ import org.neo4j.kernel.impl.util.IoPrimitiveUtils; import org.neo4j.unsafe.batchinsert.BatchInserterIndex; +import static java.lang.String.format; + class LuceneBatchInserterIndex implements BatchInserterIndex { private final IndexIdentifier identifier; @@ -426,8 +428,13 @@ public Long getSingle() { try { - long singleId = PrimitiveLongCollections.single( ids, -1L ); - return singleId == -1 ? null : singleId; + final Long result = ids.hasNext() ? ids.next() : null; + + if ( ids.hasNext() ) + { + throw new NoSuchElementException( format( "More than one item in %s, first:%d, second:%d", ids, result, ids.next() ) ); + } + return result; } finally {