From: <lh...@us...> - 2008-08-12 11:36:53
|
Revision: 119 http://tinytim.svn.sourceforge.net/tinytim/?rev=119&view=rev Author: lheuer Date: 2008-08-12 11:36:58 +0000 (Tue, 12 Aug 2008) Log Message: ----------- - Code reorg - Docs - Introduced IConstant for initial set/map sizes 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/IConstruct.java tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java tinytim/trunk/src/main/java/org/tinytim/core/IScope.java tinytim/trunk/src/main/java/org/tinytim/core/IScoped.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/RoleImpl.java tinytim/trunk/src/main/java/org/tinytim/core/Scope.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/utils/TypeInstanceConverter.java tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java tinytim/trunk/src/main/java/org/tinytim/internal/ tinytim/trunk/src/main/java/org/tinytim/internal/utils/ tinytim/trunk/src/main/java/org/tinytim/internal/utils/CollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/DefaultIntObjectMap.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/ICollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/IIntObjectMap.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/JavaCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/TroveCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/WeakObjectRegistry.java tinytim/trunk/src/main/java/org/tinytim/utils/DuplicateRemovalUtils.java tinytim/trunk/src/main/java/org/tinytim/utils/TopicUtils.java tinytim/trunk/src/test/java/org/tinytim/utils/ tinytim/trunk/src/test/java/org/tinytim/utils/TestDuplicateRemovalUtils.java tinytim/trunk/src/test/java/org/tinytim/utils/TestTopicUtils.java Removed Paths: ------------- tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java tinytim/trunk/src/main/java/org/tinytim/core/TopicUtils.java tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/utils/ICollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java tinytim/trunk/src/test/java/org/tinytim/core/TestDuplicateRemovalUtils.java tinytim/trunk/src/test/java/org/tinytim/core/TestTopicUtils.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-08-12 11:36:58 UTC (rev 119) @@ -20,11 +20,12 @@ */ package org.tinytim.core; -import java.util.ArrayList; import java.util.Collections; import java.util.Set; +import org.tinytim.internal.utils.CollectionFactory; import org.tmapi.core.Association; +import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Role; import org.tmapi.core.Topic; import org.tmapi.core.TopicMap; @@ -41,12 +42,12 @@ AssociationImpl(TopicMapImpl tm) { super(tm); - _roles = _makeSet(2); + _roles = CollectionFactory.createIdentitySet(IConstant.ASSOC_ROLE_SIZE); } AssociationImpl(TopicMapImpl topicMap, Topic type, IScope scope) { super(topicMap, type, scope); - _roles = _makeSet(2); + _roles = CollectionFactory.createIdentitySet(IConstant.ASSOC_ROLE_SIZE); } /* (non-Javadoc) @@ -101,10 +102,10 @@ */ public Role createRole(Topic type, Topic player) { if (type == null) { - throw new IllegalArgumentException("The type must not be null"); + throw new ModelConstraintException(this, "The type must not be null"); } if (player == null) { - throw new IllegalArgumentException("The player must not be null"); + throw new ModelConstraintException(this, "The player must not be null"); } RoleImpl role = new RoleImpl(_tm, type, player); addRole(role); @@ -122,7 +123,7 @@ * @see org.tmapi.core.Association#getRoleTypes() */ public Set<Topic> getRoleTypes() { - Set<Topic> roleTypes = _makeSet(_roles.size()); + Set<Topic> roleTypes = CollectionFactory.createIdentitySet(_roles.size()); for (Role role: _roles) { roleTypes.add(role.getType()); } @@ -136,7 +137,7 @@ if (type == null) { throw new IllegalArgumentException("The type must not be null"); } - Set<Role> roles = _makeSet(_roles.size()); + Set<Role> roles = CollectionFactory.createIdentitySet(_roles.size()); for (Role role: _roles) { if (type == role.getType()) { roles.add(role); @@ -158,7 +159,7 @@ */ public void remove() { _tm.removeAssociation(this); - for (Role role: new ArrayList<Role>(_roles)) { + for (Role role: CollectionFactory.createList(_roles)) { role.remove(); } _roles = null; Modified: tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-08-12 11:36:58 UTC (rev 119) @@ -23,7 +23,7 @@ import java.util.Collections; import java.util.Set; -import org.tinytim.utils.CollectionFactory; +import org.tinytim.internal.utils.CollectionFactory; import org.tmapi.core.Construct; import org.tmapi.core.Locator; import org.tmapi.core.TopicMap; @@ -45,14 +45,6 @@ _tm = topicMap; } - protected <E> Set<E> _makeSet() { - return CollectionFactory.createIdentitySet(); - } - - protected <E> Set<E> _makeSet(int size) { - return CollectionFactory.createIdentitySet(size); - } - /* (non-Javadoc) * @see org.tmapi.core.Construct#getParent() */ @@ -94,7 +86,7 @@ } _fireEvent(Event.ADD_IID, null, itemIdentifier); if (_iids == null) { - _iids = _makeSet(); + _iids = CollectionFactory.createIdentitySet(IConstant.CONSTRUCT_IID_SIZE); } _iids.add(itemIdentifier); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-12 11:36:58 UTC (rev 119) @@ -23,8 +23,8 @@ import java.util.Map; import java.util.Set; -import org.tinytim.utils.CollectionFactory; -import org.tinytim.utils.IIntObjectMap; +import org.tinytim.internal.utils.CollectionFactory; +import org.tinytim.internal.utils.IIntObjectMap; import org.tmapi.core.Association; import org.tmapi.core.Construct; import org.tmapi.core.Locator; Modified: tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-08-12 11:36:58 UTC (rev 119) @@ -29,7 +29,7 @@ import org.tmapi.core.Topic; /** - * Implementation of {@link org.tinytim.IDatatypeAwareConstruct}. + * Implementation of {@link org.tmapi.core.DatatypeAware}. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ @@ -166,8 +166,8 @@ * @see org.tmapi.core.DatatypeAware#locatorValue() */ public Locator locatorValue() { - return XSD.ANY_URI.equals(_literal.getDatatype()) ? (Locator) _literal - : Literal.createIRI(_literal.getValue()); + return XSD.ANY_URI == _literal.getDatatype() ? (Locator) _literal + : Literal.createIRI(_literal.getValue()); } /* (non-Javadoc) Deleted: tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java 2008-08-12 11:36:58 UTC (rev 119) @@ -1,181 +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.ArrayList; -import java.util.Collection; - -import org.tinytim.utils.CollectionFactory; -import org.tinytim.utils.IIntObjectMap; -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.TopicMap; -import org.tmapi.core.Variant; -import org.tmapi.index.TypeInstanceIndex; - -/** - * Removes duplicates from Topic Maps constructs. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public final class DuplicateRemovalUtils { - - private DuplicateRemovalUtils() { - // noop. - } - - /** - * Removes duplicate Topic Maps constructs from a topic map. - * - * @param topicMap The topic map to remove the duplicates from. - */ - public static void removeDuplicates(TopicMap topicMap) { - TopicMapImpl tm = (TopicMapImpl) topicMap; - for (Topic topic: tm.getTopics()) { - removeDuplicates(topic); - } - IIntObjectMap<Association> sig2Assoc = CollectionFactory.createIntObjectMap(); - TypeInstanceIndex typeInstanceIdx = tm.getIndexManager().getTypeInstanceIndex(); - if (!typeInstanceIdx.isAutoUpdated()) { - typeInstanceIdx.reindex(); - } - for (Topic type: typeInstanceIdx.getAssociationTypes()) { - _removeDuplicateAssociations(sig2Assoc, typeInstanceIdx.getAssociations(type)); - } - } - - private static void _removeDuplicateAssociations(IIntObjectMap<Association> sig2Assoc, Collection<Association> assocs) { - sig2Assoc.clear(); - Association existing = null; - for (Association assoc: assocs) { - removeDuplicates(assoc); - int sig = SignatureGenerator.generateSignature(assoc); - existing = sig2Assoc.get(sig); - if (existing != null) { - MergeUtils.moveRoleCharacteristics(assoc, existing); - assoc.remove(); - } - else { - sig2Assoc.put(sig, assoc); - } - } - } - - /** - * Removes duplicate occurrences and names from a topic. - * - * @param topic The topic from which duplicates should be removed from. - */ - public static void removeDuplicates(Topic topic) { - _removeDuplicateOccurrences(topic.getOccurrences()); - _removeDuplicateNames(topic.getNames()); - } - - /** - * Removes duplicate variants from a name. - * - * @param name The name from which the duplicates should be removed. - */ - public static void removeDuplicates(Name name) { - IIntObjectMap<Variant> sigs = CollectionFactory.createIntObjectMap(); - for (Variant variant: new ArrayList<Variant>(name.getVariants())) { - int sig = SignatureGenerator.generateSignature(variant); - Variant existing = sigs.get(sig); - if (existing != null) { - MergeUtils.handleExistingConstruct(variant, existing); - variant.remove(); - } - else { - sigs.put(sig, variant); - } - } - } - - /** - * - * - * @param occs - */ - private static void _removeDuplicateOccurrences(Collection<Occurrence> occs) { - IIntObjectMap<Occurrence> sigs = CollectionFactory.createIntObjectMap(occs.size()); - Occurrence existing = null; - for (Occurrence occ: new ArrayList<Occurrence>(occs)) { - int sig = SignatureGenerator.generateSignature(occ); - existing = sigs.get(sig); - if (existing != null) { - MergeUtils.handleExistingConstruct(occ, existing); - occ.remove(); - } - else { - sigs.put(sig, occ); - } - } - } - - /** - * - * - * @param names - */ - private static void _removeDuplicateNames(Collection<Name> names) { - IIntObjectMap<Name> sigs = CollectionFactory.createIntObjectMap(names.size()); - Name existing = null; - for (Name name: new ArrayList<Name>(names)) { - removeDuplicates(name); - int sig = SignatureGenerator.generateSignature(name); - existing = sigs.get(sig); - if (existing != null) { - MergeUtils.handleExistingConstruct(name, existing); - MergeUtils.moveVariants(name, existing); - name.remove(); - } - else { - sigs.put(sig, name); - } - } - } - - /** - * Removes duplicate roles from an association. - * - * @param assoc The association to remove duplicate roles from. - */ - public static void removeDuplicates(Association assoc) { - IIntObjectMap<Role> sig2Role = CollectionFactory.createIntObjectMap(); - Role existing = null; - for (Role role: new ArrayList<Role>(assoc.getRoles())) { - int sig = SignatureGenerator.generateSignature(role); - existing = sig2Role.get(sig); - if (existing != null) { - MergeUtils.handleExistingConstruct(role, existing); - role.remove(); - } - else { - sig2Role.put(sig, role); - } - } - } - -} Added: tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java 2008-08-12 11:36:58 UTC (rev 119) @@ -0,0 +1,112 @@ +/* + * 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; + +/** + * Provides constants. + * + * 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:$ + */ +interface IConstant { + /** + * Initial size of the {@link TopicMapImpl} topic set + */ + public static final int TM_TOPIC_SIZE = 100; + /** + * Initial size of the {@link TopicMapImpl} association set + */ + public static final int TM_ASSOCIATION_SIZE = 100; + /** + * Initial size of the {@link ConstructImpl} item identifier set. + */ + public static final int CONSTRUCT_IID_SIZE = 4; + /** + * Initial size of the {@link TopicImpl} subject identifier set. + */ + public static final int TOPIC_SID_SIZE = 4; + /** + * Initial size of the {@link TopicImpl} subject locator set. + */ + public static final int TOPIC_SLO_SIZE = 2; + /** + * Initial size of the {@link TopicImpl} types set. + */ + public static final int TOPIC_TYPE_SIZE = 2; + /** + * Initial size of the {@link TopicImpl} name set. + */ + public static final int TOPIC_NAME_SIZE = 2; + /** + * Initial size of the {@link TopicImpl} occurrence set. + */ + public static final int TOPIC_OCCURRENCE_SIZE = 2; + /** + * Initial size of the {@link TopicImpl} roles-played set. + */ + public static final int TOPIC_ROLE_SIZE = 2; + /** + * Initial size of the {@link AssociationImpl} roles set. + */ + public static final int ASSOC_ROLE_SIZE = 2; + /** + * Initial size of the {@link NameImpl} variants set. + */ + public static final int NAME_VARIANT_SIZE = 2; + /** + * Initial size of the {@link IdentityManager} id->construct map. + */ + public static final int IDENTITY_ID2CONSTRUCT_SIZE = 200; + /** + * Initial size of the {@link IdentityManager} item identifier->construct map. + */ + public static final int IDENTITY_IID2CONSTRUCT_SIZE = 50; + /** + * Initial size of the {@link IdentityManager} subject identifier->topic map. + */ + public static final int IDENTITY_SID2TOPIC_SIZE = 50; + /** + * Initial size of the {@link IdentityManager} subject locator -> topic map. + */ + public static final int IDENTITY_SLO2TOPIC_SIZE = 20; + /** + * Initial size of the {@link Literal}'s IRI registry. + */ + public static final int LITERAL_IRI_SIZE = 100; + /** + * Initial size of the {@link Literal}'s String registry. + */ + public static final int LITERAL_STRING_SIZE = 50; + /** + * Initial size of the {@link Literal}'s literal (!= String/IRI) registry. + */ + public static final int LITERAL_OTHER_SIZE = 50; + /** + * Initial size of the {@link Scope}'s scope registry. + */ + public static final int SCOPE_SCOPES_SIZE = 10; + /** + * Initial size of the {@link TopicMapSystemImpl} topic map map. + */ + public static final int SYSTEM_TM_SIZE = 4; +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java 2008-08-12 11:36:58 UTC (rev 119) @@ -23,7 +23,9 @@ import org.tmapi.core.Construct; /** + * Enhancement of the {@link org.tmapi.core.Construct} interface. * + * 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$ Modified: tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java 2008-08-12 11:36:58 UTC (rev 119) @@ -26,8 +26,8 @@ import org.tmapi.core.Locator; /** + * Represents an immutable value with a datatype. * - * * 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> @@ -35,18 +35,53 @@ */ public interface ILiteral { + /** + * Returns the string value. + * + * @return The string value. + */ public String getValue(); + /** + * Returns the datatype. + * + * @return The datatype. + */ public Locator getDatatype(); + /** + * Returns the BigDecimal value. + * + * @return BigDecimal value. + */ public BigDecimal decimalValue(); + /** + * Returns the float value. + * + * @return Float value. + */ public float floatValue(); + /** + * Returns the BigInteger value. + * + * @return BigInteger value. + */ public BigInteger integerValue(); + /** + * Returns the int value. + * + * @return Int value. + */ public int intValue(); + /** + * Returns the long value. + * + * @return Long value. + */ public long longValue(); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java 2008-08-12 11:36:58 UTC (rev 119) @@ -21,8 +21,8 @@ package org.tinytim.core; /** + * Indicates that a literal can be attached to a construct. * - * * 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> @@ -30,8 +30,18 @@ */ public interface ILiteralAware { + /** + * Returns the literal. + * + * @return The literal. + */ public ILiteral getLiteral(); + /** + * Sets the literal. + * + * @param literal The literal. + */ public void setLiteral(ILiteral literal); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/IScope.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IScope.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/IScope.java 2008-08-12 11:36:58 UTC (rev 119) @@ -34,16 +34,53 @@ */ public interface IScope extends Iterable<Topic> { + /** + * Returns the scope as set of topics. + * + * @return A set of topics. + */ public Set<Topic> asSet(); + /** + * Returns <tt>true</tt> if the theme is part of this scope. + * + * @param theme A topic. + * @return <tt>true</tt> if the theme is part of this scope, otherwise <tt>false</tt>. + */ public boolean contains(Topic theme); + /** + * Returns a <tt>IScope</tt> consisting of all themes contained in this + * scope and the <tt>theme</tt>. + * + * @param theme The theme to add. + * @return A scope instance which is contains all themes of this scope plus + * the specified <tt>theme</tt>. + */ public IScope add(Topic theme); + /** + * Returns a <tt>IScope</tt> where the <tt>theme</tt> is removed from this + * set of themes.. + * + * @param theme The theme to remove. + * @return A scope instance which is contains all themes of this scope minus + * the specified <tt>theme</tt>. + */ public IScope remove(Topic theme); + /** + * Returns if this scope is unconstrained (empty). + * + * @return <tt>true</tt> if the scope is unconstrained, <tt>false</tt> otherwise. + */ public boolean isUnconstrained(); + /** + * Returns the number of themes contained in this scope. + * + * @return Number of themes. + */ public int size(); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java 2008-08-12 11:36:58 UTC (rev 119) @@ -23,14 +23,27 @@ import org.tmapi.core.Scoped; /** + * Enhancement of the {@link org.tmapi.core.Scoped} interface which is + * {@link IScope} aware. * + * 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 IScoped extends Scoped, IConstruct { + /** + * Returns the scope. + * + * @return The scope. + */ public IScope getScopeObject(); + /** + * Sets the scope. + * + * @param scope The scope. + */ public void setScopeObject(IScope scope); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-08-12 11:36:58 UTC (rev 119) @@ -23,7 +23,9 @@ import java.util.concurrent.atomic.AtomicLong; /** + * Class used to generate identifiers. * + * This class 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$ @@ -32,6 +34,11 @@ private static final AtomicLong _COUNTER = new AtomicLong(); + /** + * Returns the next identifier. + * + * @return <tt>long</tt> value. + */ 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-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java 2008-08-12 11:36:58 UTC (rev 119) @@ -22,7 +22,7 @@ import java.util.Map; -import org.tinytim.utils.CollectionFactory; +import org.tinytim.internal.utils.CollectionFactory; import org.tmapi.core.Construct; import org.tmapi.core.IdentityConstraintException; import org.tmapi.core.Locator; @@ -34,6 +34,8 @@ * The identity manager takes care about the TMDM identity constraints and * provides an index to get Topic Maps constructs by their identity. * + * This class 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$ */ @@ -45,10 +47,10 @@ private Map<String, IConstruct> _id2Construct; IdentityManager(TopicMapImpl tm) { - _id2Construct = CollectionFactory.createIdentityMap(); - _sid2Topic = CollectionFactory.createIdentityMap(); - _slo2Topic = CollectionFactory.createIdentityMap(); - _iid2Construct = CollectionFactory.createIdentityMap(); + _id2Construct = CollectionFactory.createIdentityMap(IConstant.IDENTITY_ID2CONSTRUCT_SIZE); + _sid2Topic = CollectionFactory.createIdentityMap(IConstant.IDENTITY_SID2TOPIC_SIZE); + _slo2Topic = CollectionFactory.createIdentityMap(IConstant.IDENTITY_SLO2TOPIC_SIZE); + _iid2Construct = CollectionFactory.createIdentityMap(IConstant.IDENTITY_IID2CONSTRUCT_SIZE); _subscribe(tm); _register(tm); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/Literal.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Literal.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/Literal.java 2008-08-12 11:36:58 UTC (rev 119) @@ -23,7 +23,7 @@ import java.math.BigDecimal; import java.math.BigInteger; -import org.tinytim.utils.WeakObjectRegistry; +import org.tinytim.internal.utils.WeakObjectRegistry; import org.tinytim.voc.XSD; import org.tmapi.core.Locator; @@ -37,9 +37,9 @@ */ public final class Literal implements ILiteral { - private static final WeakObjectRegistry<IRI> _IRIS = new WeakObjectRegistry<IRI>(); - private static final WeakObjectRegistry<ILiteral> _STRINGS = new WeakObjectRegistry<ILiteral>(); - private static final WeakObjectRegistry<ILiteral> _LITERALS = new WeakObjectRegistry<ILiteral>();; + private static final WeakObjectRegistry<IRI> _IRIS = new WeakObjectRegistry<IRI>(IConstant.LITERAL_IRI_SIZE); + private static final WeakObjectRegistry<ILiteral> _STRINGS = new WeakObjectRegistry<ILiteral>(IConstant.LITERAL_STRING_SIZE); + private static final WeakObjectRegistry<ILiteral> _OTHERS = new WeakObjectRegistry<ILiteral>(IConstant.LITERAL_OTHER_SIZE); private final String _value; private final Locator _datatype; @@ -84,7 +84,7 @@ if (XSD.STRING.equals(datatype)) { return get(value); } - return _LITERALS.get(new Literal(value, datatype)); + return _OTHERS.get(new Literal(value, datatype)); } @@ -102,11 +102,11 @@ return create(value); } ILiteral literal = new Literal(value, datatype); - ILiteral existing = _LITERALS.get(literal); + ILiteral existing = _OTHERS.get(literal); if (existing != null) { return existing; } - _LITERALS.add(literal); + _OTHERS.add(literal); return literal; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-12 11:36:58 UTC (rev 119) @@ -25,8 +25,8 @@ import java.util.List; import org.tinytim.index.IIndexManager; -import org.tinytim.utils.CollectionFactory; -import org.tinytim.utils.IIntObjectMap; +import org.tinytim.internal.utils.CollectionFactory; +import org.tinytim.internal.utils.IIntObjectMap; import org.tmapi.core.Association; import org.tmapi.core.Construct; import org.tmapi.core.Locator; @@ -52,7 +52,7 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -final class MergeUtils { +public final class MergeUtils { private MergeUtils() { // noop. @@ -176,7 +176,7 @@ * @param source The association to remove the characteristics from. * @param target The association which takes the role characteristics. */ - static void moveRoleCharacteristics(Association source, Association target) { + public static void moveRoleCharacteristics(Association source, Association target) { IIntObjectMap<Role> sigs = CollectionFactory.createIntObjectMap(); for (Role role: target.getRoles()) { sigs.put(SignatureGenerator.generateSignature(role), role); @@ -194,7 +194,7 @@ * @param source The name to take the variants from. * @param target The target to add the variants to. */ - static void moveVariants(Name source, Name target) { + public static void moveVariants(Name source, Name target) { IIntObjectMap<Variant> sigs = CollectionFactory.createIntObjectMap(); for (Variant var: target.getVariants()) { sigs.put(SignatureGenerator.generateSignature(var), var); @@ -224,7 +224,7 @@ * @param source The source Topic Maps construct. * @param target The target Topic Maps construct. */ - static void handleExistingConstruct(Reifiable source, Reifiable target) { + public static void handleExistingConstruct(Reifiable source, Reifiable target) { _moveItemIdentifiers(source, target); if (source.getReifier() == null) { return; Modified: tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2008-08-12 11:36:58 UTC (rev 119) @@ -25,6 +25,7 @@ import java.util.Collections; import java.util.Set; +import org.tinytim.internal.utils.CollectionFactory; import org.tmapi.core.Locator; import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Name; @@ -87,6 +88,9 @@ * @see org.tmapi.core.Name#setValue(java.lang.String) */ public void setValue(String value) { + if (value == null) { + throw new ModelConstraintException(this, "The value must not be null"); + } setLiteral(Literal.create(value)); } @@ -98,10 +102,30 @@ : Collections.unmodifiableSet(_variants); } + private void _checkVariantValue(Object value) { + if (value == null) { + throw new ModelConstraintException(this, "The variant's value must not be null"); + } + } + + private void _checkVariantValue(String value, Locator datatype) { + _checkVariantValue(value); + if (datatype == null) { + throw new ModelConstraintException(this, "The variant's datatype must not be null"); + } + } + + private void _checkVariantScope(Topic[] scope) { + if (scope == null) { + throw new ModelConstraintException(this, "The variant's scope must not be null"); + } + } + /* (non-Javadoc) * @see org.tmapi.core.Name#createVariant(org.tmapi.core.Locator, java.util.Collection) */ public Variant createVariant(Locator value, Collection<Topic> scope) { + _checkVariantValue(value); return _createVariant(Literal.create(value), scope); } @@ -109,6 +133,7 @@ * @see org.tmapi.core.Name#createVariant(java.lang.String, java.util.Collection) */ public Variant createVariant(String value, Collection<Topic> scope) { + _checkVariantValue(value); return _createVariant(Literal.create(value), scope); } @@ -116,6 +141,7 @@ * @see org.tmapi.core.Name#createVariant(org.tmapi.core.Locator, org.tmapi.core.Topic[]) */ public Variant createVariant(Locator value, Topic... scope) { + _checkVariantScope(scope); return createVariant(value, Arrays.asList(scope)); } @@ -124,6 +150,7 @@ */ public Variant createVariant(String value, Locator datatype, Collection<Topic> scope) { + _checkVariantValue(value, datatype); return _createVariant(value, datatype, scope); } @@ -131,6 +158,7 @@ * @see org.tmapi.core.Name#createVariant(java.lang.String, org.tmapi.core.Locator, org.tmapi.core.Topic[]) */ public Variant createVariant(String value, Locator datatype, Topic... scope) { + _checkVariantScope(scope); return createVariant(value, datatype, Arrays.asList(scope)); } @@ -138,18 +166,20 @@ * @see org.tmapi.core.Name#createVariant(java.lang.String, org.tmapi.core.Topic[]) */ public Variant createVariant(String value, Topic... scope) { + _checkVariantScope(scope); return createVariant(value, Arrays.asList(scope)); } private Variant _createVariant(String value, Locator datatype, Collection<Topic> scope) { + _checkVariantValue(value, datatype); return _createVariant(Literal.create(value, datatype), scope); } Variant _createVariant(ILiteral literal, Collection<Topic> scope) { if (scope.isEmpty()) { - throw new IllegalArgumentException("The scope of the variant must not be unconstrained"); + throw new ModelConstraintException(this, "The scope of the variant must not be unconstrained"); } - Set<Topic> scope_ = _makeSet(scope.size()); + Set<Topic> scope_ = CollectionFactory.createIdentitySet(scope.size()); scope_.addAll(scope); scope_.removeAll(super.getScope()); if (scope_.isEmpty()) { @@ -181,7 +211,7 @@ void attachVariant(VariantImpl variant) { if (_variants == null) { - _variants = _makeSet(); + _variants = CollectionFactory.createIdentitySet(IConstant.NAME_VARIANT_SIZE); } variant._parent = this; _variants.add(variant); Modified: tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java 2008-08-12 11:36:58 UTC (rev 119) @@ -21,6 +21,7 @@ package org.tinytim.core; import org.tmapi.core.Association; +import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Role; import org.tmapi.core.Topic; @@ -62,7 +63,7 @@ */ public void setPlayer(Topic player) { if (player == null) { - throw new IllegalArgumentException("The role player must not be null"); + throw new ModelConstraintException(this, "The role player must not be null"); } if (_player == player) { return; Modified: tinytim/trunk/src/main/java/org/tinytim/core/Scope.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Scope.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/Scope.java 2008-08-12 11:36:58 UTC (rev 119) @@ -25,8 +25,8 @@ import java.util.Iterator; import java.util.Set; -import org.tinytim.utils.CollectionFactory; -import org.tinytim.utils.WeakObjectRegistry; +import org.tinytim.internal.utils.CollectionFactory; +import org.tinytim.internal.utils.WeakObjectRegistry; import org.tmapi.core.Topic; /** @@ -39,7 +39,7 @@ public static final IScope UCS = new Scope(); - private static final WeakObjectRegistry<IScope> _SCOPES = new WeakObjectRegistry<IScope>(); + private static final WeakObjectRegistry<IScope> _SCOPES = new WeakObjectRegistry<IScope>(IConstant.SCOPE_SCOPES_SIZE); private final Set<Topic> _set; @@ -52,10 +52,6 @@ _set.addAll(themes); } - private Scope(Set<Topic> themes) { - _set = themes; - } - /* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ @@ -75,19 +71,17 @@ return _set.hashCode(); } - public static synchronized IScope create(Collection<Topic> scope) { - if (scope.isEmpty()) { + public static synchronized IScope create(Collection<Topic> themes) { + if (themes.isEmpty()) { return UCS; } - Set<Topic> themes = CollectionFactory.createIdentitySet(scope.size()); - themes.addAll(scope); - IScope scope_ = new Scope(themes); - IScope existing = _SCOPES.get(scope_); + IScope scope = new Scope(themes); + IScope existing = _SCOPES.get(scope); if (existing != null) { return existing; } - _SCOPES.add(scope_); - return scope_; + _SCOPES.add(scope); + return scope; } /* (non-Javadoc) @@ -111,8 +105,7 @@ if (_set.contains(theme)) { return this; } - Collection<Topic> themes = CollectionFactory.createIdentitySet(_set.size()); - themes.addAll(_set); + Collection<Topic> themes = CollectionFactory.createList(_set); themes.add(theme); return create(themes); } @@ -124,8 +117,7 @@ if (!_set.contains(theme)) { return this; } - Collection<Topic> themes = CollectionFactory.createIdentitySet(_set.size()); - themes.addAll(_set); + Collection<Topic> themes = CollectionFactory.createList(_set); themes.remove(theme); return create(themes); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java 2008-08-12 11:36:58 UTC (rev 119) @@ -45,7 +45,7 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -final class SignatureGenerator { +public final class SignatureGenerator { private SignatureGenerator() { // noop. Modified: tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java 2008-08-12 11:36:58 UTC (rev 119) @@ -25,6 +25,8 @@ import java.util.Collections; import java.util.Set; +import org.tinytim.internal.utils.CollectionFactory; +import org.tinytim.utils.TopicUtils; import org.tmapi.core.Locator; import org.tmapi.core.Name; import org.tmapi.core.Occurrence; @@ -52,9 +54,9 @@ TopicImpl(TopicMapImpl topicMap) { super(topicMap); - _sids = _makeSet(2); - _occs = _makeSet(2); - _names = _makeSet(2); + _sids = CollectionFactory.createIdentitySet(IConstant.TOPIC_SID_SIZE); + _occs = CollectionFactory.createIdentitySet(IConstant.TOPIC_OCCURRENCE_SIZE); + _names = CollectionFactory.createIdentitySet(IConstant.TOPIC_NAME_SIZE); } /* (non-Javadoc) @@ -117,7 +119,7 @@ } _fireEvent(Event.ADD_SLO, null, slo); if (_slos == null) { - _slos = _makeSet(2); + _slos = CollectionFactory.createIdentitySet(IConstant.TOPIC_SLO_SIZE); } _slos.add(slo); } @@ -250,7 +252,7 @@ if (type == null) { throw new IllegalArgumentException("The type must not be null"); } - Set<Name> names = _makeSet(); + Set<Name> names = CollectionFactory.createIdentitySet(); for (Name name: _names) { if (type == name.getType()) { names.add(name); @@ -280,7 +282,7 @@ if (type == null) { throw new IllegalArgumentException("The type must not be null"); } - Set<Occurrence> occs = _makeSet(); + Set<Occurrence> occs = CollectionFactory.createIdentitySet(); for (Occurrence occ: _occs) { if (type == occ.getType()) { occs.add(occ); @@ -372,7 +374,7 @@ if (_rolesPlayed == null) { return Collections.emptySet(); } - Set<Role> roles = _makeSet(_rolesPlayed.size()); + Set<Role> roles = CollectionFactory.createIdentitySet(_rolesPlayed.size()); for (Role role: _rolesPlayed) { if (type == role.getType()) { roles.add(role); @@ -394,7 +396,7 @@ if (_rolesPlayed == null) { return Collections.emptySet(); } - Set<Role> roles = _makeSet(_rolesPlayed.size()); + Set<Role> roles = CollectionFactory.createIdentitySet(_rolesPlayed.size()); for (Role role: _rolesPlayed) { if (type == role.getType() && assoc == role.getParent().getType()) { roles.add(role); @@ -405,7 +407,7 @@ void addRolePlayed(Role role) { if (_rolesPlayed == null) { - _rolesPlayed = _makeSet(4); + _rolesPlayed = CollectionFactory.createIdentitySet(IConstant.TOPIC_ROLE_SIZE); } _rolesPlayed.add(role); } @@ -437,7 +439,7 @@ } _fireEvent(Event.ADD_TYPE, null, type); if (_types == null) { - _types = _makeSet(); + _types = CollectionFactory.createIdentitySet(IConstant.TOPIC_TYPE_SIZE); } _types.add(type); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java 2008-08-12 11:36:58 UTC (rev 119) @@ -30,7 +30,7 @@ import org.tinytim.index.IndexManager; import org.tinytim.index.IIndexManager; -import org.tinytim.utils.CollectionFactory; +import org.tinytim.internal.utils.CollectionFactory; import org.tinytim.voc.TMDM; import org.tmapi.core.Association; import org.tmapi.core.IdentityConstraintException; @@ -68,8 +68,8 @@ super._tm = this; _sys = sys; _locator = locator; - _topics = CollectionFactory.createIdentitySet(100); - _assocs = CollectionFactory.createIdentitySet(100); + _topics = CollectionFactory.createIdentitySet(IConstant.TM_TOPIC_SIZE); + _assocs = CollectionFactory.createIdentitySet(IConstant.TM_ASSOCIATION_SIZE); _evtHandlers = CollectionFactory.createIdentityMap(); _identityManager = new IdentityManager(this); _indexManager = new IndexManager(this); Modified: tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemFactoryImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemFactoryImpl.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemFactoryImpl.java 2008-08-12 11:36:58 UTC (rev 119) @@ -20,9 +20,9 @@ */ package org.tinytim.core; -import java.util.HashMap; import java.util.Map; +import org.tinytim.internal.utils.CollectionFactory; import org.tinytim.utils.Feature; import org.tmapi.core.FeatureNotRecognizedException; import org.tmapi.core.FeatureNotSupportedException; @@ -52,8 +52,8 @@ private Map<String, Boolean> _features; public TopicMapSystemFactoryImpl() { - _properties = new HashMap<String, Object>(); - _features = new HashMap<String, Boolean>(_FEATURES.length); + _properties = CollectionFactory.createMap(); + _features = CollectionFactory.createMap(_FEATURES.length); for (FeatureInfo feature: _FEATURES) { _features.put(feature.name, feature.defaultValue); } @@ -64,7 +64,7 @@ */ @Override public TopicMapSystem newTopicMapSystem() throws TMAPIException { - return new TopicMapSystemImpl(new HashMap<String, Boolean>(_features), new HashMap<String, Object>(_properties)); + return new TopicMapSystemImpl(CollectionFactory.createMap(_features), CollectionFactory.createMap(_properties)); } /* (non-Javadoc) Modified: tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemImpl.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemImpl.java 2008-08-12 11:36:58 UTC (rev 119) @@ -24,7 +24,7 @@ import java.util.Map; import java.util.Set; -import org.tinytim.utils.CollectionFactory; +import org.tinytim.internal.utils.CollectionFactory; import org.tmapi.core.FeatureNotRecognizedException; import org.tmapi.core.Locator; import org.tmapi.core.TopicMap; @@ -47,7 +47,7 @@ TopicMapSystemImpl(Map<String, Boolean> features, Map<String, Object> properties) { _features = features; _properties = properties; - _topicMaps = CollectionFactory.createIdentityMap(4); + _topicMaps = CollectionFactory.createIdentityMap(IConstant.SYSTEM_TM_SIZE); } /** Deleted: tinytim/trunk/src/main/java/org/tinytim/core/TopicUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TopicUtils.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/TopicUtils.java 2008-08-12 11:36:58 UTC (rev 119) @@ -1,103 +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.tinytim.index.IIndexManager; -import org.tmapi.core.Topic; -import org.tmapi.index.ScopedIndex; -import org.tmapi.index.TypeInstanceIndex; - -/** - * 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, and is not not used as theme of a scoped - * Topic Maps construct. - * - * This function returns the same result as - * <code>isRemovable(topic, false)</code>. - * - * @param topic The topic to check. - * @return <code>true</code> if the topic is removable, <code>false</code> - * otherwise. - */ - public static boolean isRemovable(Topic topic) { - return isRemovable(topic, false); - } - - /** - * 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 - * (if <code>includeReified</code> is <code>true</code>). - * - * @param topic The topic to check. - * @param includeReified Indicates if a reified Topic Maps construct (if any) - * is considered as dependency. - * @return <code>true</code> if the topic is removable, <code>false</code> - * otherwise. - */ - public static boolean isRemovable(Topic topic, boolean includeReified) { - if (includeReified && topic.getReified() != null) { - return false; - } - if (!topic.getRolesPlayed().isEmpty()) { - return false; - } - IIndexManager idxMan = ((TopicMapImpl) topic.getTopicMap()).getIndexManager(); - TypeInstanceIndex typeInstanceIdx = idxMan.getTypeInstanceIndex(); - if (!typeInstanceIdx.isAutoUpdated()) { - typeInstanceIdx.reindex(); - } - boolean removable = typeInstanceIdx.getAssociations(topic).isEmpty() - && typeInstanceIdx.getRoles(topic).isEmpty() - && typeInstanceIdx.getOccurrences(topic).isEmpty() - && typeInstanceIdx.getNames(topic).isEmpty(); - typeInstanceIdx.close(); - if (removable) { - ScopedIndex scopedIdx = idxMan.getScopedIndex(); - if (!scopedIdx.isAutoUpdated()) { - scopedIdx.reindex(); - } - removable = scopedIdx.getAssociations(topic).isEmpty() - && scopedIdx.getOccurrences(topic).isEmpty() - && scopedIdx.getNames(topic).isEmpty() - && scopedIdx.getVariants(topic).isEmpty(); - scopedIdx.close(); - } - return removable; - } - -} Modified: tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java 2008-08-12 11:36:58 UTC (rev 119) @@ -20,6 +20,7 @@ */ package org.tinytim.core; +import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Reifiable; import org.tmapi.core.Topic; @@ -60,7 +61,7 @@ */ public void setType(Topic type) { if (type == null) { - throw new IllegalArgumentException("The type cannot be set to null"); + throw new ModelConstraintException(this, "The type cannot be set to null"); } if (_type == type) { return; Modified: tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java 2008-08-11 16:45:18 UTC (rev 118) +++ tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java 2008-08-12 11:36:58 UTC (rev 119) @@ -22,6 +22,7 @@ import java.util.Set; +import org.tinytim.internal.utils.CollectionFactory; import org.tmapi.core.Name; import org.tmapi.core.Scoped; import org.tmapi.core.Topic; @@ -59,7 +60,7 @@ if (_tm == null || _parent == null) { return super.getScope(); } - Set<Topic> scope = _makeSet(4); + Set<Topic> scope = CollectionFactory.createIdentitySet(4); scope.addAll(super.getScope()); scope.addAll(((Scoped) _parent).getScope()); return scope; Added: tinytim/trunk/src/main/java/org/tinytim/internal/utils/CollectionFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/internal/utils/CollectionFactory.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/internal/utils/CollectionFactory.java 2008-08-12 11:36:58 UTC (rev 119) @@ -0,0 +1,139 @@ +/* + * 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.internal.utils; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public final class CollectionFactory { + + private static final String _COLL_FACTORY_TROVE = "org.tinytim.internal.utils.TroveCollectionFactory"; + + private static final ICollectionFactory _COLL_FACTORY; + + static { + ICollectionFactory collFactory; + try { + Class.forName("gnu.trove.THashSet"); + collFactory = (ICollectionFactory) Class.forName(_COLL_FACTORY_TROVE).newInstance(); + } + catch (Exception ex) { + collFactory = new JavaCollectionFactory(); + } + _COLL_FACTORY = collFactory; + } + + private CollectionFactory() { + // noop. + } + + /* (non-Javadoc) + * @see org.tinytim.utils.ICollectionFactory#createIdentityMap() + */ + public static <K, V> Map<K, V> createIdentityMap() { + return _COLL_FACTORY.createIdentityMap(); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.ICollectionFactory#createIdentityMap(int) + */ + public static <K, V> Map<K, V> createIdentityMap(int size) { + return _COLL_FACTORY.createIdentityMap(size); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.ICollectionFactory#createIdentitySet(int) + */ + public static <E> Set<E> createIdentitySet(int size) { + return _COLL_FACTORY.createIdentitySet(size); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.ICollectionFactory#createIdentitySet() + */ + public static <E> Set<E> createIdentitySet() { + return _COLL_FACTORY.createIdentitySet(); + } + + public static <E> Set<E> createIdentitySet(Set<? extends E> elements) { + return _COLL_FACTORY.createIdentitySet(elements); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.ICollectionFactory#createMap() + */ + public static <K, V> Map<K, V> createMap() { + return _COLL_FACTORY.createMap(); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.ICollectionFactory#createMap(int) + */ + public static <K, V> Map<K, V> createMap(int size) { + return _COLL_FACTORY.createMap(size); + } + + public static <K, V> Map<K, V> createMap(Map<? extends K,? extends V> map) { + return _COLL_FACTORY.createMap(map); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.ICollectionFactory#createSet(int) + */ + public static <E> Set<E> createSet(int size) { + return _COLL_FACTORY.createSet(size); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.ICollectionFactory#createSet() + */ + public static <E> Set<E> createSet() { + return _COLL_FACTORY.createSet(); + } + + public static <E> IIntObjectMap<E> createIntObjectMap() { + return _COLL_FACTORY.createIntObjectMap(); + } + + public static <E> IIntObjectMap<E> createIntObjectMap(int size) { + return _COLL_FACTORY.createIntObjectMap(size); + } + + public static <E> List<E> createList() { + ... [truncated message content] |