Skip to content

Commit 4a0ac35

Browse files
committed
Rename Text#length to Text#stringLength
1 parent 7114fa9 commit 4a0ac35

File tree

1 file changed

+14
-6
lines changed
  • libs/x-content/src/main/java/org/elasticsearch/xcontent

1 file changed

+14
-6
lines changed

libs/x-content/src/main/java/org/elasticsearch/xcontent/Text.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,23 @@ public static Text[] convertFromStringArray(String[] strings) {
3434
private ByteBuffer bytes;
3535
private String text;
3636
private int hash;
37-
private int length = -1;
37+
private int stringLength = -1;
3838

39+
/**
40+
* Construct a Text from a UTF-8 encoded ByteBuffer. Since no string length is specified, {@link #stringLength()}
41+
* will perform a string conversion to measure the string length.
42+
*/
3943
public Text(ByteBuffer bytes) {
4044
this.bytes = bytes;
4145
}
4246

43-
public Text(ByteBuffer bytes, int length) {
47+
/**
48+
* Construct a Text from a UTF-8 encoded ByteBuffer and an explicit string length. Used to avoid string conversion
49+
* in {@link #stringLength()}.
50+
*/
51+
public Text(ByteBuffer bytes, int stringLength) {
4452
this.bytes = bytes;
45-
this.length = length;
53+
this.stringLength = stringLength;
4654
}
4755

4856
public Text(String text) {
@@ -81,10 +89,10 @@ public String string() {
8189

8290
@Override
8391
public int stringLength() {
84-
if (length < 0) {
85-
length = string().length();
92+
if (stringLength < 0) {
93+
stringLength = string().length();
8694
}
87-
return length;
95+
return stringLength;
8896
}
8997

9098
@Override

0 commit comments

Comments
 (0)