All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.semanticweb.owlapi.search.AnnotationVisitor Maven / Gradle / Ivy

There is a newer version: 4.7.5
Show newest version
package org.semanticweb.owlapi.search;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import javax.annotation.Nonnull;

import org.semanticweb.owlapi.model.OWLAnnotation;
import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.util.CollectionFactory;
import org.semanticweb.owlapi.util.OWLAxiomVisitorExAdapter;

@SuppressWarnings("unchecked")
class AnnotationVisitor extends OWLAxiomVisitorExAdapter> {

    private final boolean value;

    AnnotationVisitor(boolean value) {
        super(CollectionFactory. emptySet());
        this.value = value;
    }

    @Nonnull
    @Override
    protected Set doDefault(@Nonnull OWLAxiom object) {
        return get(object.getAnnotations());
    }

    @Nonnull
    private Set get(@Nonnull Collection collection) {
        Set toReturn = new HashSet<>();
        for (OWLAnnotation c : collection) {
            if (value) {
                toReturn.add((C) c.getValue());
            } else {
                toReturn.add((C) c);
            }
        }
        return toReturn;
    }

    @Nonnull
    @Override
    public Set visit(@Nonnull OWLAnnotationAssertionAxiom axiom) {
        if (value) {
            return CollectionFactory.createSet((C) axiom.getValue());
        }
        return CollectionFactory.createSet((C) axiom.getAnnotation());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy