Skip to content
This repository has been archived by the owner on Jan 8, 2019. It is now read-only.

Commit

Permalink
Move transaction check to superclass
Browse files Browse the repository at this point in the history
  • Loading branch information
maltemoeser committed Mar 2, 2016
1 parent a66d710 commit 273d509
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* An evaluator rule that stops once the path's end node exceeds a certain block height.
*/
public class MaximumHeightEvaluator implements Evaluator {
public class MaximumHeightEvaluator extends TransactionEvaluator implements Evaluator {

protected int height;

Expand All @@ -17,13 +17,7 @@ public MaximumHeightEvaluator(int height) {
}

@Override
public Evaluation evaluate(Path path) {
BCTransaction transaction = new BCTransaction(path.endNode());

if (!transaction.isTransaction()) {
throw new UnsupportedOperationException("MaximumHeightEvaluator can only be used on transaction nodes.");
}

public Evaluation doEvaluate(Path path) {
if (transaction.getHeight() > height) {
return Evaluation.EXCLUDE_AND_PRUNE;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package de.maltemoeser.bcgraph.traversal.evaluator;

import de.maltemoeser.bcgraph.entities.BCTransaction;
import org.neo4j.graphdb.Path;
import org.neo4j.graphdb.traversal.Evaluation;
import org.neo4j.graphdb.traversal.Evaluator;

/**
* An evaluator rule that stops once the path's end node falls below a certain block height.
*/
public class MinimumHeightEvaluator implements Evaluator {
public class MinimumHeightEvaluator extends TransactionEvaluator implements Evaluator {

protected int height;

Expand All @@ -17,13 +16,7 @@ public MinimumHeightEvaluator(int height) {
}

@Override
public Evaluation evaluate(Path path) {
BCTransaction transaction = new BCTransaction(path.endNode());

if (!transaction.isTransaction()) {
throw new UnsupportedOperationException("MinimumHeightEvaluator can only be used on transaction nodes.");
}

public Evaluation doEvaluate(Path path) {
if (transaction.getHeight() < height) {
return Evaluation.EXCLUDE_AND_PRUNE;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package de.maltemoeser.bcgraph.traversal.evaluator;

import de.maltemoeser.bcgraph.entities.BCTransaction;
import org.neo4j.graphdb.Path;
import org.neo4j.graphdb.traversal.Evaluation;


public abstract class TransactionEvaluator {

BCTransaction transaction;

public Evaluation evaluate(Path path) {
transaction = new BCTransaction(path.endNode());

if (!transaction.isTransaction()) {
throw new UnsupportedOperationException("A TransactionEvaluator can only be used with transaction nodes.");
}

return doEvaluate(path);
}

public abstract Evaluation doEvaluate(Path path);
}

0 comments on commit 273d509

Please sign in to comment.