Skip to content

Commit b016fdf

Browse files
committed
Simplify exposed API
o Replace Field, Property by Entry o Fuse MapAccessor and PropertyMapAccessor into MapAccessor o Made RecordAccessor a separate interface o Remove some unneeded methods o Replace propertyCount, fieldCount with size
1 parent 93c26a1 commit b016fdf

30 files changed

+177
-495
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
@@ -24,9 +24,9 @@
2424
import org.neo4j.driver.internal.util.Iterables;
2525
import org.neo4j.driver.internal.value.MapValue;
2626
import org.neo4j.driver.v1.Entity;
27+
import org.neo4j.driver.v1.Entry;
2728
import org.neo4j.driver.v1.Function;
2829
import org.neo4j.driver.v1.Identity;
29-
import org.neo4j.driver.v1.Property;
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<Entry<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<Entry<V>> properties( final Function<Value, V> Function )
140135
{
141136
return Extract.properties( this, Function );
142137
}

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

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

2121
import java.util.Objects;
2222

23+
import org.neo4j.driver.v1.Entry;
2324
import org.neo4j.driver.v1.Function;
24-
import org.neo4j.driver.v1.Property;
2525

26-
public class InternalProperty<V> implements Property<V>
26+
public class InternalEntry<V> implements Entry<V>
2727
{
2828
private final String key;
2929
private final V value;
3030

31-
protected InternalProperty( String key, V value )
31+
protected InternalEntry( String key, V value )
3232
{
3333
if ( key == null )
3434
{
@@ -52,9 +52,9 @@ public V value()
5252
return value;
5353
}
5454

55-
public static <V> Property<V> of( String key, V value )
55+
public static <V> Entry<V> of( String key, V value )
5656
{
57-
return new InternalProperty<>( key, value );
57+
return new InternalEntry<>( key, value );
5858
}
5959

6060
@Override
@@ -80,7 +80,7 @@ public boolean equals( Object o )
8080
return false;
8181
}
8282

83-
InternalProperty<?> that = (InternalProperty<?>) o;
83+
InternalEntry<?> that = (InternalEntry<?>) o;
8484

8585
return key.equals( that.key ) && value.equals( that.value );
8686
}

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/InternalRecord.java

Lines changed: 7 additions & 13 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.formatEntries;
3635
import static org.neo4j.driver.v1.Values.valueAsIs;
3736

3837
public class InternalRecord extends InternalRecordAccessor implements Record
@@ -56,9 +55,9 @@ public Value value( int index )
5655
}
5756

5857
@Override
59-
public String key( int index )
58+
public int size()
6059
{
61-
return keys.get( index );
60+
return values.length;
6261
}
6362

6463
@Override
@@ -111,18 +110,13 @@ public Record record()
111110
@Override
112111
public Map<String, Value> asMap()
113112
{
114-
return asMap( valueAsIs() );
115-
}
116-
117-
public <T> Map<String, T> asMap( Function<Value, T> mapFunction )
118-
{
119-
return Extract.map( this, mapFunction );
113+
return Extract.map( this, valueAsIs() );
120114
}
121115

122116
@Override
123117
public String toString()
124118
{
125-
return format( "Record<%s>", formatFields( VALUE_WITH_TYPE, fieldCount(), fields() ) );
119+
return format( "Record<%s>", formatEntries( InternalValue.Format.VALUE_WITH_TYPE, size(), fields() ) );
126120
}
127121

128122
public boolean equals( Object other )
@@ -135,7 +129,7 @@ else if ( other instanceof Record )
135129
{
136130
Record otherRecord = (Record) other;
137131
int size = fieldCount();
138-
if ( ! ( size == otherRecord.fieldCount() ) )
132+
if ( ! ( size == otherRecord.size() ) )
139133
{
140134
return false;
141135
}

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

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,43 +21,22 @@
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.Entry;
2625
import org.neo4j.driver.v1.RecordAccessor;
2726
import org.neo4j.driver.v1.Value;
2827

2928
import static org.neo4j.driver.v1.Values.valueAsIs;
3029

3130
public abstract class InternalRecordAccessor implements RecordAccessor
3231
{
33-
@Override
3432
public int fieldCount()
3533
{
3634
return keys().size();
3735
}
3836

3937
@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 )
38+
public List<Entry<Value>> fields()
6039
{
61-
return Extract.fields( this, mapFunction );
40+
return Extract.fields( this, valueAsIs() );
6241
}
6342
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ public boolean containsKey( String key )
7373
return keys.contains( key );
7474
}
7575

76-
@Override
77-
public String key( int index )
78-
{
79-
return record().key( index );
80-
}
81-
8276
@Override
8377
public int index( String key )
8478
{
@@ -90,6 +84,12 @@ public List<String> keys()
9084
return keys;
9185
}
9286

87+
@Override
88+
public int size()
89+
{
90+
return keys.size();
91+
}
92+
9393
private Value throwNoRecord()
9494
{
9595
throw new ClientException(

driver/src/main/java/org/neo4j/driver/internal/messaging/PackStreamMessageFormatV1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ private void packNode( Node node ) throws IOException
367367
private void packProperties( Entity entity ) throws IOException
368368
{
369369
Iterable<String> keys = entity.keys();
370-
packer.packMapHeader( entity.propertyCount() );
370+
packer.packMapHeader( entity.size() );
371371
for ( String propKey : keys )
372372
{
373373
packer.pack( propKey );

0 commit comments

Comments
 (0)