    001    // This file is part of the Attempto Java Packages.
    002    // Copyright 2008, Attempto Group, University of Zurich (see http://attempto.ifi.uzh.ch).
    003    //
    004    // The Attempto Java Packages is free software: you can redistribute it and/or modify it under the
    005    // terms of the GNU Lesser General Public License as published by the Free Software Foundation,
    006    // either version 3 of the License, or (at your option) any later version.
    007    //
    008    // The Attempto Java Packages is distributed in the hope that it will be useful, but WITHOUT ANY
    009    // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    010    // PURPOSE. See the GNU Lesser General Public License for more details.
    011    //
    012    // You should have received a copy of the GNU Lesser General Public License along with the Attempto
    013    // Java Packages. If not, see http://www.gnu.org/licenses/.
    014
    015    package ch.uzh.ifi.attempto.acewiki.core.ontology;
    016
    017    import java.util.ArrayList;
    018    import java.util.List;
    019
    020    /**
    021     * This abstract class represents a concept (other terminologies call it "unary relation", "class",
    022     * or "type").
    023     *
    024     * @author Tobias Kuhn
    025     */
    026    public abstract class Concept extends OntologyElement {
    027
    028            private List<Individual> individualsCache;
    029            private long individualsCacheStateID = -1;
    030
    031            private List<Concept> superConceptsCache;
    032            private long superConceptsCacheStateID = -1;
    033
    034            private List<Concept> subConceptsCache;
    035            private long subConceptsCacheStateID = -1;
    036
    037            /**
    038             * Initializes the concept.
    039             */
    040            protected Concept() {
    041            }
    042
    043            /**
    044             * Returns all individuals that belong to this concept.
    045             *
    046             * @return A list of all individuals of this concept.
    047             * @see Ontology#getIndividuals(Concept)
    048             */
    049            public List<Individual> getIndividuals() {
    050                    Ontology o = getOntology();
    051                    if (individualsCacheStateID != o.getStateID()) {
    052                            individualsCache = o.getIndividuals(this);
    053                            individualsCacheStateID = o.getStateID();
    054                    }
    055                    return new ArrayList<Individual>(individualsCache);
    056            }
    057
    058            /**
    059             * Returns true if the individuals of this concept are cached and do not have
    060             * to be recalculated.
    061             *
    062             * @return true if the individuals are cached.
    063             */
    064            public boolean areIndividualsCached() {
    065                    return individualsCacheStateID == getOntology().getStateID();
    066            }
    067
    068            /**
    069             * Returns all super-concepts of this concept.
    070             *
    071             * @return A list of all super-concepts.
    072             * @see Ontology#getSuperConcepts(Concept)
    073             */
    074            public List<Concept> getSuperConcepts() {
    075                    Ontology o = getOntology();
    076                    if (superConceptsCacheStateID != o.getStateID()) {
    077                            superConceptsCache = o.getSuperConcepts(this);
    078                            superConceptsCacheStateID = o.getStateID();
    079                    }
    080                    return new ArrayList<Concept>(superConceptsCache);
    081            }
    082
    083            /**
    084             * Returns true if the suber-concepts of this concept are cached and do not have
    085             * to be recalculated.
    086             *
    087             * @return true if the super-concepts are cached.
    088             */
    089            public boolean areSuperConceptsCached() {
    090                    return superConceptsCacheStateID == getOntology().getStateID();
    091            }
    092
    093            /**
    094             * Returns all sub-concepts of this concept.
    095             *
    096             * @return A list of all sub-concepts.
    097             * @see Ontology#getSubConcepts(Concept)
    098             */
    099            public List<Concept> getSubConcepts() {
    100                    Ontology o = getOntology();
    101                    if (subConceptsCacheStateID != o.getStateID()) {
    102                            subConceptsCache = o.getSubConcepts(this);
    103                            subConceptsCacheStateID = o.getStateID();
    104                    }
    105                    return new ArrayList<Concept>(subConceptsCache);
    106            }
    107
    108            /**
    109             * Returns true if the sub-concepts of this concept are cached and do not have
    110             * to be recalculated.
    111             *
    112             * @return true if the sub-concepts are cached.
    113             */
    114            public boolean areSubConceptsCached() {
    115                    return subConceptsCacheStateID == getOntology().getStateID();
    116            }
    117
    118    }