@SuppressWarnings("unchecked") public void deserialize(ByteBuffer b) { serialized = b.duplicate(); components = new ArrayList<Component<?>>(); String comparator = null; int i = 0; while ((comparator = getComparator(i, b)) != null) { ByteBuffer data = getWithShortLength(b); if (data != null) { Serializer<?> s = getSerializer(i, comparator); ComponentEquality equality = ComponentEquality.fromByte(b.get()); components.add(new Component(null, data.slice(), s, comparator, equality)); } else { throw new RuntimeException("Missing component data in composite type"); } i++; } }
public <T> T get(int i, Serializer<T> s) throws ClassCastException { T value = null; Component<?> c = components.get(i); if (c != null) { value = c.getValue(s); } return value; }
for (Component c : components) { Serializer<?> s = serializerForPosition(i); ByteBuffer cb = c.getBytes(s); if (cb == null) { cb = ByteBuffer.allocate(0); String comparator = comparatorForPosition(i); if (comparator == null) { comparator = c.getComparator(); out.write(c.getEquality().toByte()); i++;
@SuppressWarnings("unchecked") @Override public Object set(int index, Object element) { serialized = null; if (element instanceof Component) { Component prev = components.set(index, (Component<?>) element); if (prev != null) { return prev.getValue(); } return null; } element = mapIfNumber(element); Serializer s = serializerForPosition(index); if (s == null) { s = SerializerTypeInferer.getSerializer(element); } String c = comparatorForPosition(index); if (c == null) { c = comparatorForSerializer(s); } Component prev = components.set(index, new Component(element, null, s, c, ComponentEquality.EQUAL)); if (prev != null) { return prev.getValue(); } return null; }
@SuppressWarnings("unchecked") @Override public void add(int index, Object element) { serialized = null; if (element instanceof Component) { components.add(index, (Component<?>) element); return; } element = mapIfNumber(element); Serializer s = serializerForPosition(index); if (s == null) { s = SerializerTypeInferer.getSerializer(element); } String c = comparatorForPosition(index); if (c == null) { c = comparatorForSerializer(s); } components.add(index, new Component(element, null, s, c, ComponentEquality.EQUAL)); }
@SuppressWarnings("unchecked") public <T> AbstractComposite addComponent(int index, T value, Serializer<T> s, String comparator, ComponentEquality equality) { serialized = null; if (index < 0) { index = components.size(); } while (components.size() < index) { components.add(null); } components.add(index, new Component(value, null, s, comparator, equality)); return this; }
public T getValue() { return getValue(serializer); }
public ByteBuffer getBytes() { return getBytes(serializer); }
@Override public String toString() { return "Component [" + getValue() + "]"; } }
@Override public Object remove(int index) { serialized = null; Component prev = components.remove(index); if (prev != null) { return prev.getValue(); } return null; }
@SuppressWarnings("unchecked") public <T> AbstractComposite setComponent(int index, T value, Serializer<T> s, String comparator, ComponentEquality equality) { serialized = null; while (components.size() <= index) { components.add(null); } components.set(index, new Component(value, null, s, comparator, equality)); return this; }
@Override public Object get(int i) { Component c = components.get(i); if (c != null) { return c.getValue(); } return null; }