|
From: <lh...@us...> - 2008-08-11 12:19:04
|
Revision: 111
http://tinytim.svn.sourceforge.net/tinytim/?rev=111&view=rev
Author: lheuer
Date: 2008-08-11 12:18:58 +0000 (Mon, 11 Aug 2008)
Log Message:
-----------
- Introduced Scope as first class object
- Introduced a constructor which takes a TopicMapImpl for association, role etc.
- Removed CollectionFactory from the TopicMapImpl and TopicMapSystemFactoryImpl
- Added a static CollectionFactory
- Various modifications
Modified Paths:
--------------
tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java
tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java
tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java
tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java
tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java
tinytim/trunk/src/main/java/org/tinytim/core/Event.java
tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java
tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java
tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java
tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java
tinytim/trunk/src/main/java/org/tinytim/core/Literal.java
tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java
tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java
tinytim/trunk/src/main/java/org/tinytim/core/OccurrenceImpl.java
tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java
tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java
tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java
tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java
tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java
tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemFactoryImpl.java
tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemImpl.java
tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java
tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java
tinytim/trunk/src/main/java/org/tinytim/index/AbstractIndex.java
tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java
tinytim/trunk/src/main/java/org/tinytim/index/LiteralIndexImpl.java
tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndexImpl.java
tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndexImpl.java
tinytim/trunk/src/main/java/org/tinytim/utils/ICollectionFactory.java
Added Paths:
-----------
tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java
tinytim/trunk/src/main/java/org/tinytim/core/IScope.java
tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java
Removed Paths:
-------------
tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java
tinytim/trunk/src/main/java/org/tinytim/core/JavaCollectionFactory.java
tinytim/trunk/src/main/java/org/tinytim/core/TroveCollectionFactory.java
tinytim/trunk/src/main/java/org/tinytim/utils/Property.java
Modified: tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-08-08 14:10:59 UTC (rev 110)
+++ tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -21,7 +21,6 @@
package org.tinytim.core;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.Set;
@@ -40,7 +39,12 @@
private Set<Role> _roles;
- AssociationImpl(TopicMapImpl topicMap, Topic type, Collection<Topic> scope) {
+ AssociationImpl(TopicMapImpl tm) {
+ super(tm);
+ _roles = _makeSet(2);
+ }
+
+ AssociationImpl(TopicMapImpl topicMap, Topic type, IScope scope) {
super(topicMap, type, scope);
_roles = _makeSet(2);
}
@@ -142,6 +146,14 @@
}
/* (non-Javadoc)
+ * @see org.tinytim.core.ConstructImpl#isAssociation()
+ */
+ @Override
+ public final boolean isAssociation() {
+ return true;
+ }
+
+ /* (non-Javadoc)
* @see org.tmapi.core.TopicMapObject#remove()
*/
public void remove() {
Modified: tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-08-08 14:10:59 UTC (rev 110)
+++ tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -23,6 +23,7 @@
import java.util.Collections;
import java.util.Set;
+import org.tinytim.utils.CollectionFactory;
import org.tmapi.core.Construct;
import org.tmapi.core.Locator;
import org.tmapi.core.TopicMap;
@@ -33,7 +34,7 @@
* @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
* @version $Rev$ - $Date$
*/
-abstract class ConstructImpl implements Construct {
+abstract class ConstructImpl implements IConstruct {
protected String _id;
protected TopicMapImpl _tm;
@@ -45,11 +46,11 @@
}
protected <E> Set<E> _makeSet() {
- return _tm.getCollectionFactory().createIdentitySet();
+ return CollectionFactory.createIdentitySet();
}
protected <E> Set<E> _makeSet(int size) {
- return _tm.getCollectionFactory().createIdentitySet(size);
+ return CollectionFactory.createIdentitySet(size);
}
/* (non-Javadoc)
@@ -135,7 +136,7 @@
* @param newValue The new value.
*/
protected void _fireEvent(Event evt, Object oldValue, Object newValue) {
- if (_tm != null) {
+ if (_tm != null && _parent != null) {
_tm.handleEvent(evt, this, oldValue, newValue);
}
}
@@ -153,6 +154,55 @@
}
/* (non-Javadoc)
+ * @see org.tinytim.core.IConstruct#isAssociation()
+ */
+ public boolean isAssociation() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.IConstruct#isName()
+ */
+ public boolean isName() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.IConstruct#isOccurrence()
+ */
+ public boolean isOccurrence() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.IConstruct#isRole()
+ */
+ public boolean isRole() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.IConstruct#isTopic()
+ */
+ public boolean isTopic() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.IConstruct#isTopicMap()
+ */
+ public boolean isTopicMap() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.IConstruct#isVariant()
+ */
+ public boolean isVariant() {
+ return false;
+ }
+
+ /* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
Modified: tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-08 14:10:59 UTC (rev 110)
+++ tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -23,6 +23,9 @@
import java.util.Map;
import java.util.Set;
+import org.tinytim.utils.CollectionFactory;
+import org.tinytim.utils.IIntObjectMap;
+import org.tinytim.utils.IntObjectMap;
import org.tmapi.core.Association;
import org.tmapi.core.Construct;
import org.tmapi.core.Locator;
@@ -66,7 +69,7 @@
if (source == target) {
return;
}
- Map<Topic, Topic> mergeMap = target.getCollectionFactory().createIdentityMap();
+ Map<Topic, Topic> mergeMap = CollectionFactory.createIdentityMap();
Topic existing = null;
Construct existingConstruct = null;
for (Topic topic: source.getTopics()) {
@@ -176,7 +179,7 @@
*/
private static void _copyCharacteristics(Topic topic, TopicImpl targetTopic,
Map<Topic, Topic> mergeMap) {
- Map<Integer, Reifiable> sigs = ((TopicMapImpl) targetTopic.getTopicMap()).getCollectionFactory().createMap();
+ IIntObjectMap<Reifiable> sigs = IntObjectMap.create();
for (Occurrence occ: targetTopic.getOccurrences()) {
sigs.put(SignatureGenerator.generateSignature(occ), occ);
}
@@ -226,7 +229,7 @@
*/
private static void _copyVariants(Name source, NameImpl target,
Map<Topic, Topic> mergeMap) {
- Map<Integer, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap();
+ IIntObjectMap<Variant> sigs = IntObjectMap.create();
for (Variant variant: target.getVariants()) {
sigs.put(SignatureGenerator.generateSignature(variant), variant);
}
@@ -288,7 +291,7 @@
*/
private static Set<Topic>_copyScope(Scoped source, TopicMap tm,
Map<Topic, Topic> mergeMap) {
- Set<Topic> themes = ((TopicMapImpl) tm).getCollectionFactory().createIdentitySet(source.getScope().size());
+ Set<Topic> themes = CollectionFactory.createIdentitySet(source.getScope().size());
Topic theme = null;
for (Topic sourceTheme: source.getScope()) {
theme = mergeMap.containsKey(sourceTheme) ? mergeMap.get(sourceTheme)
@@ -321,7 +324,7 @@
private static void _copyAssociations(TopicMap source,
TopicMapImpl target, Map<Topic, Topic> mergeMap) {
Set<Association> assocs = target.getAssociations();
- Map<Integer, Association> sigs = target.getCollectionFactory().createMap(assocs.size());
+ IIntObjectMap<Association> sigs = IntObjectMap.create(assocs.size());
for (Association assoc: assocs) {
sigs.put(SignatureGenerator.generateSignature(assoc), assoc);
}
Modified: tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-08-08 14:10:59 UTC (rev 110)
+++ tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -22,7 +22,6 @@
import java.math.BigDecimal;
import java.math.BigInteger;
-import java.util.Collection;
import org.tinytim.voc.XSD;
import org.tmapi.core.DatatypeAware;
@@ -40,7 +39,11 @@
private ILiteral _literal;
- DatatypeAwareConstruct(TopicMapImpl topicMap, Topic type, ILiteral literal, Collection<Topic> scope) {
+ DatatypeAwareConstruct(TopicMapImpl tm) {
+ super(tm);
+ }
+
+ DatatypeAwareConstruct(TopicMapImpl topicMap, Topic type, ILiteral literal, IScope scope) {
super(topicMap, type, scope);
_literal = literal;
}
Modified: tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java 2008-08-08 14:10:59 UTC (rev 110)
+++ tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -22,9 +22,9 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Map;
-import org.tinytim.utils.ICollectionFactory;
+import org.tinytim.utils.IIntObjectMap;
+import org.tinytim.utils.IntObjectMap;
import org.tmapi.core.Association;
import org.tmapi.core.Name;
import org.tmapi.core.Occurrence;
@@ -56,7 +56,7 @@
for (Topic topic: tm.getTopics()) {
removeDuplicates(topic);
}
- Map<Integer, Association> sig2Assoc = tm.getCollectionFactory().createMap();
+ IIntObjectMap<Association> sig2Assoc = IntObjectMap.create();
TypeInstanceIndex typeInstanceIdx = tm.getIndexManager().getTypeInstanceIndex();
if (!typeInstanceIdx.isAutoUpdated()) {
typeInstanceIdx.reindex();
@@ -66,13 +66,12 @@
}
}
- private static void _removeDuplicateAssociations(Map<Integer, Association> sig2Assoc, Collection<Association> assocs) {
+ private static void _removeDuplicateAssociations(IIntObjectMap<Association> sig2Assoc, Collection<Association> assocs) {
sig2Assoc.clear();
Association existing = null;
- Integer sig = null;
for (Association assoc: assocs) {
removeDuplicates(assoc);
- sig = SignatureGenerator.generateSignature(assoc);
+ int sig = SignatureGenerator.generateSignature(assoc);
existing = sig2Assoc.get(sig);
if (existing != null) {
MergeUtils.moveRoleCharacteristics(assoc, existing);
@@ -90,9 +89,8 @@
* @param topic The topic from which duplicates should be removed from.
*/
public static void removeDuplicates(Topic topic) {
- ICollectionFactory collFactory = ((TopicMapImpl) topic.getTopicMap()).getCollectionFactory();
- _removeDuplicateOccurrences(topic.getOccurrences(), collFactory);
- _removeDuplicateNames(topic.getNames(), collFactory);
+ _removeDuplicateOccurrences(topic.getOccurrences());
+ _removeDuplicateNames(topic.getNames());
}
/**
@@ -101,10 +99,9 @@
* @param name The name from which the duplicates should be removed.
*/
public static void removeDuplicates(Name name) {
- Map<Integer, Variant> sigs = ((TopicMapImpl) name.getTopicMap()).getCollectionFactory().createMap();
- Integer sig = null;
+ IIntObjectMap<Variant> sigs = IntObjectMap.create();
for (Variant variant: new ArrayList<Variant>(name.getVariants())) {
- sig = SignatureGenerator.generateSignature(variant);
+ int sig = SignatureGenerator.generateSignature(variant);
Variant existing = sigs.get(sig);
if (existing != null) {
MergeUtils.handleExistingConstruct(variant, existing);
@@ -121,12 +118,11 @@
*
* @param occs
*/
- private static void _removeDuplicateOccurrences(Collection<Occurrence> occs, ICollectionFactory collFactory) {
- Map<Integer, Occurrence> sigs = collFactory.createMap(occs.size());
+ private static void _removeDuplicateOccurrences(Collection<Occurrence> occs) {
+ IIntObjectMap<Occurrence> sigs = IntObjectMap.create(occs.size());
Occurrence existing = null;
- Integer sig = null;
for (Occurrence occ: new ArrayList<Occurrence>(occs)) {
- sig = SignatureGenerator.generateSignature(occ);
+ int sig = SignatureGenerator.generateSignature(occ);
existing = sigs.get(sig);
if (existing != null) {
MergeUtils.handleExistingConstruct(occ, existing);
@@ -143,13 +139,12 @@
*
* @param names
*/
- private static void _removeDuplicateNames(Collection<Name> names, ICollectionFactory collFactory) {
- Map<Integer, Name> sigs = collFactory.createMap(names.size());
+ private static void _removeDuplicateNames(Collection<Name> names) {
+ IIntObjectMap<Name> sigs = IntObjectMap.create(names.size());
Name existing = null;
- Integer sig = null;
for (Name name: new ArrayList<Name>(names)) {
removeDuplicates(name);
- sig = SignatureGenerator.generateSignature(name);
+ int sig = SignatureGenerator.generateSignature(name);
existing = sigs.get(sig);
if (existing != null) {
MergeUtils.handleExistingConstruct(name, existing);
@@ -168,11 +163,10 @@
* @param assoc The association to remove duplicate roles from.
*/
public static void removeDuplicates(Association assoc) {
- Map<Integer, Role> sig2Role = ((TopicMapImpl) assoc.getTopicMap()).getCollectionFactory().createMap();
+ IIntObjectMap<Role> sig2Role = IntObjectMap.create();
Role existing = null;
- Integer sig = null;
for (Role role: new ArrayList<Role>(assoc.getRoles())) {
- sig = SignatureGenerator.generateSignature(role);
+ int sig = SignatureGenerator.generateSignature(role);
existing = sig2Role.get(sig);
if (existing != null) {
MergeUtils.handleExistingConstruct(role, existing);
Modified: tinytim/trunk/src/main/java/org/tinytim/core/Event.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/Event.java 2008-08-08 14:10:59 UTC (rev 110)
+++ tinytim/trunk/src/main/java/org/tinytim/core/Event.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -121,14 +121,9 @@
SET_TYPE,
/**
- * Notification that a theme should be added to a {@link IScoped} construct.
+ * Notification that the scope is changed.
*/
- ADD_THEME,
- /**
- * Notification that a theme should be removed from a
- * {@link IScoped} construct.
- */
- REMOVE_THEME,
+ SET_SCOPE,
/**
* Notification that the player of a role should be set.
Added: tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java (rev 0)
+++ tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -0,0 +1,41 @@
+/*
+ * 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.core;
+
+import org.tmapi.core.Construct;
+
+/**
+ *
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public interface IConstruct extends Construct {
+
+ public boolean isTopicMap();
+ public boolean isTopic();
+ public boolean isAssociation();
+ public boolean isRole();
+ public boolean isOccurrence();
+ public boolean isName();
+ public boolean isVariant();
+
+}
Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Modified: tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java 2008-08-08 14:10:59 UTC (rev 110)
+++ tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -20,8 +20,6 @@
*/
package org.tinytim.core;
-import org.tmapi.core.Construct;
-
/**
* Event handler that is able to handle Topic Maps events.
*
@@ -44,6 +42,6 @@
* @param newValue The new value or <code>null</code> if the new value
* is not available or should become <code>null</code>.
*/
- public void handleEvent(Event evt, Construct sender, Object oldValue, Object newValue);
+ public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue);
}
Deleted: tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java 2008-08-08 14:10:59 UTC (rev 110)
+++ tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -1,48 +0,0 @@
-/*
- * 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.core;
-
-import org.tmapi.core.Association;
-import org.tmapi.core.Name;
-import org.tmapi.core.Occurrence;
-import org.tmapi.core.Role;
-import org.tmapi.core.Topic;
-import org.tmapi.core.Variant;
-
-/**
- *
- *
- * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
- * @version $Rev$ - $Date$
- */
-public interface IFactory {
-
- public Association createAssociation();
-
- public Role createRole(Association parent);
-
- public Occurrence createOccurrence(Topic parent);
-
- public Name createName(Topic parent);
-
- public Variant createVariant(Name parent);
-
-}
Modified: tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java 2008-08-08 14:10:59 UTC (rev 110)
+++ tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -23,8 +23,9 @@
import org.tmapi.core.Locator;
/**
+ * Marker interface which unifies the {@link org.tmapi.core.Locator} and
+ * tinyTiM's {@link ILiteral}.
*
- *
* This interface is not meant to be used outside of the tinyTiM package.
*
* @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
Added: tinytim/trunk/src/main/java/org/tinytim/core/IScope.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/IScope.java (rev 0)
+++ tinytim/trunk/src/main/java/org/tinytim/core/IScope.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -0,0 +1,49 @@
+/*
+ * 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.core;
+
+import java.util.Set;
+
+import org.tmapi.core.Topic;
+
+/**
+ * Represents an immutable set of {@link org.tmapi.core.Topic}s.
+ *
+ * This interface is not meant to be used outside of the tinyTiM package.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public interface IScope extends Iterable<Topic> {
+
+ public Set<Topic> asSet();
+
+ public boolean contains(Topic theme);
+
+ public IScope add(Topic theme);
+
+ public IScope remove(Topic theme);
+
+ public boolean isUnconstrained();
+
+ public int size();
+
+}
Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/IScope.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java (rev 0)
+++ tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -0,0 +1,36 @@
+/*
+ * 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.core;
+
+import org.tmapi.core.Scoped;
+
+/**
+ *
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public interface IScoped extends Scoped, IConstruct {
+
+ public IScope getScopeObject();
+
+ public void setScopeObject(IScope scope);
+}
Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Modified: tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-08-08 14:10:59 UTC (rev 110)
+++ tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -31,13 +31,8 @@
final class IdGenerator {
private static final AtomicLong _COUNTER = new AtomicLong();
- private static final IdGenerator _INSTANCE = new IdGenerator();
- public static IdGenerator getInstance() {
- return _INSTANCE;
- }
-
- public long nextId() {
+ public static long nextId() {
return _COUNTER.getAndIncrement();
}
}
Modified: tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java 2008-08-08 14:10:59 UTC (rev 110)
+++ tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -22,7 +22,7 @@
import java.util.Map;
-import org.tinytim.utils.ICollectionFactory;
+import org.tinytim.utils.CollectionFactory;
import org.tmapi.core.Construct;
import org.tmapi.core.IdentityConstraintException;
import org.tmapi.core.Locator;
@@ -41,15 +41,14 @@
private Map<Locator, Topic> _sid2Topic;
private Map<Locator, Topic> _slo2Topic;
- private Map<Locator, Construct> _iid2Construct;
- private Map<String, Construct> _id2Construct;
+ private Map<Locator, IConstruct> _iid2Construct;
+ private Map<String, IConstruct> _id2Construct;
IdentityManager(TopicMapImpl tm) {
- ICollectionFactory collFactory = tm.getCollectionFactory();
- _id2Construct = collFactory.createIdentityMap();
- _sid2Topic = collFactory.createIdentityMap();
- _slo2Topic = collFactory.createIdentityMap();
- _iid2Construct = collFactory.createIdentityMap();
+ _id2Construct = CollectionFactory.createIdentityMap();
+ _sid2Topic = CollectionFactory.createIdentityMap();
+ _slo2Topic = CollectionFactory.createIdentityMap();
+ _iid2Construct = CollectionFactory.createIdentityMap();
_subscribe(tm);
_register(tm);
}
@@ -95,10 +94,10 @@
*
* @param construct The construct to register.
*/
- private void _register(Construct construct) {
+ private void _register(IConstruct construct) {
ConstructImpl c = (ConstructImpl) construct;
if (c._id == null) {
- String id = "" + IdGenerator.getInstance().nextId();
+ String id = "" + IdGenerator.nextId();
c._id = id.intern();
}
if (!_id2Construct.containsKey(c._id)) {
@@ -163,16 +162,16 @@
}
private class TopicMapsConstructAddHandler implements IEventHandler {
- public void handleEvent(Event evt, Construct sender, Object oldValue,
+ public void handleEvent(Event evt, IConstruct sender, Object oldValue,
Object newValue) {
- _register((ConstructImpl)newValue);
+ _register((IConstruct)newValue);
}
}
private class TopicMapsConstructRemoveHandler implements IEventHandler {
- public void handleEvent(Event evt, Construct sender, Object oldValue,
+ public void handleEvent(Event evt, IConstruct sender, Object oldValue,
Object newValue) {
- _unregister((ConstructImpl)oldValue);
+ _unregister((IConstruct)oldValue);
}
}
@@ -181,19 +180,19 @@
* item identifier to the index.
*/
private class AddItemIdentifierHandler implements IEventHandler {
- public void handleEvent(Event evt, Construct sender, Object oldValue,
+ public void handleEvent(Event evt, IConstruct sender, Object oldValue,
Object newValue) {
Locator iid = (Locator) newValue;
- Construct existing = _iid2Construct.get(iid);
+ IConstruct existing = _iid2Construct.get(iid);
if (existing != null) {
if (existing != sender) {
- if (sender instanceof Topic && existing instanceof Topic) {
+ if (sender.isTopic() && existing.isTopic()) {
throw new IdentityConstraintException((Topic) sender, (Topic) existing, iid, "A topic with the same item identifier '" + iid.getReference() + "' exists");
}
throw new IdentityConstraintException(sender, existing, iid, "A Topic Maps construct with the same item identifier '" + iid.getReference() + "' exists");
}
}
- if (sender instanceof Topic) {
+ if (sender.isTopic()) {
Topic existingTopic = _sid2Topic.get(iid);
if (existingTopic != null && existingTopic != sender) {
throw new IdentityConstraintException((Topic) sender, existingTopic, iid, "A topic with a subject identifier equals to the item identifier '" + iid.getReference() + "' exists");
@@ -207,7 +206,7 @@
* Removes an item identifier and its Topic Maps constructs from the index.
*/
private class RemoveItemIdentifierHandler implements IEventHandler {
- public void handleEvent(Event evt, Construct sender, Object oldValue,
+ public void handleEvent(Event evt, IConstruct sender, Object oldValue,
Object newValue) {
_iid2Construct.remove(oldValue);
}
@@ -218,16 +217,16 @@
* subject identifier to the index.
*/
private class AddSubjectIdentifierHandler implements IEventHandler {
- public void handleEvent(Event evt, Construct sender, Object oldValue,
+ public void handleEvent(Event evt, IConstruct sender, Object oldValue,
Object newValue) {
Topic topic = (Topic) sender;
Locator sid = (Locator) newValue;
- Construct existing = _sid2Topic.get(sid);
+ IConstruct existing = (IConstruct) _sid2Topic.get(sid);
if (existing != null && existing != topic) {
throw new IdentityConstraintException(topic, (Topic) existing, sid, "A topic with the same subject identifier '" + sid.getReference() + "' exists");
}
existing = _iid2Construct.get(sid);
- if (existing != null && existing instanceof Topic && existing != topic) {
+ if (existing != null && existing.isTopic() && existing != topic) {
throw new IdentityConstraintException(topic, (Topic) existing, sid, "A topic with an item identifier equals to the subject identifier '" + sid.getReference() + "' exists");
}
_sid2Topic.put(sid, topic);
@@ -238,7 +237,7 @@
* Removes a subject identifier and its topic from the index.
*/
private class RemoveSubjectIdentifierHandler implements IEventHandler {
- public void handleEvent(Event evt, Construct sender, Object oldValue,
+ public void handleEvent(Event evt, IConstruct sender, Object oldValue,
Object newValue) {
_sid2Topic.remove(oldValue);
}
@@ -249,7 +248,7 @@
* subject locator to the index.
*/
private class AddSubjectLocatorHandler implements IEventHandler {
- public void handleEvent(Event evt, Construct sender, Object oldValue,
+ public void handleEvent(Event evt, IConstruct sender, Object oldValue,
Object newValue) {
Topic topic = (Topic) sender;
Locator slo = (Locator) newValue;
@@ -265,7 +264,7 @@
* Removes a subject locator and its topic from the index.
*/
private class RemoveSubjectLocatorHandler implements IEventHandler {
- public void handleEvent(Event evt, Construct sender, Object oldValue,
+ public void handleEvent(Event evt, IConstruct sender, Object oldValue,
Object newValue) {
_slo2Topic.remove(oldValue);
}
@@ -275,7 +274,7 @@
* Checks if setting the reifier is allowed.
*/
private static class ReifierConstraintHandler implements IEventHandler {
- public void handleEvent(Event evt, Construct sender, Object oldValue,
+ public void handleEvent(Event evt, IConstruct sender, Object oldValue,
Object newValue) {
if (newValue == null) {
return;
Deleted: tinytim/trunk/src/main/java/org/tinytim/core/JavaCollectionFactory.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/JavaCollectionFactory.java 2008-08-08 14:10:59 UTC (rev 110)
+++ tinytim/trunk/src/main/java/org/tinytim/core/JavaCollectionFactory.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -1,161 +0,0 @@
-/*
- * 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.core;
-
-import java.util.AbstractSet;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.IdentityHashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import org.tinytim.utils.ICollectionFactory;
-
-/**
- * {@link ICollectionFactory} which uses the standard Java collections.
- *
- * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
- * @version $Rev$ - $Date$
- */
-final class JavaCollectionFactory implements ICollectionFactory {
-
- /* (non-Javadoc)
- * @see org.tinytim.ICollectionFactory#createMap(int)
- */
- public <K, V> Map<K, V> createMap(int size) {
- return new HashMap<K, V>(size);
- }
-
- /* (non-Javadoc)
- * @see org.tinytim.ICollectionFactory#createMap()
- */
- public <K, V> Map<K, V> createMap() {
- return new HashMap<K, V>();
- }
-
- /* (non-Javadoc)
- * @see org.tinytim.core.ICollectionFactory#createIdentityMap()
- */
- public <K, V> Map<K, V> createIdentityMap() {
- return new IdentityHashMap<K,V>();
- }
-
- /* (non-Javadoc)
- * @see org.tinytim.core.ICollectionFactory#createIdentityMap(int)
- */
- public <K, V> Map<K, V> createIdentityMap(int size) {
- return new IdentityHashMap<K,V>(size);
- }
-
- /* (non-Javadoc)
- * @see org.tinytim.ICollectionFactory#createSet(int)
- */
- public <E> Set<E> createSet(int size) {
- return new HashSet<E>(size);
- }
-
- /* (non-Javadoc)
- * @see org.tinytim.ICollectionFactory#createSet()
- */
- public <E> Set<E> createSet() {
- return new HashSet<E>();
- }
-
- /* (non-Javadoc)
- * @see org.tinytim.core.ICollectionFactory#createIdentitySet()
- */
- public <E> Set<E> createIdentitySet() {
- return new IdentityHashSet<E>();
- }
-
- /* (non-Javadoc)
- * @see org.tinytim.core.ICollectionFactory#createIdentitySet(int)
- */
- public <E> Set<E> createIdentitySet(int size) {
- return new IdentityHashSet<E>(size);
- }
-
- /**
- * {@link java.util.Set} implementation that compares its elements by
- * identity.
- */
- private static class IdentityHashSet<E> extends AbstractSet<E> {
-
- private final Map<E, Boolean> _map;
-
- public IdentityHashSet() {
- _map = new IdentityHashMap<E, Boolean>();
- }
-
- public IdentityHashSet(int size) {
- _map = new IdentityHashMap<E, Boolean>(size);
- }
-
- /* (non-Javadoc)
- * @see java.util.AbstractCollection#add(java.lang.Object)
- */
- @Override
- public boolean add(E obj) {
- return _map.put(obj, Boolean.TRUE) == null;
- }
-
- /* (non-Javadoc)
- * @see java.util.AbstractCollection#remove(java.lang.Object)
- */
- @Override
- public boolean remove(Object obj) {
- return _map.remove(obj) != null;
- }
-
- /* (non-Javadoc)
- * @see java.util.AbstractCollection#contains(java.lang.Object)
- */
- @Override
- public boolean contains(Object obj) {
- return _map.containsKey(obj);
- }
-
- /* (non-Javadoc)
- * @see java.util.AbstractCollection#iterator()
- */
- @Override
- public Iterator<E> iterator() {
- return _map.keySet().iterator();
- }
-
- /* (non-Javadoc)
- * @see java.util.AbstractCollection#size()
- */
- @Override
- public int size() {
- return _map.size();
- }
-
- /* (non-Javadoc)
- * @see java.util.AbstractCollection#clear()
- */
- @Override
- public void clear() {
- _map.clear();
- }
- }
-}
Modified: tinytim/trunk/src/main/java/org/tinytim/core/Literal.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/Literal.java 2008-08-08 14:10:59 UTC (rev 110)
+++ tinytim/trunk/src/main/java/org/tinytim/core/Literal.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -20,14 +20,10 @@
*/
package org.tinytim.core;
-import java.lang.ref.WeakReference;
import java.math.BigDecimal;
import java.math.BigInteger;
-import java.util.AbstractSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.WeakHashMap;
+import org.tinytim.utils.WeakObjectRegistry;
import org.tinytim.voc.XSD;
import org.tmapi.core.Locator;
@@ -210,77 +206,4 @@
&& this._datatype.equals(other._datatype);
}
-
- private static class WeakObjectRegistry<E> extends AbstractSet<E> {
-
- private final Map<E, WeakReference<E>> _obj2Ref;
-
- public WeakObjectRegistry() {
- super();
- _obj2Ref = new WeakHashMap<E, WeakReference<E>>();
- }
-
- /**
- *
- *
- * @param key
- * @return
- */
- public E get(Object key) {
- WeakReference<E> weakRef = _obj2Ref.get(key);
- return weakRef != null ? weakRef.get() : null;
- }
-
- /* (non-Javadoc)
- * @see java.util.AbstractCollection#add(java.lang.Object)
- */
- @Override
- public boolean add(E obj) {
- WeakReference<E> ref = new WeakReference<E>(obj);
- ref = _obj2Ref.put(obj, ref);
- return ref != null && ref.get() != null;
- }
-
- /* (non-Javadoc)
- * @see java.util.AbstractCollection#remove(java.lang.Object)
- */
- @Override
- public boolean remove(Object obj) {
- WeakReference<E> ref = _obj2Ref.remove(obj);
- return ref != null && ref.get() != null;
- }
-
- /* (non-Javadoc)
- * @see java.util.AbstractCollection#clear()
- */
- @Override
- public void clear() {
- _obj2Ref.clear();
- }
-
- /* (non-Javadoc)
- * @see java.util.AbstractCollection#contains(java.lang.Object)
- */
- @Override
- public boolean contains(Object obj) {
- return get(obj) != null;
- }
-
- /* (non-Javadoc)
- * @see java.util.AbstractCollection#iterator()
- */
- @Override
- public Iterator<E> iterator() {
- return _obj2Ref.keySet().iterator();
- }
-
- /* (non-Javadoc)
- * @see java.util.AbstractCollection#size()
- */
- @Override
- public int size() {
- return _obj2Ref.size();
- }
- }
-
}
Modified: tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-08 14:10:59 UTC (rev 110)
+++ tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -23,9 +23,10 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import java.util.Map;
import org.tinytim.index.IIndexManager;
+import org.tinytim.utils.IIntObjectMap;
+import org.tinytim.utils.IntObjectMap;
import org.tmapi.core.Association;
import org.tmapi.core.Construct;
import org.tmapi.core.Locator;
@@ -86,8 +87,7 @@
/**
* @see #merge(Topic, Topic)
*/
- @SuppressWarnings("unchecked")
- private static void _merge(TopicImpl source, TopicImpl target) {
+ private static void _merge(TopicImpl source, Topic target) {
if (source == null || target == null) {
throw new IllegalArgumentException("Neither the source topic nor the target topic must be null");
}
@@ -121,7 +121,7 @@
for(Topic type: source.getTypes()) {
target.addType(type);
}
- Map<Integer, Reifiable> sigs = ((TopicMapImpl) source.getTopicMap()).getCollectionFactory().createMap();
+ IIntObjectMap<Reifiable> sigs = IntObjectMap.create();
for (Occurrence occ: target.getOccurrences()) {
sigs.put(SignatureGenerator.generateSignature(occ), occ);
}
@@ -133,7 +133,7 @@
occ.remove();
}
else {
- ((IMovable<Topic>) occ).moveTo(target);
+ ((OccurrenceImpl) occ).moveTo(target);
}
}
sigs.clear();
@@ -148,7 +148,7 @@
name.remove();
}
else {
- ((IMovable<Topic>) name).moveTo(target);
+ ((NameImpl) name).moveTo(target);
}
}
sigs.clear();
@@ -177,7 +177,7 @@
* @param target The association which takes the role characteristics.
*/
static void moveRoleCharacteristics(Association source, Association target) {
- Map<Integer, Role> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap();
+ IIntObjectMap<Role> sigs = IntObjectMap.create();
for (Role role: target.getRoles()) {
sigs.put(SignatureGenerator.generateSignature(role), role);
}
@@ -194,9 +194,8 @@
* @param source The name to take the variants from.
* @param target The target to add the variants to.
*/
- @SuppressWarnings("unchecked")
static void moveVariants(Name source, Name target) {
- Map<Integer, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap();
+ IIntObjectMap<Variant> sigs = IntObjectMap.create();
for (Variant var: target.getVariants()) {
sigs.put(SignatureGenerator.generateSignature(var), var);
}
@@ -208,7 +207,7 @@
var.remove();
}
else {
- ((IMovable<Name>) var).moveTo(target);
+ ((VariantImpl) var).moveTo(target);
}
}
}
Modified: tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2008-08-08 14:10:59 UTC (rev 110)
+++ tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -44,7 +44,11 @@
private Set<Variant> _variants;
- NameImpl(TopicMapImpl topicMap, Topic type, ILiteral literal, Collection<Topic> scope) {
+ NameImpl(TopicMapImpl tm) {
+ super(tm);
+ }
+
+ NameImpl(TopicMapImpl topicMap, Topic type, ILiteral literal, IScope scope) {
super(topicMap, type, scope);
_literal = literal;
}
@@ -151,7 +155,7 @@
if (scope_.isEmpty()) {
throw new ModelConstraintException(this, "The variant's scope is not a true superset of the parent's scope");
}
- Variant variant = new VariantImpl(_tm, literal, scope_);
+ Variant variant = new VariantImpl(_tm, literal, Scope.create(scope_));
addVariant(variant);
return variant;
}
@@ -198,6 +202,14 @@
}
/* (non-Javadoc)
+ * @see org.tinytim.core.ConstructImpl#isName()
+ */
+ @Override
+ public final boolean isName() {
+ return true;
+ }
+
+ /* (non-Javadoc)
* @see org.tmapi.core.Construct#remove()
*/
public void remove() {
Modified: tinytim/trunk/src/main/java/org/tinytim/core/OccurrenceImpl.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/OccurrenceImpl.java 2008-08-08 14:10:59 UTC (rev 110)
+++ tinytim/trunk/src/main/java/org/tinytim/core/OccurrenceImpl.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -20,8 +20,6 @@
*/
package org.tinytim.core;
-import java.util.Collection;
-
import org.tmapi.core.Occurrence;
import org.tmapi.core.Topic;
@@ -34,7 +32,11 @@
final class OccurrenceImpl extends DatatypeAwareConstruct implements
Occurrence, IMovable<Topic> {
- OccurrenceImpl(TopicMapImpl topicMap, Topic type, ILiteral literal, Collection<Topic> scope) {
+ OccurrenceImpl(TopicMapImpl tm) {
+ super(tm);
+ }
+
+ OccurrenceImpl(TopicMapImpl topicMap, Topic type, ILiteral literal, IScope scope) {
super(topicMap, type, literal, scope);
}
@@ -55,6 +57,14 @@
}
/* (non-Javadoc)
+ * @see org.tinytim.core.ConstructImpl#isOccurrence()
+ */
+ @Override
+ public final boolean isOccurrence() {
+ return true;
+ }
+
+ /* (non-Javadoc)
* @see org.tmapi.core.Construct#remove()
*/
public void remove() {
Modified: tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java 2008-08-08 14:10:59 UTC (rev 110)
+++ tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -34,6 +34,10 @@
private Topic _player;
+ RoleImpl(TopicMapImpl tm) {
+ super(tm);
+ }
+
RoleImpl(TopicMapImpl tm, Topic type, Topic player) {
super(tm, type);
_player = player;
@@ -74,6 +78,14 @@
}
/* (non-Javadoc)
+ * @see org.tinytim.core.ConstructImpl#isRole()
+ */
+ @Override
+ public final boolean isRole() {
+ return true;
+ }
+
+ /* (non-Javadoc)
* @see org.tmapi.core.Construct#remove()
*/
public void remove() {
Modified: tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java 2008-08-08 14:10:59 UTC (rev 110)
+++ tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -20,8 +20,6 @@
*/
package org.tinytim.core;
-import java.util.Collection;
-import java.util.Collections;
import java.util.Set;
import org.tmapi.core.Topic;
@@ -33,28 +31,45 @@
* @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
* @version $Rev$ - $Date$
*/
-abstract class ScopedImpl extends TypedImpl {
+abstract class ScopedImpl extends TypedImpl implements IScoped {
//NOTE: This class does NOT implement IScoped by intention!
- private Set<Topic> _scope;
+ private IScope _scope;
- ScopedImpl(TopicMapImpl topicMap, Topic type, Collection<Topic> scope) {
+ ScopedImpl(TopicMapImpl tm) {
+ super(tm);
+ _scope = Scope.UCS;
+ }
+
+ ScopedImpl(TopicMapImpl topicMap, Topic type, IScope scope) {
super(topicMap, type);
- if (scope != null && !scope.isEmpty()) {
- _scope = _makeSet(scope.size());
- for (Topic theme: scope) {
- _scope.add(theme);
- }
+ _scope = scope;
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.IScoped#getScopeObject()
+ */
+ public IScope getScopeObject() {
+ return _scope;
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.core.IScoped#setScopeObject(org.tinytim.core.IScope)
+ */
+ public void setScopeObject(IScope scope) {
+ if (_scope == scope) {
+ return;
}
+ _fireEvent(Event.SET_SCOPE, _scope, scope);
+ _scope = scope;
}
/* (non-Javadoc)
* @see org.tmapi.core.ScopedObject#getScope()
*/
public Set<Topic> getScope() {
- return _scope == null ? Collections.<Topic>emptySet()
- : Collections.unmodifiableSet(_scope);
+ return _scope.asSet();
}
/* (non-Javadoc)
@@ -64,25 +79,14 @@
if (theme == null) {
throw new IllegalArgumentException("The theme must not be null");
}
- if (_scope != null && _scope.contains(theme)) {
- return;
- }
- _fireEvent(Event.ADD_THEME, null, theme);
- if (_scope == null) {
- _scope = _makeSet();
- }
- _scope.add(theme);
+ setScopeObject(_scope.add(theme));
}
/* (non-Javadoc)
* @see org.tmapi.Scoped#removeTheme(org.tmapi.core.Topic)
*/
public void removeTheme(Topic theme) {
- if (_scope == null || _scope.isEmpty()) {
- return;
- }
- _fireEvent(Event.REMOVE_THEME, theme, null);
- _scope.remove(theme);
+ setScopeObject(_scope.remove(theme));
}
/* (non-Javadoc)
Modified: tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java 2008-08-08 14:10:59 UTC (rev 110)
+++ tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -22,7 +22,6 @@
import java.util.Arrays;
import java.util.Collection;
-import java.util.Set;
import org.tmapi.core.Association;
import org.tmapi.core.Name;
@@ -166,17 +165,7 @@
* @return The signature.
*/
private static int _generateScopeSignature(final Scoped scoped) {
- Set<Topic> scope = scoped.getScope();
- if (scope.isEmpty()) {
- return 0;
- }
- int[] ids = new int[scope.size()];
- int i = 0;
- for (Topic topic : scope) {
- ids[i++] = _signature(topic);
- }
- Arrays.sort(ids);
- return Arrays.hashCode(ids);
+ return System.identityHashCode(((IScoped) scoped).getScopeObject());
}
private static int _signature(Topic topic) {
Modified: tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java 2008-08-08 14:10:59 UTC (rev 110)
+++ tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -193,7 +193,7 @@
if (scope == null) {
throw new IllegalArgumentException("The scope must not be null");
}
- Occurrence occ = new OccurrenceImpl(_tm, type, literal, scope);
+ Occurrence occ = new OccurrenceImpl(_tm, type, literal, Scope.create(scope));
addOccurrence(occ);
return occ;
}
@@ -313,7 +313,7 @@
if (scope == null) {
throw new IllegalArgumentException("The scope must not be null");
}
- NameImpl name = new NameImpl(_tm, type, literal, scope);
+ NameImpl name = new NameImpl(_tm, type, literal, Scope.create(scope));
addName(name);
return name;
}
@@ -461,6 +461,14 @@
}
/* (non-Javadoc)
+ * @see org.tinytim.core.ConstructImpl#isTopic()
+ */
+ @Override
+ public final boolean isTopic() {
+ return true;
+ }
+
+ /* (non-Javadoc)
* @see org.tmapi.core.TopicMapObject#remove()
*/
public void remove() throws TopicInUseException {
Modified: tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java 2008-08-08 14:10:59 UTC (rev 110)
+++ tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java 2008-08-11 12:18:58 UTC (rev 111)
@@ -30,7 +30,7 @@
import org.tinytim.index.IndexManager;
import org.tinytim.index.IIndexManager;
-import org.tinytim.utils.ICollectionFactory;
+import org.tinytim.utils.CollectionFactory;
import org.tinytim.voc.TMDM;
import org.tmapi.core.Association;
import org.tmapi.core.IdentityConstraintException;
@@ -55,8 +55,6 @@
private IdentityManager _identityManager;
private IndexManager _indexManager;
- private ICollectionFactory _collectionFactory;
- private IFactory _factory;
private Locator _locator;
private Set<Topic> _topics;
private Set<Association> _assocs;
@@ -70,23 +68,14 @@
super._tm = this;
_sys = sys;
_locator = locator;
- _collectionFactory = _sys.getCollectionFactory();
- _topics = _collectionFactory.createIdentitySet(100);
- _assocs = _collectionFactory.createIdentitySet(100);
- _evtHandlers = _collectionFactory.createIdentityMap();
+ _topics = CollectionFactory.createIdentitySet(100);
+ _assocs = CollectionFactory.createIdentitySet(100);
+ _evtHandlers = CollectionFactory.createIdentityMap();
_identityManager = new IdentityManager(this);
- _indexManager = new IndexManager(this, _collectionFactory);
+ _indexManager = new IndexManager(this);
_eventMultiplier = new EventMultiplier(this);
}
- ICollectionFactory getCollectionFactory() {
- return _collectionFactory;
- }
-
- public IFactory getFactory() {
- return _factory;
- }
-
Locator getLocator() {
return _locator;
}
@@ -119,7 +108,7 @@
public Topic createTopic() {
TopicImpl topic = new TopicImpl(this);
addTopic(topic);
- topic.addItemIdentifier(Literal.createIRI("urn:x-tinytim:" + IdGenerator.getInstance().nextId()));
+ topic.addItemIdentifier(Literal.createIRI("urn:x-tinytim:" + IdGenerator.nextId()));
return topic;
}
@@ -244,7 +233,7 @@
if (scope == null) {
throw new IllegalArgumentException("The scope must not be null");
}
- AssociationImpl assoc = new AssociationImpl(this, type, scope);
+ AssociationImpl assoc = new AssociationImpl(this, type, Scope.create(scope));
addAssociation(assoc);
return assoc;
}
@@ -328,15 +317,16 @@
/* (non-Javadoc)
* @see org.tmapi.core.TopicMap#getIndex(java.lang.Class)
*/
- public Index getIndex(Class<? extends Index> indexInterface) {
+ @SuppressWarnings("unchecked")
+ public <I extends Index> I getIndex(Class<I> indexInterface) {
if (indexInterface.getName().equals("org.tmapi.index.TypeInstanceIndex")) {
- return _indexManager.getTypeInstanceIndex();
+ return (I) _indexManager.getTypeInstanceIndex();
}
if (indexInterface.getName().equals("org.tmapi.index.ScopedIndex")) {
- return _indexManager.getScopedIndex();
+ return (I) _indexManager.getScopedIndex();
}
if (indexInterface.getName().equals("org.tmapi.index.LiteralIndex")) {
- return _indexManager.getLiteralIndex();
+ return (I) _indexManager.getLiteralIndex();
}
throw new UnsupportedOperationException("Index '" + indexInterface.getName() + "' is unknown");
}
@@ -356,6 +346,14 @@
}
/* (non-Javadoc)
+ * @see org.tinytim.core.ConstructImpl#isTopicMap()
+ */
+ @Override
+ public boolean isTopicMap() {
+ return true;
+ }
+
+ /* (non-Javadoc)
* @see org.tmapi.core.TopicMap#remove()
*/
public void remove() {
@@ -373,9 +371,17 @@
}
/* (non-Javadoc)
+ * @see org.tinytim.core.ConstructImpl#_fireEvent(org.tinytim.core.Event, java.lang.Object, java.lang.Object)
+ */
+ @Override
+ protected final void _fireEvent(Event evt, Object oldValue, Object newValue) {
+ handleEvent(evt, this, oldValue, newValue);
+ }
+
+ /* (non-Javadoc)
* @see org.tinytim.IEventHandler#handleEvent(org.tinytim.Event, org.tinytim.IConstruct, java.lang.Object, java.lang.Object)
*/
- public void handleEvent(Event evt, Construct sender, Object oldValue, Object newValue) {
+ public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) {
if (!_evtHandlers.containsKey(evt)) {
_eventMultiplier.handleEvent(evt, sender, oldValue, newValue);
return;
@@ -421,25 +427,25 @@
_handler = handler;
}
- public void handleEvent(Event evt, Construct sender, Object oldValue,
+ public void handleEvent(Event evt, IConstruct sender, Object oldValue,
Object newValue) {
switch (evt) {
- case ADD_TOPIC: _topicAdd((Topic)newValue); break;
- case ADD_ASSOCIATION: _associationAdd((Association)newValue); break;
- case ADD_NAME: _nameAdd((Name)newValue); break;
+ case ADD_TOPIC: _topicAdd((TopicImpl)newValue); break;
+ case ADD_ASSOCIATION: _associationAdd((AssociationImpl)newValue); break;
+ case ADD_NAME: _nameAdd((NameImpl)newValue); break;
case ADD_ROLE:
case ADD_OCCURRENCE:
- ...
[truncated message content] |