Skip to content

Commit 975437b

Browse files
authored
Make MapAccessorWithDefaultValue extend MapAccessor (#1148) (#1161)
1 parent cfb4003 commit 975437b

File tree

4 files changed

+28
-58
lines changed

4 files changed

+28
-58
lines changed

driver/clirr-ignored-differences.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,16 @@
4343
<method>org.reactivestreams.Publisher close()</method>
4444
</difference>
4545

46+
<difference>
47+
<className>org/neo4j/driver/Record</className>
48+
<differenceType>7012</differenceType>
49+
<method>java.lang.Iterable keys()</method>
50+
</difference>
51+
52+
<difference>
53+
<className>org/neo4j/driver/Record</className>
54+
<differenceType>7012</differenceType>
55+
<method>java.lang.Iterable values()</method>
56+
</difference>
57+
4658
</differences>

driver/src/main/java/org/neo4j/driver/Record.java

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@
1919
package org.neo4j.driver;
2020

2121
import java.util.List;
22-
import java.util.Map;
2322

24-
import org.neo4j.driver.internal.value.NullValue;
2523
import org.neo4j.driver.exceptions.ClientException;
2624
import org.neo4j.driver.exceptions.NoSuchRecordException;
2725
import org.neo4j.driver.types.MapAccessorWithDefaultValue;
28-
import java.util.function.Function;
2926
import org.neo4j.driver.util.Immutable;
3027
import org.neo4j.driver.util.Pair;
3128

@@ -49,23 +46,17 @@ public interface Record extends MapAccessorWithDefaultValue
4946
*
5047
* @return all field keys in order
5148
*/
49+
@Override
5250
List<String> keys();
5351

5452
/**
5553
* Retrieve the values of the underlying map
5654
*
5755
* @return all field keys in order
5856
*/
57+
@Override
5958
List<Value> values();
6059

61-
/**
62-
* Check if the list of keys contains the given key
63-
*
64-
* @param key the key
65-
* @return {@code true} if this map keys contains the given key otherwise {@code false}
66-
*/
67-
boolean containsKey( String key );
68-
6960
/**
7061
* Retrieve the index of the field with the given key
7162
*
@@ -75,15 +66,6 @@ public interface Record extends MapAccessorWithDefaultValue
7566
*/
7667
int index( String key );
7768

78-
/**
79-
* Retrieve the value of the property with the given key
80-
*
81-
* @param key the key of the property
82-
* @return the property's value or a {@link NullValue} if no such key exists
83-
* @throws NoSuchRecordException if the associated underlying record is not available
84-
*/
85-
Value get( String key );
86-
8769
/**
8870
* Retrieve the value at the given field index
8971
*
@@ -93,40 +75,11 @@ public interface Record extends MapAccessorWithDefaultValue
9375
*/
9476
Value get( int index );
9577

96-
/**
97-
* Retrieve the number of fields in this record
98-
*
99-
* @return the number of fields in this record
100-
*/
101-
int size();
102-
103-
/**
104-
* Return this record as a map, where each value has been converted to a default
105-
* java object using {@link Value#asObject()}.
106-
*
107-
* This is equivalent to calling {@link #asMap(Function)} with {@link Values#ofObject()}.
108-
*
109-
* @return this record as a map
110-
*/
111-
Map<String, Object> asMap();
112-
113-
/**
114-
* Return this record as a map, where each value has been converted using the provided
115-
* mapping function. You can find a library of common mapping functions in {@link Values}.
116-
*
117-
* @see Values for a long list of built-in conversion functions
118-
* @param mapper the mapping function
119-
* @param <T> the type to convert to
120-
* @return this record as a map
121-
*/
122-
<T> Map<String, T> asMap( Function<Value, T> mapper );
123-
12478
/**
12579
* Retrieve all record fields
12680
*
12781
* @return all fields in key order
12882
* @throws NoSuchRecordException if the associated underlying record is not available
12983
*/
13084
List<Pair<String, Value>> fields();
131-
13285
}

driver/src/main/java/org/neo4j/driver/internal/InternalRecord.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Map;
2424
import java.util.NoSuchElementException;
2525
import java.util.function.Function;
26+
import java.util.stream.Collectors;
2627

2728
import org.neo4j.driver.Record;
2829
import org.neo4j.driver.Value;
@@ -68,7 +69,13 @@ public List<Value> values()
6869
}
6970

7071
@Override
71-
public List<Pair<String, Value>> fields()
72+
public <T> Iterable<T> values( Function<Value,T> mapFunction )
73+
{
74+
return values().stream().map( mapFunction ).collect( Collectors.toList() );
75+
}
76+
77+
@Override
78+
public List<Pair<String,Value>> fields()
7279
{
7380
return Extract.fields( this, ofValue() );
7481
}

driver/src/main/java/org/neo4j/driver/types/MapAccessorWithDefaultValue.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,17 @@
2020

2121
import java.util.List;
2222
import java.util.Map;
23+
import java.util.function.Function;
2324

2425
import org.neo4j.driver.Value;
25-
import java.util.function.Function;
2626

2727
/**
28-
* Provides methods to access the value of an underlying unordered map by key.
29-
* When calling the methods, a user need to provides a default value, which will be given back if no match found by
30-
* the key provided.
31-
* The default value also servers the purpose of specifying the return type of the value found in map by key.
32-
* If the type of the value found A differs from the type of the default value B, a cast from A to B would happen
33-
* automatically. Note: Error might arise if the cast from A to B is not possible.
28+
* Provides methods to access the value of an underlying unordered map by key. When calling the methods, a user need to provides a default value, which will be
29+
* given back if no match found by the key provided. The default value also servers the purpose of specifying the return type of the value found in map by key.
30+
* If the type of the value found A differs from the type of the default value B, a cast from A to B would happen automatically. Note: Error might arise if the
31+
* cast from A to B is not possible.
3432
*/
35-
public interface MapAccessorWithDefaultValue
33+
public interface MapAccessorWithDefaultValue extends MapAccessor
3634
{
3735
/**
3836
* Retrieve the value with the given key.

0 commit comments

Comments
 (0)