-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introducing parameter object for common request scoped things
- Loading branch information
1 parent
1f18c44
commit 909feda
Showing
6 changed files
with
180 additions
and
4 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
algo/src/main/java/org/neo4j/gds/algorithms/RequestScopedDependencies.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.gds.algorithms; | ||
|
||
import org.neo4j.gds.api.DatabaseId; | ||
import org.neo4j.gds.api.User; | ||
import org.neo4j.gds.termination.TerminationFlag; | ||
|
||
/** | ||
* This is a handy class for transporting similar dependencies through layers. | ||
* And especially useful when that list grows or shrinks - less sites to edit innit | ||
*/ | ||
public final class RequestScopedDependencies { | ||
private final DatabaseId databaseId; | ||
private final TerminationFlag terminationFlag; | ||
private final User user; | ||
|
||
/** | ||
* Over-doing it with a private constructor? | ||
* <p> | ||
* I just really like the <code>RequestScopedDependencies.builder().build()</code> form | ||
*/ | ||
private RequestScopedDependencies( | ||
DatabaseId databaseId, | ||
TerminationFlag terminationFlag, | ||
User user | ||
) { | ||
this.databaseId = databaseId; | ||
this.terminationFlag = terminationFlag; | ||
this.user = user; | ||
} | ||
|
||
public static RequestScopedDependenciesBuilder builder() { | ||
return new RequestScopedDependenciesBuilder(); | ||
} | ||
|
||
public DatabaseId getDatabaseId() { | ||
return databaseId; | ||
} | ||
|
||
public TerminationFlag getTerminationFlag() { | ||
return terminationFlag; | ||
} | ||
|
||
public User getUser() { | ||
return user; | ||
} | ||
|
||
public static class RequestScopedDependenciesBuilder { | ||
private DatabaseId databaseId = DatabaseId.DEFAULT; | ||
private User user = User.DEFAULT; | ||
private TerminationFlag terminationFlag = TerminationFlag.DEFAULT; | ||
|
||
public RequestScopedDependenciesBuilder with(DatabaseId databaseId) { | ||
this.databaseId = databaseId; | ||
return this; | ||
} | ||
|
||
public RequestScopedDependenciesBuilder with(TerminationFlag terminationFlag) { | ||
this.terminationFlag = terminationFlag; | ||
return this; | ||
} | ||
|
||
public RequestScopedDependenciesBuilder with(User user) { | ||
this.user = user; | ||
return this; | ||
} | ||
|
||
public RequestScopedDependencies build() { | ||
return new RequestScopedDependencies(databaseId, terminationFlag, user); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...rc/test/java/org/neo4j/gds/algorithms/someotherpackage/RequestScopedDependenciesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.gds.algorithms.someotherpackage; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.neo4j.gds.algorithms.RequestScopedDependencies; | ||
import org.neo4j.gds.api.DatabaseId; | ||
import org.neo4j.gds.api.User; | ||
import org.neo4j.gds.termination.TerminationFlag; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class RequestScopedDependenciesTest { | ||
@Test | ||
void shouldBeSafeAndConvenient() { | ||
var rsd = RequestScopedDependencies.builder().build(); | ||
|
||
assertThat(rsd.getDatabaseId()).isEqualTo(DatabaseId.DEFAULT); | ||
assertThat(rsd.getUser()).isEqualTo(User.DEFAULT); | ||
assertThat(rsd.getTerminationFlag()).isEqualTo(TerminationFlag.DEFAULT); | ||
} | ||
|
||
@Test | ||
void shouldBuildBespokeProducts() { | ||
var rsd = RequestScopedDependencies.builder() | ||
.with(DatabaseId.of("IMDB")) | ||
.with(TerminationFlag.STOP_RUNNING) | ||
.with(new User("Colin Needham", true)) | ||
.build(); | ||
|
||
assertThat(rsd.getDatabaseId()).isEqualTo(DatabaseId.of("IMDB")); | ||
assertThat(rsd.getTerminationFlag()).isEqualTo(TerminationFlag.STOP_RUNNING); | ||
assertThat(rsd.getUser()).isEqualTo(new User("Colin Needham", true)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters