@Override public Term fromJSONObject(Object parsed) throws MarshalException { if (parsed instanceof String) parsed = Json.decodeJson((String) parsed); if (!(parsed instanceof List)) throw new MarshalException( String.format( "Expected a list (representing a set), but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); List list = (List) parsed; Set<Term> terms = new HashSet<>(list.size()); for (Object element : list) { if (element == null) throw new MarshalException("Invalid null element in set"); terms.add(elements.fromJSONObject(element)); } return new Sets.DelayedValue(elements, terms); }
static int compareListOrSet(AbstractType<?> elementsComparator, ByteBuffer o1, ByteBuffer o2) { // Note that this is only used if the collection is inside an UDT if (!o1.hasRemaining() || !o2.hasRemaining()) return o1.hasRemaining() ? 1 : o2.hasRemaining() ? -1 : 0; ByteBuffer bb1 = o1.duplicate(); ByteBuffer bb2 = o2.duplicate(); int size1 = CollectionSerializer.readCollectionSize(bb1, 3); int size2 = CollectionSerializer.readCollectionSize(bb2, 3); for (int i = 0; i < Math.min(size1, size2); i++) { ByteBuffer v1 = CollectionSerializer.readValue(bb1, 3); ByteBuffer v2 = CollectionSerializer.readValue(bb2, 3); int cmp = elementsComparator.compare(v1, v2); if (cmp != 0) return cmp; } return size1 == size2 ? 0 : (size1 < size2 ? -1 : 1); }
private ListType(AbstractType<T> elements) { super(Kind.LIST); this.elements = elements; this.serializer = ListSerializer.getInstance(elements.getSerializer()); }
public SetType(AbstractType<T> elements, boolean isMultiCell) { super(ComparisonType.CUSTOM, Kind.SET); this.elements = elements; this.serializer = SetSerializer.getInstance(elements.getSerializer(), elements); this.isMultiCell = isMultiCell; }