@Override public int compareTo(Id other) { return this.id.compareTo(other.asString()); }
@Override public int compareTo(Id other) { return Long.compare(this.id, other.asLong()); }
protected static boolean indexIdLengthExceedLimit(Id id) { return id.asBytes().length > BytesBuffer.INDEX_ID_MAX_LENGTH; }
public BytesBuffer writeId(Id id, boolean big) { boolean number = id.number(); if (number) { long value = id.asLong(); this.writeNumber(value); } else { byte[] bytes = id.asBytes(); int len = bytes.length; E.checkArgument(len > 0, "Can't write empty id"); if (!big) { E.checkArgument(len <= ID_MAX_LEN, "Id max length is %s, but got %s {%s}", ID_MAX_LEN, len, id); len -= 1; // mapping [1, 128] to [0, 127] this.writeUInt8(len | 0x80); } else { E.checkArgument(len <= BIG_ID_MAX_LEN, "Big id max length is %s, but got %s", BIG_ID_MAX_LEN, len); len -= 1; int high = len >> 8; int low = len & 0xff; this.writeUInt8(high | 0x80); this.writeUInt8(low); } this.write(bytes); } return this; }
protected static Object serializeValue(Object value) { // Serialize value (TODO: should move to Serializer) if (value instanceof Id) { value = ((Id) value).asObject(); } return value; }
private byte[] writeId(Id id) { int size = 1 + id.length(); BytesBuffer buffer = BytesBuffer.allocate(size); buffer.writeId(id); return buffer.bytes(); }
protected List<Object> idColumnValue(Id id) { return ImmutableList.of(id.asObject()); }
private byte[] writeIds(Collection<Id> ids) { E.checkState(ids.size() <= BytesBuffer.UINT16_MAX, "The number of properties of vertex/edge label " + "cannot exceed '%s'", BytesBuffer.UINT16_MAX); int size = 2; for (Id id : ids) { size += (1 + id.length()); } BytesBuffer buffer = BytesBuffer.allocate(size); buffer.writeUInt16(ids.size()); for (Id id : ids) { buffer.writeId(id); } return buffer.bytes(); }
public static String desc(String prefix, Collection<Id> elems) { StringBuilder sb = new StringBuilder(); for (Id elem : elems) { sb.append("\"").append(elem.asString()).append("\","); } int endIdx = sb.lastIndexOf(",") > 0 ? sb.length() - 1 : sb.length(); return String.format(".%s(%s)", prefix, sb.substring(0, endIdx)); }
@Override protected Object toLongList(Collection<Id> ids) { List<Long> results = new ArrayList<>(ids.size()); for (Id id : ids) { results.add(id.asLong()); } return results; }
protected List<Object> idColumnValue(Id id) { return ImmutableList.of(id.asObject()); }
@Override public BinaryBackendEntry newBackendEntry(HugeType type, Id id) { BytesBuffer buffer = BytesBuffer.allocate(1 + id.length()); BinaryId bid = new BinaryId(buffer.writeId(id).bytes(), id); return new BinaryBackendEntry(type, bid); }