Skip to content

Commit

Permalink
Remove homegrown Mutable*
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Aug 31, 2016
1 parent 4a9be58 commit 461e6de
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 155 deletions.
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.consistency.checking.full;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.mutable.MutableInt;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
Expand Down Expand Up @@ -83,12 +84,12 @@
import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge;
import org.neo4j.kernel.impl.store.AbstractDynamicStore;
import org.neo4j.kernel.impl.store.NodeLabelsField;
import org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator;
import org.neo4j.kernel.impl.store.PropertyType;
import org.neo4j.kernel.impl.store.RecordStore;
import org.neo4j.kernel.impl.store.SchemaStorage;
import org.neo4j.kernel.impl.store.SchemaStore;
import org.neo4j.kernel.impl.store.StoreAccess;
import org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator;
import org.neo4j.kernel.impl.store.record.AbstractSchemaRule;
import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.IndexRule;
Expand All @@ -103,7 +104,6 @@
import org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord;
import org.neo4j.kernel.impl.store.record.UniquePropertyConstraintRule;
import org.neo4j.kernel.impl.util.Bits;
import org.neo4j.kernel.impl.util.MutableInteger;
import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.logging.FormattedLog;
import org.neo4j.storageengine.api.schema.SchemaRule;
Expand All @@ -123,7 +123,6 @@
import static org.neo4j.graphdb.Label.label;
import static org.neo4j.graphdb.RelationshipType.withName;
import static org.neo4j.helpers.collection.Iterables.asIterable;
import static org.neo4j.helpers.collection.Iterators.iterator;
import static org.neo4j.helpers.collection.MapUtil.stringMap;
import static org.neo4j.kernel.api.ReadOperations.ANY_LABEL;
import static org.neo4j.kernel.api.ReadOperations.ANY_RELATIONSHIP_TYPE;
Expand All @@ -134,13 +133,15 @@
import static org.neo4j.kernel.impl.store.DynamicNodeLabels.dynamicPointer;
import static org.neo4j.kernel.impl.store.LabelIdArray.prependNodeId;
import static org.neo4j.kernel.impl.store.PropertyType.ARRAY;
import static org.neo4j.kernel.impl.store.record.NodePropertyExistenceConstraintRule.nodePropertyExistenceConstraintRule;
import static org.neo4j.kernel.impl.store.record.NodePropertyExistenceConstraintRule
.nodePropertyExistenceConstraintRule;
import static org.neo4j.kernel.impl.store.record.Record.NO_LABELS_FIELD;
import static org.neo4j.kernel.impl.store.record.Record.NO_NEXT_PROPERTY;
import static org.neo4j.kernel.impl.store.record.Record.NO_NEXT_RELATIONSHIP;
import static org.neo4j.kernel.impl.store.record.Record.NO_PREV_RELATIONSHIP;
import static org.neo4j.kernel.impl.store.record.RecordLoad.FORCE;
import static org.neo4j.kernel.impl.store.record.RelationshipPropertyExistenceConstraintRule.relPropertyExistenceConstraintRule;
import static org.neo4j.kernel.impl.store.record.RelationshipPropertyExistenceConstraintRule
.relPropertyExistenceConstraintRule;
import static org.neo4j.kernel.impl.util.Bits.bits;
import static org.neo4j.test.Property.property;
import static org.neo4j.test.Property.set;
Expand Down Expand Up @@ -2055,7 +2056,7 @@ protected String getRecordFormatName()

private int createLabel() throws Exception
{
final MutableInteger id = new MutableInteger( -1 );
final MutableInt id = new MutableInt( -1 );

fixture.apply( new GraphStoreFixture.Transaction()
{
Expand All @@ -2065,16 +2066,16 @@ protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx,
{
int labelId = next.label();
tx.nodeLabel( labelId, "label" );
id.value = labelId;
id.setValue( labelId );
}
} );

return id.value;
return id.intValue();
}

private int createPropertyKey() throws Exception
{
final MutableInteger id = new MutableInteger( -1 );
final MutableInt id = new MutableInt( -1 );

fixture.apply( new GraphStoreFixture.Transaction()
{
Expand All @@ -2084,16 +2085,16 @@ protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx,
{
int propertyKeyId = next.propertyKey();
tx.propertyKey( propertyKeyId, "property" );
id.value = propertyKeyId;
id.setValue( propertyKeyId );
}
} );

return id.value;
return id.intValue();
}

private int createRelType() throws Exception
{
final MutableInteger id = new MutableInteger( -1 );
final MutableInt id = new MutableInt( -1 );

fixture.apply( new GraphStoreFixture.Transaction()
{
Expand All @@ -2103,11 +2104,11 @@ protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx,
{
int relTypeId = next.relationshipType();
tx.relationshipType( relTypeId, "relType" );
id.value = relTypeId;
id.setValue( relTypeId );
}
} );

return id.value;
return id.intValue();
}

private void createIndexRule( final int labelId, final int propertyKeyId ) throws Exception
Expand Down
Expand Up @@ -19,6 +19,8 @@
*/
package org.neo4j.graphalgo.impl.path;

import org.apache.commons.lang3.mutable.MutableDouble;

import java.util.Collections;
import java.util.Iterator;

Expand All @@ -42,7 +44,6 @@
import org.neo4j.graphdb.traversal.Traverser;
import org.neo4j.graphdb.traversal.Uniqueness;
import org.neo4j.kernel.impl.traversal.MonoDirectionalTraversalDescription;
import org.neo4j.kernel.impl.util.MutableDouble;
import org.neo4j.kernel.impl.util.NoneStrictMath;

import static org.neo4j.graphalgo.impl.util.PathInterestFactory.single;
Expand Down Expand Up @@ -185,7 +186,8 @@ private Traverser traverser( Node start, final Node end, PathInterest<Double> in
}
else
{
MutableDouble shortestSoFar = new MutableDouble( Double.MAX_VALUE );
org.apache.commons.lang3.mutable.MutableDouble
shortestSoFar = new org.apache.commons.lang3.mutable.MutableDouble( Double.MAX_VALUE );
dijkstraExpander = new DijkstraPathExpander( expander, shortestSoFar, epsilon,
interest.stopAfterLowestCost() );
dijkstraEvaluator = new DijkstraEvaluator( shortestSoFar, end, costEvaluator );
Expand Down Expand Up @@ -218,7 +220,7 @@ private static class DijkstraPathExpander implements PathExpander<Double>
protected final boolean stopAfterLowestCost;

DijkstraPathExpander( final PathExpander source,
MutableDouble shortestSoFar, double epsilon, boolean stopAfterLowestCost )
org.apache.commons.lang3.mutable.MutableDouble shortestSoFar, double epsilon, boolean stopAfterLowestCost )
{
this.source = source;
this.shortestSoFar = shortestSoFar;
Expand All @@ -229,7 +231,7 @@ private static class DijkstraPathExpander implements PathExpander<Double>
@Override
public Iterable<Relationship> expand( Path path, BranchState<Double> state )
{
if ( NoneStrictMath.compare( state.getState(), shortestSoFar.value, epsilon ) > 0 && stopAfterLowestCost )
if ( NoneStrictMath.compare( state.getState(), shortestSoFar.doubleValue(), epsilon ) > 0 && stopAfterLowestCost )
{
return Collections.emptyList();
}
Expand Down Expand Up @@ -266,7 +268,7 @@ public Evaluation evaluate( Path path, BranchState<Double> state )
}
if ( path.endNode().equals( endNode ) )
{
shortestSoFar.value = Math.min( shortestSoFar.value, nextState );
shortestSoFar.setValue( Math.min( shortestSoFar.doubleValue(), nextState ) );
return Evaluation.INCLUDE_AND_PRUNE;
}
return Evaluation.EXCLUDE_AND_CONTINUE;
Expand Down
Expand Up @@ -19,6 +19,8 @@
*/
package org.neo4j.graphalgo.impl.path;

import org.apache.commons.lang3.mutable.MutableDouble;

import java.util.Collections;
import java.util.function.Predicate;

Expand Down Expand Up @@ -48,7 +50,6 @@
import org.neo4j.graphdb.traversal.TraversalMetadata;
import org.neo4j.graphdb.traversal.Traverser;
import org.neo4j.graphdb.traversal.Uniqueness;
import org.neo4j.kernel.impl.util.MutableDouble;
import org.neo4j.kernel.impl.util.NoneStrictMath;

import static org.neo4j.graphdb.Direction.OUTGOING;
Expand Down Expand Up @@ -108,7 +109,8 @@ public Iterable<WeightedPath> findAllPaths( Node start, final Node end )
private Traverser traverser( Node start, final Node end, PathInterest interest )
{
final MutableDouble shortestSoFar = new MutableDouble( Double.MAX_VALUE );
final MutableDouble startSideShortest = new MutableDouble( 0 );
final org.apache.commons.lang3.mutable.MutableDouble
startSideShortest = new org.apache.commons.lang3.mutable.MutableDouble( 0 );
final MutableDouble endSideShortest = new MutableDouble( 0 );
PathExpander dijkstraExpander = new DijkstraBidirectionalPathExpander( expander, shortestSoFar, true,
startSideShortest, endSideShortest, epsilon);
Expand Down Expand Up @@ -164,7 +166,7 @@ private static class DijkstraBidirectionalPathExpander implements PathExpander<D
private final boolean stopAfterLowestCost;

DijkstraBidirectionalPathExpander( PathExpander source, MutableDouble shortestSoFar,
boolean stopAfterLowestCost, MutableDouble thisSideShortest, MutableDouble otherSideShortest,
boolean stopAfterLowestCost, org.apache.commons.lang3.mutable.MutableDouble thisSideShortest, MutableDouble otherSideShortest,
double epsilon )
{
this.source = source;
Expand All @@ -179,8 +181,8 @@ private static class DijkstraBidirectionalPathExpander implements PathExpander<D
public Iterable<Relationship> expand( Path path, BranchState<Double> state )
{
double thisState = state.getState();
thisSideShortest.value = thisState;
if ( NoneStrictMath.compare( thisState + otherSideShortest.value, shortestSoFar.value, epsilon ) > 0 &&
thisSideShortest.setValue( thisState );
if ( NoneStrictMath.compare( thisState + otherSideShortest.doubleValue(), shortestSoFar.doubleValue(), epsilon ) > 0 &&
stopAfterLowestCost )
{
return Collections.emptyList();
Expand Down

0 comments on commit 461e6de

Please sign in to comment.