edu.stanford.protege.webprotege.object.OWLEntitySelector Maven / Gradle / Ivy
The newest version!
package edu.stanford.protege.webprotege.object;
import org.semanticweb.owlapi.model.EntityType;
import org.semanticweb.owlapi.model.OWLEntity;
import org.semanticweb.owlapi.model.OWLObject;
import java.util.Comparator;
import java.util.Optional;
/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 04/02/15
*/
public abstract class OWLEntitySelector implements OWLObjectSelector {
private final EntityType entityType;
private final Comparator super E> entityComparator;
public OWLEntitySelector(EntityType entityType, Comparator super E> entityComparator) {
this.entityType = entityType;
this.entityComparator = entityComparator;
}
@Override
public Optional selectOne(Iterable objects) {
Optional result = Optional.empty();
for (OWLObject obj : objects) {
if (obj instanceof OWLEntity) {
OWLEntity entity = (OWLEntity) obj;
if(entity.getEntityType() == entityType) {
E currentEntity = (E) entity;
if (result.isPresent()) {
if (entityComparator.compare(currentEntity, result.get()) < 0) {
result = Optional.of(currentEntity);
}
} else {
result = Optional.of(currentEntity);
}
}
}
}
if (result.isPresent()) {
return Optional.of(toType(result.get()));
}
else {
return Optional.empty();
}
}
protected abstract T toType(E entity);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy