}
}
}
public static boolean instanceOf(final Sequence<? extends Item> value, final Type type) {
final Occurrence occ = type.quantifier();
if(value.isEmpty()) {
return occ.accepts(Occurrence.OCC_ZERO.getAlignment());
}
final Type expected = (type instanceof SequenceType) ? ((SequenceType) type).prime() : type;
int count = 0;
final IFocus<? extends Item> valueItor = value.iterator();
for(Item it : valueItor) {
final Type actual = it.getType();
if(!subtypeOf(actual, expected)) {
valueItor.closeQuietly();
return false;
}
count++;
}
valueItor.closeQuietly();
if(count == 0) {
throw new IllegalStateException();
}
if(count == 1) {
return occ.accepts(Occurrence.OCC_EXACTLY_ONE.getAlignment());
} else {
return occ.accepts(Occurrence.OCC_MORE.getAlignment());
}
}