Merge pull request #3978 from TGIshib/key
authorWouter van Oortmerssen <wvo@google.com>
Fri, 26 Aug 2016 19:03:28 +0000 (12:03 -0700)
committerGitHub <noreply@github.com>
Fri, 26 Aug 2016 19:03:28 +0000 (12:03 -0700)
Find by key on C# and Java (2)

1  2 
java/com/google/flatbuffers/FlatBufferBuilder.java
tests/JavaTest.java

@@@ -367,29 -367,32 +367,54 @@@ public class FlatBufferBuilder 
      }
      /// @endcond
  
 +    /**
 +     * Create a new array/vector and return a ByteBuffer to be filled later.
 +     * Call {@link #endVector} after this method to get an offset to the beginning
 +     * of vector.
 +     *
 +     * @param elem_size the size of each element in bytes.
 +     * @param num_elems number of elements in the vector.
 +     * @param alignment byte alignment.
 +     * @return ByteBuffer with position and limit set to the space allocated for the array.
 +     */
 +    public ByteBuffer createUnintializedVector(int elem_size, int num_elems, int alignment) {
 +        int length = elem_size * num_elems;
 +        startVector(elem_size, num_elems, alignment);
 +
 +        bb.position(space -= length);
 +
 +        // Slice and limit the copy vector to point to the 'array'
 +        ByteBuffer copy = bb.slice().order(ByteOrder.LITTLE_ENDIAN);
 +        copy.limit(length);
 +        return copy;
 +    }
 +
     /**
+      * Create a vector of tables.
+      *
+      * @param offsets Offsets of the tables.
+      * @return Returns offset of the vector.
+      */
+     public int createVectorOfTables(int[] offsets) {
+         notNested();
+         startVector(Constants.SIZEOF_INT, offsets.length, Constants.SIZEOF_INT);
+         for(int i = offsets.length - 1; i >= 0; i--) addOffset(offsets[i]);
+         return endVector();
+     }
+     /**
+      * Create a vector of sorted by the key tables.
+      *
+      * @param obj Instance of the table subclass.
+      * @param offsets Offsets of the tables.
+      * @return Returns offset of the sorted vector.
+      */
+     public <T extends Table> int createSortedVectorOfTables(T obj, int[] offsets) {
+         obj.sortTables(offsets, bb);
+         return createVectorOfTables(offsets);
+     }
+       
+    /**
      * Encode the string `s` in the buffer using UTF-8.  If {@code s} is
      * already a {@link CharBuffer}, this method is allocation free.
      *
Simple merge