Skip to content

Commit cb44963

Browse files
FlorentinDs1ck
authored andcommitted
Replace DataClass in NodeProjection
This also avoids accessing static base class members via derived types.
1 parent 499f54f commit cb44963

File tree

10 files changed

+23
-23
lines changed

10 files changed

+23
-23
lines changed

etc/spotbugs/spotbugs-exclude.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@
697697
<Or>
698698
<Class name="org.neo4j.gds.core.utils.progress.EmptyTaskStore" />
699699
<Class name="org.neo4j.gds.core.utils.warnings.EmptyUserLogStore" />
700-
<Class name="org.neo4j.gds.AbstractNodeProjection" />
700+
<Class name="org.neo4j.gds.NodeProjection" />
701701
</Or>
702702
<Bug code="MS" />
703703
</Match>

graph-projection-api/src/main/java/org/neo4j/gds/AbstractNodeProjection.java renamed to graph-projection-api/src/main/java/org/neo4j/gds/NodeProjection.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@
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.core.ConfigKeyValidation;
2626
import org.neo4j.gds.utils.StringFormatting;
2727

2828
import java.util.List;
2929
import java.util.Map;
3030
import java.util.TreeMap;
3131

32-
@DataClass
33-
public abstract class AbstractNodeProjection extends ElementProjection {
32+
@ValueClass
33+
public abstract class NodeProjection extends ElementProjection {
3434

35-
private static final NodeProjection ALL = of(PROJECT_ALL);
35+
private static final NodeProjection ALL = fromString(PROJECT_ALL);
3636

3737
public abstract String label();
3838

@@ -50,7 +50,7 @@ public boolean projectAll() {
5050
public static final String LABEL_KEY = "label";
5151

5252
public static NodeProjection of(String label) {
53-
return NodeProjection.of(label, PropertyMappings.of());
53+
return ImmutableNodeProjection.of(label, PropertyMappings.of());
5454
}
5555

5656
public static NodeProjection all() {
@@ -85,7 +85,7 @@ public static NodeProjection fromString(@Nullable String label) {
8585
public static NodeProjection fromMap(Map<String, Object> map, NodeLabel nodeLabel) {
8686
validateConfigKeys(map);
8787
String label = String.valueOf(map.getOrDefault(LABEL_KEY, nodeLabel.name));
88-
return create(map, properties -> NodeProjection.of(label, properties));
88+
return create(map, properties -> ImmutableNodeProjection.of(label, properties));
8989
}
9090

9191
@Override
@@ -102,9 +102,9 @@ void writeToObject(Map<String, Object> value) {
102102
public NodeProjection withAdditionalPropertyMappings(PropertyMappings mappings) {
103103
PropertyMappings newMappings = properties().mergeWith(mappings);
104104
if (newMappings == properties()) {
105-
return (NodeProjection) this;
105+
return this;
106106
}
107-
return ((NodeProjection) this).withProperties(newMappings);
107+
return ((ImmutableNodeProjection) this).withProperties(newMappings);
108108
}
109109

110110
public static Builder builder() {
@@ -116,7 +116,7 @@ private static void validateConfigKeys(Map<String, Object> map) {
116116
}
117117

118118
@org.immutables.builder.Builder.AccessibleFields
119-
public static final class Builder extends NodeProjection.Builder implements InlineProperties<Builder> {
119+
public static final class Builder extends ImmutableNodeProjection.Builder implements InlineProperties<Builder> {
120120

121121
private InlinePropertiesBuilder propertiesBuilder;
122122

graph-projection-api/src/test/java/org/neo4j/gds/NodeProjectionsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
import static org.hamcrest.MatcherAssert.assertThat;
4040
import static org.hamcrest.text.MatchesPattern.matchesPattern;
4141
import static org.junit.jupiter.api.Assertions.assertThrows;
42-
import static org.neo4j.gds.AbstractNodeProjection.LABEL_KEY;
4342
import static org.neo4j.gds.ElementProjection.PROPERTIES_KEY;
4443
import static org.neo4j.gds.NodeLabel.ALL_NODES;
44+
import static org.neo4j.gds.NodeProjection.LABEL_KEY;
4545

4646
class NodeProjectionsTest {
4747

proc/catalog/src/test/java/org/neo4j/gds/catalog/GraphProjectProcTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@
8282
import static org.junit.jupiter.api.Assertions.assertEquals;
8383
import static org.junit.jupiter.api.Assertions.assertFalse;
8484
import static org.junit.jupiter.api.Assertions.assertTrue;
85-
import static org.neo4j.gds.AbstractNodeProjection.LABEL_KEY;
8685
import static org.neo4j.gds.ElementProjection.PROPERTIES_KEY;
86+
import static org.neo4j.gds.NodeProjection.LABEL_KEY;
8787
import static org.neo4j.gds.RelationshipProjection.AGGREGATION_KEY;
8888
import static org.neo4j.gds.RelationshipProjection.INDEX_INVERSE_KEY;
8989
import static org.neo4j.gds.RelationshipProjection.ORIENTATION_KEY;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ default void testRunOnEmptyGraph() {
323323
loadedGraphName,
324324
NodeProjections.of(
325325
Map.of(
326-
NodeLabel.of("X"), NodeProjection.of("X", PropertyMappings.of(propertyMappings))
326+
NodeLabel.of("X"), ImmutableNodeProjection.of("X", PropertyMappings.of(propertyMappings))
327327
)
328328
),
329329
relationshipProjections()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ default void testSeedPropertyValidation() {
8585
GraphProjectFromStoreConfig graphProjectConfig = ImmutableGraphProjectFromStoreConfig.of(
8686
"",
8787
graphName,
88-
NodeProjections.single(NodeLabel.of("A"), NodeProjection.of("A", PropertyMappings.of(nodeProperties))),
88+
NodeProjections.single(NodeLabel.of("A"), ImmutableNodeProjection.of("A", PropertyMappings.of(nodeProperties))),
8989
allRelationshipsProjection()
9090
);
9191

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ default GraphProjectFromStoreConfig withNameAndRelationshipProjections(
6060
graphName,
6161
AbstractNodeProjections.create(singletonMap(
6262
ALL_NODES,
63-
NodeProjection.of(PROJECT_ALL, PropertyMappings.of(propertyMappings))
63+
ImmutableNodeProjection.of(PROJECT_ALL, PropertyMappings.of(propertyMappings))
6464
)),
6565
rels
6666
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ default void testWriteBackGraphMutationOnFilteredGraph() {
6060
StoreLoaderBuilder storeLoaderBuilder = new StoreLoaderBuilder()
6161
.databaseService(graphDb())
6262
.graphName(graphName)
63-
.addNodeProjection(NodeProjection.of(
63+
.addNodeProjection(ImmutableNodeProjection.of(
6464
"A",
6565
PropertyMappings.of(nodeProperties().stream().map(PropertyMapping::of).collect(Collectors.toList()))
6666
))
67-
.addNodeProjection(NodeProjection.of(
67+
.addNodeProjection(ImmutableNodeProjection.of(
6868
"B",
6969
PropertyMappings.of(nodeProperties().stream().map(PropertyMapping::of).collect(Collectors.toList()))
7070
));

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,8 @@ private static MinimalObject toMinimalObject(
817817
ElementProjection projection,
818818
ElementIdentifier identifier
819819
) {
820-
if (projection instanceof AbstractNodeProjection) {
821-
return toMinimalObject(((AbstractNodeProjection) projection), identifier);
820+
if (projection instanceof NodeProjection) {
821+
return toMinimalObject(((NodeProjection) projection), identifier);
822822
}
823823
if (projection instanceof RelationshipProjection) {
824824
return toMinimalObject(((RelationshipProjection) projection), identifier);
@@ -827,7 +827,7 @@ private static MinimalObject toMinimalObject(
827827
}
828828

829829
private static MinimalObject toMinimalObject(
830-
AbstractNodeProjection projection,
830+
NodeProjection projection,
831831
ElementIdentifier identifier
832832
) {
833833
MinimalObject properties = toMinimalObject(projection.properties(), false);
@@ -836,12 +836,12 @@ private static MinimalObject toMinimalObject(
836836
}
837837

838838
Map<String, Object> value = new LinkedHashMap<>();
839-
value.put(AbstractNodeProjection.LABEL_KEY, projection.label());
839+
value.put(NodeProjection.LABEL_KEY, projection.label());
840840
properties.toObject().ifPresent(o -> value.put(PROPERTIES_KEY, o));
841841
return MinimalObject.map(value);
842842
}
843843

844-
private static boolean matchesLabel(String label, AbstractNodeProjection projection) {
844+
private static boolean matchesLabel(String label, NodeProjection projection) {
845845
return Objects.equals(projection.label(), label);
846846
}
847847

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static GraphProjectFromStoreConfig storeConfig(
7070
) {
7171
// Node projections
7272
Map<String, NodeProjection> tempNP = new LinkedHashMap<>();
73-
nodeLabels.forEach(label -> tempNP.put(label, NodeProjection.of(label, PropertyMappings.of())));
73+
nodeLabels.forEach(label -> tempNP.put(label, NodeProjection.of(label)));
7474
nodeProjections.forEach(np -> tempNP.put(np.label(), np));
7575
nodeProjectionsWithIdentifier.forEach(tempNP::put);
7676

0 commit comments

Comments
 (0)