Skip to content

Commit 3aa0d19

Browse files
add toString() method for the NativeArray class
1 parent c42b487 commit 3aa0d19

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/main/java/io/tiledb/java/api/NativeArray.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,25 @@ public long getNBytes() {
11081108
return ((long) size) * nativeTypeSize;
11091109
}
11101110

1111+
@Override
1112+
public String toString() {
1113+
StringBuilder result = new StringBuilder("[");
1114+
for (int i = 0; i < this.size; i++) {
1115+
if (floatArray != null) result.append(this.floatArray.getitem(i)).append(", ");
1116+
else if (doubleArray != null) result.append(this.doubleArray.getitem(i)).append(", ");
1117+
else if (int8_tArray != null) result.append(this.int8_tArray.getitem(i)).append(", ");
1118+
else if (int16_tArray != null) result.append(this.int16_tArray.getitem(i)).append(", ");
1119+
else if (int32_tArray != null) result.append(this.int32_tArray.getitem(i)).append(", ");
1120+
else if (int64_tArray != null) result.append(this.int64_tArray.getitem(i)).append(", ");
1121+
else if (uint8_tArray != null) result.append(this.uint8_tArray.getitem(i)).append(", ");
1122+
else if (uint16_tArray != null) result.append(this.uint16_tArray.getitem(i)).append(", ");
1123+
else if (uint32_tArray != null) result.append(this.uint32_tArray.getitem(i)).append(", ");
1124+
else if (uint64_tArray != null) result.append(this.uint64_tArray.getitem(i)).append(", ");
1125+
}
1126+
result = new StringBuilder(result.substring(0, result.length() - 2));
1127+
return result + "]";
1128+
}
1129+
11111130
/** Free's NativeArray off heap allocated resources */
11121131
public void close() {
11131132
if (floatArray != null) {

0 commit comments

Comments
 (0)