Skip to content

New results api, take 2 #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.neo4j.driver.v1.Entity;
import org.neo4j.driver.v1.Function;
import org.neo4j.driver.v1.Identity;
import org.neo4j.driver.v1.Property;
import org.neo4j.driver.v1.Pair;
import org.neo4j.driver.v1.Value;
import org.neo4j.driver.v1.Values;

Expand All @@ -50,12 +50,7 @@ public Identity identity()
}

@Override
public Property property( String key )
{
return InternalProperty.of( key, value( key ) );
}

public int propertyCount()
public int size()
{
return properties.size();
}
Expand Down Expand Up @@ -130,13 +125,13 @@ public <T> Iterable<T> values( Function<Value,T> mapFunction )
}

@Override
public Iterable<Property<Value>> properties()
public Iterable<Pair<String, Value>> properties()
{
return properties( valueAsIs() );
}

@Override
public <V> Iterable<Property<V>> properties( final Function<Value, V> Function )
public <V> Iterable<Pair<String, V>> properties( final Function<Value, V> Function )
{
return Extract.properties( this, Function );
}
Expand Down
110 changes: 0 additions & 110 deletions driver/src/main/java/org/neo4j/driver/internal/InternalField.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,22 @@
import java.util.Objects;

import org.neo4j.driver.v1.Function;
import org.neo4j.driver.v1.Property;
import org.neo4j.driver.v1.Pair;

public class InternalProperty<V> implements Property<V>
public class InternalPair<K, V> implements Pair<K, V>
{
private final String key;
private final K key;
private final V value;

protected InternalProperty( String key, V value )
protected InternalPair( K key, V value )
{
if ( key == null )
{
throw new IllegalArgumentException( "null key" );
}
if ( value == null )
{
throw new IllegalArgumentException( "null value" );
}
Objects.requireNonNull( key );
Objects.requireNonNull( value );
this.key = key;
this.value = value;
}

public String key()
public K key()
{
return key;
}
Expand All @@ -52,15 +46,15 @@ public V value()
return value;
}

public static <V> Property<V> of( String key, V value )
public static <K, V> Pair<K, V> of( K key, V value )
{
return new InternalProperty<>( key, value );
return new InternalPair<>( key, value );
}

@Override
public String toString()
{
return String.format( "%s: %s", key, Objects.toString( value ) );
return String.format( "%s: %s", Objects.toString( key ), Objects.toString( value ) );
}

public String toString( Function<V, String> printValue )
Expand All @@ -80,7 +74,7 @@ public boolean equals( Object o )
return false;
}

InternalProperty<?> that = (InternalProperty<?>) o;
InternalPair<?, ?> that = (InternalPair<?, ?>) o;

return key.equals( that.key ) && value.equals( that.value );
}
Expand Down
48 changes: 24 additions & 24 deletions driver/src/main/java/org/neo4j/driver/internal/InternalRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@
import java.util.NoSuchElementException;

import org.neo4j.driver.internal.util.Extract;
import org.neo4j.driver.v1.Function;
import org.neo4j.driver.internal.value.InternalValue;
import org.neo4j.driver.v1.Record;
import org.neo4j.driver.v1.Value;
import org.neo4j.driver.v1.Values;

import static java.lang.String.format;

import static org.neo4j.driver.internal.util.Format.formatFields;
import static org.neo4j.driver.internal.value.InternalValue.Format.VALUE_WITH_TYPE;
import static org.neo4j.driver.internal.util.Format.formatPairs;
import static org.neo4j.driver.v1.Values.valueAsIs;

public class InternalRecord extends InternalRecordAccessor implements Record
Expand All @@ -49,18 +48,6 @@ public InternalRecord( List<String> keys, Map<String, Integer> keyIndexLookup, V
this.values = values;
}

@Override
public Value value( int index )
{
return index >= 0 && index < values.length ? values[index] : Values.NULL;
}

@Override
public String key( int index )
{
return keys.get( index );
}

@Override
public List<String> keys()
{
Expand Down Expand Up @@ -103,26 +90,39 @@ public Value value( String key )
}

@Override
public Record record()
public Value value( int index )
{
return this;
return index >= 0 && index < values.length ? values[index] : Values.NULL;
}

@Override
public Map<String, Value> asMap()
public int size()
{
return asMap( valueAsIs() );
return values.length;
}

public <T> Map<String, T> asMap( Function<Value, T> mapFunction )
@Override
public boolean hasRecord()
{
return true;
}

@Override
public Record record()
{
return this;
}

@Override
public Map<String, Value> asMap()
{
return Extract.map( this, mapFunction );
return Extract.map( this, valueAsIs() );
}

@Override
public String toString()
{
return format( "Record<%s>", formatFields( VALUE_WITH_TYPE, fieldCount(), fields() ) );
return format( "Record<%s>", formatPairs( InternalValue.Format.VALUE_WITH_TYPE, size(), fields() ) );
}

public boolean equals( Object other )
Expand All @@ -134,8 +134,8 @@ public boolean equals( Object other )
else if ( other instanceof Record )
{
Record otherRecord = (Record) other;
int size = fieldCount();
if ( ! ( size == otherRecord.fieldCount() ) )
int size = size();
if ( ! ( size == otherRecord.size() ) )
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import java.util.List;

import org.neo4j.driver.internal.util.Extract;
import org.neo4j.driver.v1.Field;
import org.neo4j.driver.v1.Function;
import org.neo4j.driver.v1.Pair;
import org.neo4j.driver.v1.RecordAccessor;
import org.neo4j.driver.v1.Value;

Expand All @@ -31,33 +30,8 @@
public abstract class InternalRecordAccessor implements RecordAccessor
{
@Override
public int fieldCount()
public List<Pair<String, Value>> fields()
{
return keys().size();
}

@Override
public Field field( String key )
{
int index = index( key );
return InternalField.of( key, index, value( index ) );
}

@Override
public Field field( int index )
{
return InternalField.of( key( index ), index, value( index) );
}

@Override
public List<Field<Value>> fields()
{
return fields( valueAsIs() );
}

@Override
public <V> List<Field<V>> fields( final Function<Value, V> mapFunction )
{
return Extract.fields( this, mapFunction );
return Extract.fields( this, valueAsIs() );
}
}
Loading