001    package de.deepamehta.core.model;
002    
003    import de.deepamehta.core.Topic;
004    import java.util.List;
005    
006    
007    
008    public class TopicReferenceModel extends TopicModel {
009    
010        // ---------------------------------------------------------------------------------------------------- Constructors
011    
012        public TopicReferenceModel(long topicId) {
013            super(topicId);
014        }
015    
016        public TopicReferenceModel(String uri) {
017            super(uri, (String) null);   // typeUri=null ### FIXME: OK?
018        }
019    
020        // -------------------------------------------------------------------------------------------------- Public Methods
021    
022        public boolean isReferenceById() {
023            return getId() != -1;
024        }
025    
026        public boolean isReferenceByUri() {
027            return !getUri().equals("");
028        }
029    
030        // ---
031    
032        /**
033         * Checks weather this reference refers to the given topic.
034         */
035        public boolean isReferingTo(Topic topic) {
036            if (isReferenceById()) {
037                return getId() == topic.getId();
038            } else if (isReferenceByUri()) {
039                return getUri().equals(topic.getUri());
040            } else {
041                throw new RuntimeException("Invalid topic reference (" + this + ")");
042            }
043        }
044    
045        /**
046         * Checks weather this reference refers to any of the given topics.
047         */
048        public boolean isReferingToAny(List<Topic> topics) {
049            for (Topic topic : topics) {
050                if (isReferingTo(topic)) {
051                    return true;
052                }
053            }
054            return false;
055        }
056    }