Skip to content

Commit

Permalink
Make MapAccessorWithDefaultValue extend MapAccessor (#1148) (#1161)
Browse files Browse the repository at this point in the history
  • Loading branch information
injectives authored Feb 24, 2022
1 parent cfb4003 commit 975437b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 58 deletions.
12 changes: 12 additions & 0 deletions driver/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,16 @@
<method>org.reactivestreams.Publisher close()</method>
</difference>

<difference>
<className>org/neo4j/driver/Record</className>
<differenceType>7012</differenceType>
<method>java.lang.Iterable keys()</method>
</difference>

<difference>
<className>org/neo4j/driver/Record</className>
<differenceType>7012</differenceType>
<method>java.lang.Iterable values()</method>
</difference>

</differences>
51 changes: 2 additions & 49 deletions driver/src/main/java/org/neo4j/driver/Record.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@
package org.neo4j.driver;

import java.util.List;
import java.util.Map;

import org.neo4j.driver.internal.value.NullValue;
import org.neo4j.driver.exceptions.ClientException;
import org.neo4j.driver.exceptions.NoSuchRecordException;
import org.neo4j.driver.types.MapAccessorWithDefaultValue;
import java.util.function.Function;
import org.neo4j.driver.util.Immutable;
import org.neo4j.driver.util.Pair;

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

/**
* Retrieve the values of the underlying map
*
* @return all field keys in order
*/
@Override
List<Value> values();

/**
* Check if the list of keys contains the given key
*
* @param key the key
* @return {@code true} if this map keys contains the given key otherwise {@code false}
*/
boolean containsKey( String key );

/**
* Retrieve the index of the field with the given key
*
Expand All @@ -75,15 +66,6 @@ public interface Record extends MapAccessorWithDefaultValue
*/
int index( String key );

/**
* Retrieve the value of the property with the given key
*
* @param key the key of the property
* @return the property's value or a {@link NullValue} if no such key exists
* @throws NoSuchRecordException if the associated underlying record is not available
*/
Value get( String key );

/**
* Retrieve the value at the given field index
*
Expand All @@ -93,40 +75,11 @@ public interface Record extends MapAccessorWithDefaultValue
*/
Value get( int index );

/**
* Retrieve the number of fields in this record
*
* @return the number of fields in this record
*/
int size();

/**
* Return this record as a map, where each value has been converted to a default
* java object using {@link Value#asObject()}.
*
* This is equivalent to calling {@link #asMap(Function)} with {@link Values#ofObject()}.
*
* @return this record as a map
*/
Map<String, Object> asMap();

/**
* Return this record as a map, where each value has been converted using the provided
* mapping function. You can find a library of common mapping functions in {@link Values}.
*
* @see Values for a long list of built-in conversion functions
* @param mapper the mapping function
* @param <T> the type to convert to
* @return this record as a map
*/
<T> Map<String, T> asMap( Function<Value, T> mapper );

/**
* Retrieve all record fields
*
* @return all fields in key order
* @throws NoSuchRecordException if the associated underlying record is not available
*/
List<Pair<String, Value>> fields();

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.neo4j.driver.Record;
import org.neo4j.driver.Value;
Expand Down Expand Up @@ -68,7 +69,13 @@ public List<Value> values()
}

@Override
public List<Pair<String, Value>> fields()
public <T> Iterable<T> values( Function<Value,T> mapFunction )
{
return values().stream().map( mapFunction ).collect( Collectors.toList() );
}

@Override
public List<Pair<String,Value>> fields()
{
return Extract.fields( this, ofValue() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@

import java.util.List;
import java.util.Map;
import java.util.function.Function;

import org.neo4j.driver.Value;
import java.util.function.Function;

/**
* 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 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.
* 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 cast from A to B is not possible.
* 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
* 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.
* 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
* cast from A to B is not possible.
*/
public interface MapAccessorWithDefaultValue
public interface MapAccessorWithDefaultValue extends MapAccessor
{
/**
* Retrieve the value with the given key.
Expand Down

0 comments on commit 975437b

Please sign in to comment.