From c0e1e397129c5f5a99c3a05a363eeba8482f792c Mon Sep 17 00:00:00 2001 From: lutovich Date: Wed, 16 Dec 2015 00:17:23 +0100 Subject: [PATCH] Removed org.neo4j.test.AlgebraicFunction All usages changed to java.util.function.Function. --- .../org/neo4j/test/AlgebraicFunction.java | 77 ---------------- .../org/neo4j/test/DatabaseFunctions.java | 88 ++++++------------- .../java/org/neo4j/test/DatabaseRule.java | 21 +---- .../impl/index/UniqueIndexApplicationIT.java | 22 ++--- 4 files changed, 42 insertions(+), 166 deletions(-) delete mode 100644 community/kernel/src/test/java/org/neo4j/test/AlgebraicFunction.java diff --git a/community/kernel/src/test/java/org/neo4j/test/AlgebraicFunction.java b/community/kernel/src/test/java/org/neo4j/test/AlgebraicFunction.java deleted file mode 100644 index 9c7ce136314f9..0000000000000 --- a/community/kernel/src/test/java/org/neo4j/test/AlgebraicFunction.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2002-2015 "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.test; - -import java.util.function.Function; - -public abstract class AlgebraicFunction implements Function -{ - public AlgebraicFunction then( final Function function ) - { - return new AlgebraicFunction( repr + " then " + function.toString() ) - { - @Override - public NEXT apply( FROM from ) - { - return function.apply( AlgebraicFunction.this.apply( from ) ); - } - }; - } - - public AlgebraicFunction() - { - String repr = getClass().getSimpleName(); - if ( getClass().isAnonymousClass() ) - { - for ( StackTraceElement trace : Thread.currentThread().getStackTrace() ) - { - if ( trace.getClassName().equals( Thread.class.getName() ) && - trace.getMethodName().equals( "getStackTrace" ) ) - { - continue; - } - if ( trace.getClassName().equals( AlgebraicFunction.class.getName() ) ) - { - continue; - } - if ( trace.getClassName().equals( getClass().getName() ) ) - { - continue; - } - repr = trace.getMethodName(); - break; - } - } - this.repr = repr; - } - - private final String repr; - - private AlgebraicFunction( String repr ) - { - this.repr = repr; - } - - @Override - public String toString() - { - return repr; - } -} diff --git a/community/kernel/src/test/java/org/neo4j/test/DatabaseFunctions.java b/community/kernel/src/test/java/org/neo4j/test/DatabaseFunctions.java index 02b7990989308..cdf7c7f67338f 100644 --- a/community/kernel/src/test/java/org/neo4j/test/DatabaseFunctions.java +++ b/community/kernel/src/test/java/org/neo4j/test/DatabaseFunctions.java @@ -20,95 +20,61 @@ package org.neo4j.test; import java.util.concurrent.TimeUnit; +import java.util.function.Function; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Label; import org.neo4j.graphdb.Node; -public class DatabaseFunctions +public final class DatabaseFunctions { - public static AlgebraicFunction createNode() + private DatabaseFunctions() { - return new AlgebraicFunction() - { - @Override - public Node apply( GraphDatabaseService graphDb ) - { - return graphDb.createNode(); - } - }; + throw new AssertionError( "Not for instantiation!" ); } - public static AlgebraicFunction addLabel( final Label label ) + public static Function createNode() { - return new AlgebraicFunction() - { - @Override - public Node apply( Node node ) - { - node.addLabel( label ); - return node; - } - }; + return GraphDatabaseService::createNode; } - public static AlgebraicFunction setProperty( final String propertyKey, final Object value ) + public static Function addLabel( Label label ) { - return new AlgebraicFunction() - { - @Override - public Node apply( Node node ) - { - node.setProperty( propertyKey, value ); - return node; - } + return node -> { + node.addLabel( label ); + return node; }; } - public static AlgebraicFunction index( - final Label label, final String propertyKey ) + public static Function setProperty( String propertyKey, Object value ) { - return new AlgebraicFunction() - { - @Override - public Void apply( GraphDatabaseService graphDb ) - { - graphDb.schema().indexFor( label ).on( propertyKey ).create(); - return null; - } + return node -> { + node.setProperty( propertyKey, value ); + return node; }; } - public static AlgebraicFunction uniquenessConstraint( - final Label label, final String propertyKey ) + public static Function index( Label label, String propertyKey ) { - return new AlgebraicFunction() - { - @Override - public Void apply( GraphDatabaseService graphDb ) - { - graphDb.schema().constraintFor( label ).assertPropertyIsUnique( propertyKey ).create(); - return null; - } + return graphDb -> { + graphDb.schema().indexFor( label ).on( propertyKey ).create(); + return null; }; } - public static AlgebraicFunction awaitIndexesOnline( - final long timeout, final TimeUnit unit ) + public static Function uniquenessConstraint( Label label, String propertyKey ) { - return new AlgebraicFunction() - { - @Override - public Void apply( GraphDatabaseService graphDb ) - { - graphDb.schema().awaitIndexesOnline( timeout, unit ); - return null; - } + return graphDb -> { + graphDb.schema().constraintFor( label ).assertPropertyIsUnique( propertyKey ).create(); + return null; }; } - private DatabaseFunctions() + public static Function awaitIndexesOnline( long timeout, TimeUnit unit ) { - // no instances + return graphDb -> { + graphDb.schema().awaitIndexesOnline( timeout, unit ); + return null; + }; } } diff --git a/community/kernel/src/test/java/org/neo4j/test/DatabaseRule.java b/community/kernel/src/test/java/org/neo4j/test/DatabaseRule.java index 07cee83a6c062..ce7cddae58678 100644 --- a/community/kernel/src/test/java/org/neo4j/test/DatabaseRule.java +++ b/community/kernel/src/test/java/org/neo4j/test/DatabaseRule.java @@ -95,24 +95,11 @@ public T executeAndRollback( Function funct return transaction( function, false ); } - public AlgebraicFunction tx( final Function function ) + public Function tx( Function function ) { - return new AlgebraicFunction() - { - @Override - public TO apply( final FROM from ) - { - return executeAndCommit( graphDb -> { - return function.apply( from ); - } ); - } - - @Override - public String toString() - { - return "tx( " + function + " )"; - } - }; + return from -> executeAndCommit( graphDb -> { + return function.apply( from ); + } ); } private T transaction( Function function, boolean commit ) diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/UniqueIndexApplicationIT.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/UniqueIndexApplicationIT.java index 6898daef758d7..8977fe3d13f89 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/UniqueIndexApplicationIT.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/UniqueIndexApplicationIT.java @@ -86,7 +86,7 @@ public void given() throws Exception public void tx_createNode_addLabel_setProperty() throws Exception { db.when( db.tx( - createNode().then( addLabel( label( "Label1" ) ).then( setProperty( "key1", "value1" ) ) ) + createNode().andThen( addLabel( label( "Label1" ) ).andThen( setProperty( "key1", "value1" ) ) ) ) ); } @@ -95,8 +95,8 @@ public void tx_createNode_tx_addLabel_setProperty() throws Exception { db.when( db.tx( createNode() - ).then( db.tx( - addLabel( label( "Label1" ) ).then( setProperty( "key1", "value1" ) ) + ).andThen( db.tx( + addLabel( label( "Label1" ) ).andThen( setProperty( "key1", "value1" ) ) ) ) ); } @@ -104,8 +104,8 @@ public void tx_createNode_tx_addLabel_setProperty() throws Exception public void tx_createNode_addLabel_tx_setProperty() throws Exception { db.when( db.tx( - createNode().then( addLabel( label( "Label1" ) ) ) - ).then( db.tx( + createNode().andThen( addLabel( label( "Label1" ) ) ) + ).andThen( db.tx( setProperty( "key1", "value1" ) ) ) ); } @@ -114,8 +114,8 @@ public void tx_createNode_addLabel_tx_setProperty() throws Exception public void tx_createNode_setProperty_tx_addLabel() throws Exception { db.when( db.tx( - createNode().then( setProperty( "key1", "value1" ) ) - ).then( db.tx( + createNode().andThen( setProperty( "key1", "value1" ) ) + ).andThen( db.tx( addLabel( label( "Label1" ) ) ) ) ); } @@ -125,9 +125,9 @@ public void tx_createNode_tx_addLabel_tx_setProperty() throws Exception { db.when( db.tx( createNode() - ).then( db.tx( + ).andThen( db.tx( addLabel( label( "Label1" ) ) - ).then( db.tx( + ).andThen( db.tx( setProperty( "key1", "value1" ) ) ) ) ); } @@ -137,9 +137,9 @@ public void tx_createNode_tx_setProperty_tx_addLabel() throws Exception { db.when( db.tx( createNode() - ).then( db.tx( + ).andThen( db.tx( setProperty( "key1", "value1" ) - ).then( db.tx( + ).andThen( db.tx( addLabel( label( "Label1" ) ) ) ) ) ); }