/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.reflection.impl;

import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
import net.ranides.assira.collection.query.CQuery;
import net.ranides.assira.collection.query.CQueryBuilder;
import net.ranides.assira.reflection.*;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class AAnnotations extends AElements<Annotation> implements IAnnotations {
    
    public static final AAnnotations EMPTY = FElements.newAnnotations(AHints.EMPTY, CQueryBuilder.empty());

    AAnnotations(IHints hints, CQuery<Annotation> stream) {
        super(hints, stream);
    }
    
    @Override
    public List<String> names() {
        return list(a -> a.annotationType().getName());
    }

    @Override
    public <A extends Annotation> Optional<A> first(Class<A> type) {
        return (Optional<A>)require(a -> type.isInstance(a)).first();
    }

    @Override
    public IAnnotations require(Predicate<? super Annotation> predicate) {
        filter(predicate);
        return this;
    }

    @Override
    public IAnnotations require(Class<? extends Annotation> type) {
        return require(a -> type.isInstance(a));
    }

    @Override
    public IAnnotations discard(Predicate<? super Annotation> predicate) {
        return require(predicate.negate());
    }

    @Override
    public IAnnotations discard(Class<? extends Annotation> type) {
        return require(a -> !type.isInstance(a));
    }

    @Override
    public IElements<? extends IElement> parent() {
        throw new UnsupportedOperationException("Annotations don't have parents");
    }
    
}
