|
From: <lh...@us...> - 2008-04-21 14:03:13
|
Revision: 23
http://tinytim.svn.sourceforge.net/tinytim/?rev=23&view=rev
Author: lheuer
Date: 2008-04-21 07:02:48 -0700 (Mon, 21 Apr 2008)
Log Message:
-----------
Added TopicUtils, updated TopicMerge test
Modified Paths:
--------------
tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java
Added Paths:
-----------
tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java
tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java
Added: tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java (rev 0)
+++ tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java 2008-04-21 14:02:48 UTC (rev 23)
@@ -0,0 +1,81 @@
+/*
+ * This is tinyTiM, a tiny Topic Maps engine.
+ *
+ * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+package org.tinytim;
+
+import org.tinytim.index.IScopedIndex;
+import org.tinytim.index.ITypeInstanceIndex;
+import org.tinytim.index.IndexManager;
+import org.tmapi.core.Topic;
+
+/**
+ * This class provides utility functions for {@link org.tmapi.core.Topic}s.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public final class TopicUtils {
+
+ private TopicUtils() {
+ // noop.
+ }
+
+ /**
+ * Returns if the <code>topic</code> is removable.
+ *
+ * A topic is removable iff it plays no role, is not used as type of
+ * a typed Topic Maps construct, is not not used as theme of a scoped
+ * Topic Maps construct and iff it is not used reifier.
+ *
+ * @param topic The topic to check.
+ * @return <code>true</code> if the topic has no dependencies,
+ * otherwise <code>false</code>.
+ */
+ public static boolean isRemovable(Topic topic) {
+ if (((TopicImpl) topic)._reified != null) {
+ return false;
+ }
+ if (!topic.getRolesPlayed().isEmpty()) {
+ return false;
+ }
+ IndexManager idxMan = ((TopicMapImpl) topic.getTopicMap()).getIndexManager();
+ ITypeInstanceIndex typeInstanceIdx = idxMan.getTypeInstanceIndex();
+ if (!typeInstanceIdx.isAutoUpdated()) {
+ typeInstanceIdx.reindex();
+ }
+ if (!typeInstanceIdx.getAssociations(topic).isEmpty()
+ || !typeInstanceIdx.getRoles(topic).isEmpty()
+ || !typeInstanceIdx.getOccurrences(topic).isEmpty()
+ || !typeInstanceIdx.getNames(topic).isEmpty()) {
+ return false;
+ }
+ IScopedIndex scopedIdx = idxMan.getScopedIndex();
+ if (!scopedIdx.isAutoUpdated()) {
+ scopedIdx.reindex();
+ }
+ if (!scopedIdx.getAssociationsByTheme(topic).isEmpty()
+ || !scopedIdx.getOccurrencesByTheme(topic).isEmpty()
+ || !scopedIdx.getNamesByTheme(topic).isEmpty()
+ || !scopedIdx.getVariantsByTheme(topic).isEmpty()) {
+ return false;
+ }
+ return true;
+ }
+}
Property changes on: tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Modified: tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java 2008-04-21 13:55:44 UTC (rev 22)
+++ tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java 2008-04-21 14:02:48 UTC (rev 23)
@@ -26,6 +26,7 @@
import org.tmapi.core.ModelConstraintException;
import org.tmapi.core.Topic;
import org.tmapi.core.TopicName;
+import org.tmapi.core.Variant;
/**
* Tests merging of topics.
@@ -156,4 +157,28 @@
topic1.mergeIn(topic2);
assertEquals(2, topic1.getTopicNames().size());
}
+
+ /**
+ * Tests if merging detects duplicate names and moves the variants.
+ */
+ public void testDuplicateSuppressionName2() {
+ Topic topic1 = _tm.createTopic();
+ Topic topic2 = _tm.createTopic();
+ TopicName name1 = topic1.createTopicName("tinyTiM", null, null);
+ TopicName name2 = topic2.createTopicName("tinyTiM", null, null);
+ Variant var = name2.createVariant("tiny", null);
+ assertEquals(1, topic1.getTopicNames().size());
+ assertTrue(topic1.getTopicNames().contains(name1));
+ assertEquals(0, name1.getVariants().size());
+ assertEquals(1, topic2.getTopicNames().size());
+ assertTrue(topic2.getTopicNames().contains(name2));
+ assertEquals(1, name2.getVariants().size());
+ assertTrue(name2.getVariants().contains(var));
+ topic1.mergeIn(topic2);
+ assertEquals(1, topic1.getTopicNames().size());
+ TopicName tmpName = (TopicName) topic1.getTopicNames().iterator().next();
+ assertEquals(1, tmpName.getVariants().size());
+ Variant tmpVar = (Variant) tmpName.getVariants().iterator().next();
+ assertEquals("tiny", tmpVar.getValue());
+ }
}
Added: tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java (rev 0)
+++ tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java 2008-04-21 14:02:48 UTC (rev 23)
@@ -0,0 +1,63 @@
+/*
+ * This is tinyTiM, a tiny Topic Maps engine.
+ *
+ * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+package org.tinytim;
+
+import org.tmapi.core.Association;
+import org.tmapi.core.AssociationRole;
+import org.tmapi.core.Topic;
+
+/**
+ * Tests against the {@link TopicUtils}.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public class TestTopicUtils extends TinyTimTestCase {
+
+ /**
+ * Tests if a topic is considered as 'removable'.
+ */
+ public void testRemovable() {
+ Topic topic = _tm.createTopic();
+ assertTrue(TopicUtils.isRemovable(topic));
+ Association assoc = _tm.createAssociation();
+ // Type
+ assoc.setType(topic);
+ assertFalse(TopicUtils.isRemovable(topic));
+ assoc.setType(null);
+ assertTrue(TopicUtils.isRemovable(topic));
+ // Role played
+ AssociationRole role = assoc.createAssociationRole(topic, _tm.createTopic());
+ assertFalse(TopicUtils.isRemovable(topic));
+ role.setPlayer(null);
+ assertTrue(TopicUtils.isRemovable(topic));
+ // Theme
+ assoc.addScopingTopic(topic);
+ assertFalse(TopicUtils.isRemovable(topic));
+ assoc.removeScopingTopic(topic);
+ assertTrue(TopicUtils.isRemovable(topic));
+ // Reifier
+ ((IReifiable) assoc).setReifier(topic);
+ assertFalse(TopicUtils.isRemovable(topic));
+ ((IReifiable) assoc).setReifier(null);
+ assertTrue(TopicUtils.isRemovable(topic));
+ }
+}
Property changes on: tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|