diff --git a/community/collections/pom.xml b/community/collections/pom.xml index c53c5eb9a9a5e..537c9792e9ff7 100644 --- a/community/collections/pom.xml +++ b/community/collections/pom.xml @@ -72,11 +72,14 @@ the relevant Commercial Agreement. neo4j-common ${project.version} - - junit - junit + org.eclipse.collections + eclipse-collections + + junit + junit + org.mockito mockito-core diff --git a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveArrays.java b/community/collections/src/main/java/org/neo4j/collection/primitive/PrimitiveArrays.java similarity index 93% rename from community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveArrays.java rename to community/collections/src/main/java/org/neo4j/collection/primitive/PrimitiveArrays.java index adf108a95c342..3e1130141047e 100644 --- a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveArrays.java +++ b/community/collections/src/main/java/org/neo4j/collection/primitive/PrimitiveArrays.java @@ -19,8 +19,6 @@ */ package org.neo4j.collection.primitive; -import org.eclipse.collections.api.iterator.LongIterator; - import java.util.Arrays; import static org.neo4j.collection.primitive.PrimitiveLongCollections.EMPTY_LONG_ARRAY; @@ -225,23 +223,6 @@ else if ( left[l] < right[r] ) return difference; } - /** - * Copy PrimitiveLongCollection into new long array - * @param collection the collection to copy - * @return the new long array - */ - public static long[] of( PrimitiveLongCollection collection ) - { - int i = 0; - long[] result = new long[collection.size()]; - final LongIterator iterator = collection.longIterator(); - while ( iterator.hasNext() ) - { - result[i++] = iterator.next(); - } - return result; - } - /** * Compute the number of unique values in two sorted long array sets * @param left a sorted array set diff --git a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveCommons.java b/community/collections/src/main/java/org/neo4j/collection/primitive/PrimitiveCommons.java similarity index 100% rename from community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveCommons.java rename to community/collections/src/main/java/org/neo4j/collection/primitive/PrimitiveCommons.java diff --git a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveIntCollections.java b/community/collections/src/main/java/org/neo4j/collection/primitive/PrimitiveIntCollections.java similarity index 100% rename from community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveIntCollections.java rename to community/collections/src/main/java/org/neo4j/collection/primitive/PrimitiveIntCollections.java diff --git a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongArrayQueue.java b/community/collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongArrayQueue.java similarity index 96% rename from community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongArrayQueue.java rename to community/collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongArrayQueue.java index 1b7ae57aea02e..dd724c238e33e 100644 --- a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongArrayQueue.java +++ b/community/collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongArrayQueue.java @@ -31,7 +31,7 @@ * Queue capacity should always be power of two to be able to use * '&' mask operation with {@link #values} length. */ -public class PrimitiveLongArrayQueue implements PrimitiveLongCollection +public class PrimitiveLongArrayQueue { private static final int DEFAULT_CAPACITY = 16; private long[] values; @@ -49,31 +49,26 @@ public PrimitiveLongArrayQueue() initValues( capacity ); } - @Override public boolean isEmpty() { return head == tail; } - @Override public void clear() { initValues( DEFAULT_CAPACITY ); } - @Override public int size() { return (tail - head) & (values.length - 1); } - @Override public void close() { values = PrimitiveLongCollections.EMPTY_LONG_ARRAY; } - @Override public LongIterator longIterator() { return new PrimitiveLongArrayQueueIterator(); diff --git a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongCollections.java b/community/collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongCollections.java similarity index 100% rename from community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongCollections.java rename to community/collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongCollections.java diff --git a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongResourceCollections.java b/community/collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongResourceCollections.java similarity index 100% rename from community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongResourceCollections.java rename to community/collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongResourceCollections.java diff --git a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongResourceIterator.java b/community/collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongResourceIterator.java similarity index 100% rename from community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongResourceIterator.java rename to community/collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongResourceIterator.java diff --git a/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/PrimitiveArraysTest.java b/community/collections/src/test/java/org/neo4j/collection/primitive/PrimitiveArraysTest.java similarity index 100% rename from community/primitive-collections/src/test/java/org/neo4j/collection/primitive/PrimitiveArraysTest.java rename to community/collections/src/test/java/org/neo4j/collection/primitive/PrimitiveArraysTest.java diff --git a/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/PrimitiveArraysUnionTest.java b/community/collections/src/test/java/org/neo4j/collection/primitive/PrimitiveArraysUnionTest.java similarity index 100% rename from community/primitive-collections/src/test/java/org/neo4j/collection/primitive/PrimitiveArraysUnionTest.java rename to community/collections/src/test/java/org/neo4j/collection/primitive/PrimitiveArraysUnionTest.java diff --git a/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/PrimitiveLongArrayQueueTest.java b/community/collections/src/test/java/org/neo4j/collection/primitive/PrimitiveLongArrayQueueTest.java similarity index 98% rename from community/primitive-collections/src/test/java/org/neo4j/collection/primitive/PrimitiveLongArrayQueueTest.java rename to community/collections/src/test/java/org/neo4j/collection/primitive/PrimitiveLongArrayQueueTest.java index ce4ed5303f2f0..9958c3c7d23ae 100644 --- a/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/PrimitiveLongArrayQueueTest.java +++ b/community/collections/src/test/java/org/neo4j/collection/primitive/PrimitiveLongArrayQueueTest.java @@ -20,6 +20,7 @@ package org.neo4j.collection.primitive; import org.eclipse.collections.api.iterator.LongIterator; +import org.junit.Assert; import org.junit.Test; import java.util.NoSuchElementException; @@ -172,7 +173,7 @@ public void tailBeforeHeadCorrectIteration() for ( int j = 10; j < 24; j++ ) { assertTrue( iterator.hasNext() ); - assertEquals( j, iterator.next() ); + Assert.assertEquals( j, iterator.next() ); } assertFalse( iterator.hasNext() ); } diff --git a/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/PrimitiveLongCollectionsTest.java b/community/collections/src/test/java/org/neo4j/collection/primitive/PrimitiveLongCollectionsTest.java similarity index 97% rename from community/primitive-collections/src/test/java/org/neo4j/collection/primitive/PrimitiveLongCollectionsTest.java rename to community/collections/src/test/java/org/neo4j/collection/primitive/PrimitiveLongCollectionsTest.java index 49e1dbe940840..45ef972bbb062 100644 --- a/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/PrimitiveLongCollectionsTest.java +++ b/community/collections/src/test/java/org/neo4j/collection/primitive/PrimitiveLongCollectionsTest.java @@ -22,6 +22,7 @@ import org.eclipse.collections.api.iterator.LongIterator; import org.eclipse.collections.api.set.primitive.LongSet; import org.eclipse.collections.impl.set.mutable.primitive.LongHashSet; +import org.junit.Assert; import org.junit.Test; import java.util.Arrays; @@ -190,10 +191,10 @@ protected boolean fetchNext() // WHEN/THEN assertTrue( iterator.hasNext() ); assertTrue( iterator.hasNext() ); - assertEquals( 1L, iterator.next() ); + Assert.assertEquals( 1L, iterator.next() ); assertTrue( iterator.hasNext() ); assertTrue( iterator.hasNext() ); - assertEquals( 0L, iterator.next() ); + Assert.assertEquals( 0L, iterator.next() ); assertFalse( iterator.hasNext() ); assertFalse( iterator.hasNext() ); assertEquals( -1L, count.get() ); @@ -207,7 +208,7 @@ public void convertJavaCollectionToSetOfPrimitives() assertTrue( longSet.contains( 1L ) ); assertTrue( longSet.contains( 4L ) ); assertTrue( longSet.contains( 7L ) ); - assertEquals( 3, longSet.size() ); + Assert.assertEquals( 3, longSet.size() ); } @Test @@ -235,7 +236,7 @@ private void assertNoMoreItems( LongIterator iterator ) private void assertNextEquals( long expected, LongIterator iterator ) { assertTrue( iterator + " should have had more items", iterator.hasNext() ); - assertEquals( expected, iterator.next() ); + Assert.assertEquals( expected, iterator.next() ); } private void assertItems( LongIterator iterator, long... expectedItems ) diff --git a/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/PrimitiveLongResourceCollectionsTest.java b/community/collections/src/test/java/org/neo4j/collection/primitive/PrimitiveLongResourceCollectionsTest.java similarity index 100% rename from community/primitive-collections/src/test/java/org/neo4j/collection/primitive/PrimitiveLongResourceCollectionsTest.java rename to community/collections/src/test/java/org/neo4j/collection/primitive/PrimitiveLongResourceCollectionsTest.java diff --git a/community/primitive-collections/src/main/java/org/neo4j/register/Register.java b/community/common/src/main/java/org/neo4j/register/Register.java similarity index 100% rename from community/primitive-collections/src/main/java/org/neo4j/register/Register.java rename to community/common/src/main/java/org/neo4j/register/Register.java diff --git a/community/primitive-collections/src/main/java/org/neo4j/register/Registers.java b/community/common/src/main/java/org/neo4j/register/Registers.java similarity index 100% rename from community/primitive-collections/src/main/java/org/neo4j/register/Registers.java rename to community/common/src/main/java/org/neo4j/register/Registers.java diff --git a/community/primitive-collections/pom.xml b/community/primitive-collections/pom.xml index 2338e76bc63a8..9b55fa15df0d5 100644 --- a/community/primitive-collections/pom.xml +++ b/community/primitive-collections/pom.xml @@ -64,10 +64,6 @@ the relevant Commercial Agreement. neo4j-resource ${project.version} - - org.eclipse.collections - eclipse-collections - junit diff --git a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveCollection.java b/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveCollection.java deleted file mode 100644 index 5897997c09ebf..0000000000000 --- a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveCollection.java +++ /dev/null @@ -1,35 +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.primitive; - -public interface PrimitiveCollection extends AutoCloseable -{ - boolean isEmpty(); - - void clear(); - - int size(); - - /** - * Free any attached resources. - */ - @Override - void close(); -} diff --git a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongCollection.java b/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongCollection.java deleted file mode 100644 index 94b8c106110e5..0000000000000 --- a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongCollection.java +++ /dev/null @@ -1,27 +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.primitive; - -import org.eclipse.collections.api.iterator.LongIterator; - -public interface PrimitiveLongCollection extends PrimitiveCollection -{ - LongIterator longIterator(); -} diff --git a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongLongVisitor.java b/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongLongVisitor.java deleted file mode 100644 index 4677ee7fc97c0..0000000000000 --- a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/PrimitiveLongLongVisitor.java +++ /dev/null @@ -1,34 +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.primitive; - -public interface PrimitiveLongLongVisitor -{ - /** - * Visit the given entry. - * - * @param key The key of the entry. - * @param value The value of the entry. - * @return 'true' to signal that the iteration should be stopped, 'false' to signal that the iteration should - * continue if there are more entries to look at. - * @throws E any thrown exception of type 'E' will bubble up through the 'visit' method. - */ - boolean visited( long key, long value ) throws E; -} diff --git a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/hopscotch/AbstractHopScotchCollection.java b/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/hopscotch/AbstractHopScotchCollection.java deleted file mode 100644 index ac67aacc2b6ca..0000000000000 --- a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/hopscotch/AbstractHopScotchCollection.java +++ /dev/null @@ -1,99 +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.primitive.hopscotch; - -import org.neo4j.collection.primitive.PrimitiveCollection; -import org.neo4j.collection.primitive.hopscotch.HopScotchHashingAlgorithm.ResizeMonitor; - -/** - * Typical design of a hop scotch collection holding a table and communicating with - * {@link HopScotchHashingAlgorithm} It's a {@link ResizeMonitor} which will have the {@link Table} - * reassigned when it grows. - */ -public abstract class AbstractHopScotchCollection implements PrimitiveCollection, ResizeMonitor -{ - protected Table table; - - public AbstractHopScotchCollection( Table table ) - { - this.table = table; - } - - @Override - public int size() - { - return table.size(); - } - - @Override - public boolean isEmpty() - { - return table.isEmpty(); - } - - @Override - public String toString() - { - return table.toString(); - } - - @Override - public void clear() - { - table.clear(); - } - - @Override - public void tableGrew( Table newTable ) - { - this.table = newTable; - } - - @Override - public Table getLastTable() - { - return table; - } - - @Override - public void close() - { - table.close(); - } - - @Override - public abstract boolean equals( Object other ); - - @Override - public abstract int hashCode(); - - protected final boolean typeAndSizeEqual( Object other ) - { - if ( this.getClass() == other.getClass() ) - { - AbstractHopScotchCollection that = (AbstractHopScotchCollection) other; - if ( this.size() == that.size() ) - { - return true; - } - } - return false; - } -} diff --git a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/hopscotch/AbstractLongHopScotchCollection.java b/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/hopscotch/AbstractLongHopScotchCollection.java deleted file mode 100644 index 93705f0ff84b2..0000000000000 --- a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/hopscotch/AbstractLongHopScotchCollection.java +++ /dev/null @@ -1,39 +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.primitive.hopscotch; - -import org.eclipse.collections.api.iterator.LongIterator; - -import org.neo4j.collection.primitive.PrimitiveLongCollection; - -public abstract class AbstractLongHopScotchCollection extends AbstractHopScotchCollection - implements PrimitiveLongCollection -{ - public AbstractLongHopScotchCollection( Table table ) - { - super( table ); - } - - @Override - public LongIterator longIterator() - { - return new TableKeyIterator<>( table, this ); - } -} diff --git a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/hopscotch/TableKeyIterator.java b/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/hopscotch/TableKeyIterator.java deleted file mode 100644 index 1d7471e3c95ce..0000000000000 --- a/community/primitive-collections/src/main/java/org/neo4j/collection/primitive/hopscotch/TableKeyIterator.java +++ /dev/null @@ -1,61 +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.primitive.hopscotch; - -import org.neo4j.collection.primitive.PrimitiveLongCollections.PrimitiveLongBaseIterator; - -public class TableKeyIterator extends PrimitiveLongBaseIterator -{ - protected final Table stable; - protected final AbstractHopScotchCollection collection; - protected final long nullKey; - protected final int version; - private final int max; - private int i; - - TableKeyIterator( Table table, AbstractHopScotchCollection collection ) - { - this.stable = table; - this.collection = collection; - this.nullKey = stable.nullKey(); - this.max = stable.capacity(); - this.version = stable.version(); - } - - protected boolean isVisible( int index, long key ) - { - return key != nullKey; - } - - @Override - protected boolean fetchNext() - { - while ( i < max ) - { - int index = i++; - long key = stable.key( index ); - if ( isVisible( index, key ) ) - { - return next( key ); - } - } - return false; - } -} diff --git a/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/hopscotch/ClosingTablesTest.java b/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/hopscotch/ClosingTablesTest.java deleted file mode 100644 index cbcfdd9647e1f..0000000000000 --- a/community/primitive-collections/src/test/java/org/neo4j/collection/primitive/hopscotch/ClosingTablesTest.java +++ /dev/null @@ -1,57 +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.primitive.hopscotch; - -import org.junit.Test; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -@SuppressWarnings( "unchecked" ) -public class ClosingTablesTest -{ - @Test - public void longCollectionsMustDelegateCloseToTable() - { - // Given - Table table = mock( Table.class ); - AbstractLongHopScotchCollection coll = - new AbstractLongHopScotchCollection( table ) - { - @Override - public boolean equals( Object other ) - { - return false; - } - - @Override - public int hashCode() - { - return 0; - } - }; - - // When - coll.close(); - - // Then - verify( table ).close(); - } -}