Skip to content

Commit 12a9e04

Browse files
author
Stefan Plantikow
committed
Merge pull request #97 from boggle/new-results-api
New results api, take 2
2 parents 93c26a1 + a51f810 commit 12a9e04

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+795
-637
lines changed

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.neo4j.driver.v1.Entity;
2727
import org.neo4j.driver.v1.Function;
2828
import org.neo4j.driver.v1.Identity;
29-
import org.neo4j.driver.v1.Property;
29+
import org.neo4j.driver.v1.Pair;
3030
import org.neo4j.driver.v1.Value;
3131
import org.neo4j.driver.v1.Values;
3232

@@ -50,12 +50,7 @@ public Identity identity()
5050
}
5151

5252
@Override
53-
public Property property( String key )
54-
{
55-
return InternalProperty.of( key, value( key ) );
56-
}
57-
58-
public int propertyCount()
53+
public int size()
5954
{
6055
return properties.size();
6156
}
@@ -130,13 +125,13 @@ public <T> Iterable<T> values( Function<Value,T> mapFunction )
130125
}
131126

132127
@Override
133-
public Iterable<Property<Value>> properties()
128+
public Iterable<Pair<String, Value>> properties()
134129
{
135130
return properties( valueAsIs() );
136131
}
137132

138133
@Override
139-
public <V> Iterable<Property<V>> properties( final Function<Value, V> Function )
134+
public <V> Iterable<Pair<String, V>> properties( final Function<Value, V> Function )
140135
{
141136
return Extract.properties( this, Function );
142137
}

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

Lines changed: 0 additions & 110 deletions
This file was deleted.

driver/src/main/java/org/neo4j/driver/internal/InternalProperty.java renamed to driver/src/main/java/org/neo4j/driver/internal/InternalPair.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,22 @@
2121
import java.util.Objects;
2222

2323
import org.neo4j.driver.v1.Function;
24-
import org.neo4j.driver.v1.Property;
24+
import org.neo4j.driver.v1.Pair;
2525

26-
public class InternalProperty<V> implements Property<V>
26+
public class InternalPair<K, V> implements Pair<K, V>
2727
{
28-
private final String key;
28+
private final K key;
2929
private final V value;
3030

31-
protected InternalProperty( String key, V value )
31+
protected InternalPair( K key, V value )
3232
{
33-
if ( key == null )
34-
{
35-
throw new IllegalArgumentException( "null key" );
36-
}
37-
if ( value == null )
38-
{
39-
throw new IllegalArgumentException( "null value" );
40-
}
33+
Objects.requireNonNull( key );
34+
Objects.requireNonNull( value );
4135
this.key = key;
4236
this.value = value;
4337
}
4438

45-
public String key()
39+
public K key()
4640
{
4741
return key;
4842
}
@@ -52,15 +46,15 @@ public V value()
5246
return value;
5347
}
5448

55-
public static <V> Property<V> of( String key, V value )
49+
public static <K, V> Pair<K, V> of( K key, V value )
5650
{
57-
return new InternalProperty<>( key, value );
51+
return new InternalPair<>( key, value );
5852
}
5953

6054
@Override
6155
public String toString()
6256
{
63-
return String.format( "%s: %s", key, Objects.toString( value ) );
57+
return String.format( "%s: %s", Objects.toString( key ), Objects.toString( value ) );
6458
}
6559

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

83-
InternalProperty<?> that = (InternalProperty<?>) o;
77+
InternalPair<?, ?> that = (InternalPair<?, ?>) o;
8478

8579
return key.equals( that.key ) && value.equals( that.value );
8680
}

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@
2424
import java.util.NoSuchElementException;
2525

2626
import org.neo4j.driver.internal.util.Extract;
27-
import org.neo4j.driver.v1.Function;
27+
import org.neo4j.driver.internal.value.InternalValue;
2828
import org.neo4j.driver.v1.Record;
2929
import org.neo4j.driver.v1.Value;
3030
import org.neo4j.driver.v1.Values;
3131

3232
import static java.lang.String.format;
3333

34-
import static org.neo4j.driver.internal.util.Format.formatFields;
35-
import static org.neo4j.driver.internal.value.InternalValue.Format.VALUE_WITH_TYPE;
34+
import static org.neo4j.driver.internal.util.Format.formatPairs;
3635
import static org.neo4j.driver.v1.Values.valueAsIs;
3736

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

52-
@Override
53-
public Value value( int index )
54-
{
55-
return index >= 0 && index < values.length ? values[index] : Values.NULL;
56-
}
57-
58-
@Override
59-
public String key( int index )
60-
{
61-
return keys.get( index );
62-
}
63-
6451
@Override
6552
public List<String> keys()
6653
{
@@ -103,26 +90,39 @@ public Value value( String key )
10390
}
10491

10592
@Override
106-
public Record record()
93+
public Value value( int index )
10794
{
108-
return this;
95+
return index >= 0 && index < values.length ? values[index] : Values.NULL;
10996
}
11097

11198
@Override
112-
public Map<String, Value> asMap()
99+
public int size()
113100
{
114-
return asMap( valueAsIs() );
101+
return values.length;
115102
}
116103

117-
public <T> Map<String, T> asMap( Function<Value, T> mapFunction )
104+
@Override
105+
public boolean hasRecord()
106+
{
107+
return true;
108+
}
109+
110+
@Override
111+
public Record record()
112+
{
113+
return this;
114+
}
115+
116+
@Override
117+
public Map<String, Value> asMap()
118118
{
119-
return Extract.map( this, mapFunction );
119+
return Extract.map( this, valueAsIs() );
120120
}
121121

122122
@Override
123123
public String toString()
124124
{
125-
return format( "Record<%s>", formatFields( VALUE_WITH_TYPE, fieldCount(), fields() ) );
125+
return format( "Record<%s>", formatPairs( InternalValue.Format.VALUE_WITH_TYPE, size(), fields() ) );
126126
}
127127

128128
public boolean equals( Object other )
@@ -134,8 +134,8 @@ public boolean equals( Object other )
134134
else if ( other instanceof Record )
135135
{
136136
Record otherRecord = (Record) other;
137-
int size = fieldCount();
138-
if ( ! ( size == otherRecord.fieldCount() ) )
137+
int size = size();
138+
if ( ! ( size == otherRecord.size() ) )
139139
{
140140
return false;
141141
}

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

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
import java.util.List;
2222

2323
import org.neo4j.driver.internal.util.Extract;
24-
import org.neo4j.driver.v1.Field;
25-
import org.neo4j.driver.v1.Function;
24+
import org.neo4j.driver.v1.Pair;
2625
import org.neo4j.driver.v1.RecordAccessor;
2726
import org.neo4j.driver.v1.Value;
2827

@@ -31,33 +30,8 @@
3130
public abstract class InternalRecordAccessor implements RecordAccessor
3231
{
3332
@Override
34-
public int fieldCount()
33+
public List<Pair<String, Value>> fields()
3534
{
36-
return keys().size();
37-
}
38-
39-
@Override
40-
public Field field( String key )
41-
{
42-
int index = index( key );
43-
return InternalField.of( key, index, value( index ) );
44-
}
45-
46-
@Override
47-
public Field field( int index )
48-
{
49-
return InternalField.of( key( index ), index, value( index) );
50-
}
51-
52-
@Override
53-
public List<Field<Value>> fields()
54-
{
55-
return fields( valueAsIs() );
56-
}
57-
58-
@Override
59-
public <V> List<Field<V>> fields( final Function<Value, V> mapFunction )
60-
{
61-
return Extract.fields( this, mapFunction );
35+
return Extract.fields( this, valueAsIs() );
6236
}
6337
}

0 commit comments

Comments
 (0)