private static<D,K> int getMetaDataSize(EntryMetaData[] schema, D entry, StaticArrayEntry.GetColVal<D,K> metaGetter) { int dataSize = 0; if (schema.length>0) { assert schema.length==metaGetter.getMetaSchema(entry).length; for (EntryMetaData meta : schema) { Object data = metaGetter.getMetaData(entry,meta); assert data!=null; dataSize+=getSerializer(meta).getByteLength(data); } } return dataSize; }
private static<D,K> int writeMetaData(byte[] data, int startPos, EntryMetaData[] schema, D entry, StaticArrayEntry.GetColVal<D,K> metaGetter) { if (schema.length==0) return startPos; for (EntryMetaData meta : schema) { Object d = metaGetter.getMetaData(entry,meta); assert d!=null; MetaDataSerializer s = getSerializer(meta); s.write(data,startPos,d); startPos+=s.getByteLength(d); } return startPos; }
@Override public void write(byte[] data, int startPos, Integer value) { assert data.length>=startPos+getByteLength(value); assert value!=null; StaticArrayBuffer.putInt(data, startPos, value); }
private static <E,D> Entry of(E element, StaticArrayEntry.GetColVal<E,D> getter, StaticArrayEntry.DataHandler<D> dataHandler) { StaticArrayEntry entry = of(getter.getColumn(element),getter.getValue(element),dataHandler); //Add meta data if exists if (getter.getMetaSchema(element).length>0) { for (EntryMetaData meta : getter.getMetaSchema(element)) { entry.setMetaData(meta,getter.getMetaData(element,meta)); } } return entry; }
public static StaticBuffer fillBuffer(int len, byte value) { byte[] res = new byte[len]; for (int i = 0; i < len; i++) res[i]=value; return StaticArrayBuffer.of(res); }
private static <E,D> StaticArrayEntry of(D column, D value, StaticArrayEntry.DataHandler<D> dataHandler) { int valuePos = dataHandler.getSize(column); byte[] data = new byte[valuePos+dataHandler.getSize(value)]; dataHandler.copy(column,data,0); dataHandler.copy(value,data,valuePos); return new StaticArrayEntry(data,valuePos); }
@Override public void write(byte[] data, int startPos, Long value) { assert data.length>=startPos+getByteLength(value); assert value!=null; StaticArrayBuffer.putLong(data,startPos,value); }
public byte[] getBytes(int length) { byte[] result = super.getBytes(position,length); position += length*BYTE_LEN; return result; }
/** * Returns a byte buffer representation for the given partition id * @param partition * @return */ protected StaticBuffer getPartitionKey(int partition) { return BufferUtil.getIntBuffer(partition); }
@Override public short getShort(int position) { int base = require(position, SHORT_LEN); return (short) (((array[base++] & 0xFF) << 8) | (array[base] & 0xFF)); }
public double[] getDoubles(int position, int length) { double[] result = new double[length]; for (int i = 0; i < length; i++) { result[i]=getDouble(position); position += DOUBLE_LEN; } return result; }
@Override public void setCache(RelationCache cache) { verifyAccess(); caches[currentIndex]=cache; }
@Override public Integer read(byte[] data, int startPos) { assert data.length>=startPos+4; return StaticArrayBuffer.getInt(data, startPos); } }
public short[] getShorts(int length) { short[] result = super.getShorts(position,length); position += length*SHORT_LEN; return result; }
@Override public DataOutput putBytes(byte[] val) { super.putBytes(val); return this; }
@Override public DataOutput putFloat(float val) { super.putFloat(val); return this; }
public static<R> R execute(final Transactional<R> exe, final TransactionalProvider provider, final TimestampProvider times, Duration maxTime) throws JanusGraphException { return execute(new Callable<R>() { @Override public R call() throws Exception { return execute(exe,provider,times); } @Override public String toString() { return exe.toString(); } },maxTime); }
/** * Compares two {@link java.nio.ByteBuffer}s and checks whether the first ByteBuffer is smaller than the second. * * @param a First ByteBuffer * @param b Second ByteBuffer * @return true if the first ByteBuffer is smaller than the second */ public static boolean isSmallerThan(ByteBuffer a, ByteBuffer b) { return compare(a, b)<0; }
public char[] getChars(int length) { char[] result = super.getChars(position,length); position += length*CHAR_LEN; return result; }
public static String bytesToHex(byte... bytes) { char[] c = new char[bytes.length * 2]; for (int i = 0; i < bytes.length; i++) { int byteAsInteger = bytes[i]; c[i * 2] = byteToChar[(byteAsInteger & 0xf0) >> 4]; c[1 + i * 2] = byteToChar[byteAsInteger & 0x0f]; } return wrapCharArray(c); }