use of org.apache.cassandra.db.marshal.ListType in project cassandra by apache.
the class SSTableHeaderFixTest method freezeUdt.
private AbstractType<?> freezeUdt(AbstractType<?> type) {
if (type instanceof CollectionType) {
if (type.getClass() == ListType.class) {
ListType<?> cHeader = (ListType<?>) type;
return ListType.getInstance(freezeUdt(cHeader.getElementsType()), cHeader.isMultiCell());
} else if (type.getClass() == SetType.class) {
SetType<?> cHeader = (SetType<?>) type;
return SetType.getInstance(freezeUdt(cHeader.getElementsType()), cHeader.isMultiCell());
} else if (type.getClass() == MapType.class) {
MapType<?, ?> cHeader = (MapType<?, ?>) type;
return MapType.getInstance(freezeUdt(cHeader.getKeysType()), freezeUdt(cHeader.getValuesType()), cHeader.isMultiCell());
}
} else if (type instanceof AbstractCompositeType) {
if (type.getClass() == CompositeType.class) {
CompositeType cHeader = (CompositeType) type;
return CompositeType.getInstance(cHeader.types.stream().map(this::freezeUdt).collect(Collectors.toList()));
}
} else if (type instanceof TupleType) {
if (type.getClass() == UserType.class) {
UserType cHeader = (UserType) type;
cHeader = cHeader.freeze();
return new UserType(cHeader.keyspace, cHeader.name, cHeader.fieldNames(), cHeader.allTypes().stream().map(this::freezeUdt).collect(Collectors.toList()), cHeader.isMultiCell());
}
}
return type;
}
use of org.apache.cassandra.db.marshal.ListType in project cassandra by apache.
the class SSTableHeaderFixTest method assertFrozenUdt.
private void assertFrozenUdt(String name, AbstractType<?> type, boolean frozen, boolean checkInner) {
if (type instanceof CompositeType) {
if (checkInner)
for (AbstractType<?> component : ((CompositeType) type).types) assertFrozenUdt(name, component, frozen, true);
} else if (type instanceof CollectionType) {
if (checkInner) {
if (type instanceof MapType) {
MapType map = (MapType) type;
// only descend for non-frozen types (checking frozen in frozen is just stupid)
if (map.isMultiCell()) {
assertFrozenUdt(name + "<map-key>", map.getKeysType(), frozen, true);
assertFrozenUdt(name + "<map-value>", map.getValuesType(), frozen, true);
}
} else if (type instanceof SetType) {
SetType set = (SetType) type;
// only descend for non-frozen types (checking frozen in frozen is just stupid)
if (set.isMultiCell())
assertFrozenUdt(name + "<set>", set.getElementsType(), frozen, true);
} else if (type instanceof ListType) {
ListType list = (ListType) type;
// only descend for non-frozen types (checking frozen in frozen is just stupid)
if (list.isMultiCell())
assertFrozenUdt(name + "<list>", list.getElementsType(), frozen, true);
}
}
} else if (type instanceof TupleType) {
if (checkInner) {
TupleType tuple = (TupleType) type;
// only descend for non-frozen types (checking frozen in frozen is just stupid)
if (tuple.isMultiCell())
for (AbstractType<?> component : tuple.allTypes()) assertFrozenUdt(name + "<tuple>", component, frozen, true);
}
}
if (type instanceof UserType) {
String typeString = type.toString();
assertEquals(name + ": " + typeString, frozen, !type.isMultiCell());
if (typeString.startsWith(UserType.class.getName() + '('))
if (frozen)
fail(name + ": " + typeString);
if (typeString.startsWith(FrozenType.class.getName() + '(' + UserType.class.getName() + '('))
if (!frozen)
fail(name + ": " + typeString);
}
}
Aggregations