Skip to content

Commit a51f810

Browse files
committed
Rename Entry to Pair
1 parent 5bf0e5e commit a51f810

File tree

15 files changed

+69
-75
lines changed

15 files changed

+69
-75
lines changed

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

Lines changed: 3 additions & 3 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;
2827
import org.neo4j.driver.v1.Function;
2928
import org.neo4j.driver.v1.Identity;
29+
import org.neo4j.driver.v1.Pair;
3030
import org.neo4j.driver.v1.Value;
3131
import org.neo4j.driver.v1.Values;
3232

@@ -125,13 +125,13 @@ public <T> Iterable<T> values( Function<Value,T> mapFunction )
125125
}
126126

127127
@Override
128-
public Iterable<Entry<Value>> properties()
128+
public Iterable<Pair<String, Value>> properties()
129129
{
130130
return properties( valueAsIs() );
131131
}
132132

133133
@Override
134-
public <V> Iterable<Entry<V>> properties( final Function<Value, V> Function )
134+
public <V> Iterable<Pair<String, V>> properties( final Function<Value, V> Function )
135135
{
136136
return Extract.properties( this, Function );
137137
}

driver/src/main/java/org/neo4j/driver/internal/InternalEntry.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
@@ -20,29 +20,23 @@
2020

2121
import java.util.Objects;
2222

23-
import org.neo4j.driver.v1.Entry;
2423
import org.neo4j.driver.v1.Function;
24+
import org.neo4j.driver.v1.Pair;
2525

26-
public class InternalEntry<V> implements Entry<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 InternalEntry( 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> Entry<V> of( String key, V value )
49+
public static <K, V> Pair<K, V> of( K key, V value )
5650
{
57-
return new InternalEntry<>( 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-
InternalEntry<?> that = (InternalEntry<?>) 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

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

34-
import static org.neo4j.driver.internal.util.Format.formatEntries;
34+
import static org.neo4j.driver.internal.util.Format.formatPairs;
3535
import static org.neo4j.driver.v1.Values.valueAsIs;
3636

3737
public class InternalRecord extends InternalRecordAccessor implements Record
@@ -122,7 +122,7 @@ public Map<String, Value> asMap()
122122
@Override
123123
public String toString()
124124
{
125-
return format( "Record<%s>", formatEntries( InternalValue.Format.VALUE_WITH_TYPE, size(), fields() ) );
125+
return format( "Record<%s>", formatPairs( InternalValue.Format.VALUE_WITH_TYPE, size(), fields() ) );
126126
}
127127

128128
public boolean equals( Object other )

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

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

2323
import org.neo4j.driver.internal.util.Extract;
24-
import org.neo4j.driver.v1.Entry;
24+
import org.neo4j.driver.v1.Pair;
2525
import org.neo4j.driver.v1.RecordAccessor;
2626
import org.neo4j.driver.v1.Value;
2727

@@ -30,7 +30,7 @@
3030
public abstract class InternalRecordAccessor implements RecordAccessor
3131
{
3232
@Override
33-
public List<Entry<Value>> fields()
33+
public List<Pair<String, Value>> fields()
3434
{
3535
return Extract.fields( this, valueAsIs() );
3636
}

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

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

24-
import org.neo4j.driver.v1.Entry;
2524
import org.neo4j.driver.v1.Function;
25+
import org.neo4j.driver.v1.Pair;
2626
import org.neo4j.driver.v1.Record;
2727
import org.neo4j.driver.v1.RecordAccessor;
2828
import org.neo4j.driver.v1.ResultCursor;
@@ -310,7 +310,7 @@ public int size()
310310
}
311311

312312
@Override
313-
public List<Entry<Value>> fields()
313+
public List<Pair<String, Value>> fields()
314314
{
315315
return record().fields();
316316
}

driver/src/main/java/org/neo4j/driver/internal/util/Extract.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
import java.util.List;
2525
import java.util.Map;
2626

27-
import org.neo4j.driver.internal.InternalEntry;
28-
import org.neo4j.driver.v1.Entry;
27+
import org.neo4j.driver.internal.InternalPair;
2928
import org.neo4j.driver.v1.Function;
3029
import org.neo4j.driver.v1.MapAccessor;
30+
import org.neo4j.driver.v1.Pair;
3131
import org.neo4j.driver.v1.RecordAccessor;
3232
import org.neo4j.driver.v1.Value;
3333

@@ -134,7 +134,7 @@ public static <T> Map<String, T> map( RecordAccessor record, Function<Value, T>
134134
}
135135
}
136136

137-
public static <V> Iterable<Entry<V>> properties( final MapAccessor map, final Function<Value, V> mapFunction )
137+
public static <V> Iterable<Pair<String, V>> properties( final MapAccessor map, final Function<Value, V> mapFunction )
138138
{
139139
int size = map.size();
140140
switch ( size )
@@ -146,23 +146,23 @@ public static <V> Iterable<Entry<V>> properties( final MapAccessor map, final Fu
146146
{
147147
String key = map.keys().iterator().next();
148148
Value value = map.value( key );
149-
return singletonList( InternalEntry.of( key, mapFunction.apply( value ) ) );
149+
return singletonList( InternalPair.of( key, mapFunction.apply( value ) ) );
150150
}
151151

152152
default:
153153
{
154-
List<Entry<V>> list = new ArrayList<>( size );
154+
List<Pair<String, V>> list = new ArrayList<>( size );
155155
for ( String key : map.keys() )
156156
{
157157
Value value = map.value( key );
158-
list.add( InternalEntry.of( key, mapFunction.apply( value ) ) );
158+
list.add( InternalPair.of( key, mapFunction.apply( value ) ) );
159159
}
160160
return unmodifiableList( list );
161161
}
162162
}
163163
}
164164

165-
public static <V> List<Entry<V>> fields( final RecordAccessor map, final Function<Value, V> mapFunction )
165+
public static <V> List<Pair<String, V>> fields( final RecordAccessor map, final Function<Value, V> mapFunction )
166166
{
167167
int size = map.keys().size();
168168
switch ( size )
@@ -174,18 +174,18 @@ public static <V> List<Entry<V>> fields( final RecordAccessor map, final Functio
174174
{
175175
String key = map.keys().iterator().next();
176176
Value value = map.value( key );
177-
return singletonList( InternalEntry.of( key, mapFunction.apply( value ) ) );
177+
return singletonList( InternalPair.of( key, mapFunction.apply( value ) ) );
178178
}
179179

180180
default:
181181
{
182-
List<Entry<V>> list = new ArrayList<>( size );
182+
List<Pair<String, V>> list = new ArrayList<>( size );
183183
List<String> keys = map.keys();
184184
for ( int i = 0; i < size; i++ )
185185
{
186186
String key = keys.get( i );
187187
Value value = map.value( i );
188-
list.add( InternalEntry.of( key, mapFunction.apply( value ) ) );
188+
list.add( InternalPair.of( key, mapFunction.apply( value ) ) );
189189
}
190190
return unmodifiableList( list );
191191
}

driver/src/main/java/org/neo4j/driver/internal/util/Format.java

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

2121
import java.util.Iterator;
2222

23-
import org.neo4j.driver.internal.InternalEntry;
24-
import org.neo4j.driver.v1.Entry;
23+
import org.neo4j.driver.internal.InternalPair;
2524
import org.neo4j.driver.v1.Function;
25+
import org.neo4j.driver.v1.Pair;
2626

2727
public abstract class Format
2828
{
@@ -31,30 +31,30 @@ private Format()
3131
throw new UnsupportedOperationException();
3232
}
3333

34-
public static <V> String formatEntries( Function<V, String> printValue,
35-
int propertyCount,
36-
Iterable<Entry<V>> Entries )
34+
public static <V> String formatPairs( Function<V, String> printValue,
35+
int propertyCount,
36+
Iterable<Pair<String, V>> Entries )
3737
{
3838
switch ( propertyCount ) {
3939
case 0:
4040
return "{}";
4141

4242
case 1:
4343
{
44-
return String.format( "{%s}", internalEntry( Entries.iterator().next() ).toString( printValue ) );
44+
return String.format( "{%s}", internalPair( Entries.iterator().next() ).toString( printValue ) );
4545
}
4646

4747
default:
4848
{
4949
StringBuilder builder = new StringBuilder();
5050
builder.append( "{" );
51-
Iterator<Entry<V>> iterator = Entries.iterator();
52-
builder.append( internalEntry( iterator.next() ).toString( printValue ) );
51+
Iterator<Pair<String, V>> iterator = Entries.iterator();
52+
builder.append( internalPair( iterator.next() ).toString( printValue ) );
5353
while ( iterator.hasNext() )
5454
{
5555
builder.append( ',' );
5656
builder.append( ' ' );
57-
builder.append( internalEntry( iterator.next() ).toString( printValue ) );
57+
builder.append( internalPair( iterator.next() ).toString( printValue ) );
5858
}
5959
builder.append( "}" );
6060
return builder.toString();
@@ -63,9 +63,9 @@ public static <V> String formatEntries( Function<V, String> printValue,
6363
}
6464

6565
@SuppressWarnings("unchecked")
66-
private static <V> InternalEntry<V> internalEntry( Entry<V> property )
66+
private static <V> InternalPair<String, V> internalPair( Pair<String, V> property )
6767
{
68-
return (InternalEntry<V>) property;
68+
return (InternalPair<String, V>) property;
6969
}
7070

7171
public static <V> String formatElements( Function<V, String> printValue, V[] elements )

driver/src/main/java/org/neo4j/driver/internal/value/MapValue.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.neo4j.driver.v1.Value;
2828
import org.neo4j.driver.v1.Values;
2929

30-
import static org.neo4j.driver.internal.util.Format.formatEntries;
30+
import static org.neo4j.driver.internal.util.Format.formatPairs;
3131
import static org.neo4j.driver.internal.value.InternalValue.Format.VALUE_ONLY;
3232
import static org.neo4j.driver.v1.Values.valueAsObject;
3333

@@ -116,7 +116,7 @@ public String toString( Format valueFormat )
116116
{
117117
return maybeWithType(
118118
valueFormat.includeType(),
119-
formatEntries( valueFormat.inner(), size(), properties() )
119+
formatPairs( valueFormat.inner(), size(), properties() )
120120
);
121121
}
122122

driver/src/main/java/org/neo4j/driver/internal/value/ValueAdapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
import org.neo4j.driver.internal.types.TypeRepresentation;
2626
import org.neo4j.driver.internal.util.Extract;
2727
import org.neo4j.driver.v1.Entity;
28-
import org.neo4j.driver.v1.Entry;
2928
import org.neo4j.driver.v1.Function;
3029
import org.neo4j.driver.v1.Identity;
3130
import org.neo4j.driver.v1.Node;
31+
import org.neo4j.driver.v1.Pair;
3232
import org.neo4j.driver.v1.Path;
3333
import org.neo4j.driver.v1.Relationship;
3434
import org.neo4j.driver.v1.Type;
@@ -302,13 +302,13 @@ public <T> Iterable<T> values( Function<Value,T> mapFunction )
302302
}
303303

304304
@Override
305-
public Iterable<Entry<Value>> properties()
305+
public Iterable<Pair<String, Value>> properties()
306306
{
307307
return properties( valueAsIs() );
308308
}
309309

310310
@Override
311-
public <V> Iterable<Entry<V>> properties( final Function<Value, V> mapFunction )
311+
public <V> Iterable<Pair<String, V>> properties( final Function<Value, V> mapFunction )
312312
{
313313
return Extract.properties( this, mapFunction );
314314
}

driver/src/main/java/org/neo4j/driver/v1/MapAccessor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,19 @@ public interface MapAccessor
8080
/**
8181
* Retrieve all properties of the underlying map
8282
*
83-
* @see Entry
83+
* @see Pair
8484
* @return all properties in unspecified order
8585
*/
86-
Iterable<Entry<Value>> properties();
86+
Iterable<Pair<String, Value>> properties();
8787

8888
/**
8989
* Retrieve all properties of the underlying map
9090
*
91-
* @see Entry
91+
* @see Pair
9292
* @param mapFunction a function to map from Value to T. See {@link Values} for some predefined functions, such
9393
* as {@link Values#valueAsBoolean()}, {@link Values#valueAsList(Function)}.
9494
* @param <V> the target type of mapping
9595
* @return all mapped properties in unspecified order
9696
*/
97-
<V> Iterable<Entry<V>> properties( Function<Value, V> mapFunction );
97+
<V> Iterable<Pair<String, V>> properties( Function<Value, V> mapFunction );
9898
}

driver/src/main/java/org/neo4j/driver/v1/Entry.java renamed to driver/src/main/java/org/neo4j/driver/v1/Pair.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
* @param <V> the Java type of the contained value
2727
*/
2828
@Immutable
29-
public interface Entry<V>
29+
public interface Pair<K, V>
3030
{
3131
/**
3232
* @return the property key
3333
*/
34-
String key();
34+
K key();
3535

3636
/**
3737
* @return the property value

driver/src/main/java/org/neo4j/driver/v1/RecordAccessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* This provides only read methods. Subclasses may chose to provide additional methods
3030
* for changing the underlying record.
3131
*
32-
* @see Entry
32+
* @see Pair
3333
*/
3434
public interface RecordAccessor extends ListAccessor
3535
{
@@ -80,7 +80,7 @@ public interface RecordAccessor extends ListAccessor
8080
* @return all fields in key order
8181
* @throws NoRecordException if the associated underlying record is not available
8282
*/
83-
List<Entry<Value>> fields();
83+
List<Pair<String, Value>> fields();
8484

8585
/**
8686
* @return if this record accessor is currently associated with an underlying record

0 commit comments

Comments
 (0)