summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorWouter van Oortmerssen <wvo@google.com>2016-08-26 13:57:40 -0700
committerWouter van Oortmerssen <wvo@google.com>2016-08-26 13:58:16 -0700
commite1f8037cb55cbeac5d96ad63c2f5c70560737340 (patch)
treef40d000c0c13692455d8676b39f4d57c697d8aef /java
parent49ee30a20752b4876a30bfded80c69f5babc9cb2 (diff)
downloadflatbuffers-e1f8037cb55cbeac5d96ad63c2f5c70560737340.tar.gz
flatbuffers-e1f8037cb55cbeac5d96ad63c2f5c70560737340.tar.bz2
flatbuffers-e1f8037cb55cbeac5d96ad63c2f5c70560737340.zip
Fixed Java LookupByKey functionality for Java 1.6
Tested: on Linux. Change-Id: Iea336f75a3b6e722743563813c3c9ed9db4d02fe
Diffstat (limited to 'java')
-rw-r--r--java/com/google/flatbuffers/Table.java22
1 files changed, 16 insertions, 6 deletions
diff --git a/java/com/google/flatbuffers/Table.java b/java/com/google/flatbuffers/Table.java
index c9c65456..b853842a 100644
--- a/java/com/google/flatbuffers/Table.java
+++ b/java/com/google/flatbuffers/Table.java
@@ -37,6 +37,12 @@ public class Table {
return Charset.forName("UTF-8").newDecoder();
}
};
+ public final static ThreadLocal<Charset> UTF8_CHARSET = new ThreadLocal<Charset>() {
+ @Override
+ protected Charset initialValue() {
+ return Charset.forName("UTF-8");
+ }
+ };
private final static ThreadLocal<CharBuffer> CHAR_BUFFER = new ThreadLocal<CharBuffer>();
/** Used to hold the position of the `bb` buffer. */
protected int bb_pos;
@@ -75,7 +81,7 @@ public class Table {
protected int __indirect(int offset) {
return offset + bb.getInt(offset);
}
-
+
protected static int __indirect(int offset, ByteBuffer bb) {
return offset + bb.getInt(offset);
}
@@ -197,17 +203,21 @@ public class Table {
}
return true;
}
-
+
/**
* Sort tables by the key.
*
* @param offsets An 'int' indexes of the tables into the bb.
* @param bb A {@code ByteBuffer} to get the tables.
*/
- protected void sortTables(int[] offsets, ByteBuffer bb) {
+ protected void sortTables(int[] offsets, final ByteBuffer bb) {
Integer[] off = new Integer[offsets.length];
for (int i = 0; i < offsets.length; i++) off[i] = offsets[i];
- Arrays.sort(off, (Integer o1, Integer o2) -> keysCompare(o1, o2, bb));
+ java.util.Arrays.sort(off, new java.util.Comparator<Integer>() {
+ public int compare(Integer o1, Integer o2) {
+ return keysCompare(o1, o2, bb);
+ }
+ });
for (int i = 0; i < offsets.length; i++) offsets[i] = off[i];
}
@@ -219,7 +229,7 @@ public class Table {
* @param bb A {@code ByteBuffer} to get the keys.
*/
protected int keysCompare(Integer o1, Integer o2, ByteBuffer bb) { return 0; }
-
+
/**
* Compare two strings in the buffer.
*
@@ -242,7 +252,7 @@ public class Table {
}
return len_1 - len_2;
}
-
+
/**
* Compare string from the buffer with the 'String' object.
*