class CollectionQueryEngine implements QueryEngineInternal<O> {

    @Override
    public void removeIndex(Index<O> index, QueryOptions queryOptions) {
        boolean removed;
        if (index instanceof StandingQueryIndex) {
            @SuppressWarnings({"unchecked"})
            StandingQueryIndex<O> standingQueryIndex = (StandingQueryIndex<O>) index;

            removed = standingQueryIndexes.remove(standingQueryIndex.getStandingQuery(), standingQueryIndex);
        }
        else if (index instanceof CompoundIndex) {
            @SuppressWarnings({"unchecked"})
            CompoundIndex<O> compoundIndex = (CompoundIndex<O>) index;
            CompoundAttribute<O> compoundAttribute = compoundIndex.getAttribute();

            removed = compoundIndexes.remove(compoundAttribute, compoundIndex);
        }
        else if (index instanceof AttributeIndex) {
            @SuppressWarnings({"unchecked"})
            AttributeIndex<?, O> attributeIndex = (AttributeIndex<?, O>) index;
            Attribute<O, ?> indexedAttribute = attributeIndex.getAttribute();

            if (indexedAttribute instanceof StandingQueryAttribute) {
                @SuppressWarnings("unchecked")
                StandingQueryAttribute<O> standingQueryAttribute = (StandingQueryAttribute<O>) indexedAttribute;
                Query<O> standingQuery = standingQueryAttribute.getQuery();

                removed = standingQueryIndexes.remove(standingQuery, index);
            }
            else {
                Set<Index<O>> indexesOnThisAttribute = attributeIndexes.get(indexedAttribute);

                removed = indexesOnThisAttribute.remove(attributeIndex);

                if (attributeIndex instanceof UniqueIndex) {
                    // Remove from UniqueIndexes as well...
                    removed = uniqueIndexes.remove(indexedAttribute, attributeIndex) || removed;
                }

                if (indexesOnThisAttribute.isEmpty()) {
                    // If there are no more indexes left on this attribute,
                    // remove the Set which was used to store indexes on the attribute also...
                    attributeIndexes.remove(indexedAttribute);
                }
            }
        }
        else {
            throw new IllegalStateException("Unexpected type of index: " + (index == null ? null : index.getClass().getName()));
        }
        if (removed && !index.isMutable()) {
            // Remove from the set of immutable indexes; this is used by ensureMutable() and the isMutable() method...
            immutableIndexes.remove(index);
        }
        // Notify the index that it has been removed, so that it can delete underlying storage used if necessary...
        index.destroy(queryOptions);
    }

    public  CollectionQueryEngine();

}