Skip to content

Commit 0753a40

Browse files
FlorentinDs1ck
authored andcommitted
Replace DataClass in NodeProjections
This also avoids accessing static base class members via derived types. Also makes the code more aligned to other immutable classes in our code base.
1 parent cb44963 commit 0753a40

File tree

6 files changed

+16
-15
lines changed

6 files changed

+16
-15
lines changed

core/src/main/java/org/neo4j/gds/config/GraphProjectFromStoreConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public interface GraphProjectFromStoreConfig extends GraphProjectConfig {
5252
String RELATIONSHIP_PROPERTIES_KEY = "relationshipProperties";
5353

5454
@Key(NODE_PROJECTION_KEY)
55-
@ConvertWith(method = "org.neo4j.gds.AbstractNodeProjections#fromObject")
56-
@Configuration.ToMapValue("org.neo4j.gds.AbstractNodeProjections#toObject")
55+
@ConvertWith(method = "org.neo4j.gds.NodeProjections#fromObject")
56+
@Configuration.ToMapValue("org.neo4j.gds.NodeProjections#toObject")
5757
NodeProjections nodeProjections();
5858

5959
@Key(RELATIONSHIP_PROJECTION_KEY)

core/src/main/java/org/neo4j/gds/config/RandomGraphGeneratorConfig.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.immutables.value.Value;
2323
import org.jetbrains.annotations.Nullable;
24+
import org.neo4j.gds.ImmutableNodeProjections;
2425
import org.neo4j.gds.ImmutableRelationshipProjections;
2526
import org.neo4j.gds.NodeLabel;
2627
import org.neo4j.gds.NodeProjection;
@@ -97,9 +98,9 @@ default Map<String, Object> relationshipProperty() {
9798
}
9899

99100
@Value.Default
100-
@Configuration.ToMapValue("org.neo4j.gds.AbstractNodeProjections#toObject")
101+
@Configuration.ToMapValue("org.neo4j.gds.NodeProjections#toObject")
101102
default NodeProjections nodeProjections() {
102-
return NodeProjections.builder()
103+
return ImmutableNodeProjections.builder()
103104
.putProjection(
104105
NodeLabel.of(nodeCount() + "_Nodes"),
105106
NodeProjection.of(nodeCount() + "_Nodes"))

graph-projection-api/src/main/java/org/neo4j/gds/AbstractNodeProjections.java renamed to graph-projection-api/src/main/java/org/neo4j/gds/NodeProjections.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import org.immutables.value.Value;
2323
import org.jetbrains.annotations.Nullable;
24-
import org.neo4j.gds.annotation.DataClass;
24+
import org.neo4j.gds.annotation.ValueClass;
2525
import org.neo4j.gds.utils.StringFormatting;
2626

2727
import java.util.HashMap;
@@ -37,9 +37,9 @@
3737
import static org.neo4j.gds.NodeLabel.ALL_NODES;
3838
import static org.neo4j.gds.utils.StringFormatting.formatWithLocale;
3939

40-
@DataClass
40+
@ValueClass
4141
@Value.Immutable(singleton = true)
42-
public abstract class AbstractNodeProjections extends AbstractProjections<NodeLabel, NodeProjection> {
42+
public abstract class NodeProjections extends AbstractProjections<NodeLabel, NodeProjection> {
4343

4444
public static final NodeProjections ALL = create(singletonMap(ALL_NODES, NodeProjection.all()));
4545

@@ -112,11 +112,11 @@ public static NodeProjections create(Map<NodeLabel, NodeProjection> projections)
112112
"An empty node projection was given; at least one node label must be projected."
113113
);
114114
}
115-
return NodeProjections.of(unmodifiableMap(projections));
115+
return ImmutableNodeProjections.of(unmodifiableMap(projections));
116116
}
117117

118118
public static NodeProjections single(NodeLabel label, NodeProjection projection) {
119-
return NodeProjections.of(Map.of(label, projection));
119+
return ImmutableNodeProjections.of(Map.of(label, projection));
120120
}
121121

122122
public static NodeProjections all() {
@@ -125,7 +125,7 @@ public static NodeProjections all() {
125125

126126
public NodeProjections addPropertyMappings(PropertyMappings mappings) {
127127
if (!mappings.hasMappings()) {
128-
return NodeProjections.copyOf(this);
128+
return ImmutableNodeProjections.copyOf(this);
129129
}
130130
Map<NodeLabel, NodeProjection> newProjections = projections().entrySet().stream().collect(toMap(
131131
Map.Entry::getKey,
@@ -150,7 +150,7 @@ public String labelProjection() {
150150
}
151151

152152
public boolean isEmpty() {
153-
return this == NodeProjections.of();
153+
return this == ImmutableNodeProjections.of();
154154
}
155155

156156
public Map<String, Object> toObject() {
@@ -161,7 +161,7 @@ public Map<String, Object> toObject() {
161161
return value;
162162
}
163163

164-
public static Map<String, Object> toObject(AbstractNodeProjections nodeProjections) {
164+
public static Map<String, Object> toObject(NodeProjections nodeProjections) {
165165
return nodeProjections.toObject();
166166
}
167167

proc/test/src/main/java/org/neo4j/gds/AlgoBaseProcTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ default void testRunOnEmptyGraph() {
321321
GraphProjectConfig graphProjectConfig = withNameAndProjections(
322322
"",
323323
loadedGraphName,
324-
NodeProjections.of(
324+
ImmutableNodeProjections.of(
325325
Map.of(
326326
NodeLabel.of("X"), ImmutableNodeProjection.of("X", PropertyMappings.of(propertyMappings))
327327
)

proc/test/src/main/java/org/neo4j/gds/GraphProjectConfigSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ default GraphProjectFromStoreConfig withNameAndRelationshipProjections(
5858
return ImmutableGraphProjectFromStoreConfig.of(
5959
userName,
6060
graphName,
61-
AbstractNodeProjections.create(singletonMap(
61+
NodeProjections.create(singletonMap(
6262
ALL_NODES,
6363
ImmutableNodeProjection.of(PROJECT_ALL, PropertyMappings.of(propertyMappings))
6464
)),

test-utils/src/main/java/org/neo4j/gds/GraphProjectConfigBuilders.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public static GraphProjectFromStoreConfig storeConfig(
111111
.withDefaultAggregation(aggregation)
112112
.build();
113113

114-
NodeProjections np = NodeProjections.of(tempNP.entrySet().stream().collect(Collectors.toMap(
114+
NodeProjections np = ImmutableNodeProjections.of(tempNP.entrySet().stream().collect(Collectors.toMap(
115115
e -> NodeLabel.of(e.getKey()),
116116
Map.Entry::getValue
117117
)));

0 commit comments

Comments
 (0)