|
66 | 66 | import org.neo4j.values.AnyValue; |
67 | 67 | import org.neo4j.values.SequenceValue; |
68 | 68 | import org.neo4j.values.storable.BooleanValue; |
| 69 | +import org.neo4j.values.storable.ByteValue; |
| 70 | +import org.neo4j.values.storable.IntValue; |
69 | 71 | import org.neo4j.values.storable.IntegralValue; |
| 72 | +import org.neo4j.values.storable.LongValue; |
70 | 73 | import org.neo4j.values.storable.NoValue; |
| 74 | +import org.neo4j.values.storable.ShortValue; |
71 | 75 | import org.neo4j.values.storable.StringArray; |
72 | 76 | import org.neo4j.values.storable.StringValue; |
73 | 77 | import org.neo4j.values.storable.TextArray; |
@@ -711,18 +715,7 @@ private static RelationshipType typeConfig( |
711 | 715 | } |
712 | 716 |
|
713 | 717 | private static long extractNodeId(@NotNull AnyValue node) { |
714 | | - // TODO: mapper |
715 | | - if (node instanceof VirtualNodeValue) { |
716 | | - return ((VirtualNodeValue) node).id(); |
717 | | - } else if (node instanceof IntegralValue) { |
718 | | - return ((IntegralValue) node).longValue(); |
719 | | - } else { |
720 | | - throw invalidNodeType(node); |
721 | | - } |
722 | | - } |
723 | | - |
724 | | - private static IllegalArgumentException invalidNodeType(@NotNull AnyValue node) { |
725 | | - return new IllegalArgumentException("The node has to be either a NODE or an INTEGER, but got " + node.getTypeName()); |
| 718 | + return node.map(ExtractNodeId.INSTANCE); |
726 | 719 | } |
727 | 720 | } |
728 | 721 |
|
@@ -888,4 +881,52 @@ public NodeLabelToken mapStringArray(StringArray value) { |
888 | 881 | return mapTextArray(value); |
889 | 882 | } |
890 | 883 | } |
| 884 | + |
| 885 | + private enum ExtractNodeId implements PartialValueMapper<Long> { |
| 886 | + INSTANCE; |
| 887 | + |
| 888 | + @Override |
| 889 | + public Long unsupported(AnyValue value) { |
| 890 | + throw invalidNodeType(value.getTypeName()); |
| 891 | + } |
| 892 | + |
| 893 | + @Override |
| 894 | + public Long mapNode(VirtualNodeValue value) { |
| 895 | + return value.id(); |
| 896 | + } |
| 897 | + |
| 898 | + @Override |
| 899 | + public Long mapSequence(SequenceValue value) { |
| 900 | + throw invalidNodeType("List"); |
| 901 | + } |
| 902 | + |
| 903 | + @Override |
| 904 | + public Long mapIntegral(IntegralValue value) { |
| 905 | + return value.longValue(); |
| 906 | + } |
| 907 | + |
| 908 | + @Override |
| 909 | + public Long mapByte(ByteValue value) { |
| 910 | + return value.longValue(); |
| 911 | + } |
| 912 | + |
| 913 | + @Override |
| 914 | + public Long mapShort(ShortValue value) { |
| 915 | + return value.longValue(); |
| 916 | + } |
| 917 | + |
| 918 | + @Override |
| 919 | + public Long mapInt(IntValue value) { |
| 920 | + return value.longValue(); |
| 921 | + } |
| 922 | + |
| 923 | + @Override |
| 924 | + public Long mapLong(LongValue value) { |
| 925 | + return value.longValue(); |
| 926 | + } |
| 927 | + |
| 928 | + private static IllegalArgumentException invalidNodeType(String typeName) { |
| 929 | + return new IllegalArgumentException("The node has to be either a NODE or an INTEGER, but got " + typeName); |
| 930 | + } |
| 931 | + } |
891 | 932 | } |
0 commit comments