Skip to content

Commit 378484b

Browse files
author
Zhen Li
committed
Merge pull request #83 from neo4j/rename-text-to-string
Rename TEXT to STRING
2 parents c19256d + 2db0b6d commit 378484b

File tree

11 files changed

+81
-91
lines changed

11 files changed

+81
-91
lines changed

driver/src/main/java/org/neo4j/driver/Value.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* <code>typeValue</code> methods. The first set of these correlate with types from
2929
* the Neo4j Type System and are used to determine which Neo4j type is represented.
3030
* The second set of methods perform coercions to Java types (wherever possible).
31-
* For example, a common Text value should be tested for using <code>isText</code>
31+
* For example, a common String value should be tested for using <code>isString</code>
3232
* and extracted using <code>stringValue</code>.
3333
*
3434
* <h2>Navigating a tree structure</h2>
@@ -166,8 +166,8 @@ public interface Value extends Iterable<Value>
166166
*/
167167
Iterable<String> keys();
168168

169-
/** @return true if the underlying value is a Neo4j text value */
170-
boolean isText();
169+
/** @return true if the underlying value is a Neo4j string value */
170+
boolean isString();
171171

172172
/** @return if the underlying value is a Neo4j 64-bit integer */
173173
boolean isInteger();

driver/src/main/java/org/neo4j/driver/Values.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import org.neo4j.driver.internal.value.NodeValue;
3737
import org.neo4j.driver.internal.value.PathValue;
3838
import org.neo4j.driver.internal.value.RelationshipValue;
39-
import org.neo4j.driver.internal.value.TextValue;
39+
import org.neo4j.driver.internal.value.StringValue;
4040

4141
/**
4242
* Utility for wrapping regular Java types and exposing them as {@link org.neo4j.driver.Value}
@@ -146,15 +146,15 @@ public static Value value( double[] val )
146146

147147
public static Value value( char[] val )
148148
{
149-
return new TextValue( new String( val ) );
149+
return new StringValue( new String( val ) );
150150
}
151151

152152
public static Value value( String[] val )
153153
{
154-
TextValue[] values = new TextValue[val.length];
154+
StringValue[] values = new StringValue[val.length];
155155
for ( int i = 0; i < val.length; i++ )
156156
{
157-
values[i] = new TextValue( val[i] );
157+
values[i] = new StringValue( val[i] );
158158
}
159159
return new ListValue( values );
160160
}
@@ -206,12 +206,12 @@ public static Value value( final boolean val )
206206

207207
public static Value value( final char val )
208208
{
209-
return new TextValue( Character.toString( val ) );
209+
return new StringValue( Character.toString( val ) );
210210
}
211211

212212
public static Value value( final String val )
213213
{
214-
return new TextValue( val );
214+
return new StringValue( val );
215215
}
216216

217217
public static Value value( final Map<String,Object> val )

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ else if ( value.isFloat() )
231231
{
232232
packer.pack( value.javaDouble() );
233233
}
234-
else if ( value.isText() )
234+
else if ( value.isString() )
235235
{
236236
packer.pack( value.javaString() );
237237
}
@@ -501,7 +501,7 @@ private Value unpackValue() throws IOException
501501
return value( unpacker.unpackLong() );
502502
case FLOAT:
503503
return value( unpacker.unpackDouble() );
504-
case TEXT:
504+
case STRING:
505505
return value( unpacker.unpackString() );
506506
case MAP:
507507
{

driver/src/main/java/org/neo4j/driver/internal/packstream/PackStream.java

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import java.util.List;
2626
import java.util.Map;
2727

28-
import org.neo4j.driver.Value;
29-
3028
import static java.lang.Integer.toHexString;
3129
import static java.lang.String.format;
3230
import static java.util.Arrays.asList;
@@ -44,7 +42,7 @@
4442
* <table>
4543
* <tr><th>Marker</th><th>Binary</th><th>Type</th><th>Description</th></tr>
4644
* <tr><td><code>00..7F</code></td><td><code>0xxxxxxx</code></td><td>+TINY_INT</td><td>Integer 0 to 127</td></tr>
47-
* <tr><td><code>80..8F</code></td><td><code>1000xxxx</code></td><td>TINY_TEXT</td><td></td></tr>
45+
* <tr><td><code>80..8F</code></td><td><code>1000xxxx</code></td><td>TINY_STRING</td><td></td></tr>
4846
* <tr><td><code>90..9F</code></td><td><code>1001xxxx</code></td><td>TINY_LIST</td><td></td></tr>
4947
* <tr><td><code>A0..AF</code></td><td><code>1010xxxx</code></td><td>TINY_MAP</td><td></td></tr>
5048
* <tr><td><code>B0..BF</code></td><td><code>1011xxxx</code></td><td>TINY_STRUCT</td><td></td></tr>
@@ -61,9 +59,9 @@
6159
* <tr><td><code>CD</code></td><td><code>11001101</code></td><td>BYTES_16</td><td>Byte string (fewer than 2<sup>16</sup> bytes)</td></tr>
6260
* <tr><td><code>CE</code></td><td><code>11001110</code></td><td>BYTES_32</td><td>Byte string (fewer than 2<sup>32</sup> bytes)</td></tr>
6361
* <tr><td><code>CF</code></td><td><code>11001111</code></td><td><em>RESERVED</em></td><td></td></tr>
64-
* <tr><td><code>D0</code></td><td><code>11010000</code></td><td>TEXT_8</td><td>UTF-8 encoded text string (fewer than 2<sup>8</sup> bytes)</td></tr>
65-
* <tr><td><code>D1</code></td><td><code>11010001</code></td><td>TEXT_16</td><td>UTF-8 encoded text string (fewer than 2<sup>16</sup> bytes)</td></tr>
66-
* <tr><td><code>D2</code></td><td><code>11010010</code></td><td>TEXT_32</td><td>UTF-8 encoded text string (fewer than 2<sup>32</sup> bytes)</td></tr>
62+
* <tr><td><code>D0</code></td><td><code>11010000</code></td><td>STRING_8</td><td>UTF-8 encoded string (fewer than 2<sup>8</sup> bytes)</td></tr>
63+
* <tr><td><code>D1</code></td><td><code>11010001</code></td><td>STRING_16</td><td>UTF-8 encoded string (fewer than 2<sup>16</sup> bytes)</td></tr>
64+
* <tr><td><code>D2</code></td><td><code>11010010</code></td><td>STRING_32</td><td>UTF-8 encoded string (fewer than 2<sup>32</sup> bytes)</td></tr>
6765
* <tr><td><code>D3</code></td><td><code>11010011</code></td><td><em>RESERVED</em></td><td></td></tr>
6866
* <tr><td><code>D4</code></td><td><code>11010100</code></td><td>LIST_8</td><td>List (fewer than 2<sup>8</sup> items)</td></tr>
6967
* <tr><td><code>D5</code></td><td><code>11010101</code></td><td>LIST_16</td><td>List (fewer than 2<sup>16</sup> items)</td></tr>
@@ -85,7 +83,7 @@
8583
public class PackStream
8684
{
8785

88-
public static final byte TINY_TEXT = (byte) 0x80;
86+
public static final byte TINY_STRING = (byte) 0x80;
8987
public static final byte TINY_LIST = (byte) 0x90;
9088
public static final byte TINY_MAP = (byte) 0xA0;
9189
public static final byte TINY_STRUCT = (byte) 0xB0;
@@ -105,9 +103,9 @@ public class PackStream
105103
public static final byte BYTES_16 = (byte) 0xCD;
106104
public static final byte BYTES_32 = (byte) 0xCE;
107105
public static final byte RESERVED_CF = (byte) 0xCF;
108-
public static final byte TEXT_8 = (byte) 0xD0;
109-
public static final byte TEXT_16 = (byte) 0xD1;
110-
public static final byte TEXT_32 = (byte) 0xD2;
106+
public static final byte STRING_8 = (byte) 0xD0;
107+
public static final byte STRING_16 = (byte) 0xD1;
108+
public static final byte STRING_32 = (byte) 0xD2;
111109
public static final byte RESERVED_D3 = (byte) 0xD3;
112110
public static final byte LIST_8 = (byte) 0xD4;
113111
public static final byte LIST_16 = (byte) 0xD5;
@@ -242,17 +240,17 @@ public void pack( String value ) throws IOException
242240
else
243241
{
244242
byte[] utf8 = value.getBytes( UTF_8 );
245-
packTextHeader( utf8.length );
243+
packStringHeader( utf8.length );
246244
packRaw( utf8 );
247245
}
248246
}
249247

250-
public void packText( byte[] utf8 ) throws IOException
248+
public void packString( byte[] utf8 ) throws IOException
251249
{
252250
if ( utf8 == null ) { packNull(); }
253251
else
254252
{
255-
packTextHeader( utf8.length );
253+
packStringHeader( utf8.length );
256254
packRaw( utf8 );
257255
}
258256
}
@@ -329,25 +327,25 @@ else if ( size <= Short.MAX_VALUE )
329327
}
330328
}
331329

332-
public void packTextHeader( int size ) throws IOException
330+
public void packStringHeader( int size ) throws IOException
333331
{
334332
if ( size < 0x10 )
335333
{
336-
out.writeByte( (byte) (TINY_TEXT | size) );
334+
out.writeByte( (byte) (TINY_STRING | size) );
337335
}
338336
else if ( size <= Byte.MAX_VALUE )
339337
{
340-
out.writeByte( TEXT_8 )
338+
out.writeByte( STRING_8 )
341339
.writeByte( (byte) size );
342340
}
343341
else if ( size <= Short.MAX_VALUE )
344342
{
345-
out.writeByte( TEXT_16 )
343+
out.writeByte( STRING_16 )
346344
.writeShort( (short) size );
347345
}
348346
else
349347
{
350-
out.writeByte( TEXT_32 )
348+
out.writeByte( STRING_32 )
351349
.writeInt( size );
352350
}
353351
}
@@ -537,7 +535,7 @@ public double unpackDouble() throws IOException
537535
public String unpackString() throws IOException
538536
{
539537
final byte markerByte = in.readByte();
540-
if( markerByte == TINY_TEXT ) // Note no mask, so we compare to 0x80.
538+
if( markerByte == TINY_STRING ) // Note no mask, so we compare to 0x80.
541539
{
542540
return EMPTY_STRING;
543541
}
@@ -591,12 +589,12 @@ private byte[] unpackUtf8(byte markerByte) throws IOException
591589
final byte markerHighNibble = (byte) (markerByte & 0xF0);
592590
final byte markerLowNibble = (byte) (markerByte & 0x0F);
593591

594-
if ( markerHighNibble == TINY_TEXT ) { return unpackBytes( markerLowNibble ); }
592+
if ( markerHighNibble == TINY_STRING ) { return unpackBytes( markerLowNibble ); }
595593
switch(markerByte)
596594
{
597-
case TEXT_8: return unpackBytes( unpackUINT8() );
598-
case TEXT_16: return unpackBytes( unpackUINT16() );
599-
case TEXT_32:
595+
case STRING_8: return unpackBytes( unpackUINT8() );
596+
case STRING_16: return unpackBytes( unpackUINT16() );
597+
case STRING_32:
600598
{
601599
long size = unpackUINT32();
602600
if ( size <= Integer.MAX_VALUE )
@@ -605,7 +603,7 @@ private byte[] unpackUtf8(byte markerByte) throws IOException
605603
}
606604
else
607605
{
608-
throw new Overflow( "TEXT_32 too long for Java" );
606+
throw new Overflow( "STRING_32 too long for Java" );
609607
}
610608
}
611609
default: throw new Unexpected( "Expected a string, but got: 0x" + toHexString( markerByte & 0xFF ));
@@ -655,7 +653,7 @@ public PackType peekNextType() throws IOException
655653

656654
switch(markerHighNibble)
657655
{
658-
case TINY_TEXT: return PackType.TEXT;
656+
case TINY_STRING: return PackType.STRING;
659657
case TINY_LIST: return PackType.LIST;
660658
case TINY_MAP: return PackType.MAP;
661659
case TINY_STRUCT: return PackType.STRUCT;
@@ -674,10 +672,10 @@ public PackType peekNextType() throws IOException
674672
case BYTES_16:
675673
case BYTES_32:
676674
return PackType.BYTES;
677-
case TEXT_8:
678-
case TEXT_16:
679-
case TEXT_32:
680-
return PackType.TEXT;
675+
case STRING_8:
676+
case STRING_16:
677+
case STRING_32:
678+
return PackType.STRING;
681679
case LIST_8:
682680
case LIST_16:
683681
case LIST_32:

driver/src/main/java/org/neo4j/driver/internal/packstream/PackType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020

2121
public enum PackType
2222
{
23-
NULL, BOOLEAN, INTEGER, FLOAT, BYTES, TEXT, LIST, MAP, STRUCT
23+
NULL, BOOLEAN, INTEGER, FLOAT, BYTES,
24+
STRING, LIST, MAP, STRUCT
2425
}

driver/src/main/java/org/neo4j/driver/internal/value/TextValue.java renamed to driver/src/main/java/org/neo4j/driver/internal/value/StringValue.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
*/
1919
package org.neo4j.driver.internal.value;
2020

21-
public class TextValue extends ValueAdapter
21+
public class StringValue extends ValueAdapter
2222
{
2323
private final String val;
2424

25-
public TextValue( String val )
25+
public StringValue( String val )
2626
{
2727
assert val != null;
2828
this.val = val;
@@ -41,7 +41,7 @@ public String javaString()
4141
}
4242

4343
@Override
44-
public boolean isText()
44+
public boolean isString()
4545
{
4646
return true;
4747
}
@@ -70,7 +70,7 @@ public boolean equals( Object o )
7070
return false;
7171
}
7272

73-
TextValue values = (TextValue) o;
73+
StringValue values = (StringValue) o;
7474

7575
return val.equals( values.val );
7676

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public Iterable<String> keys()
133133
}
134134

135135
@Override
136-
public boolean isText()
136+
public boolean isString()
137137
{
138138
return false;
139139
}
@@ -209,7 +209,7 @@ protected String typeName()
209209
if ( isFloat() ) { return "float"; }
210210
if ( isInteger() ) { return "integer"; }
211211
if ( isBoolean() ) { return "boolean"; }
212-
if ( isText() ) { return "text"; }
212+
if ( isString() ) { return "string"; }
213213
if ( isList() ) { return "list"; }
214214
if ( isMap() ) { return "map"; }
215215
if ( isIdentity() ) { return "identity"; }

driver/src/test/java/org/neo4j/driver/integration/ParametersIT.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void shouldBeAbleToSetAndReturnCharacterProperty()
152152
for ( Record record : result.retain() )
153153
{
154154
Value value = record.get( "a.value" );
155-
assertThat( value.isText(), equalTo( true ) );
155+
assertThat( value.isString(), equalTo( true ) );
156156
assertThat( value.javaString(), equalTo( "ö" ) );
157157
}
158158

@@ -170,7 +170,7 @@ public void shouldBeAbleToSetAndReturnCharacterArrayProperty()
170170
for ( Record record : result.retain() )
171171
{
172172
Value value = record.get( "a.value" );
173-
assertThat( value.isText(), equalTo( true ) );
173+
assertThat( value.isString(), equalTo( true ) );
174174
assertThat( value.javaString(), equalTo( "Mjölnir" ) );
175175
}
176176

@@ -187,7 +187,7 @@ public void shouldBeAbleToSetAndReturnStringProperty()
187187
for ( Record record : result.retain() )
188188
{
189189
Value value = record.get( "a.value" );
190-
assertThat( value.isText(), equalTo( true ) );
190+
assertThat( value.isString(), equalTo( true ) );
191191
assertThat( value.javaString(), equalTo( "Mjölnir" ) );
192192
}
193193

@@ -278,7 +278,7 @@ public void shouldBeAbleToSetAndReturnSpecialStringArrayProperty()
278278
assertThat( value.size(), equalTo( 3L ) );
279279
for ( Value item : value )
280280
{
281-
assertThat( item.isText(), equalTo( true ) );
281+
assertThat( item.isString(), equalTo( true ) );
282282
assertThat( item.javaString(), equalTo( "Mjölnir" ) );
283283
}
284284
}
@@ -300,7 +300,7 @@ public void shouldBeAbleToSetAndReturnStringArrayProperty()
300300
assertThat( value.size(), equalTo( 3L ) );
301301
for ( Value item : value )
302302
{
303-
assertThat( item.isText(), equalTo( true ) );
303+
assertThat( item.isString(), equalTo( true ) );
304304
assertThat( item.javaString(), equalTo( "cat" ) );
305305
}
306306
}
@@ -373,7 +373,7 @@ public void shouldBeAbleToSetAndReturnStringPropertyWithinMap()
373373
for ( Record record : result.retain() )
374374
{
375375
Value value = record.get( "a.value" );
376-
assertThat( value.isText(), equalTo( true ) );
376+
assertThat( value.isString(), equalTo( true ) );
377377
assertThat( value.javaString(), equalTo( "Mjölnir" ) );
378378
}
379379
}

driver/src/test/java/org/neo4j/driver/internal/ValuesTest.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,16 @@
2929
import org.neo4j.driver.Value;
3030
import org.neo4j.driver.Values;
3131
import org.neo4j.driver.exceptions.ClientException;
32-
import org.neo4j.driver.internal.value.BooleanValue;
33-
import org.neo4j.driver.internal.value.FloatValue;
34-
import org.neo4j.driver.internal.value.IntegerValue;
3532
import org.neo4j.driver.internal.value.ListValue;
3633
import org.neo4j.driver.internal.value.MapValue;
37-
import org.neo4j.driver.internal.value.TextValue;
34+
import org.neo4j.driver.internal.value.StringValue;
3835

3936
import static org.hamcrest.CoreMatchers.equalTo;
4037
import static org.hamcrest.MatcherAssert.assertThat;
4138
import static org.junit.Assert.assertEquals;
42-
import static org.junit.Assert.assertFalse;
4339
import static org.junit.Assert.assertNotEquals;
4440
import static org.neo4j.driver.Values.value;
45-
import static org.neo4j.driver.Values.valueToBoolean;
46-
import static org.neo4j.driver.Values.valueToDouble;
47-
import static org.neo4j.driver.Values.valueToFloat;
48-
import static org.neo4j.driver.Values.valueToInt;
4941
import static org.neo4j.driver.Values.valueToList;
50-
import static org.neo4j.driver.Values.valueToLong;
5142
import static org.neo4j.driver.Values.valueToString;
5243
import static org.neo4j.driver.Values.values;
5344

@@ -66,7 +57,7 @@ public void shouldConvertPrimitiveArrays() throws Throwable
6657
equalTo( (Value) new ListValue( values( 1, 2, 3 ) ) ) );
6758

6859
assertThat( value( new char[]{'a', 'b', 'c'} ),
69-
equalTo( (Value) new TextValue( "abc" ) ) );
60+
equalTo( (Value) new StringValue( "abc" ) ) );
7061

7162
assertThat( value( new long[]{1, 2, 3} ),
7263
equalTo( (Value) new ListValue( values( 1, 2, 3 ) ) ) );

0 commit comments

Comments
 (0)