Skip to content

Commit

Permalink
Remove getEnum-API.
Browse files Browse the repository at this point in the history
This removes the new API on the AnnotationInfo. This API was very well done and tested, but it increases our surface again and we don’t want that. It’s needed in two places and it’s ok to duplicate it the instantiation there.

There’s one signifacant change we’re we check whether the attribute is an enum or not.  For comparision: #644
  • Loading branch information
michael-simons committed Apr 6, 2020
1 parent 98dde71 commit 2a44a4f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 135 deletions.
22 changes: 3 additions & 19 deletions core/src/main/java/org/neo4j/ogm/metadata/AnnotationInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.apache.commons.lang3.StringUtils;
import org.neo4j.ogm.annotation.ValueFor;
import org.neo4j.ogm.support.ClassUtils;

/**
* @author Vince Bickers
Expand All @@ -41,7 +42,7 @@ private static String convert(Method element, Object value) {
return String.valueOf(value);
} else if (returnType.equals(Class.class)) {
return ((Class) value).getName();
} else if (Enum.class.isAssignableFrom(returnType)) {
} else if (ClassUtils.isEnum(returnType)) {
return ((Enum<?>) value).name();
} else {
final String result = value.toString();
Expand Down Expand Up @@ -105,27 +106,10 @@ public Annotation getAnnotation() {
}

public String get(String key, String defaultValue) {
elements.putIfAbsent(key, defaultValue);
return get(key);
return elements.computeIfAbsent(key, k -> defaultValue);
}

public String get(String key) {
return elements.get(key);
}

@SuppressWarnings("unchecked")
public <T extends Enum<T>> T getEnum(String key, T defaultValue) {
elements.putIfAbsent(key, defaultValue.name());
return (T) getEnum(defaultValue.getClass(), key);
}

public <T extends Enum<T>> T getEnum(Class<T> enumType, String key) {
String currentValue = elements.get(key);
if (currentValue == null) {
return null;
}

return T.valueOf(enumType, currentValue);
}

}
2 changes: 1 addition & 1 deletion core/src/main/java/org/neo4j/ogm/metadata/FieldInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public Direction relationshipDirectionOrDefault(Direction defaultDirection) {
if (annotationInfo == null) {
return defaultDirection;
}
return annotationInfo.getEnum(Relationship.DIRECTION, defaultDirection);
return Direction.valueOf(annotationInfo.get(Relationship.DIRECTION, defaultDirection.name()));
}
throw new RuntimeException("relationship direction call invalid");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.neo4j.ogm.metadata.schema;

import org.neo4j.ogm.annotation.Relationship.Direction;

/**
* Relationship in a {@link Schema}
*
Expand All @@ -35,7 +37,7 @@ public interface Relationship {
*
* @return direction
*/
org.neo4j.ogm.annotation.Relationship.Direction direction(Node node);
Direction direction(Node node);

/**
* Return start node of this relationship
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.neo4j.ogm.annotation.EndNode;
import org.neo4j.ogm.annotation.Property;
import org.neo4j.ogm.annotation.Relationship;
import org.neo4j.ogm.annotation.Relationship.*;
import org.neo4j.ogm.annotation.Relationship.Direction;
import org.neo4j.ogm.annotation.StartNode;
import org.neo4j.ogm.cypher.Filter;
import org.neo4j.ogm.cypher.FilterWithRelationship;
Expand Down Expand Up @@ -112,7 +112,9 @@ private void updateRelationship(FilterWithRelationship filter, FieldInfo fieldIn
AnnotationInfo annotation = fieldInfo.getAnnotations().get(Relationship.class);
if (annotation != null) {
filter.setRelationshipType(annotation.get(Relationship.TYPE, relationshipType));
filter.setRelationshipDirection(annotation.getEnum(Relationship.DIRECTION, Direction.UNDIRECTED));
Direction direction = Direction
.valueOf(annotation.get(Relationship.DIRECTION, Direction.UNDIRECTED.name()));
filter.setRelationshipDirection(direction);
}
if (fieldInfo.getAnnotations().get(StartNode.class) != null) {
filter.setRelationshipDirection(Direction.OUTGOING);
Expand Down
112 changes: 0 additions & 112 deletions core/src/test/java/org/neo4j/ogm/metadata/AnnotationInfoTest.java

This file was deleted.

0 comments on commit 2a44a4f

Please sign in to comment.