001/**
002 * Copyright (C) 2007 - 2016, Jens Lehmann
003 *
004 * This file is part of DL-Learner.
005 *
006 * DL-Learner is free software; you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation; either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * DL-Learner is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package org.dllearner.core.owl;
020
021import java.util.ArrayList;
022import java.util.List;
023import java.util.Set;
024import java.util.TreeSet;
025
026import org.semanticweb.owlapi.model.*;
027import org.semanticweb.owlapi.util.CollectionFactory;
028
029import uk.ac.manchester.cs.owl.owlapi.OWLAnonymousClassExpressionImpl;
030
031/**
032 * @author Matthew Horridge, The University Of Manchester, Bio-Health Informatics
033 *         Group, Date: 26-Oct-2006
034 *         
035 * modified by
036 * @author Lorenz Buehmann
037 * @since Jan 24, 2015
038 * 
039 * Modification: use a list instead of a set of operands to allow for 
040 * (A and A) as well as (A or A)
041 */
042public abstract class OWLNaryBooleanClassExpressionImplExt extends
043        OWLAnonymousClassExpressionImpl implements
044        OWLNaryBooleanClassExpression {
045
046    private static final long serialVersionUID = 30406L;
047    private final List<OWLClassExpression> operands;
048
049    /**
050     * @param operands
051     *        operands
052     */
053    public OWLNaryBooleanClassExpressionImplExt(
054            Set<? extends OWLClassExpression> operands) {
055        super();
056        this.operands = new ArrayList<>(new TreeSet<>(operands));
057    }
058    
059    /**
060     * @param operands
061     *        operands
062     */
063    public OWLNaryBooleanClassExpressionImplExt(
064            List<? extends OWLClassExpression> operands) {
065        super();
066        this.operands = new ArrayList<>(operands);
067    }
068
069    @Override
070    public void addSignatureEntitiesToSet(Set<OWLEntity> entities) {
071        for (OWLClassExpression operand : operands) {
072            addSignatureEntitiesToSetForValue(entities, operand);
073        }
074    }
075
076    @Override
077    public void addAnonymousIndividualsToSet(Set<OWLAnonymousIndividual> anons) {
078        for (OWLClassExpression operand : operands) {
079            addAnonymousIndividualsToSetForValue(anons, operand);
080        }
081    }
082
083    @Override
084    public List<OWLClassExpression> getOperandsAsList() {
085        return new ArrayList<>(operands);
086    }
087
088    @Override
089    public Set<OWLClassExpression> getOperands() {
090        return CollectionFactory
091                .getCopyOnRequestSetFromImmutableCollection(operands);
092    }
093
094    @Override
095    public boolean isClassExpressionLiteral() {
096        return false;
097    }
098
099    @Override
100    public boolean equals(Object obj) {
101        if (super.equals(obj)) {
102            if (!(obj instanceof OWLNaryBooleanClassExpression)) {
103                return false;
104            }
105            return ((OWLNaryBooleanClassExpression) obj).getOperandsAsList().equals(
106                    operands);
107        }
108        return false;
109    }
110
111    @Override
112    protected int compareObjectOfSameType(OWLObject object) {
113        return compareLists(operands,
114                ((OWLNaryBooleanClassExpression) object).getOperandsAsList());
115    }
116}