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] |
From: <lh...@us...> - 2008-08-14 11:58:31
|
Revision: 122 http://tinytim.svn.sourceforge.net/tinytim/?rev=122&view=rev Author: lheuer Date: 2008-08-14 11:58:37 +0000 (Thu, 14 Aug 2008) Log Message: ----------- - Adapted TMAPI 2.0 changes - Simplified argument checks 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/DatatypeAwareConstruct.java tinytim/trunk/src/main/java/org/tinytim/core/IConstant.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/ScopedImpl.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/TypedImpl.java tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/DefaultIntObjectMap.java tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -23,9 +23,9 @@ import java.util.Collections; import java.util.Set; +import org.tinytim.internal.utils.Check; 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; @@ -101,12 +101,8 @@ * @see org.tmapi.core.Association#createRole(org.tmapi.core.Topic, org.tmapi.core.Topic) */ public Role createRole(Topic type, Topic player) { - if (type == null) { - throw new ModelConstraintException(this, "The type must not be null"); - } - if (player == null) { - throw new ModelConstraintException(this, "The player must not be null"); - } + Check.typeNotNull(this, type); + Check.playerNotNull(this, player); RoleImpl role = new RoleImpl(_tm, type, player); addRole(role); return role; Modified: tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -26,6 +26,7 @@ import org.tinytim.internal.utils.CollectionFactory; import org.tmapi.core.Construct; import org.tmapi.core.Locator; +import org.tmapi.core.ModelConstraintException; import org.tmapi.core.TopicMap; /** @@ -79,7 +80,7 @@ */ public void addItemIdentifier(Locator itemIdentifier) { if (itemIdentifier == null) { - throw new IllegalArgumentException("The item identifier must not be null"); + throw new ModelConstraintException(this, "The item identifier must not be null"); } if (_iids != null && _iids.contains(itemIdentifier)) { return; Modified: tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-08-14 11:58:37 UTC (rev 122) @@ -23,6 +23,7 @@ import java.math.BigDecimal; import java.math.BigInteger; +import org.tinytim.internal.utils.Check; import org.tinytim.voc.XSD; import org.tmapi.core.DatatypeAware; import org.tmapi.core.Locator; @@ -82,6 +83,7 @@ * @see org.tmapi.core.DatatypeAware#setValue(java.lang.String) */ public void setValue(String value) { + Check.valueNotNull(this, value); setLiteral(Literal.create(value)); } @@ -89,6 +91,7 @@ * @see org.tmapi.core.DatatypeAware#setValue(java.math.BigDecimal) */ public void setValue(BigDecimal value) { + Check.valueNotNull(this, value); setLiteral(Literal.create(value)); } @@ -96,6 +99,7 @@ * @see org.tmapi.core.DatatypeAware#setValue(java.math.BigInteger) */ public void setValue(BigInteger value) { + Check.valueNotNull(this, value); setLiteral(Literal.create(value)); } @@ -117,6 +121,7 @@ * @see org.tmapi.core.DatatypeAware#setValue(org.tmapi.core.Locator) */ public void setValue(Locator value) { + Check.valueNotNull(this, value); setLiteral(Literal.create(value)); } @@ -131,6 +136,7 @@ * @see org.tmapi.core.DatatypeAware#setValue(java.lang.String, org.tmapi.core.Locator) */ public void setValue(String value, Locator datatype) { + Check.valueNotNull(this, value, datatype); setLiteral(Literal.create(value, datatype)); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java 2008-08-14 11:58:37 UTC (rev 122) @@ -26,7 +26,7 @@ * 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:$ + * @version $Rev$ - $Date$ */ interface IConstant { /** Modified: tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-14 11:58:37 UTC (rev 122) @@ -20,7 +20,6 @@ */ package org.tinytim.core; -import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -107,12 +106,12 @@ if (sourceReifiable != null) { sourceReifiable.setReifier(target); } - List<Locator> locs = new ArrayList<Locator>(source.getSubjectIdentifiers()); + List<Locator> locs = CollectionFactory.createList(source.getSubjectIdentifiers()); for (Locator sid: locs) { source.removeSubjectIdentifier(sid); target.addSubjectIdentifier(sid); } - locs = new ArrayList<Locator>(source.getSubjectLocators()); + locs = CollectionFactory.createList(source.getSubjectLocators()); for (Locator slo: locs) { source.removeSubjectLocator(slo); target.addSubjectLocator(slo); @@ -126,7 +125,7 @@ sigs.put(SignatureGenerator.generateSignature(occ), occ); } Reifiable existing = null; - for (Occurrence occ: new ArrayList<Occurrence>(source.getOccurrences())) { + for (Occurrence occ: CollectionFactory.createList(source.getOccurrences())) { existing = sigs.get(SignatureGenerator.generateSignature(occ)); if (existing != null) { handleExistingConstruct(occ, existing); @@ -140,7 +139,7 @@ for (Name name: target.getNames()) { sigs.put(SignatureGenerator.generateSignature(name), name); } - for (Name name: new ArrayList<Name>(source.getNames())) { + for (Name name: CollectionFactory.createList(source.getNames())) { existing = sigs.get(SignatureGenerator.generateSignature(name)); if (existing != null) { handleExistingConstruct(name, existing); @@ -156,7 +155,7 @@ Association parent = role.getParent(); sigs.put(SignatureGenerator.generateSignature(parent), parent); } - for (Role role: new ArrayList<Role>(source.getRolesPlayed())) { + for (Role role: CollectionFactory.createList(source.getRolesPlayed())) { role.setPlayer(target); Association parent = role.getParent(); existing = sigs.get(SignatureGenerator.generateSignature(parent)); @@ -181,8 +180,7 @@ for (Role role: target.getRoles()) { sigs.put(SignatureGenerator.generateSignature(role), role); } - List<Role> roles = new ArrayList<Role>(source.getRoles()); - for (Role role: roles) { + for (Role role: CollectionFactory.createList(source.getRoles())) { handleExistingConstruct(role, sigs.get(SignatureGenerator.generateSignature(role))); role.remove(); } @@ -200,7 +198,7 @@ sigs.put(SignatureGenerator.generateSignature(var), var); } Variant existing = null; - for (Variant var: new ArrayList<Variant>(source.getVariants())) { + for (Variant var: CollectionFactory.createList(source.getVariants())) { existing = sigs.get(SignatureGenerator.generateSignature(var)); if (existing != null) { handleExistingConstruct(var, existing); @@ -311,7 +309,7 @@ * @param target The target which get the item identifiers. */ private static void _moveItemIdentifiers(Construct source, Construct target) { - List<Locator> iids = new ArrayList<Locator>(source.getItemIdentifiers()); + List<Locator> iids = CollectionFactory.createList(source.getItemIdentifiers()); for (Locator iid: iids) { source.removeItemIdentifier(iid); target.addItemIdentifier(iid); Modified: tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -25,6 +25,7 @@ import java.util.Collections; import java.util.Set; +import org.tinytim.internal.utils.Check; import org.tinytim.internal.utils.CollectionFactory; import org.tmapi.core.Locator; import org.tmapi.core.ModelConstraintException; @@ -88,44 +89,49 @@ * @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"); - } + Check.valueNotNull(this, value); setLiteral(Literal.create(value)); } /* (non-Javadoc) - * @see org.tmapi.core.TopicName#getVariants() + * @see org.tinytim.core.ScopedImpl#addTheme(org.tmapi.core.Topic) */ - public Set<Variant> getVariants() { - return _variants == null ? Collections.<Variant>emptySet() - : Collections.unmodifiableSet(_variants); - } - - private void _checkVariantValue(Object value) { - if (value == null) { - throw new ModelConstraintException(this, "The variant's value must not be null"); + @Override + public void addTheme(Topic theme) { + super.addTheme(theme); + if (_variants != null) { + for (Variant variant: _variants) { + variant.addTheme(theme); + } } } - private void _checkVariantValue(String value, Locator datatype) { - _checkVariantValue(value); - if (datatype == null) { - throw new ModelConstraintException(this, "The variant's datatype must not be null"); + /* (non-Javadoc) + * @see org.tinytim.core.ScopedImpl#removeTheme(org.tmapi.core.Topic) + */ + @Override + public void removeTheme(Topic theme) { + super.removeTheme(theme); + if (_variants != null) { + for (Variant variant: _variants) { + variant.removeTheme(theme); + } } } - 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.TopicName#getVariants() + */ + public Set<Variant> getVariants() { + return _variants == null ? Collections.<Variant>emptySet() + : Collections.unmodifiableSet(_variants); } /* (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); + Check.valueNotNull(this, value); return _createVariant(Literal.create(value), scope); } @@ -133,7 +139,7 @@ * @see org.tmapi.core.Name#createVariant(java.lang.String, java.util.Collection) */ public Variant createVariant(String value, Collection<Topic> scope) { - _checkVariantValue(value); + Check.valueNotNull(this, value); return _createVariant(Literal.create(value), scope); } @@ -141,7 +147,7 @@ * @see org.tmapi.core.Name#createVariant(org.tmapi.core.Locator, org.tmapi.core.Topic[]) */ public Variant createVariant(Locator value, Topic... scope) { - _checkVariantScope(scope); + Check.scopeNotNull(this, scope); return createVariant(value, Arrays.asList(scope)); } @@ -150,7 +156,7 @@ */ public Variant createVariant(String value, Locator datatype, Collection<Topic> scope) { - _checkVariantValue(value, datatype); + Check.valueNotNull(this, value, datatype); return _createVariant(value, datatype, scope); } @@ -158,7 +164,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); + Check.scopeNotNull(this, scope); return createVariant(value, datatype, Arrays.asList(scope)); } @@ -166,12 +172,12 @@ * @see org.tmapi.core.Name#createVariant(java.lang.String, org.tmapi.core.Topic[]) */ public Variant createVariant(String value, Topic... scope) { - _checkVariantScope(scope); + Check.scopeNotNull(this, scope); return createVariant(value, Arrays.asList(scope)); } private Variant _createVariant(String value, Locator datatype, Collection<Topic> scope) { - _checkVariantValue(value, datatype); + Check.valueNotNull(this, value, datatype); return _createVariant(Literal.create(value, datatype), scope); } @@ -179,12 +185,13 @@ if (scope.isEmpty()) { throw new ModelConstraintException(this, "The scope of the variant must not be unconstrained"); } - Set<Topic> scope_ = CollectionFactory.createIdentitySet(scope.size()); - scope_.addAll(scope); - scope_.removeAll(super.getScope()); - if (scope_.isEmpty()) { + Set<Topic> nameScope = super.getScope(); + if (nameScope.containsAll(scope)) { throw new ModelConstraintException(this, "The variant's scope is not a true superset of the parent's scope"); } + Set<Topic> scope_ = CollectionFactory.createIdentitySet(scope.size() + nameScope.size()); + scope_.addAll(scope); + scope_.addAll(nameScope); Variant variant = new VariantImpl(_tm, literal, Scope.create(scope_)); addVariant(variant); return variant; Modified: tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -20,8 +20,8 @@ */ package org.tinytim.core; +import org.tinytim.internal.utils.Check; import org.tmapi.core.Association; -import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Role; import org.tmapi.core.Topic; @@ -62,9 +62,7 @@ * @see org.tmapi.core.Role#setPlayer(org.tmapi.core.Topic) */ public void setPlayer(Topic player) { - if (player == null) { - throw new ModelConstraintException(this, "The role player must not be null"); - } + Check.playerNotNull(this, player); if (_player == player) { return; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -22,6 +22,7 @@ import java.util.Set; +import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Topic; /** @@ -77,7 +78,7 @@ */ public void addTheme(Topic theme) { if (theme == null) { - throw new IllegalArgumentException("The theme must not be null"); + throw new ModelConstraintException(this, "The theme must not be null"); } setScopeObject(_scope.add(theme)); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -25,9 +25,11 @@ import java.util.Collections; import java.util.Set; +import org.tinytim.internal.utils.Check; import org.tinytim.internal.utils.CollectionFactory; import org.tinytim.utils.TopicUtils; import org.tmapi.core.Locator; +import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Name; import org.tmapi.core.Occurrence; import org.tmapi.core.Reifiable; @@ -79,7 +81,7 @@ */ public void addSubjectIdentifier(Locator sid) { if (sid == null) { - throw new IllegalArgumentException("The subject identifier must not be null"); + throw new ModelConstraintException(this, "The subject identifier must not be null"); } if (_sids.contains(sid)) { return; @@ -112,7 +114,7 @@ */ public void addSubjectLocator(Locator slo) { if (slo == null) { - throw new IllegalArgumentException("The subject locator must not be null"); + throw new ModelConstraintException(this, "The subject locator must not be null"); } if (_slos != null && _sids.contains(slo)) { return; @@ -146,6 +148,7 @@ * @see org.tmapi.core.Topic#createOccurrence(org.tmapi.core.Topic, java.lang.String, java.util.Collection) */ public Occurrence createOccurrence(Topic type, String value, Collection<Topic> scope) { + Check.valueNotNull(this, value); return _createOccurrence(type, Literal.create(value), scope); } @@ -153,6 +156,7 @@ * @see org.tmapi.core.Topic#createOccurrence(org.tmapi.core.Locator, org.tmapi.core.Topic, java.util.Collection) */ public Occurrence createOccurrence(Topic type, Locator value, Collection<Topic> scope) { + Check.valueNotNull(this, value); return _createOccurrence(type, Literal.create(value), scope); } @@ -160,41 +164,37 @@ * @see org.tmapi.core.Topic#createOccurrence(org.tmapi.core.Topic, java.lang.String, org.tmapi.core.Locator, java.util.Collection) */ public Occurrence createOccurrence(Topic type, String value, Locator datatype, Collection<Topic> scope) { + Check.valueNotNull(this, value, datatype); return _createOccurrence(type, Literal.create(value, datatype), scope); } /* (non-Javadoc) * @see org.tmapi.core.Topic#createOccurrence(org.tmapi.core.Topic, java.lang.String, org.tmapi.core.Locator, org.tmapi.core.Topic[]) */ - public Occurrence createOccurrence(Topic type, String value, Locator datatype, Topic... themes) { - return _createOccurrence(type, Literal.create(value, datatype), Arrays.asList(themes)); + public Occurrence createOccurrence(Topic type, String value, Locator datatype, Topic... scope) { + Check.scopeNotNull(this, scope); + return createOccurrence(type, value, datatype, Arrays.asList(scope)); } /* (non-Javadoc) * @see org.tmapi.core.Topic#createOccurrence(org.tmapi.core.Topic, org.tmapi.core.Locator, org.tmapi.core.Topic[]) */ - public Occurrence createOccurrence(Topic type, Locator value, - Topic... scope) { - return _createOccurrence(type, Literal.create(value), Arrays.asList(scope)); + public Occurrence createOccurrence(Topic type, Locator value, Topic... scope) { + Check.scopeNotNull(this, scope); + return createOccurrence(type, value, Arrays.asList(scope)); } /* (non-Javadoc) * @see org.tmapi.core.Topic#createOccurrence(org.tmapi.core.Topic, java.lang.String, org.tmapi.core.Topic[]) */ public Occurrence createOccurrence(Topic type, String value, Topic... scope) { + Check.scopeNotNull(this, scope); return createOccurrence(type, value, Arrays.asList(scope)); } Occurrence _createOccurrence(Topic type, ILiteral literal, Collection<Topic> scope) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } - if (literal == null) { - throw new IllegalArgumentException("The value must not be null"); - } - if (scope == null) { - throw new IllegalArgumentException("The scope must not be null"); - } + Check.typeNotNull(this, type); + Check.scopeNotNull(this, scope); Occurrence occ = new OccurrenceImpl(_tm, type, literal, Scope.create(scope)); addOccurrence(occ); return occ; @@ -265,6 +265,7 @@ * @see org.tmapi.core.Topic#createName(java.lang.String, org.tmapi.core.Topic[]) */ public Name createName(String value, Topic... scope) { + Check.scopeNotNull(this, scope); return createName(value, Arrays.asList(scope)); } @@ -272,6 +273,7 @@ * @see org.tmapi.core.Topic#createName(org.tmapi.core.Topic, java.lang.String, org.tmapi.core.Topic[]) */ public Name createName(Topic type, String value, Topic... scope) { + Check.scopeNotNull(this, scope); return createName(type, value, Arrays.asList(scope)); } @@ -302,19 +304,13 @@ * @see org.tmapi.core.Topic#createName(org.tmapi.core.Topic, java.lang.String, java.util.Collection) */ public Name createName(Topic type, String value, Collection<Topic> scope) { + Check.valueNotNull(this, value); return _createName(type, Literal.create(value), scope); } public Name _createName(Topic type, ILiteral literal, Collection<Topic> scope) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } - if (literal == null) { - throw new IllegalArgumentException("The value must not be null"); - } - if (scope == null) { - throw new IllegalArgumentException("The scope must not be null"); - } + Check.typeNotNull(this, type); + Check.scopeNotNull(this, scope); NameImpl name = new NameImpl(_tm, type, literal, Scope.create(scope)); addName(name); return name; @@ -431,9 +427,7 @@ * @see org.tmapi.core.Topic#addType(org.tmapi.core.Topic) */ public void addType(Topic type) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } + Check.typeNotNull(this, type); if (_types != null && _types.contains(type)) { return; } @@ -475,7 +469,7 @@ */ public void remove() throws TopicInUseException { if (!TopicUtils.isRemovable(this, true)) { - throw new TopicInUseException(this, "The topic is used as type, player, or theme"); + throw new TopicInUseException(this, "The topic is used as type, player, reifier, or theme"); } if (_reified != null) { _reified.setReifier(null); Modified: tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -20,7 +20,6 @@ */ package org.tinytim.core; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -30,10 +29,12 @@ import org.tinytim.index.IndexManager; import org.tinytim.index.IIndexManager; +import org.tinytim.internal.utils.Check; import org.tinytim.internal.utils.CollectionFactory; import org.tinytim.voc.TMDM; import org.tmapi.core.Association; import org.tmapi.core.IdentityConstraintException; +import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Role; import org.tmapi.core.Locator; import org.tmapi.core.Occurrence; @@ -117,7 +118,7 @@ */ public Topic createTopicByItemIdentifier(Locator iid) { if (iid == null) { - throw new IllegalArgumentException("The item identifier must not be null"); + throw new ModelConstraintException(null, "The item identifier must not be null"); } Construct construct = getConstructByItemIdentifier(iid); if (construct != null) { @@ -148,7 +149,7 @@ */ public Topic createTopicBySubjectIdentifier(Locator sid) { if (sid == null) { - throw new IllegalArgumentException("The subject identifier must not be null"); + throw new ModelConstraintException(null, "The subject identifier must not be null"); } Topic topic = getTopicBySubjectIdentifier(sid); if (topic != null) { @@ -170,7 +171,7 @@ public Topic createTopicBySubjectLocator(Locator slo) { if (slo == null) { - throw new IllegalArgumentException("The subject locator must not be null"); + throw new ModelConstraintException(null, "The subject locator must not be null"); } Topic topic = getTopicBySubjectLocator(slo); if (topic != null) { @@ -223,16 +224,13 @@ } public Association createAssociation(Topic type, Topic... scope) { + Check.scopeNotNull(this, scope); return createAssociation(type, Arrays.asList(scope)); } public Association createAssociation(Topic type, Collection<Topic> scope) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } - if (scope == null) { - throw new IllegalArgumentException("The scope must not be null"); - } + Check.typeNotNull(this, type); + Check.scopeNotNull(this, scope); AssociationImpl assoc = new AssociationImpl(this, type, Scope.create(scope)); addAssociation(assoc); return assoc; @@ -399,7 +397,7 @@ public void subscribe(Event event, IEventHandler handler) { List<IEventHandler> handlers = _evtHandlers.get(event); if (handlers == null) { - handlers = new ArrayList<IEventHandler>(); + handlers = CollectionFactory.createList(); _evtHandlers.put(event, handlers); } handlers.add(handler); Modified: tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -20,7 +20,7 @@ */ package org.tinytim.core; -import org.tmapi.core.ModelConstraintException; +import org.tinytim.internal.utils.Check; import org.tmapi.core.Reifiable; import org.tmapi.core.Topic; @@ -60,9 +60,7 @@ * @see org.tinytim.ITyped#setType(org.tmapi.core.Topic) */ public void setType(Topic type) { - if (type == null) { - throw new ModelConstraintException(this, "The type cannot be set to null"); - } + Check.typeNotNull(this, type); 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-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -20,12 +20,7 @@ */ package org.tinytim.core; -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; import org.tmapi.core.Variant; /** @@ -53,20 +48,6 @@ } /* (non-Javadoc) - * @see org.tinytim.core.ScopedImpl#getScope() - */ - @Override - public Set<Topic> getScope() { - if (_tm == null || _parent == null) { - return super.getScope(); - } - Set<Topic> scope = CollectionFactory.createIdentitySet(4); - scope.addAll(super.getScope()); - scope.addAll(((Scoped) _parent).getScope()); - return scope; - } - - /* (non-Javadoc) * @see org.tinytim.IMovable#moveTo(java.lang.Object) */ public void moveTo(Name newParent) { Added: tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java 2008-08-14 11:58:37 UTC (rev 122) @@ -0,0 +1,79 @@ +/* + * 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 org.tmapi.core.Construct; +import org.tmapi.core.Locator; +import org.tmapi.core.ModelConstraintException; +import org.tmapi.core.Topic; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class Check { + + private static void _reportError(Construct sender, String msg) { + throw new ModelConstraintException(sender, msg); + } + + public static void scopeNotNull(Construct sender, Topic[] scope) { + if (scope == null) { + _reportError(sender, "The scope must not be null"); + } + } + + public static void scopeNotNull(Construct sender, Collection<Topic> scope) { + if (scope == null) { + _reportError(sender, "The scope must not be null"); + } + } + + public static void typeNotNull(Construct sender, Topic type) { + if (type == null) { + _reportError(sender, "The type must not be null"); + } + } + + public static void valueNotNull(Construct sender, Object value) { + if (value == null) { + _reportError(sender, "The value must not be null"); + } + } + + public static void valueNotNull(Construct sender, Object value, Locator datatype) { + valueNotNull(sender, value); + if (datatype == null) { + _reportError(sender, "The datatype must not be null"); + } + } + + public static void playerNotNull(Construct sender, Topic player) { + if (player == null) { + _reportError(sender, "The role player must not be null"); + } + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/internal/utils/DefaultIntObjectMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/internal/utils/DefaultIntObjectMap.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/internal/utils/DefaultIntObjectMap.java 2008-08-14 11:58:37 UTC (rev 122) @@ -26,7 +26,7 @@ * Default implementation of the {@link IIntObjectMap} which wraps a map. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ final class DefaultIntObjectMap<E> implements IIntObjectMap<E> { Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java 2008-08-14 11:58:37 UTC (rev 122) @@ -28,7 +28,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class TestScope extends TinyTimTestCase { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-09-04 11:36:15
|
Revision: 152 http://tinytim.svn.sourceforge.net/tinytim/?rev=152&view=rev Author: lheuer Date: 2008-09-04 11:36:23 +0000 (Thu, 04 Sep 2008) Log Message: ----------- - More docs - Added LiteralNormalizer which normalizes a few datatypes Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java tinytim/trunk/src/main/java/org/tinytim/core/IScope.java tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java tinytim/trunk/src/main/java/org/tinytim/core/Literal.java tinytim/trunk/src/main/java/org/tinytim/core/Scope.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java tinytim/trunk/src/test/java/org/tinytim/core/TestIConstruct.java tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/core/LiteralNormalizer.java tinytim/trunk/src/test/java/org/tinytim/core/TestLiteralNormalizer.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-26 16:57:58 UTC (rev 151) +++ tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-09-04 11:36:23 UTC (rev 152) @@ -47,10 +47,6 @@ */ final class CopyUtils { - private CopyUtils() { - // noop. - } - /** * Copies the topics and associations from the <tt>source</tt> to the * <tt>target</tt> topic map. Modified: tinytim/trunk/src/main/java/org/tinytim/core/IScope.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IScope.java 2008-08-26 16:57:58 UTC (rev 151) +++ tinytim/trunk/src/main/java/org/tinytim/core/IScope.java 2008-09-04 11:36:23 UTC (rev 152) @@ -51,6 +51,15 @@ public boolean contains(Topic theme); /** + * Returns <tt>true</tt> if all themes of the other <tt>scope</tt> are part + * of this scope. + * + * @param scope A collection of themes. + * @return <tt>true</tt> if all themes are part of this scope, otherwise <tt>false</tt>. + */ + public boolean containsAll(Collection<Topic> scope); + + /** * Returns a <tt>IScope</tt> consisting of all themes contained in this * scope and the <tt>theme</tt>. * @@ -84,6 +93,4 @@ */ public int size(); - public boolean containsAll(Collection<Topic> scope); - } Modified: tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-08-26 16:57:58 UTC (rev 151) +++ tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-09-04 11:36:23 UTC (rev 152) @@ -34,10 +34,6 @@ private static final AtomicLong _COUNTER = new AtomicLong(); - private IdGenerator() { - // noop. - } - /** * Returns the next identifier. * Modified: tinytim/trunk/src/main/java/org/tinytim/core/Literal.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Literal.java 2008-08-26 16:57:58 UTC (rev 151) +++ tinytim/trunk/src/main/java/org/tinytim/core/Literal.java 2008-09-04 11:36:23 UTC (rev 152) @@ -48,14 +48,20 @@ if (value == null) { throw new IllegalArgumentException("The value must not be null"); } - _value = value; + _value = LiteralNormalizer.normalize(value, datatype); _datatype = datatype; } + /* (non-Javadoc) + * @see org.tinytim.core.ILiteral#getDatatype() + */ public Locator getDatatype() { return _datatype; } + /* (non-Javadoc) + * @see org.tinytim.core.ILiteral#getValue() + */ public String getValue() { return _value; } Added: tinytim/trunk/src/main/java/org/tinytim/core/LiteralNormalizer.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/LiteralNormalizer.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/LiteralNormalizer.java 2008-09-04 11:36:23 UTC (rev 152) @@ -0,0 +1,164 @@ +/* + * 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.voc.XSD; +import org.tmapi.core.Locator; + +/** + * Normalizes literal values. + * + * 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:$ + */ +final class LiteralNormalizer { + + private LiteralNormalizer() { + // noop. + } + + /** + * Normalizes the <tt>value</tt> dependent on the <tt>datatype</tt>. + * + * @param value The value to normalize. + * @param datatype The datatype. + * @return A normalized value. + */ + public static String normalize(final String value, final Locator datatype) { + if (XSD.BOOLEAN.equals(datatype)) { + return normalizeBoolean(value); + } + else if (XSD.INTEGER.equals(datatype)) { + return normalizeInteger(value); + } + else if (XSD.DECIMAL.equals(datatype)) { + return normalizeDecimal(value); + } + return value; + } + + public static String normalizeBoolean(final String value) { + if ("0".equals(value) || "false".equals(value)) { + return "false"; + } + else if ("1".equals(value) || "true".equals(value)) { + return "true"; + } + throw new IllegalArgumentException("Illegal boolean value: " + value); + } + + public static String normalizeInteger(final String value) { + final String val = value.trim(); + int len = value.length(); + if (len == 0) { + throw new IllegalArgumentException(); + } + int idx = 0; + boolean negative = false; + switch (val.charAt(idx)) { + case '-': + idx++; + negative = true; + break; + case '+': + idx++; + break; + } + // Skip leading zeros if any + while (idx < len && val.charAt(idx) == '0') { + idx++; + } + if (idx == len) { + return "0"; + } + final String normalized = val.substring(idx); + len = normalized.length(); + // Check if everything is a digit + for (int i = 0; i < len; i++) { + if (!Character.isDigit(normalized.charAt(i))) { + throw new IllegalArgumentException(); + } + } + return negative && normalized.charAt(0) != 0 ? '-' + normalized : normalized; + } + + public static String normalizeDecimal(final String value) { + final String val = value.trim(); + int len = value.length(); + if (len == 0) { + throw new IllegalArgumentException(); + } + int idx = 0; + boolean negative = false; + switch (val.charAt(idx)) { + case '-': + idx++; + negative = true; + break; + case '+': + idx++; + break; + } + // Skip leading zeros if any + while (idx < len && val.charAt(idx) == '0') { + idx++; + } + if (idx == len) { + return "0.0"; + } + StringBuilder normalized = new StringBuilder(len); + if (val.charAt(idx) == '.') { + normalized.append('0'); + } + else { + while (idx < len && val.charAt(idx) != '.') { + char c = val.charAt(idx); + if (!Character.isDigit(c)) { + throw new IllegalArgumentException("Illegal decimal value: " + value); + } + normalized.append(c); + idx++; + } + } + normalized.append('.'); + len--; + while (len >= idx && val.charAt(len) == '0') { + len--; + } + if (len == idx || len < idx) { + normalized.append('0'); + } + else { + while (idx < len) { + char c = val.charAt(idx); + if (!Character.isDigit(c)) { + throw new IllegalArgumentException("Illegal decimal value: " + value); + } + normalized.append(c); + idx++; + } + } + return negative && normalized.charAt(0) != '0' ? '-' + normalized.toString() : normalized.toString(); + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/LiteralNormalizer.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/core/Scope.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Scope.java 2008-08-26 16:57:58 UTC (rev 151) +++ tinytim/trunk/src/main/java/org/tinytim/core/Scope.java 2008-09-04 11:36:23 UTC (rev 152) @@ -30,8 +30,8 @@ import org.tmapi.core.Topic; /** + * {@link IScope} implementation. * - * * @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/internal/utils/Check.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java 2008-08-26 16:57:58 UTC (rev 151) +++ tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java 2008-09-04 11:36:23 UTC (rev 152) @@ -28,87 +28,78 @@ import org.tmapi.core.Topic; /** - * Utility class to check arguments and to throw - * {@link org.tmapi.core.ModelConstraintException}s if the arg violates a - * constraint. + * Provides various argument constraint checks. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ public final class Check { - private Check() { - // noop. - } - - /** - * Throws a {@link ModelConstraintException} with the specified <tt>sender</tt> - * and <tt>msg</tt> - * - * @param sender The sender - * @param msg The error message - */ - private static void _reportError(final Construct sender, final String msg) { + private static void _reportError(Construct sender, String msg) { throw new ModelConstraintException(sender, msg); } /** - * Throws a {@link ModelConstraintException} if the <tt>scope</tt> is <tt>null</tt>. + * Throws a {@link ModelConstraintException} iff the <tt>scope</tt> is + * <tt>null</tt>. * - * @param sender The sender - * @param scope The scope array. + * @param sender The sender. + * @param scope The scope. */ - public static void scopeNotNull(final Construct sender, final Topic[] scope) { + public static void scopeNotNull(Construct sender, Topic[] scope) { if (scope == null) { _reportError(sender, "The scope must not be null"); } } /** - * Throws a {@link ModelConstraintException} if the <tt>scope</tt> is <tt>null</tt>. + * Throws a {@link ModelConstraintException} iff the <tt>scope</tt> is + * <tt>null</tt>. * - * @param sender The sender - * @param scope A collection. + * @param sender The sender. + * @param scope The scope. */ - public static void scopeNotNull(final Construct sender, final Collection<Topic> scope) { + public static void scopeNotNull(Construct sender, Collection<Topic> scope) { if (scope == null) { _reportError(sender, "The scope must not be null"); } } /** - * Throws a {@link ModelConstraintException} if the <tt>type</tt> is <tt>null</tt>. + * Throws a {@link ModelConstraintException} iff the <tt>type</tt> is + * <tt>null</tt>. * - * @param sender The sender - * @param type The topic to check. + * @param sender The sender. + * @param type The type. */ - public static void typeNotNull(final Construct sender, final Topic type) { + public static void typeNotNull(Construct sender, Topic type) { if (type == null) { _reportError(sender, "The type must not be null"); } } /** - * Throws a {@link ModelConstraintException} if the <tt>value</tt> is <tt>null</tt>. + * Throws a {@link ModelConstraintException} iff the <tt>value</tt> is + * <tt>null</tt>. * - * @param sender The sender + * @param sender The sender. * @param value The value. */ - public static void valueNotNull(final Construct sender, final Object value) { + public static void valueNotNull(Construct sender, Object value) { if (value == null) { _reportError(sender, "The value must not be null"); } } /** - * Throws a {@link ModelConstraintException} if the <tt>value</tt> or - * <tt>datatype</tt> is <tt>null</tt>. + * Throws a {@link ModelConstraintException} iff the <tt>value</tt> or + * the <tt>datatype</tt> is <tt>null</tt>. * - * @param sender The sender + * @param sender The sender. * @param value The value. - * @param datatype The locator indicating the datatype. + * @param datatype The datatype. */ - public static void valueNotNull(final Construct sender, final Object value, Locator datatype) { + public static void valueNotNull(Construct sender, Object value, Locator datatype) { valueNotNull(sender, value); if (datatype == null) { _reportError(sender, "The datatype must not be null"); @@ -116,12 +107,13 @@ } /** - * Throws a {@link ModelConstraintException} if the <tt>player</tt> is <tt>null</tt>. + * Throws a {@link ModelConstraintException} iff the <tt>player</tt> is + * <tt>null</tt>. * - * @param sender The sender - * @param player The topic to check. + * @param sender The sender. + * @param player The player. */ - public static void playerNotNull(final Construct sender, final Topic player) { + public static void playerNotNull(Construct sender, Topic player) { if (player == null) { _reportError(sender, "The role player must not be null"); } Modified: tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java 2008-08-26 16:57:58 UTC (rev 151) +++ tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java 2008-09-04 11:36:23 UTC (rev 152) @@ -24,13 +24,19 @@ import org.tmapi.core.Locator; /** + * Base for classes which provide PSIs. * - * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ abstract class Vocabulary { + /** + * Returns a locator with the specified <tt>reference</tt>. + * + * @param reference The address of the locator. + * @return A locator. + */ protected final static Locator _createLocator(String reference) { return Literal.createIRI(reference); } Modified: tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java 2008-08-26 16:57:58 UTC (rev 151) +++ tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java 2008-09-04 11:36:23 UTC (rev 152) @@ -23,8 +23,8 @@ import org.tmapi.core.Locator; /** + * Provides PSIs for the XML Schema Datatypes. * - * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ @@ -50,4 +50,6 @@ public final static Locator LONG = _createLocator(_BASE + "long"); + public static final Locator BOOLEAN = _createLocator(_BASE + "boolean"); + } Modified: tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2008-08-26 16:57:58 UTC (rev 151) +++ tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2008-09-04 11:36:23 UTC (rev 152) @@ -22,7 +22,6 @@ import org.tinytim.utils.TestDuplicateRemovalUtils; import org.tinytim.utils.TestTopicUtils; -import org.tinytim.utils.TestTypeInstanceConverter; import junit.framework.Test; import junit.framework.TestSuite; @@ -46,13 +45,13 @@ suite.addTestSuite(TestIConstruct.class); suite.addTestSuite(TestScope.class); suite.addTestSuite(TestLiteral.class); + suite.addTestSuite(TestLiteralNormalizer.class); suite.addTestSuite(TestItemIdentifierConstraint.class); suite.addTestSuite(TestSignatureGenerator.class); suite.addTest(TestTMAPICore.suite()); suite.addTest(TestTMAPIIndex.suite()); suite.addTestSuite(TestTopicMapSystemFactoryImpl.class); suite.addTestSuite(TestTopicUtils.class); - suite.addTestSuite(TestTypeInstanceConverter.class); return suite; } } Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestIConstruct.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestIConstruct.java 2008-08-26 16:57:58 UTC (rev 151) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestIConstruct.java 2008-09-04 11:36:23 UTC (rev 152) @@ -30,8 +30,8 @@ import org.tmapi.core.Variant; /** + * Tests against {@link IConstruct}. * - * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev:$ - $Date:$ */ Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java 2008-08-26 16:57:58 UTC (rev 151) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java 2008-09-04 11:36:23 UTC (rev 152) @@ -40,11 +40,11 @@ * * @param tmo The Topic Maps construct to test. */ - private void _testConstraint(final Construct tmo) { + private void _testConstraint(Construct tmo) throws Exception { assertTrue(tmo.getItemIdentifiers().isEmpty()); - final Locator iid = createLocator("http://sf.net/projects/tinytim"); - final Locator iid2 = createLocator("http://sf.net/projects/tinytim2"); - final Association assoc = createAssociation(); + Locator iid = createLocator("http://sf.net/projects/tinytim"); + Locator iid2 = createLocator("http://sf.net/projects/tinytim2"); + Association assoc = createAssociation(); assoc.addItemIdentifier(iid); assertFalse(tmo.getItemIdentifiers().contains(iid)); try { @@ -72,16 +72,16 @@ /** * Tests against a topic map. */ - public void testTopicMap() { + public void testTopicMap() throws Exception { _testConstraint(_tm); } /** * Tests againts a topic. */ - public void testTopic() { - final Topic topic = createTopic(); - final Locator iid = createLocator("http://sf.net/projects/tinytim"); + public void testTopic() throws Exception { + Topic topic = createTopic(); + Locator iid = createLocator("http://sf.net/projects/tinytim"); topic.addItemIdentifier(iid); assertTrue(topic.getItemIdentifiers().contains(iid)); Topic topic2 = createTopic(); @@ -107,35 +107,35 @@ /** * Tests against an association. */ - public void testAssociation() { + public void testAssociation() throws Exception { _testConstraint(createAssociation()); } /** * Tests against a role. */ - public void testRole() { + public void testRole() throws Exception { _testConstraint(createRole()); } /** * Tests against an occurrence. */ - public void testOccurrence() { + public void testOccurrence() throws Exception { _testConstraint(createOccurrence()); } /** * Tests against a name. */ - public void testName() { + public void testName() throws Exception { _testConstraint(createName()); } /** * Tests against a variant. */ - public void testVariant() { + public void testVariant() throws Exception { _testConstraint(createVariant()); } Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java 2008-08-26 16:57:58 UTC (rev 151) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java 2008-09-04 11:36:23 UTC (rev 152) @@ -24,8 +24,8 @@ import org.tmapi.core.Locator; /** + * Tests against {@link Literal}. * - * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ Added: tinytim/trunk/src/test/java/org/tinytim/core/TestLiteralNormalizer.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestLiteralNormalizer.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestLiteralNormalizer.java 2008-09-04 11:36:23 UTC (rev 152) @@ -0,0 +1,79 @@ +/* + * 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; + +/** + * Tests against the {@link LiteralNormalizer}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class TestLiteralNormalizer extends TinyTimTestCase { + + public void testNormalizeBoolean() { + assertEquals("true", LiteralNormalizer.normalizeBoolean("1")); + assertEquals("true", LiteralNormalizer.normalizeBoolean("true")); + assertEquals("false", LiteralNormalizer.normalizeBoolean("0")); + assertEquals("false", LiteralNormalizer.normalizeBoolean("false")); + try { + LiteralNormalizer.normalizeBoolean("invalid"); + fail("Expected an IllegalArgumentException"); + } + catch (IllegalArgumentException ex) { + // noop. + } + } + + public void testNormalizeInteger() { + assertEquals("0", LiteralNormalizer.normalizeInteger("0")); + assertEquals("0", LiteralNormalizer.normalizeInteger("-0")); + assertEquals("1", LiteralNormalizer.normalizeInteger("+1")); + assertEquals("1", LiteralNormalizer.normalizeInteger("00001")); + assertEquals("-1", LiteralNormalizer.normalizeInteger("-1")); + assertEquals("-1", LiteralNormalizer.normalizeInteger("-00001")); + try { + LiteralNormalizer.normalizeInteger("invalid"); + fail("Expected an IllegalArgumentException"); + } + catch (IllegalArgumentException ex) { + // noop. + } + } + + public void testNormalizeDecimal() { + assertEquals("0.0", LiteralNormalizer.normalizeDecimal("0")); + assertEquals("0.0", LiteralNormalizer.normalizeDecimal("-0")); + assertEquals("0.0", LiteralNormalizer.normalizeDecimal("-0.0")); + assertEquals("0.0", LiteralNormalizer.normalizeDecimal("+0.0")); + assertEquals("0.0", LiteralNormalizer.normalizeDecimal("+00000.0000000")); + assertEquals("0.0", LiteralNormalizer.normalizeDecimal("-00000.0000000")); + assertEquals("10.0", LiteralNormalizer.normalizeDecimal("10")); + assertEquals("-10.0", LiteralNormalizer.normalizeDecimal("-10.00")); + assertEquals("10.0", LiteralNormalizer.normalizeDecimal("+10.00")); + try { + LiteralNormalizer.normalizeDecimal("invalid"); + fail("Expected an IllegalArgumentException"); + } + catch (IllegalArgumentException ex) { + // noop. + } + } +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestLiteralNormalizer.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java 2008-08-26 16:57:58 UTC (rev 151) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java 2008-09-04 11:36:23 UTC (rev 152) @@ -25,8 +25,8 @@ import org.tmapi.core.Topic; /** + * Tests against {@link Scope}. * - * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ @@ -38,11 +38,11 @@ } public void testEquals() { - Topic theme1 = createTopic(); - Topic theme2 = createTopic(); - IScope scope1 = Scope.create(Arrays.asList(theme1, theme2)); + final Topic theme1 = createTopic(); + final Topic theme2 = createTopic(); + final IScope scope1 = Scope.create(Arrays.asList(theme1, theme2)); assertEquals(2, scope1.size()); - IScope scope2 = Scope.create(Arrays.asList(theme2, theme1)); + final IScope scope2 = Scope.create(Arrays.asList(theme2, theme1)); assertSame(scope1, scope2); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-11-12 14:48:06
|
Revision: 177 http://tinytim.svn.sourceforge.net/tinytim/?rev=177&view=rev Author: lheuer Date: 2008-11-12 14:48:00 +0000 (Wed, 12 Nov 2008) Log Message: ----------- - Fixed bug #2269551 -- Topic types are not considered as dependency - Fixed bug #2221024 -- Merging topic maps causes an autom. generated topic iid - Introduced ITopicMap - Renamed TopicMapImpl to MemoryTopicMap - Renamed TopicMapSystemImpl to MemoryTopicMapSystem 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/DecimalLiteral.java tinytim/trunk/src/main/java/org/tinytim/core/Event.java tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisher.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/ILocator.java tinytim/trunk/src/main/java/org/tinytim/core/IMovable.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/IntegerLiteral.java tinytim/trunk/src/main/java/org/tinytim/core/Literal.java tinytim/trunk/src/main/java/org/tinytim/core/LiteralNormalizer.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/TopicMapSystemFactoryImpl.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/IIndexManager.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/internal/utils/CollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/ICollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/utils/DuplicateRemovalUtils.java tinytim/trunk/src/main/java/org/tinytim/utils/Feature.java tinytim/trunk/src/main/java/org/tinytim/utils/TopicUtils.java tinytim/trunk/src/main/java/org/tinytim/utils/TypeInstanceConverter.java tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java tinytim/trunk/src/test/java/org/tinytim/core/AbstractTMAPITestSuite.java tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java tinytim/trunk/src/test/java/org/tinytim/utils/TestTopicUtils.java Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/Version.java tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisherAware.java tinytim/trunk/src/main/java/org/tinytim/core/IIndexManagerAware.java tinytim/trunk/src/main/java/org/tinytim/core/ITopicMap.java tinytim/trunk/src/main/java/org/tinytim/core/LocatorImpl.java tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMapSystem.java tinytim/trunk/src/main/java/org/tinytim/utils/Property.java tinytim/trunk/src/main/java/org/tinytim/voc/Namespace.java tinytim/trunk/src/test/java/org/tinytim/core/TestLocatorImpl.java Removed Paths: ------------- tinytim/trunk/src/main/java/org/tinytim/core/IRI.java tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemImpl.java tinytim/trunk/src/test/java/org/tinytim/core/TestIRI.java Added: tinytim/trunk/src/main/java/org/tinytim/Version.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Version.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/Version.java 2008-11-12 14:48:00 UTC (rev 177) @@ -0,0 +1,37 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim; + +/** + * Provides the version information. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class Version { + + private static final String _MAJOR = "@MAJOR@"; + private static final String _MINOR = "@MINOR@"; + private static final String _MICRO = "@MICRO@"; + private static final String _STATE ="@STATE@"; + private static final String _DATE = "@DATE@"; + + /** + * The release information. + */ + public static final String RELEASE = _MAJOR + "." + _MINOR + "." + _MICRO + _STATE + _DATE; + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/Version.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java 2008-11-12 14:48:00 UTC (rev 177) @@ -0,0 +1,92 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.core; + +import java.util.Map; + +import org.tmapi.core.FeatureNotRecognizedException; +import org.tmapi.core.Locator; +import org.tmapi.core.TMAPIException; +import org.tmapi.core.TopicMap; +import org.tmapi.core.TopicMapExistsException; +import org.tmapi.core.TopicMapSystem; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +abstract class AbstractTopicMapSystem implements TopicMapSystem { + + protected final Map<String, Boolean> _features; + protected final Map<String, Object> _properties; + + AbstractTopicMapSystem(Map<String, Boolean> features, Map<String, Object> properties) throws TMAPIException { + _features = features; + _properties = properties; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem#getFeature(java.lang.String) + */ + public boolean getFeature(String featureName) throws FeatureNotRecognizedException { + final Boolean supported = _features.get(featureName); + if (supported == null) { + TopicMapSystemFactoryImpl.reportFeatureNotRecognized(featureName); + } + return supported; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem#getProperty(java.lang.String) + */ + public Object getProperty(String propertyName) { + return _properties.get(propertyName); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem#createLocator(java.lang.String) + */ + public Locator createLocator(String reference) { + return Literal.createIRI(reference); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem#getTopicMap(java.lang.String) + */ + public TopicMap getTopicMap(String reference) { + return getTopicMap(createLocator(reference)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem#createTopicMap(java.lang.String) + */ + public TopicMap createTopicMap(String reference) throws TopicMapExistsException { + return createTopicMap(createLocator(reference)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem#close() + */ + public void close() { + _features.clear(); + _properties.clear(); + } + + abstract void removeTopicMap(MemoryTopicMap tm); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-11-12 14:48:00 UTC (rev 177) @@ -35,12 +35,12 @@ private Set<Role> _roles; - AssociationImpl(TopicMapImpl tm) { + AssociationImpl(ITopicMap tm) { super(tm); _roles = CollectionFactory.createIdentitySet(IConstant.ASSOC_ROLE_SIZE); } - AssociationImpl(TopicMapImpl topicMap, Topic type, IScope scope) { + AssociationImpl(ITopicMap topicMap, Topic type, IScope scope) { super(topicMap, type, scope); _roles = CollectionFactory.createIdentitySet(IConstant.ASSOC_ROLE_SIZE); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-11-12 14:48:00 UTC (rev 177) @@ -33,11 +33,11 @@ abstract class ConstructImpl implements IConstruct { protected String _id; - protected TopicMapImpl _tm; + protected ITopicMap _tm; protected Construct _parent; private Set<Locator> _iids; - ConstructImpl(TopicMapImpl topicMap) { + ConstructImpl(ITopicMap topicMap) { _tm = topicMap; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-11-12 14:48:00 UTC (rev 177) @@ -54,13 +54,13 @@ * @param target The topic map which should receive the topics and associations. */ public static void copy(TopicMap source, TopicMap target) { - _copy(source, (TopicMapImpl) target); + _copy(source, (ITopicMap) target); } /** * @see #copy(TopicMap, TopicMap) */ - private static void _copy(TopicMap source, TopicMapImpl target) { + private static void _copy(TopicMap source, ITopicMap target) { if (source == null || target == null) { throw new IllegalArgumentException("Neither the source topic map nor the target topic map must be null"); } @@ -123,9 +123,9 @@ * @param mergeMap The map which holds the merge mappings. * @return The newly created topic in the target topic map. */ - private static Topic _copyTopic(Topic topic, TopicMap target, + private static Topic _copyTopic(Topic topic, ITopicMap target, Map<Topic, Topic> mergeMap) { - Topic targetTopic = target.createTopic(); + Topic targetTopic = target.createTopicWithoutIdentity(); _copyIdentities(topic, targetTopic); _copyTypes(topic, targetTopic, mergeMap); _copyCharacteristics(topic, (TopicImpl)targetTopic, mergeMap); @@ -161,7 +161,7 @@ for (Topic type: topic.getTypes()) { Topic targetType = mergeMap.get(type); if (targetType == null) { - targetType = _copyTopic(type, targetTopic.getTopicMap(), mergeMap); + targetType = _copyTopic(type, (ITopicMap) targetTopic.getTopicMap(), mergeMap); } targetTopic.addType(targetType); } @@ -261,7 +261,7 @@ return; } Topic reifier = mergeMap.containsKey(sourceReifier) ? mergeMap.get(sourceReifier) - : _copyTopic(sourceReifier, target.getTopicMap(), mergeMap); + : _copyTopic(sourceReifier, (ITopicMap) target.getTopicMap(), mergeMap); target.setReifier(reifier); } @@ -276,7 +276,7 @@ Map<Topic, Topic> mergeMap) { Topic sourceType = source.getType(); return mergeMap.containsKey(sourceType) ? mergeMap.get(sourceType) - : _copyTopic(sourceType, tm, mergeMap); + : _copyTopic(sourceType, (ITopicMap) tm, mergeMap); } /** @@ -293,7 +293,7 @@ Topic theme = null; for (Topic sourceTheme: source.getScope()) { theme = mergeMap.containsKey(sourceTheme) ? mergeMap.get(sourceTheme) - : _copyTopic(sourceTheme, tm, mergeMap); + : _copyTopic(sourceTheme, (ITopicMap) tm, mergeMap); themes.add(theme); } return themes; @@ -320,7 +320,7 @@ * @param mergeMap The map which holds the merge mappings. */ private static void _copyAssociations(TopicMap source, - TopicMapImpl target, Map<Topic, Topic> mergeMap) { + TopicMap target, Map<Topic, Topic> mergeMap) { Set<Association> assocs = target.getAssociations(); IIntObjectMap<Association> sigs = CollectionFactory.createIntObjectMap(assocs.size()); for (Association assoc: assocs) { Modified: tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-11-12 14:48:00 UTC (rev 177) @@ -35,11 +35,11 @@ private ILiteral _literal; - DatatypeAwareConstruct(TopicMapImpl tm) { + DatatypeAwareConstruct(ITopicMap tm) { super(tm); } - DatatypeAwareConstruct(TopicMapImpl topicMap, Topic type, ILiteral literal, IScope scope) { + DatatypeAwareConstruct(ITopicMap topicMap, Topic type, ILiteral literal, IScope scope) { super(topicMap, type, scope); _literal = literal; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/DecimalLiteral.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DecimalLiteral.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/DecimalLiteral.java 2008-11-12 14:48:00 UTC (rev 177) @@ -25,7 +25,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ + * @version $Rev:$ - $Date:$ */ final class DecimalLiteral implements ILiteral { Modified: tinytim/trunk/src/main/java/org/tinytim/core/Event.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Event.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/Event.java 2008-11-12 14:48:00 UTC (rev 177) @@ -17,11 +17,13 @@ /** * Event constants. - * + * <p> * All events are sent before a change happens. This allows to check * some constraints. - * + * </p> + * <p> * This class is not meant to be used outside of the tinyTiM package. + * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ @@ -76,6 +78,7 @@ * Notification that a variant should be removed. */ REMOVE_VARIANT, + /** * Notification that a subject identifier should be added. @@ -137,8 +140,19 @@ */ SET_LITERAL, - MOVE_OCCURRENCE, - MOVE_NAME, - MOVE_VARIANT + /** + * Notification that an occurrence should be moved from one topic to another. + */ + MOVED_OCCURRENCE, + /** + * Notification that a name should be moved from one topic to another. + */ + MOVED_NAME, + /** + * Notification that a variant should be moved from one name to another. + */ + MOVED_VARIANT, + + ATTACHED_NAME, DETACHED_NAME, ATTACHED_OCCURRENCE, DETACHED_OCCURRENCE, } Modified: tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java 2008-11-12 14:48:00 UTC (rev 177) @@ -25,11 +25,11 @@ */ interface IConstant { /** - * Initial size of the {@link TopicMapImpl} topic set + * Initial size of the {@link MemoryTopicMap} topic set */ public static final int TM_TOPIC_SIZE = 100; /** - * Initial size of the {@link TopicMapImpl} association set + * Initial size of the {@link MemoryTopicMap} association set */ public static final int TM_ASSOCIATION_SIZE = 100; /** @@ -101,7 +101,7 @@ */ public static final int SCOPE_SCOPES_SIZE = 10; /** - * Initial size of the {@link TopicMapSystemImpl} topic map map. + * Initial size of the {@link MemoryTopicMapSystem} topic map map. */ public static final int SYSTEM_TM_SIZE = 4; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java 2008-11-12 14:48:00 UTC (rev 177) @@ -19,20 +19,65 @@ /** * Enhancement of the {@link org.tmapi.core.Construct} interface. - * + * <p> + * Avoids <tt>foo instanceof Bar</tt> checks. Each construct knows its type. + * </p> + * <p> * This interface is not meant to be used outside of the tinyTiM package. + * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ public interface IConstruct extends Construct { + /** + * Returns <tt>true</tt> if this is a topic map. + * + * @return <tt>true</tt> if this is a topic map, <tt>false</tt> otherwise. + */ public boolean isTopicMap(); + + /** + * Returns <tt>true</tt> if this is a topic. + * + * @return <tt>true</tt> if this is a topic, <tt>false</tt> otherwise. + */ public boolean isTopic(); + + /** + * Returns <tt>true</tt> if this is an association. + * + * @return <tt>true</tt> if this is an association, <tt>false</tt> otherwise. + */ public boolean isAssociation(); + + /** + * Returns <tt>true</tt> if this is a role. + * + * @return <tt>true</tt> if this is a role, <tt>false</tt> otherwise. + */ public boolean isRole(); + + /** + * Returns <tt>true</tt> if this is an occurrence. + * + * @return <tt>true</tt> if this is an occurrence, <tt>false</tt> otherwise. + */ public boolean isOccurrence(); + + /** + * Returns <tt>true</tt> if this is a name. + * + * @return <tt>true</tt> if this is a name, <tt>false</tt> otherwise. + */ public boolean isName(); + + /** + * Returns <tt>true</tt> if this is a variant. + * + * @return <tt>true</tt> if this is a variant, <tt>false</tt> otherwise. + */ public boolean isVariant(); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java 2008-11-12 14:48:00 UTC (rev 177) @@ -17,8 +17,9 @@ /** * Event handler that is able to handle Topic Maps events. - * + * <p> * This interface is not meant to be used outside of the tinyTiM package. + * </p> * * @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/IEventPublisher.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisher.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisher.java 2008-11-12 14:48:00 UTC (rev 177) @@ -17,8 +17,9 @@ /** * Publisher for Topic Maps events. - * + * <p> * This interface is not meant to be used outside of the tinyTiM package. + * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ @@ -40,4 +41,5 @@ * @param handler The event handler. */ public void unsubscribe(Event event, IEventHandler handler); + } Added: tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisherAware.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisherAware.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisherAware.java 2008-11-12 14:48:00 UTC (rev 177) @@ -0,0 +1,48 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.core; + +/** + * Something that subscribes and unsubscribes itself to an + * {org.tinytim.core.IEventPublisher}. + * <p> + * Implementations MUST have a default (public) constructor. + * </p> + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface IEventPublisherAware { + + /** + * Subscribes this instance to the specified <tt>publisher</tt>. + * + * @param publisher An event publisher. + */ + public void subscribe(IEventPublisher publisher); + + /** + * Unsubscribes this instance from the specified <tt>publisher</tt>. + * <p> + * This method is only invoked if this instance has been subscribed to + * the <tt>publisher</tt>. + * </p> + * + * @param publisher The publisher to unsubscribe from. + */ + public void unsubscribe(IEventPublisher publisher); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisherAware.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/IIndexManagerAware.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IIndexManagerAware.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/IIndexManagerAware.java 2008-11-12 14:48:00 UTC (rev 177) @@ -0,0 +1,30 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.core; + +import org.tinytim.index.IIndexManager; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface IIndexManagerAware { + + IIndexManager getIndexManager(); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/IIndexManagerAware.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java 2008-11-12 14:48:00 UTC (rev 177) @@ -22,8 +22,9 @@ /** * Represents an immutable value with a datatype. - * + * <p> * This interface is not meant to be used outside of the tinyTiM package. + * </p> * * @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/ILiteralAware.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java 2008-11-12 14:48:00 UTC (rev 177) @@ -17,8 +17,9 @@ /** * Indicates that a literal can be attached to a construct. - * + * <p> * This interface is not meant to be used outside of the tinyTiM package. + * </p> * * @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/ILocator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java 2008-11-12 14:48:00 UTC (rev 177) @@ -20,8 +20,9 @@ /** * Marker interface which unifies the {@link org.tmapi.core.Locator} and * tinyTiM's {@link ILiteral}. - * + * <p> * This interface is not meant to be used outside of the tinyTiM package. + * </p> * * @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/IMovable.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IMovable.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IMovable.java 2008-11-12 14:48:00 UTC (rev 177) @@ -20,8 +20,9 @@ /** * Indicates that a Topic Maps construct is able to be detached from the * current parent and attached to another parent. - * + * <p> * This interface is not meant to be used outside of the tinyTiM package. + * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ Deleted: tinytim/trunk/src/main/java/org/tinytim/core/IRI.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IRI.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IRI.java 2008-11-12 14:48:00 UTC (rev 177) @@ -1,138 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.core; - -import java.io.UnsupportedEncodingException; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.net.URI; -import java.net.URLDecoder; - -import org.tinytim.voc.XSD; -import org.tmapi.core.Locator; -import org.tmapi.core.TMAPIRuntimeException; - -/** - * Immutable representation of an IRI. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -final class IRI implements ILocator { - - private final URI _uri; - private final String _reference; - - IRI(String reference) { - try { - _reference = URLDecoder.decode(reference, "utf-8"); - } - catch (UnsupportedEncodingException ex) { - throw new TMAPIRuntimeException(ex); - } - _uri = URI.create(_reference.replace(" ", "%20")); - } - - private IRI(URI uri) { - try { - _reference = URLDecoder.decode(uri.toString(), "utf-8"); - } - catch (UnsupportedEncodingException ex) { - throw new TMAPIRuntimeException(ex); - } - _uri = uri; - } - - /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#getDatatype() - */ - public Locator getDatatype() { - return XSD.ANY_URI; - } - - /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#getValue() - */ - public String getValue() { - return _reference; - } - - public BigDecimal decimalValue() { - throw new NumberFormatException(); - } - - public float floatValue() { - throw new NumberFormatException(); - } - - public BigInteger integerValue() { - throw new NumberFormatException(); - } - - public int intValue() { - throw new NumberFormatException(); - } - - public long longValue() { - throw new NumberFormatException(); - } - - /* (non-Javadoc) - * @see org.tmapi.core.Locator#getReference() - */ - public String getReference() { - return _reference; - } - - /* (non-Javadoc) - * @see org.tmapi.core.Locator#resolve(java.lang.String) - */ - public Locator resolve(String reference) { - return new IRI(_uri.resolve(reference)); - } - - /* (non-Javadoc) - * @see org.tmapi.core.Locator#toExternalForm() - */ - public String toExternalForm() { - return _uri.toASCIIString(); - } - - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - return this == obj || (obj instanceof IRI && _reference.equals(((IRI) obj)._reference)); - } - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - return _reference.hashCode(); - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return _uri.toString(); - } - -} Modified: tinytim/trunk/src/main/java/org/tinytim/core/IScope.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IScope.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IScope.java 2008-11-12 14:48:00 UTC (rev 177) @@ -22,8 +22,9 @@ /** * Represents an immutable set of {@link org.tmapi.core.Topic}s. - * + * <p> * This interface is not meant to be used outside of the tinyTiM package. + * </p> * * @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/IScoped.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java 2008-11-12 14:48:00 UTC (rev 177) @@ -20,8 +20,9 @@ /** * Enhancement of the {@link org.tmapi.core.Scoped} interface which is * {@link IScope} aware. - * + * <p> * This interface is not meant to be used outside of the tinyTiM package. + * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ @@ -41,4 +42,5 @@ * @param scope The scope. */ public void setScopeObject(IScope scope); + } Added: tinytim/trunk/src/main/java/org/tinytim/core/ITopicMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ITopicMap.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/ITopicMap.java 2008-11-12 14:48:00 UTC (rev 177) @@ -0,0 +1,54 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.core; + +import org.tmapi.core.Association; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +interface ITopicMap extends TopicMap, IEventHandler, IConstruct, IIndexManagerAware { + + /** + * + * + * @return + */ + Topic getDefaultTopicNameType(); + + void removeTopic(Topic topic); + + void removeAssociation(Association association); + + void addAssociation(Association assoc); + + /** + * Returns a topic without any identity. + * <p> + * The topic won't have an item identifier, subject identifier, or subject + * locator, just an internal identifier. + * </p> + * + * @return A topic without any identity. + */ + public Topic createTopicWithoutIdentity(); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/ITopicMap.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-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-11-12 14:48:00 UTC (rev 177) @@ -19,8 +19,9 @@ /** * Class used to generate identifiers. - * + * <p> * This class is not meant to be used outside of the tinyTiM package. + * </p> * * @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/IdentityManager.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java 2008-11-12 14:48:00 UTC (rev 177) @@ -28,34 +28,33 @@ /** * The identity manager takes care about the TMDM identity constraints and * provides an index to get Topic Maps constructs by their identity. - * + * <p> * This class is not meant to be used outside of the tinyTiM package. + * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -final class IdentityManager { +final class IdentityManager implements IEventPublisherAware { private Map<Locator, Topic> _sid2Topic; private Map<Locator, Topic> _slo2Topic; private Map<Locator, IConstruct> _iid2Construct; private Map<String, IConstruct> _id2Construct; - IdentityManager(TopicMapImpl tm) { + IdentityManager(MemoryTopicMap tm) { _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); + subscribe(tm); _register(tm); } - /** - * Subscribes itself to the specified event publisher. - * - * @param publisher The publisher to subscribe to. + /* (non-Javadoc) + * @see org.tinytim.core.IEventPublisherAware#subscribe(org.tinytim.core.IEventPublisher) */ - private void _subscribe(IEventPublisher publisher) { + public void subscribe(IEventPublisher publisher) { IEventHandler handler = new TopicMapsConstructAddHandler(); publisher.subscribe(Event.ADD_TOPIC, handler); publisher.subscribe(Event.ADD_ASSOCIATION, handler); @@ -86,6 +85,13 @@ publisher.subscribe(Event.SET_REIFIER, handler); } + /* (non-Javadoc) + * @see org.tinytim.core.IEventPublisherAware#unsubscribe(org.tinytim.core.IEventPublisher) + */ + public void unsubscribe(IEventPublisher publisher) { + // noop. + } + /** * Registeres a Topic Maps construct and, if necessary, gives it an id. * Modified: tinytim/trunk/src/main/java/org/tinytim/core/IntegerLiteral.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IntegerLiteral.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IntegerLiteral.java 2008-11-12 14:48:00 UTC (rev 177) @@ -25,7 +25,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ + * @version $Rev:$ - $Date:$ */ final class IntegerLiteral implements ILiteral { Modified: tinytim/trunk/src/main/java/org/tinytim/core/Literal.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Literal.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/Literal.java 2008-11-12 14:48:00 UTC (rev 177) @@ -24,15 +24,16 @@ /** * - * + * <p> * This class is not meant to be used outside of the tinyTiM package. + * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ public final class Literal implements ILiteral { - private static final WeakObjectRegistry<IRI> _IRIS = new WeakObjectRegistry<IRI>(IConstant.LITERAL_IRI_SIZE); + private static final WeakObjectRegistry<LocatorImpl> _IRIS = new WeakObjectRegistry<LocatorImpl>(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); @@ -69,7 +70,7 @@ if (value == null) { throw new IllegalArgumentException("The value must not be null"); } - return _IRIS.get(new IRI(value)); + return _IRIS.get(new LocatorImpl(value)); } public static synchronized ILiteral get(String value, Locator datatype) { @@ -155,7 +156,7 @@ if (value == null) { throw new IllegalArgumentException("The value must not be null"); } - return _registerIfAbsent(_IRIS, new IRI(value)); + return _registerIfAbsent(_IRIS, new LocatorImpl(value)); } public static synchronized ILiteral createDecimal(String value) { Modified: tinytim/trunk/src/main/java/org/tinytim/core/LiteralNormalizer.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/LiteralNormalizer.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/LiteralNormalizer.java 2008-11-12 14:48:00 UTC (rev 177) @@ -20,8 +20,9 @@ /** * Normalizes literal values. - * + * <p> * This class is not meant to be used outside of the tinyTiM package. + * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ Added: tinytim/trunk/src/main/java/org/tinytim/core/LocatorImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/LocatorImpl.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/LocatorImpl.java 2008-11-12 14:48:00 UTC (rev 177) @@ -0,0 +1,143 @@ +/* + * 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.io.UnsupportedEncodingException; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.net.URI; +import java.net.URLDecoder; + +import org.tinytim.voc.XSD; +import org.tmapi.core.Locator; +import org.tmapi.core.TMAPIRuntimeException; + +/** + * Immutable representation of an IRI. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +final class LocatorImpl implements ILocator { + + private final URI _uri; + private final String _reference; + + LocatorImpl(String reference) { + try { + _reference = URLDecoder.decode(reference, "utf-8"); + } + catch (UnsupportedEncodingException ex) { + throw new TMAPIRuntimeException(ex); + } + _uri = URI.create(_reference.replace(" ", "%20")); + } + + private LocatorImpl(URI uri) { + try { + _reference = URLDecoder.decode(uri.toString(), "utf-8"); + } + catch (UnsupportedEncodingException ex) { + throw new TMAPIRuntimeException(ex); + } + _uri = uri; + } + + /* (non-Javadoc) + * @see org.tinytim.core.ILiteral#getDatatype() + */ + public Locator getDatatype() { + return XSD.ANY_URI; + } + + /* (non-Javadoc) + * @see org.tinytim.core.ILiteral#getValue() + */ + public String getValue() { + return _reference; + } + + public BigDecimal decimalValue() { + throw new NumberFormatException(); + } + + public float floatValue() { + throw new NumberFormatException(); + } + + public BigInteger integerValue() { + throw new NumberFormatException(); + } + + public int intValue() { + throw new NumberFormatException(); + } + + public long longValue() { + throw new NumberFormatException(); + } + + /* (non-Javadoc) + * @see org.tmapi.core.Locator#getReference() + */ + public String getReference() { + return _reference; + } + + /* (non-Javadoc) + * @see org.tmapi.core.Locator#resolve(java.lang.String) + */ + public Locator resolve(String reference) { + return new LocatorImpl(_uri.resolve(reference)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.Locator#toExternalForm() + */ + public String toExternalForm() { + return _uri.toASCIIString(); + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + return this == obj || (obj instanceof LocatorImpl && _reference.equals(((LocatorImpl) obj)._reference)); + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return _reference.hashCode(); + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return _uri.toString(); + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/LocatorImpl.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java 2008-11-12 14:48:00 UTC (rev 177) @@ -0,0 +1,521 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.core; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.tinytim.index.IndexManager; +import org.tinytim.index.IIndexManager; +import org.tinytim.internal.utils.Check; +import org.tinytim.internal.utils.CollectionFactory; +import org.tinytim.voc.TMDM; +import org.tmapi.core.Association; +import org.tmapi.core.IdentityConstraintException; +import org.tmapi.core.ModelConstraintException; +import org.tmapi.core.Role; +import org.tmapi.core.Locator; +import org.tmapi.core.Occurrence; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; +import org.tmapi.core.Construct; +import org.tmapi.core.Name; +import org.tmapi.core.Variant; +import org.tmapi.index.Index; + +/** + * {@link org.tmapi.core.TopicMap} implementation. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +final class MemoryTopicMap extends ConstructImpl implements ITopicMap, + IEventHandler, IEventPublisher { + + private IdentityManager _identityManager; + private IIndexManager _indexManager; + private Locator _locator; + private Set<Topic> _topics; + private Set<Association> _assocs; + private AbstractTopicMapSystem _sys; + private Topic _reifier; + private Map<Event, List<IEventHandler>> _evtHandlers; + private EventMultiplier _eventMultiplier; + + MemoryTopicMap(AbstractTopicMapSystem sys, Locator locator) { + super(null); + super._tm = this; + _sys = sys; + _locator = locator; + _topics = CollectionFactory.createIdentitySet(IConstant.TM_TOPIC_SIZE); + _assocs = CollectionFactory.createIdentitySet(IConstant.TM_ASSOCIATION_SIZE); + _evtHandlers = CollectionFactory.createIdentityMap(); + _identityManager = new IdentityManager(this); + _indexManager = new IndexManager(); + _indexManager.subscribe(this); + _eventMultiplier = new EventMultiplier(this); + } + + Locator getLocator() { + return _locator; + } + + /* (non-Javadoc) + * @see org.tinytim.core.ConstructImpl#getTopicMap() + */ + @Override + public TopicMap getTopicMap() { + return this; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#createLocator(java.lang.String) + */ + public Locator createLocator(String reference) { + return Literal.createIRI(reference); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#getTopics() + */ + public Set<Topic> getTopics() { + return Collections.unmodifiableSet(_topics); + } + + /* (non-Javadoc) + * @see org.tinytim.core.ITopicMap#createTopicWithoutIdentity() + */ + public TopicImpl createTopicWithoutIdentity() { + TopicImpl topic = new TopicImpl(this); + addTopic(topic); + return topic; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#createTopic() + */ + public Topic createTopic() { + Topic topic = createTopicWithoutIdentity(); + topic.addItemIdentifier(Literal.createIRI("urn:x-tinytim:" + IdGenerator.nextId())); + return topic; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#createTopicByItemIdentifier(org.tmapi.core.Locator) + */ + public Topic createTopicByItemIdentifier(Locator iid) { + if (iid == null) { + throw new ModelConstraintException(null, "The item identifier must not be null"); + } + Construct construct = getConstructByItemIdentifier(iid); + if (construct != null) { + if (construct instanceof Topic) { + return (Topic) construct; + } + throw new IdentityConstraintException(null, construct, iid, "A construct with the item identifier '" + iid.getReference() + "' already exists"); + } + else { + Topic topic = getTopicBySubjectIdentifier(iid); + if (topic != null) { + topic.addItemIdentifier(iid); + return topic; + } + } + TopicImpl topic = createTopicWithoutIdentity(); + topic.addItemIdentifier(iid); + return topic; + } + + public Topic getDefaultTopicNameType() { + return createTopicBySubjectIdentifier(TMDM.TOPIC_NAME); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#createTopicBySubjectIdentifier(org.tmapi.core.Locator) + */ + public Topic createTopicBySubjectIdentifier(Locator sid) { + if (sid == null) { + throw new ModelConstraintException(null, "The subject identifier must not be null"); + } + Topic topic = getTopicBySubjectIdentifier(sid); + if (topic != null) { + return topic; + } + else { + Construct construct = getConstructByItemIdentifier(sid); + if (construct != null && construct instanceof Topic) { + topic = (Topic) construct; + topic.addSubjectIdentifier(sid); + return topic; + } + } + topic = createTopicWithoutIdentity(); + topic.addSubjectIdentifier(sid); + return topic; + } + + public Topic createTopicBySubjectLocator(Locator slo) { + if (slo == null) { + throw new ModelConstraintException(null, "The subject locator must not be null"); + } + Topic topic = getTopicBySubjectLocator(slo); + if (topic != null) { + return topic; + } + topic = createTopicWithoutIdentity(); + topic.addSubjectLocator(slo); + return topic; + } + + /** + * Adds a topic to the topics property. + * + * @param topic The topic to add. + */ + void addTopic(TopicImpl topic) { + if (topic._parent == this) { + return; + } + _fireEvent(Event.ADD_TOPIC, null, topic); + topic._parent = this; + _topics.add(topic); + } + + public void removeTopic(Topic topic_) { + TopicImpl topic = (TopicImpl) topic_; + if (topic._parent != this) { + return; + } + assert topic._parent == null; + _fireEvent(Event.REMOVE_TOPIC, topic, null); + _topics.remove(topic); + topic._parent = null; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#getAssociations() + */ + public Set<Association> getAssociations() { + return Collections.unmodifiableSet(_assocs); + } + + public Association createAssociation(Topic type, Topic... scope) { + Check.scopeNotNull(this, scope); + return createAssociation(type, Arrays.asList(scope)); + } + + public Association createAssociation(Topic type, Collection<Topic> scope) { + Check.typeNotNull(this, type); + Check.scopeNotNull(this, scope); + AssociationImpl assoc = new AssociationImpl(this, type, Scope.create(scope)); + addAssociation(assoc); + return assoc; + } + + public void addAssociation(Association assoc_) { + AssociationImpl assoc = (AssociationImpl) assoc_; + if (assoc._parent == this) { + return; + } + _fireEvent(Event.ADD_ASSOCIATION, null, assoc); + assoc._parent = this; + _assocs.add(assoc); + } + + public void removeAssociation(Association assoc_) { + AssociationImpl assoc = (AssociationImpl) assoc_; + if (assoc._parent != this) { + return; + } + _fireEvent(Event.REMOVE_ASSOCIATION, assoc, null); + for (Role role: assoc.getRoles()) { + TopicImpl player = (TopicImpl) role.getPlayer(); + if (player != null) { + player.removeRolePlayed(role); + } + } + _assocs.remove(assoc); + assoc._parent = null; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#getConstructById(java.lang.String) + */ + public Construct getConstructById(String id) { + return _identityManager.getConstructById(id); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#getTopicBySubjectIdentifier(org.tmapi.core.Locator) + */ + public Topic getTopicBySubjectIdentifier(Locator subjectIdentifier) { + return _identityManager.getTopicBySubjectIdentifier(subjectIdentifier); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#getTopicBySubjectLocator(org.tmapi.core.Locator) + */ + public Topic getTopicBySubjectLocator(Locator subjectLocator) { + return _identityManager.getTopicBySubjectLocator(subjectLocator); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#getConstructByItemIdentifier(org.tmapi.core.Locator) + */ + public Construct getConstructByItemIdentifier(Locator itemIdentifier) { + return _identityManager.getConstructByItemIdentifier(itemIdentifier); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#getReifier() + */ + public Topic getReifier() { + return _reifier; + } + + /* (non-Javadoc) + * @see org.tinytim.IReifiable#setReifier(org.tmapi.core.Topic) + */ + public void setReifier(Topic reifier) { + if (_reifier == reifier) { + return; + } + _fireEvent(Event.SET_REIFIER, _reifier, reifier); + if (_reifier != null) { + ((TopicImpl) _reifier)._reified = null; + } + _reifier = reifier; + if (reifier != null) { + ((TopicImpl) reifier)._reified = this; + } + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#getIndex(java.lang.Class) + */ + @SuppressWarnings("unchecked") + public <I extends Index> I getIndex(Class<I> indexInterface) { + if (indexInterface.getName().equals("org.tmapi.index.TypeInstanceIndex")) { + return (I) _indexManager.getTypeInstanceIndex(); + } + if (indexInterface.getName().equals("org.tmapi.index.ScopedIndex")) { + return (I) _indexManager.getScopedIndex(); + } + if (indexInterface.getName().equals("org.tmapi.index.LiteralIndex")) { + return (I) _indexManager.getLiteralIndex(); + } + throw new UnsupportedOperationException("Index '" + indexInterface.getName() + "' is unknown"); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#mergeIn(org.tmapi.core.TopicMap) + */ + public void mergeIn(TopicMap other) { + MergeUtils.merge(other, this); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#close() + */ + public void close() { + remove(); + } + + /* (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() { + _sys.removeTopicMap(this); + _sys = null; + _locator = null; + _topics = null; + _assocs = null; + _indexManager.close(); + _indexManager = null; + _identityManager.close(); + _identityManager = null; + _eventMultiplier = null; + super.dispose(); + } + + /* (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, IConstruct sender, Object oldValue, Object newValue) { + if (!_evtHandlers.containsKey(evt)) { + _eventMultiplier.handleEvent(evt, sender, oldValue, newValue); + return; + ... [truncated message content] |
From: <lh...@us...> - 2008-11-13 13:19:45
|
Revision: 180 http://tinytim.svn.sourceforge.net/tinytim/?rev=180&view=rev Author: lheuer Date: 2008-11-13 13:19:39 +0000 (Thu, 13 Nov 2008) Log Message: ----------- - Package reorg - Introduced more internal interfaces - Simplified ITopicMap - Utility classes work on interfaces and rely not on implementations (changed casts to internal interfaces, not implementations) Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/Version.java tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java 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/DatatypeAwareConstruct.java tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMapSystem.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/Scope.java tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemFactoryImpl.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/IIndexManager.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/DuplicateRemovalUtils.java tinytim/trunk/src/main/java/org/tinytim/utils/Property.java tinytim/trunk/src/main/java/org/tinytim/utils/TopicUtils.java tinytim/trunk/src/main/java/org/tinytim/utils/TypeInstanceConverter.java tinytim/trunk/src/main/java/org/tinytim/voc/Namespace.java tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java tinytim/trunk/src/test/java/org/tinytim/core/TestIConstruct.java tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/core/MemoryConstructFactory.java tinytim/trunk/src/main/java/org/tinytim/core/value/ tinytim/trunk/src/main/java/org/tinytim/core/value/DecimalLiteral.java tinytim/trunk/src/main/java/org/tinytim/core/value/IntegerLiteral.java tinytim/trunk/src/main/java/org/tinytim/core/value/Literal.java tinytim/trunk/src/main/java/org/tinytim/core/value/LiteralNormalizer.java tinytim/trunk/src/main/java/org/tinytim/core/value/LocatorImpl.java tinytim/trunk/src/main/java/org/tinytim/internal/api/ tinytim/trunk/src/main/java/org/tinytim/internal/api/Event.java tinytim/trunk/src/main/java/org/tinytim/internal/api/IConstant.java tinytim/trunk/src/main/java/org/tinytim/internal/api/IConstruct.java tinytim/trunk/src/main/java/org/tinytim/internal/api/IConstructFactory.java tinytim/trunk/src/main/java/org/tinytim/internal/api/IEventHandler.java tinytim/trunk/src/main/java/org/tinytim/internal/api/IEventPublisher.java tinytim/trunk/src/main/java/org/tinytim/internal/api/IEventPublisherAware.java tinytim/trunk/src/main/java/org/tinytim/internal/api/IIndexManagerAware.java tinytim/trunk/src/main/java/org/tinytim/internal/api/ILiteral.java tinytim/trunk/src/main/java/org/tinytim/internal/api/ILiteralAware.java tinytim/trunk/src/main/java/org/tinytim/internal/api/ILocator.java tinytim/trunk/src/main/java/org/tinytim/internal/api/IMovable.java tinytim/trunk/src/main/java/org/tinytim/internal/api/IName.java tinytim/trunk/src/main/java/org/tinytim/internal/api/IOccurrence.java tinytim/trunk/src/main/java/org/tinytim/internal/api/IScope.java tinytim/trunk/src/main/java/org/tinytim/internal/api/IScoped.java tinytim/trunk/src/main/java/org/tinytim/internal/api/ITopic.java tinytim/trunk/src/main/java/org/tinytim/internal/api/ITopicMap.java tinytim/trunk/src/main/java/org/tinytim/internal/api/IVariant.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/CopyUtils.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/MergeUtils.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/SignatureGenerator.java tinytim/trunk/src/test/java/org/tinytim/core/value/ tinytim/trunk/src/test/java/org/tinytim/core/value/TestLiteral.java tinytim/trunk/src/test/java/org/tinytim/core/value/TestLiteralNormalizer.java tinytim/trunk/src/test/java/org/tinytim/core/value/TestLocatorImpl.java tinytim/trunk/src/test/java/org/tinytim/internal/ tinytim/trunk/src/test/java/org/tinytim/internal/utils/ tinytim/trunk/src/test/java/org/tinytim/internal/utils/TestSignatureGenerator.java Removed Paths: ------------- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java tinytim/trunk/src/main/java/org/tinytim/core/DecimalLiteral.java tinytim/trunk/src/main/java/org/tinytim/core/Event.java tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisher.java tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisherAware.java tinytim/trunk/src/main/java/org/tinytim/core/IIndexManagerAware.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/ILocator.java tinytim/trunk/src/main/java/org/tinytim/core/IMovable.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/ITopicMap.java tinytim/trunk/src/main/java/org/tinytim/core/IntegerLiteral.java tinytim/trunk/src/main/java/org/tinytim/core/Literal.java tinytim/trunk/src/main/java/org/tinytim/core/LiteralNormalizer.java tinytim/trunk/src/main/java/org/tinytim/core/LocatorImpl.java tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java tinytim/trunk/src/test/java/org/tinytim/core/TestLiteralNormalizer.java tinytim/trunk/src/test/java/org/tinytim/core/TestLocatorImpl.java tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java Modified: tinytim/trunk/src/main/java/org/tinytim/Version.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Version.java 2008-11-12 15:26:11 UTC (rev 179) +++ tinytim/trunk/src/main/java/org/tinytim/Version.java 2008-11-13 13:19:39 UTC (rev 180) @@ -19,7 +19,7 @@ * Provides the version information. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class Version { @@ -32,6 +32,7 @@ /** * The release information. */ - public static final String RELEASE = _MAJOR + "." + _MINOR + "." + _MICRO + _STATE + _DATE; + // Not final since Java compilers copy the string into classes + public static String RELEASE = _MAJOR + "." + _MINOR + "." + _MICRO + _STATE + _DATE; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java 2008-11-12 15:26:11 UTC (rev 179) +++ tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java 2008-11-13 13:19:39 UTC (rev 180) @@ -17,6 +17,8 @@ import java.util.Map; +import org.tinytim.core.value.Literal; + import org.tmapi.core.FeatureNotRecognizedException; import org.tmapi.core.Locator; import org.tmapi.core.TMAPIException; @@ -28,7 +30,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ abstract class AbstractTopicMapSystem implements TopicMapSystem { Modified: tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-11-12 15:26:11 UTC (rev 179) +++ tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-11-13 13:19:39 UTC (rev 180) @@ -18,8 +18,13 @@ import java.util.Collections; import java.util.Set; +import org.tinytim.internal.api.Event; +import org.tinytim.internal.api.IConstant; +import org.tinytim.internal.api.IScope; +import org.tinytim.internal.api.ITopicMap; import org.tinytim.internal.utils.Check; import org.tinytim.internal.utils.CollectionFactory; + import org.tmapi.core.Association; import org.tmapi.core.Role; import org.tmapi.core.Topic; Modified: tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-11-12 15:26:11 UTC (rev 179) +++ tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-11-13 13:19:39 UTC (rev 180) @@ -18,7 +18,12 @@ import java.util.Collections; import java.util.Set; +import org.tinytim.internal.api.Event; +import org.tinytim.internal.api.IConstant; +import org.tinytim.internal.api.IConstruct; +import org.tinytim.internal.api.ITopicMap; import org.tinytim.internal.utils.CollectionFactory; + import org.tmapi.core.Construct; import org.tmapi.core.Locator; import org.tmapi.core.ModelConstraintException; Deleted: tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-11-12 15:26:11 UTC (rev 179) +++ tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-11-13 13:19:39 UTC (rev 180) @@ -1,375 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.core; - -import java.util.Map; -import java.util.Set; - -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; -import org.tmapi.core.Name; -import org.tmapi.core.Occurrence; -import org.tmapi.core.Reifiable; -import org.tmapi.core.Role; -import org.tmapi.core.Scoped; -import org.tmapi.core.Topic; -import org.tmapi.core.TopicMap; -import org.tmapi.core.Typed; -import org.tmapi.core.Variant; - -/** - * This class provides methods to copy Topic Maps constructs from one - * topic map to another without creating duplicates. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -final class CopyUtils { - - private CopyUtils() { - // noop. - } - - /** - * Copies the topics and associations from the <tt>source</tt> to the - * <tt>target</tt> topic map. - * - * @param source The topic map to take the topics and associations from. - * @param target The topic map which should receive the topics and associations. - */ - public static void copy(TopicMap source, TopicMap target) { - _copy(source, (ITopicMap) target); - } - - /** - * @see #copy(TopicMap, TopicMap) - */ - private static void _copy(TopicMap source, ITopicMap target) { - if (source == null || target == null) { - throw new IllegalArgumentException("Neither the source topic map nor the target topic map must be null"); - } - if (source == target) { - return; - } - Map<Topic, Topic> mergeMap = CollectionFactory.createIdentityMap(); - Topic existing = null; - Construct existingConstruct = null; - for (Topic topic: source.getTopics()) { - for (Locator slo: topic.getSubjectLocators()) { - existing = target.getTopicBySubjectLocator(slo); - if (existing != null) { - _addMerge(topic, existing, mergeMap); - } - } - for (Locator sid: topic.getSubjectIdentifiers()) { - existing = target.getTopicBySubjectIdentifier(sid); - if (existing != null) { - _addMerge(topic, existing, mergeMap); - } - existingConstruct = target.getConstructByItemIdentifier(sid); - if (existingConstruct instanceof Topic) { - _addMerge(topic, (Topic) existingConstruct, mergeMap); - } - } - for (Locator iid: topic.getItemIdentifiers()) { - existingConstruct = target.getConstructByItemIdentifier(iid); - if (existingConstruct instanceof Topic) { - _addMerge(topic, (Topic) existingConstruct, mergeMap); - } - existing = target.getTopicBySubjectIdentifier(iid); - if (existing != null) { - _addMerge(topic, existing, mergeMap); - } - } - } - if (source.getReifier() != null && target.getReifier() != null) { - _addMerge(source.getReifier(), target.getReifier(), mergeMap); - } - for (Topic topic: source.getTopics()) { - if (!mergeMap.containsKey(topic)) { - _copyTopic(topic, target, mergeMap); - } - } - for (Topic topic: mergeMap.keySet()) { - Topic targetTopic = mergeMap.get(topic); - _copyIdentities(topic, targetTopic); - _copyTypes(topic, targetTopic, mergeMap); - _copyCharacteristics(topic, (TopicImpl)targetTopic, mergeMap); - } - _copyAssociations(source, target, mergeMap); - } - - /** - * Copies the <tt>topic</tt> to the <tt>target</tt> topic map. - * - * @param topic The topic to copy. - * @param target The target topic map. - * @param mergeMap The map which holds the merge mappings. - * @return The newly created topic in the target topic map. - */ - private static Topic _copyTopic(Topic topic, ITopicMap target, - Map<Topic, Topic> mergeMap) { - Topic targetTopic = target.createTopicWithoutIdentity(); - _copyIdentities(topic, targetTopic); - _copyTypes(topic, targetTopic, mergeMap); - _copyCharacteristics(topic, (TopicImpl)targetTopic, mergeMap); - return targetTopic; - } - - /** - * Copies the identities (item identifiers, subject identifiers and subject - * locators) from the <tt>source/tt> to the <tt>targetTopic</tt>. - * - * @param topic The topic to take the identities from. - * @param targetTopic The topic which gets the identities. - */ - private static void _copyIdentities(Topic topic, Topic targetTopic) { - for(Locator sid: topic.getSubjectIdentifiers()) { - targetTopic.addSubjectIdentifier(sid); - } - for(Locator slo: topic.getSubjectLocators()) { - targetTopic.addSubjectLocator(slo); - } - _copyItemIdentifiers(topic, targetTopic); - } - - /** - * Copies the types from the <tt>topic</tt> to the <tt>targetTopic</tt>. - * - * @param topic The topic to take the types from. - * @param targetTopic The topic which receives the types. - * @param mergeMap The map which holds the merge mappings. - */ - private static void _copyTypes(Topic topic, Topic targetTopic, - Map<Topic, Topic> mergeMap) { - for (Topic type: topic.getTypes()) { - Topic targetType = mergeMap.get(type); - if (targetType == null) { - targetType = _copyTopic(type, (ITopicMap) targetTopic.getTopicMap(), mergeMap); - } - targetTopic.addType(targetType); - } - } - - /** - * Copies the occurrences and names from <tt>topic</tt> to the - * <tt>targetTopic</tt>. - * - * @param topic The topic to take the characteristics from. - * @param targetTopic The target topic which gets the charateristics. - * @param mergeMap The map which holds the merge mappings. - */ - private static void _copyCharacteristics(Topic topic, TopicImpl targetTopic, - Map<Topic, Topic> mergeMap) { - IIntObjectMap<Reifiable> sigs = CollectionFactory.createIntObjectMap(); - for (Occurrence occ: targetTopic.getOccurrences()) { - sigs.put(SignatureGenerator.generateSignature(occ), occ); - } - Reifiable existing = null; - final TopicMap tm = targetTopic.getTopicMap(); - Topic type = null; - Set<Topic> scope = null; - Occurrence targetOcc = null; - for (Occurrence occ: topic.getOccurrences()) { - type = _copyType(occ, tm, mergeMap); - scope = _copyScope(occ, tm, mergeMap); - targetOcc = targetTopic._createOccurrence(type, ((ILiteralAware) occ).getLiteral(), scope); - existing = sigs.get(SignatureGenerator.generateSignature(targetOcc)); - if (existing != null) { - targetOcc.remove(); - targetOcc = (Occurrence)existing; - } - _copyReifier(occ, targetOcc, mergeMap); - _copyItemIdentifiers(occ, targetOcc); - } - sigs.clear(); - for (Name name: targetTopic.getNames()) { - sigs.put(SignatureGenerator.generateSignature(name), name); - } - - for (Name name: topic.getNames()) { - type = _copyType(name, tm, mergeMap); - scope = _copyScope(name, tm, mergeMap); - Name targetName = targetTopic._createName(type, ((ILiteralAware) name).getLiteral(), scope); - existing = sigs.get(SignatureGenerator.generateSignature(targetName)); - if (existing != null) { - targetName.remove(); - targetName = (Name) existing; - } - _copyReifier(name, targetName, mergeMap); - _copyItemIdentifiers(name, targetName); - _copyVariants(name, (NameImpl)targetName, mergeMap); - } - } - - /** - * Copies the variants from <tt>source</tt> to the <tt>target</tt>. - * - * @param source The name to take the variants from. - * @param target The target name which receives the variants. - * @param mergeMap The map which holds the merge mappings. - */ - private static void _copyVariants(Name source, NameImpl target, - Map<Topic, Topic> mergeMap) { - IIntObjectMap<Variant> sigs = CollectionFactory.createIntObjectMap(); - for (Variant variant: target.getVariants()) { - sigs.put(SignatureGenerator.generateSignature(variant), variant); - } - final TopicMap tm = target.getTopicMap(); - Variant existing = null; - Set<Topic> scope = null; - for (Variant variant: source.getVariants()) { - scope = _copyScope( variant, tm, mergeMap); - Variant targetVar = target._createVariant(((ILiteralAware) variant).getLiteral(), scope); - existing = sigs.get(SignatureGenerator.generateSignature(targetVar)); - if (existing != null) { - targetVar.remove(); - targetVar = existing; - } - _copyReifier(variant, targetVar, mergeMap); - _copyItemIdentifiers(variant, targetVar); - } - } - - /** - * Copies the reifier of <tt>source</tt> (if any) to the <tt>target</tt>. - * - * @param source The reifiable Topic Maps construct to take the reifier from. - * @param target The target Topic Maps construct. - * @param mergeMap The map which holds the merge mappings. - */ - private static void _copyReifier(Reifiable source, Reifiable target, - Map<Topic, Topic> mergeMap) { - Topic sourceReifier = source.getReifier(); - if (sourceReifier == null) { - return; - } - Topic reifier = mergeMap.containsKey(sourceReifier) ? mergeMap.get(sourceReifier) - : _copyTopic(sourceReifier, (ITopicMap) target.getTopicMap(), mergeMap); - target.setReifier(reifier); - } - - /** - * Copies the type of the <tt>source</tt> (if any) to the <tt>target</tt>. - * - * @param source The Topic Maps construct to take the type from. - * @param target The Topic Maps construct which receives the type. - * @param mergeMap The map which holds the merge mappings. - */ - private static Topic _copyType(Typed source, TopicMap tm, - Map<Topic, Topic> mergeMap) { - Topic sourceType = source.getType(); - return mergeMap.containsKey(sourceType) ? mergeMap.get(sourceType) - : _copyTopic(sourceType, (ITopicMap) tm, mergeMap); - } - - /** - * Copies all themes from the <tt>source</tt> scoped Topic Maps construct - * to the <tt>target</tt>. - * - * @param source The source to take the scope from. - * @param target The target which receives the scope. - * @param mergeMap The map which holds the merge mappings. - */ - private static Set<Topic>_copyScope(Scoped source, TopicMap tm, - Map<Topic, Topic> mergeMap) { - Set<Topic> themes = CollectionFactory.createIdentitySet(source.getScope().size()); - Topic theme = null; - for (Topic sourceTheme: source.getScope()) { - theme = mergeMap.containsKey(sourceTheme) ? mergeMap.get(sourceTheme) - : _copyTopic(sourceTheme, (ITopicMap) tm, mergeMap); - themes.add(theme); - } - return themes; - } - - /** - * Copies the item identifiers from <tt>source</tt> to <tt>target</tt>. - * - * @param source The source Topic Maps construct. - * @param target The target Topic Maps construct. - */ - private static void _copyItemIdentifiers(Construct source, Construct target) { - for(Locator iid: source.getItemIdentifiers()) { - target.addItemIdentifier(iid); - } - } - - /** - * Copies the associations from the <tt>source</tt> topic map to the - * <tt>target</tt> topic map. - * - * @param source The topic map to take the associations from. - * @param target The topic map which receives the associations. - * @param mergeMap The map which holds the merge mappings. - */ - private static void _copyAssociations(TopicMap source, - TopicMap target, Map<Topic, Topic> mergeMap) { - Set<Association> assocs = target.getAssociations(); - IIntObjectMap<Association> sigs = CollectionFactory.createIntObjectMap(assocs.size()); - for (Association assoc: assocs) { - sigs.put(SignatureGenerator.generateSignature(assoc), assoc); - } - Association existing = null; - Topic type = null; - Set<Topic> scope = null; - for (Association assoc: source.getAssociations()) { - type = _copyType(assoc, target, mergeMap); - scope = _copyScope(assoc, target, mergeMap); - Association targetAssoc = target.createAssociation(type, scope); - for (Role role: assoc.getRoles()) { - Role targetRole = targetAssoc.createRole(role.getType(), role.getPlayer()); - _copyItemIdentifiers(role, targetRole); - _copyReifier(role, targetRole, mergeMap); - } - existing = sigs.get(SignatureGenerator.generateSignature(targetAssoc)); - if (existing != null) { - MergeUtils.moveRoleCharacteristics(targetAssoc, existing); - targetAssoc.remove(); - targetAssoc = existing; - } - _copyReifier(assoc, targetAssoc, mergeMap); - _copyItemIdentifiers(assoc, targetAssoc); - } - } - - /** - * Adds a mapping from <tt>source</tt> to <tt>target</tt> into the - * <tt>mergeMap</tt>. - * - * If <tt>source</tt> has already a mapping to another target topic, - * <tt>target</tt> is merged with the existing target topic. - * - * @param source The source topic. - * @param target The target topic. - * @param mergeMap The map which holds the merge mappings. - */ - private static void _addMerge(Topic source, Topic target, Map<Topic, Topic> mergeMap) { - Topic prevTarget = mergeMap.get(source); - if (prevTarget != null) { - if (!prevTarget.equals(target)) { - MergeUtils.merge(target, prevTarget); - } - } - else { - mergeMap.put(source, target); - } - } - -} Modified: tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-11-12 15:26:11 UTC (rev 179) +++ tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-11-13 13:19:39 UTC (rev 180) @@ -18,8 +18,15 @@ import java.math.BigDecimal; import java.math.BigInteger; +import org.tinytim.core.value.Literal; +import org.tinytim.internal.api.Event; +import org.tinytim.internal.api.ILiteral; +import org.tinytim.internal.api.ILiteralAware; +import org.tinytim.internal.api.IScope; +import org.tinytim.internal.api.ITopicMap; import org.tinytim.internal.utils.Check; import org.tinytim.voc.XSD; + import org.tmapi.core.DatatypeAware; import org.tmapi.core.Locator; import org.tmapi.core.Topic; Deleted: tinytim/trunk/src/main/java/org/tinytim/core/DecimalLiteral.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DecimalLiteral.java 2008-11-12 15:26:11 UTC (rev 179) +++ tinytim/trunk/src/main/java/org/tinytim/core/DecimalLiteral.java 2008-11-13 13:19:39 UTC (rev 180) @@ -1,110 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.core; - -import java.math.BigDecimal; -import java.math.BigInteger; - -import org.tinytim.voc.XSD; -import org.tmapi.core.Locator; - -/** - * - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ - */ -final class DecimalLiteral implements ILiteral { - - private final BigDecimal _decimal; - private final String _lexicalForm; - - public DecimalLiteral(BigDecimal decimal) { - _decimal = decimal; - _lexicalForm = LiteralNormalizer.normalizeDecimal(decimal.toPlainString()); - } - - public DecimalLiteral(String value) { - _lexicalForm = LiteralNormalizer.normalizeDecimal(value); - _decimal = new BigDecimal(_lexicalForm); - } - - /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#decimalValue() - */ - public BigDecimal decimalValue() { - return _decimal; - } - - /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#floatValue() - */ - public float floatValue() { - return _decimal.floatValue(); - } - - /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#getDatatype() - */ - public Locator getDatatype() { - return XSD.DECIMAL; - } - - /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#getValue() - */ - public String getValue() { - return _lexicalForm; - } - - /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#intValue() - */ - public int intValue() { - return _decimal.intValue(); - } - - /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#integerValue() - */ - public BigInteger integerValue() { - return _decimal.toBigInteger(); - } - - /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#longValue() - */ - public long longValue() { - return _decimal.longValue(); - } - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - return _decimal.hashCode(); - } - - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - return this == obj || (obj instanceof DecimalLiteral) && ((DecimalLiteral) obj)._lexicalForm.equals(_lexicalForm); - } - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/core/Event.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Event.java 2008-11-12 15:26:11 UTC (rev 179) +++ tinytim/trunk/src/main/java/org/tinytim/core/Event.java 2008-11-13 13:19:39 UTC (rev 180) @@ -1,158 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.core; - -/** - * Event constants. - * <p> - * All events are sent before a change happens. This allows to check - * some constraints. - * </p> - * <p> - * This class is not meant to be used outside of the tinyTiM package. - * </p> - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public enum Event { - - /** - * Notification that a topic should be added. - */ - ADD_TOPIC, - /** - * Notification that a topic should be removed. - */ - REMOVE_TOPIC, - /** - * Notification that an association should be added. - */ - ADD_ASSOCIATION, - /** - * Notification that an association should be removed. - */ - REMOVE_ASSOCIATION, - /** - * Notification that a role should be added. - */ - ADD_ROLE, - /** - * Notification that a role should be removed. - */ - REMOVE_ROLE, - /** - * Notification that an occurrence should be added. - */ - ADD_OCCURRENCE, - /** - * Notification that an occurrence should be removed. - */ - REMOVE_OCCURRENCE, - /** - * Notification that a name should be added. - */ - ADD_NAME, - /** - * Notification that a name should be removed. - */ - REMOVE_NAME, - /** - * Notification that a variant should be added. - */ - ADD_VARIANT, - /** - * Notification that a variant should be removed. - */ - REMOVE_VARIANT, - - - /** - * Notification that a subject identifier should be added. - */ - ADD_SID, - /** - * Notification that a subject identifier should be removed. - */ - REMOVE_SID, - /** - * Notification that a subject locator should be added. - */ - ADD_SLO, - /** - * Notification that a subject locator should be removed. - */ - REMOVE_SLO, - /** - * Notification that an item identifier should be added. - */ - ADD_IID, - /** - * Notification that an item identifier should be removed. - */ - REMOVE_IID, - - /** - * Notification that a type should be added to a topic. - */ - ADD_TYPE, - /** - * Notification that a type should be removed from a topic. - */ - REMOVE_TYPE, - /** - * Notification that the type of a {@link ITyped} construct should be set. - */ - SET_TYPE, - - /** - * Notification that the scope is changed. - */ - SET_SCOPE, - - /** - * Notification that the player of a role should be set. - */ - SET_PLAYER, - - /** - * Notification that the reifier of a {@link IReifiable} construct - * should be set. - */ - SET_REIFIER, - - /** - * Notification that the literal value of a name, an occurrence or variant - * should be set. - */ - SET_LITERAL, - - /** - * Notification that an occurrence should be moved from one topic to another. - */ - MOVED_OCCURRENCE, - /** - * Notification that a name should be moved from one topic to another. - */ - MOVED_NAME, - /** - * Notification that a variant should be moved from one name to another. - */ - MOVED_VARIANT, - - ATTACHED_NAME, DETACHED_NAME, ATTACHED_OCCURRENCE, DETACHED_OCCURRENCE, - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java 2008-11-12 15:26:11 UTC (rev 179) +++ tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java 2008-11-13 13:19:39 UTC (rev 180) @@ -1,107 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 MemoryTopicMap} topic set - */ - public static final int TM_TOPIC_SIZE = 100; - /** - * Initial size of the {@link MemoryTopicMap} 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 MemoryTopicMapSystem} topic map map. - */ - public static final int SYSTEM_TM_SIZE = 4; -} Deleted: tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java 2008-11-12 15:26:11 UTC (rev 179) +++ tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java 2008-11-13 13:19:39 UTC (rev 180) @@ -1,83 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.core; - -import org.tmapi.core.Construct; - -/** - * Enhancement of the {@link org.tmapi.core.Construct} interface. - * <p> - * Avoids <tt>foo instanceof Bar</tt> checks. Each construct knows its type. - * </p> - * <p> - * This interface is not meant to be used outside of the tinyTiM package. - * </p> - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public interface IConstruct extends Construct { - - /** - * Returns <tt>true</tt> if this is a topic map. - * - * @return <tt>true</tt> if this is a topic map, <tt>false</tt> otherwise. - */ - public boolean isTopicMap(); - - /** - * Returns <tt>true</tt> if this is a topic. - * - * @return <tt>true</tt> if this is a topic, <tt>false</tt> otherwise. - */ - public boolean isTopic(); - - /** - * Returns <tt>true</tt> if this is an association. - * - * @return <tt>true</tt> if this is an association, <tt>false</tt> otherwise. - */ - public boolean isAssociation(); - - /** - * Returns <tt>true</tt> if this is a role. - * - * @return <tt>true</tt> if this is a role, <tt>false</tt> otherwise. - */ - public boolean isRole(); - - /** - * Returns <tt>true</tt> if this is an occurrence. - * - * @return <tt>true</tt> if this is an occurrence, <tt>false</tt> otherwise. - */ - public boolean isOccurrence(); - - /** - * Returns <tt>true</tt> if this is a name. - * - * @return <tt>true</tt> if this is a name, <tt>false</tt> otherwise. - */ - public boolean isName(); - - /** - * Returns <tt>true</tt> if this is a variant. - * - * @return <tt>true</tt> if this is a variant, <tt>false</tt> otherwise. - */ - public boolean isVariant(); - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java 2008-11-12 15:26:11 UTC (rev 179) +++ tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java 2008-11-13 13:19:39 UTC (rev 180) @@ -1,43 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.core; - -/** - * Event handler that is able to handle Topic Maps events. - * <p> - * This interface is not meant to be used outside of the tinyTiM package. - * </p> - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public interface IEventHandler { - - /** - * Callback method if a {@link IEventPublisher} sends an event to which - * this handler is subscribed to. - * - * @param evt The event. - * @param sender The sender of the event (this is not necessarily the - * publisher). - * @param oldValue The old value or <code>null</code> if the old value - * is not available or was <code>null</code>. - * @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, IConstruct sender, Object oldValue, Object newValue); - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisher.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisher.java 2008-11-12 15:26:11 UTC (rev 179) +++ tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisher.java 2008-11-13 13:19:39 UTC (rev 180) @@ -1,45 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.core; - -/** - * Publisher for Topic Maps events. - * <p> - * This interface is not meant to be used outside of the tinyTiM package. - * </p> - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public interface IEventPublisher { - - /** - * Subscribes the handler for the specified event. - * - * @param event The event of interesst. - * @param handler The event handler. - */ - public void subscribe(Event event, IEventHandler handler); - - /** - * Removes the handler from the publisher. - * - * @param event The event. - * @param handler The event handler. - */ - public void unsubscribe(Event event, IEventHandler handler); - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisherAware.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisherAware.java 2008-11-12 15:26:11 UTC (rev 179) +++ tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisherAware.java 2008-11-13 13:19:39 UTC (rev 180) @@ -1,48 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.core; - -/** - * Something that subscribes and unsubscribes itself to an - * {org.tinytim.core.IEventPublisher}. - * <p> - * Implementations MUST have a default (public) constructor. - * </p> - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ - */ -public interface IEventPublisherAware { - - /** - * Subscribes this instance to the specified <tt>publisher</tt>. - * - * @param publisher An event publisher. - */ - public void subscribe(IEventPublisher publisher); - - /** - * Unsubscribes this instance from the specified <tt>publisher</tt>. - * <p> - * This method is only invoked if this instance has been subscribed to - * the <tt>publisher</tt>. - * </p> - * - * @param publisher The publisher to unsubscribe from. - */ - public void unsubscribe(IEventPublisher publisher); - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/core/IIndexManagerAware.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IIndexManagerAware.java 2008-11-12 15:26:11 UTC (rev 179) +++ tinytim/trunk/src/main/java/org/tinytim/core/IIndexManagerAware.java 2008-11-13 13:19:39 UTC (rev 180) @@ -1,30 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.core; - -import org.tinytim.index.IIndexManager; - -/** - * - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ - */ -public interface IIndexManagerAware { - - IIndexManager getIndexManager(); - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java 2008-11-12 15:26:11 UTC (rev 179) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java 2008-11-13 13:19:39 UTC (rev 180) @@ -1,83 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.core; - -import java.math.BigDecimal; -import java.math.BigInteger; - -import org.tmapi.core.Locator; - -/** - * Represents an immutable value with a datatype. - * <p> - * This interface is not meant to be used outside of the tinyTiM package. - * </p> - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -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(); - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java 2008-11-12 15:26:11 UTC (rev 179) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java 2008-11-13 13:19:39 UTC (rev 180) @@ -1,43 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.core; - -/** - * Indicates that a literal can be attached to a construct. - * <p> - * This interface is not meant to be used outside of the tinyTiM package. - * </p> - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public interface ILiteralAware { - - /** - * Returns the literal. - * - * @return The literal. - */ - public ILiteral getLiteral(); - - /** - * Sets the literal. - * - * @param literal The literal. - */ - public void setLiteral(ILiteral literal); - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java 2008-11-12 15:26:11 UTC (rev 179) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java 2008-11-13 13:19:39 UTC (rev 180) @@ -1,32 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.core; - -import org.tmapi.core.Locator; - -/** - * Marker interface which unifies the {@link org.tmapi.core.Locator} and - * tinyTiM's {@link ILiteral}. - * <p> - * This interface is not meant to be used outside of the tinyTiM package. - * </p> - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public interface ILocator extends ILiteral, Locator { - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/core/IMovable.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IMovable.java 2008-11-12 15:26:11 UTC (rev 179) +++ tinytim/trunk/src/main/java/org/tinytim/core/IMovable.java 2008-11-13 13:19:39 UTC (rev 180) @@ -1,39 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.core; - -import org.tmapi.core.Construct; - -/** - * Indicates that a Topic Maps construct is able to be detached from the - * current parent and attached to another parent. - * <p> - * This interface is not meant to be used outside of the tinyTiM package. - * </p> - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -interface IMovable<T extends Construct> { - - /** - * Moves this Topic Maps construct to the new parent. - * - * @param newParent The parent to move this construct to. - */ - public void moveTo(T newParent); - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/core/IScope.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IScope.java 2008-11-12 15:26:11 UTC (rev 179) +++ tinytim/trunk/src/main/java/org/tinytim/core/IScope.java 2008-11-13 13:19:39 UTC (rev 180) @@ -1,92 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.core; - -import java.util.Collection; -import java.util.Set; - -import org.tmapi.core.Topic; - -/** - * Represents an immutable set of {@link org.tmapi.core.Topic}s. - * <p> - * This interface is not meant to be used outside of the tinyTiM package. - * </p> - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -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 <tt>true</tt> if all themes of the other <tt>scope</tt> are part - * of this scope. - * - * @param scope A collection of themes. - * @return <tt>true</tt> if all themes are part of this scope, otherwise <tt>false</tt>. - */ - public boolean containsAll(Collection<Topic> scope); - - /** - * 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(); - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java 2008-11-12 15:26:11 UTC (rev 179) +++ tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java 2008-11-13 13:19:39 UTC (rev 180) @@ -1,46 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.core; - -import org.tmapi.core.Scoped; - -/** - * Enhancement of the {@link org.tmapi.core.Scoped} interface which is - * {@link IScope} aware. - * <p> - * This interface is not meant to be used outside of the tinyTiM package. - * </p> - * - * @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); - -} Deleted: tinytim/trunk/src/main/ja... [truncated message content] |
From: <lh...@us...> - 2008-11-13 18:00:09
|
Revision: 187 http://tinytim.svn.sourceforge.net/tinytim/?rev=187&view=rev Author: lheuer Date: 2008-11-13 18:00:03 +0000 (Thu, 13 Nov 2008) Log Message: ----------- - Added test case for IConstructFactory - Modified MemoryConstructFactory accordingly Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/MemoryConstructFactory.java tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java Added Paths: ----------- tinytim/trunk/src/test/java/org/tinytim/core/TestIConstructFactory.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/MemoryConstructFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MemoryConstructFactory.java 2008-11-13 15:33:33 UTC (rev 186) +++ tinytim/trunk/src/main/java/org/tinytim/core/MemoryConstructFactory.java 2008-11-13 18:00:03 UTC (rev 187) @@ -43,14 +43,18 @@ * @see org.tinytim.internal.api.IConstructFactory#createTopic() */ public ITopic createTopic() { - return new TopicImpl(_tm); + TopicImpl topic = new TopicImpl(_tm); + _tm.addTopic(topic); + return topic; } /* (non-Javadoc) * @see org.tinytim.internal.api.IConstructFactory#createAssociation() */ public Association createAssociation() { - return new AssociationImpl(_tm); + AssociationImpl assoc = new AssociationImpl(_tm); + _tm.addAssociation(assoc); + return assoc; } /* (non-Javadoc) Modified: tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java 2008-11-13 15:33:33 UTC (rev 186) +++ tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java 2008-11-13 18:00:03 UTC (rev 187) @@ -243,7 +243,7 @@ return assoc; } - public void addAssociation(Association assoc_) { + void addAssociation(Association assoc_) { AssociationImpl assoc = (AssociationImpl) assoc_; if (assoc._parent == this) { return; Modified: tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2008-11-13 15:33:33 UTC (rev 186) +++ tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2008-11-13 18:00:03 UTC (rev 187) @@ -42,6 +42,7 @@ suite.addTestSuite(TestDuplicateRemovalUtils.class); suite.addTestSuite(TestLocatorImpl.class); suite.addTestSuite(TestIConstruct.class); + suite.addTestSuite(TestIConstructFactory.class); suite.addTestSuite(TestScope.class); suite.addTestSuite(TestLiteral.class); suite.addTestSuite(TestLiteralNormalizer.class); Added: tinytim/trunk/src/test/java/org/tinytim/core/TestIConstructFactory.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestIConstructFactory.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestIConstructFactory.java 2008-11-13 18:00:03 UTC (rev 187) @@ -0,0 +1,172 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.core; + +import org.tinytim.internal.api.IConstructFactory; +import org.tinytim.internal.api.IName; +import org.tinytim.internal.api.IOccurrence; +import org.tinytim.internal.api.ITopic; +import org.tinytim.internal.api.IVariant; + +import org.tmapi.core.Association; +import org.tmapi.core.Role; +import org.tmapi.core.Topic; + +/** + * Tests against {@link IConstructFactory}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public class TestIConstructFactory extends TinyTimTestCase { + + private IConstructFactory _factory; + + /* (non-Javadoc) + * @see org.tinytim.core.TinyTimTestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + _factory = _tm.getConstructFactory(); + } + + /* (non-Javadoc) + * @see org.tinytim.core.TinyTimTestCase#tearDown() + */ + @Override + protected void tearDown() throws Exception { + super.tearDown(); + _factory = null; + } + + /** + * Tests topic creatation. + */ + public void testTopicCreation() { + final Topic topic = _factory.createTopic(); + assertNotNull(topic.getId()); + assertTrue(topic.getItemIdentifiers().isEmpty()); + assertTrue(topic.getSubjectIdentifiers().isEmpty()); + assertTrue(topic.getSubjectLocators().isEmpty()); + assertTrue(topic.getTypes().isEmpty()); + assertTrue(topic.getOccurrences().isEmpty()); + assertTrue(topic.getNames().isEmpty()); + assertTrue(topic.getRolesPlayed().isEmpty()); + assertEquals(topic, _tm.getConstructById(topic.getId())); + assertEquals(_tm, topic.getParent()); + assertEquals(_tm, topic.getTopicMap()); + } + + /** + * Tests association creatation. + */ + public void testAssociationCreation() { + final Association assoc = _factory.createAssociation(); + assertNotNull(assoc.getId()); + assertNull(assoc.getType()); + assertTrue(assoc.getItemIdentifiers().isEmpty()); + assertTrue(assoc.getRoles().isEmpty()); + assertTrue(assoc.getScope().isEmpty()); + assertEquals(assoc, _tm.getConstructById(assoc.getId())); + assertEquals(_tm, assoc.getParent()); + assertEquals(_tm, assoc.getTopicMap()); + } + + /** + * Tests role creation. + */ + public void testRoleCreation() { + final Association assoc = createAssociation(); + final Role role = _factory.createRole(assoc); + assertNotNull(role.getId()); + assertNull(role.getType()); + assertNull(role.getPlayer()); + assertTrue(role.getItemIdentifiers().isEmpty()); + assertEquals(role, _tm.getConstructById(role.getId())); + assertEquals(assoc, role.getParent()); + assertEquals(_tm, assoc.getTopicMap()); + } + + /** + * Tests occurrence creation. + */ + public void testOccurrenceCreation() { + final ITopic topic = (ITopic) createTopic(); + final IOccurrence occ = _factory.createOccurrence(topic); + assertNotNull(occ.getId()); + assertNull(occ.getType()); + assertTrue(occ.getItemIdentifiers().isEmpty()); + assertNull(occ.getLiteral()); + assertTrue(occ.getScope().isEmpty()); + assertEquals(occ, _tm.getConstructById(occ.getId())); + assertEquals(topic, occ.getParent()); + assertEquals(_tm, occ.getTopicMap()); + } + + /** + * Tests name creation. + */ + public void testNameCreation() { + final ITopic topic = (ITopic) createTopic(); + final IName name = _factory.createName(topic); + assertNotNull(name.getId()); + assertNull(name.getType()); + assertTrue(name.getItemIdentifiers().isEmpty()); + assertNull(name.getLiteral()); + assertTrue(name.getScope().isEmpty()); + assertEquals(name, _tm.getConstructById(name.getId())); + assertEquals(topic, name.getParent()); + assertEquals(_tm, name.getTopicMap()); + } + + /** + * Tests variant creation. + */ + public void testVariantCreation() { + final IName name = (IName) createName(); + final IVariant variant = _factory.createVariant(name); + assertNotNull(variant.getId()); + assertTrue(variant.getItemIdentifiers().isEmpty()); + assertNull(variant.getLiteral()); + assertTrue(variant.getScope().isEmpty()); + assertEquals(variant, _tm.getConstructById(variant.getId())); + assertEquals(name, variant.getParent()); + assertEquals(_tm, variant.getTopicMap()); + } + + /** + * Tests variant creation with a scoped name. + */ + public void testVariantCreationScope() { + final IName name = (IName) createName(); + final Topic theme1 = createTopic(); + final Topic theme2 = createTopic(); + name.addTheme(theme1); + name.addTheme(theme2); + final IVariant variant = _factory.createVariant(name); + assertNotNull(variant.getId()); + assertTrue(variant.getItemIdentifiers().isEmpty()); + assertNull(variant.getLiteral()); + assertEquals(2, variant.getScope().size()); + assertTrue(variant.getScope().contains(theme1)); + assertTrue(variant.getScope().contains(theme2)); + assertEquals(variant, _tm.getConstructById(variant.getId())); + assertEquals(name, variant.getParent()); + assertEquals(_tm, variant.getTopicMap()); + } + +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestIConstructFactory.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-11-14 13:35:25
|
Revision: 189 http://tinytim.svn.sourceforge.net/tinytim/?rev=189&view=rev Author: lheuer Date: 2008-11-14 13:35:18 +0000 (Fri, 14 Nov 2008) Log Message: ----------- - Moved IIndexManager into internal.api - Removed remove(Topic/Association) from ITopicMap and added AbstractTopicMap instead - Added BooleanLiteral - More docs - Minor changes 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/DatatypeAwareConstruct.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/MemoryConstructFactory.java tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMapSystem.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/Scope.java tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.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/core/value/DecimalLiteral.java tinytim/trunk/src/main/java/org/tinytim/core/value/IntegerLiteral.java tinytim/trunk/src/main/java/org/tinytim/core/value/Literal.java tinytim/trunk/src/main/java/org/tinytim/core/value/LiteralNormalizer.java tinytim/trunk/src/main/java/org/tinytim/core/value/LocatorImpl.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/internal/api/IConstant.java tinytim/trunk/src/main/java/org/tinytim/internal/api/IConstructFactory.java tinytim/trunk/src/main/java/org/tinytim/internal/api/IIndexManagerAware.java tinytim/trunk/src/main/java/org/tinytim/internal/api/IName.java tinytim/trunk/src/main/java/org/tinytim/internal/api/IOccurrence.java tinytim/trunk/src/main/java/org/tinytim/internal/api/ITopic.java tinytim/trunk/src/main/java/org/tinytim/internal/api/ITopicMap.java tinytim/trunk/src/main/java/org/tinytim/internal/api/IVariant.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/CollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/MergeUtils.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/TroveCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/utils/Property.java tinytim/trunk/src/main/java/org/tinytim/utils/TopicUtils.java tinytim/trunk/src/main/java/org/tinytim/utils/TypeInstanceConverter.java tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java tinytim/trunk/src/test/java/org/tinytim/core/value/TestLiteral.java Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMap.java tinytim/trunk/src/main/java/org/tinytim/core/value/BooleanLiteral.java tinytim/trunk/src/main/java/org/tinytim/internal/api/IIndexManager.java Removed Paths: ------------- tinytim/trunk/src/main/java/org/tinytim/index/IIndexManager.java Added: tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMap.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMap.java 2008-11-14 13:35:18 UTC (rev 189) @@ -0,0 +1,38 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.core; + +import org.tinytim.internal.api.ITopicMap; +import org.tmapi.core.Association; +import org.tmapi.core.Topic; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +abstract class AbstractTopicMap extends ConstructImpl implements ITopicMap { + + protected AbstractTopicMap() { + super(null); + } + + abstract void removeAssociation(Association assoc); + + abstract void removeTopic(Topic topic); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMap.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-11-14 13:35:18 UTC (rev 189) @@ -154,7 +154,7 @@ * @see org.tmapi.core.TopicMapObject#remove() */ public void remove() { - _tm.removeAssociation(this); + ((AbstractTopicMap) _tm).removeAssociation(this); for (Role role: CollectionFactory.createList(_roles)) { role.remove(); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-11-14 13:35:18 UTC (rev 189) @@ -42,7 +42,7 @@ protected Construct _parent; private Set<Locator> _iids; - ConstructImpl(ITopicMap topicMap) { + protected ConstructImpl(ITopicMap topicMap) { _tm = topicMap; } @@ -147,49 +147,49 @@ } /* (non-Javadoc) - * @see org.tinytim.core.IConstruct#isAssociation() + * @see org.tinytim.internal.api.IConstruct#isAssociation() */ public boolean isAssociation() { return false; } /* (non-Javadoc) - * @see org.tinytim.core.IConstruct#isName() + * @see org.tinytim.internal.api.IConstruct#isName() */ public boolean isName() { return false; } /* (non-Javadoc) - * @see org.tinytim.core.IConstruct#isOccurrence() + * @see org.tinytim.internal.api.IConstruct#isOccurrence() */ public boolean isOccurrence() { return false; } /* (non-Javadoc) - * @see org.tinytim.core.IConstruct#isRole() + * @see org.tinytim.internal.api.IConstruct#isRole() */ public boolean isRole() { return false; } /* (non-Javadoc) - * @see org.tinytim.core.IConstruct#isTopic() + * @see org.tinytim.internal.api.IConstruct#isTopic() */ public boolean isTopic() { return false; } /* (non-Javadoc) - * @see org.tinytim.core.IConstruct#isTopicMap() + * @see org.tinytim.internal.api.IConstruct#isTopicMap() */ public boolean isTopicMap() { return false; } /* (non-Javadoc) - * @see org.tinytim.core.IConstruct#isVariant() + * @see org.tinytim.internal.api.IConstruct#isVariant() */ public boolean isVariant() { return false; Modified: tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-11-14 13:35:18 UTC (rev 189) @@ -42,11 +42,11 @@ private ILiteral _literal; - DatatypeAwareConstruct(ITopicMap tm) { + protected DatatypeAwareConstruct(ITopicMap tm) { super(tm); } - DatatypeAwareConstruct(ITopicMap topicMap, Topic type, ILiteral literal, IScope scope) { + protected DatatypeAwareConstruct(ITopicMap topicMap, Topic type, ILiteral literal, IScope scope) { super(topicMap, type, scope); _literal = literal; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-11-14 13:35:18 UTC (rev 189) @@ -28,7 +28,7 @@ */ final class IdGenerator { - private static final AtomicLong _COUNTER = new AtomicLong(); + private static final AtomicLong _COUNTER = new AtomicLong(1); /** * Returns the next identifier. Modified: tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java 2008-11-14 13:35:18 UTC (rev 189) @@ -44,13 +44,13 @@ */ final class IdentityManager implements IEventPublisherAware { - private Map<Locator, Topic> _sid2Topic; - private Map<Locator, Topic> _slo2Topic; - private Map<Locator, IConstruct> _iid2Construct; - private Map<String, IConstruct> _id2Construct; + private final Map<Locator, Topic> _sid2Topic; + private final Map<Locator, Topic> _slo2Topic; + private final Map<Locator, IConstruct> _iid2Construct; + private final Map<String, IConstruct> _id2Construct; IdentityManager(MemoryTopicMap tm) { - _id2Construct = CollectionFactory.createIdentityMap(IConstant.IDENTITY_ID2CONSTRUCT_SIZE); + _id2Construct = CollectionFactory.createMap(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); @@ -59,7 +59,7 @@ } /* (non-Javadoc) - * @see org.tinytim.core.IEventPublisherAware#subscribe(org.tinytim.core.IEventPublisher) + * @see org.tinytim.internal.api.IEventPublisherAware#subscribe(org.tinytim.internal.api.IEventPublisher) */ public void subscribe(IEventPublisher publisher) { IEventHandler handler = new TopicMapsConstructAddHandler(); @@ -93,7 +93,7 @@ } /* (non-Javadoc) - * @see org.tinytim.core.IEventPublisherAware#unsubscribe(org.tinytim.core.IEventPublisher) + * @see org.tinytim.internal.api.IEventPublisherAware#unsubscribe(org.tinytim.internal.api.IEventPublisher) */ public void unsubscribe(IEventPublisher publisher) { // noop. @@ -106,17 +106,18 @@ */ private void _register(IConstruct construct) { ConstructImpl c = (ConstructImpl) construct; - if (c._id == null) { - String id = "" + IdGenerator.nextId(); - c._id = id.intern(); + String id = c._id; + if (id == null) { + id = "" + IdGenerator.nextId(); } - if (!_id2Construct.containsKey(c._id)) { - _id2Construct.put(c._id, c); + if (!_id2Construct.containsKey(id)) { + _id2Construct.put(id, c); + c._id = id; } } /** - * Unregisteres the specified <code>construct</code>. + * Unregisteres the specified <tt>construct</tt>. * * @param construct The Topic Maps construct to unregister. */ @@ -128,7 +129,7 @@ * Returns a Topic Maps construct by its identifier. * * @param id The identifier. - * @return A Topic Maps construct with the <code>id</code> or <code>null</code>. + * @return A Topic Maps construct with the <tt>id</tt> or <tt>null</tt>. */ public Construct getConstructById(String id) { return _id2Construct.get(id); @@ -138,7 +139,7 @@ * Returns a topic by its subject identifier. * * @param sid The subject identifier. - * @return A topic with the <code>sid</code> or <code>null</code>. + * @return A topic with the <tt>sid</tt> or <tt>null</tt>. */ public Topic getTopicBySubjectIdentifier(Locator sid) { return _sid2Topic.get(sid); @@ -148,7 +149,7 @@ * Returns a topic by its subject locator. * * @param slo The subject locator. - * @return A topic with the <code>slo</code> or <code>null</code>. + * @return A topic with the <tt>slo</tt> or <tt>null</tt>. */ public Topic getTopicBySubjectLocator(Locator slo) { return _slo2Topic.get(slo); @@ -158,17 +159,17 @@ * Returns a Topic Maps construct by its item identifier. * * @param iid The item identifier. - * @return A Topic Maps construct with the <code>iid</code> or <code>null</code>. + * @return A Topic Maps construct with the <tt>iid</tt> or <tt>null</tt>. */ public Construct getConstructByItemIdentifier(Locator iid) { return _iid2Construct.get(iid); } public void close() { - _id2Construct = null; - _iid2Construct = null; - _sid2Topic = null; - _slo2Topic = null; + _id2Construct.clear(); + _iid2Construct.clear(); + _sid2Topic.clear(); + _slo2Topic.clear(); } private class TopicMapsConstructAddHandler implements IEventHandler { Modified: tinytim/trunk/src/main/java/org/tinytim/core/MemoryConstructFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MemoryConstructFactory.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/core/MemoryConstructFactory.java 2008-11-14 13:35:18 UTC (rev 189) @@ -29,7 +29,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ final class MemoryConstructFactory implements IConstructFactory { Modified: tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java 2008-11-14 13:35:18 UTC (rev 189) @@ -18,19 +18,17 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.List; import java.util.Map; import java.util.Set; import org.tinytim.core.value.Literal; import org.tinytim.index.IndexManager; -import org.tinytim.index.IIndexManager; import org.tinytim.internal.api.Event; import org.tinytim.internal.api.IConstant; import org.tinytim.internal.api.IConstruct; import org.tinytim.internal.api.IConstructFactory; import org.tinytim.internal.api.IEventHandler; -import org.tinytim.internal.api.IEventPublisher; +import org.tinytim.internal.api.IIndexManager; import org.tinytim.internal.api.ITopicMap; import org.tinytim.internal.utils.Check; import org.tinytim.internal.utils.CollectionFactory; @@ -55,8 +53,7 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -final class MemoryTopicMap extends ConstructImpl implements ITopicMap, - IEventHandler, IEventPublisher { +final class MemoryTopicMap extends AbstractTopicMap implements ITopicMap { private final IConstructFactory _factory; private final IdentityManager _identityManager; @@ -66,11 +63,11 @@ private final Set<Association> _assocs; private AbstractTopicMapSystem _sys; private Topic _reifier; - private final Map<Event, List<IEventHandler>> _evtHandlers; + private final Map<Event, Collection<IEventHandler>> _evtHandlers; private EventMultiplier _eventMultiplier; MemoryTopicMap(AbstractTopicMapSystem sys, Locator locator) { - super(null); + super(); super._tm = this; _factory = new MemoryConstructFactory(this); _sys = sys; @@ -118,19 +115,10 @@ } /* (non-Javadoc) - * @see org.tinytim.core.ITopicMap#createTopicWithoutIdentity() - */ - public TopicImpl createTopicWithoutIdentity() { - TopicImpl topic = new TopicImpl(this); - addTopic(topic); - return topic; - } - - /* (non-Javadoc) * @see org.tmapi.core.TopicMap#createTopic() */ public Topic createTopic() { - Topic topic = createTopicWithoutIdentity(); + Topic topic = _factory.createTopic(); topic.addItemIdentifier(Literal.createIRI("urn:x-tinytim:" + IdGenerator.nextId())); return topic; } @@ -156,7 +144,7 @@ return topic; } } - TopicImpl topic = createTopicWithoutIdentity(); + Topic topic = _factory.createTopic(); topic.addItemIdentifier(iid); return topic; } @@ -180,11 +168,14 @@ return topic; } } - topic = createTopicWithoutIdentity(); + topic = _factory.createTopic(); topic.addSubjectIdentifier(sid); return topic; } + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#createTopicBySubjectLocator(org.tmapi.core.Locator) + */ public Topic createTopicBySubjectLocator(Locator slo) { if (slo == null) { throw new ModelConstraintException(null, "The subject locator must not be null"); @@ -193,7 +184,7 @@ if (topic != null) { return topic; } - topic = createTopicWithoutIdentity(); + topic = _factory.createTopic(); topic.addSubjectLocator(slo); return topic; } @@ -207,12 +198,13 @@ if (topic._parent == this) { return; } + assert topic._parent == null; _fireEvent(Event.ADD_TOPIC, null, topic); topic._parent = this; _topics.add(topic); } - public void removeTopic(Topic topic_) { + void removeTopic(Topic topic_) { TopicImpl topic = (TopicImpl) topic_; if (topic._parent != this) { return; @@ -252,7 +244,7 @@ _assocs.add(assoc); } - public void removeAssociation(Association assoc_) { + void removeAssociation(Association assoc_) { AssociationImpl assoc = (AssociationImpl) assoc_; if (assoc._parent != this) { return; @@ -304,7 +296,7 @@ } /* (non-Javadoc) - * @see org.tinytim.IReifiable#setReifier(org.tmapi.core.Topic) + * @see org.tmapi.core.Reifiable#setReifier(org.tmapi.core.Topic) */ public void setReifier(Topic reifier) { if (_reifier == reifier) { @@ -382,14 +374,14 @@ } /* (non-Javadoc) - * @see org.tinytim.IEventHandler#handleEvent(org.tinytim.Event, org.tinytim.IConstruct, java.lang.Object, java.lang.Object) + * @see org.tinytim.internal.api.IEventHandler#handleEvent(org.tinytim.internal.api.Event, org.tinytim.internal.api.IConstruct, java.lang.Object, java.lang.Object) */ public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { if (!_evtHandlers.containsKey(evt)) { _eventMultiplier.handleEvent(evt, sender, oldValue, newValue); return; } - List<IEventHandler> handlers = _evtHandlers.get(evt); + Collection<IEventHandler> handlers = _evtHandlers.get(evt); for (IEventHandler handler: handlers) { handler.handleEvent(evt, sender, oldValue, newValue); } @@ -400,7 +392,7 @@ * @see org.tinytim.IEventPublisher#subscribe(org.tinytim.Event, org.tinytim.IEventHandler) */ public void subscribe(Event event, IEventHandler handler) { - List<IEventHandler> handlers = _evtHandlers.get(event); + Collection<IEventHandler> handlers = _evtHandlers.get(event); if (handlers == null) { handlers = CollectionFactory.createList(); _evtHandlers.put(event, handlers); @@ -409,15 +401,18 @@ } /* (non-Javadoc) - * @see org.tinytim.IEventPublisher#unsubscribe(org.tinytim.Event, org.tinytim.IEventHandler) + * @see org.tinytim.internal.api.IEventPublisher#unsubscribe(org.tinytim.internal.api.Event, org.tinytim.internal.api.IEventHandler) */ public void unsubscribe(Event event, IEventHandler handler) { - List<IEventHandler> handlers = _evtHandlers.get(event); + Collection<IEventHandler> handlers = _evtHandlers.get(event); if (handlers != null) { handlers.remove(handler); } } + /* (non-Javadoc) + * @see org.tinytim.internal.api.IIndexManagerAware#getIndexManager() + */ public IIndexManager getIndexManager() { return _indexManager; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMapSystem.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMapSystem.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMapSystem.java 2008-11-14 13:35:18 UTC (rev 189) @@ -64,7 +64,7 @@ } /* (non-Javadoc) - * @see org.tmapi.core.TopicMapSystem#getBaseLocators() + * @see org.tmapi.core.TopicMapSystem#getLocators() */ public Set<Locator> getLocators() { return Collections.unmodifiableSet(_topicMaps.keySet()); Modified: tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2008-11-14 13:35:18 UTC (rev 189) @@ -65,14 +65,14 @@ } /* (non-Javadoc) - * @see org.tinytim.core.ILiteralAware#getLiteral() + * @see org.tinytim.internal.api.ILiteralAware#getLiteral() */ public ILiteral getLiteral() { return _literal; } /* (non-Javadoc) - * @see org.tinytim.core.ILiteralAware#setLiteral(org.tinytim.core.ILiteral) + * @see org.tinytim.internal.api.ILiteralAware#setLiteral(org.tinytim.internal.api.ILiteral) */ public void setLiteral(ILiteral literal) { assert literal != null; @@ -81,7 +81,7 @@ } /* (non-Javadoc) - * @see org.tmapi.core.TopicName#getValue() + * @see org.tmapi.core.Name#getValue() */ public String getValue() { return _literal.getValue(); @@ -128,7 +128,7 @@ } /* (non-Javadoc) - * @see org.tmapi.core.TopicName#getVariants() + * @see org.tmapi.core.Name#getVariants() */ public Set<Variant> getVariants() { return _variants == null ? Collections.<Variant>emptySet() @@ -214,30 +214,30 @@ attachVariant(v); } - void removeVariant(Variant variant) { - VariantImpl v = (VariantImpl) variant; - if (v._parent != this) { - return; - } - _fireEvent(Event.REMOVE_VARIANT, v, null); - detachVariant(v); - } + void removeVariant(Variant variant) { + VariantImpl v = (VariantImpl) variant; + if (v._parent != this) { + return; + } + _fireEvent(Event.REMOVE_VARIANT, v, null); + detachVariant(v); + } - void attachVariant(VariantImpl variant) { - if (_variants == null) { - _variants = CollectionFactory.createIdentitySet(IConstant.NAME_VARIANT_SIZE); - } - variant._parent = this; - _variants.add(variant); - } + void attachVariant(VariantImpl variant) { + if (_variants == null) { + _variants = CollectionFactory.createIdentitySet(IConstant.NAME_VARIANT_SIZE); + } + variant._parent = this; + _variants.add(variant); + } - void detachVariant(VariantImpl variant) { - _variants.remove(variant); - variant._parent = null; - } + void detachVariant(VariantImpl variant) { + _variants.remove(variant); + variant._parent = null; + } /* (non-Javadoc) - * @see org.tinytim.core.IMovable#moveTo(org.tmapi.core.Construct) + * @see org.tinytim.internal.api.IMovable#moveTo(org.tmapi.core.Construct) */ public void moveTo(Topic newParent) { ((TopicImpl) _parent).detachName(this, true); Modified: tinytim/trunk/src/main/java/org/tinytim/core/OccurrenceImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/OccurrenceImpl.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/core/OccurrenceImpl.java 2008-11-14 13:35:18 UTC (rev 189) @@ -47,7 +47,7 @@ } /* (non-Javadoc) - * @see org.tinytim.IMovable#moveTo(java.lang.Object) + * @see org.tinytim.internal.api.IMovable#moveTo(org.tmapi.core.Construct) */ public void moveTo(Topic newParent) { ((TopicImpl) _parent).detachOccurrence(this, true); Modified: tinytim/trunk/src/main/java/org/tinytim/core/Scope.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Scope.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/core/Scope.java 2008-11-14 13:35:18 UTC (rev 189) @@ -84,7 +84,7 @@ } /* (non-Javadoc) - * @see org.tinytim.core.IScope#asSet() + * @see org.tinytim.internal.api.IScope#asSet() */ public Set<Topic> asSet() { // _set is immutable @@ -92,21 +92,21 @@ } /* (non-Javadoc) - * @see org.tinytim.core.IScope#contains(org.tmapi.core.Topic) + * @see org.tinytim.internal.api.IScope#contains(org.tmapi.core.Topic) */ public boolean contains(Topic theme) { return _set.contains(theme); } /* (non-Javadoc) - * @see org.tinytim.core.IScope#containsAll(java.util.Collection) + * @see org.tinytim.internal.api.IScope#containsAll(java.util.Collection) */ public boolean containsAll(Collection<Topic> scope) { return _set.containsAll(scope); } /* (non-Javadoc) - * @see org.tinytim.core.IScope#add(org.tmapi.core.Topic) + * @see org.tinytim.internal.api.IScope#add(org.tmapi.core.Topic) */ public IScope add(Topic theme) { if (_set.contains(theme)) { @@ -118,7 +118,7 @@ } /* (non-Javadoc) - * @see org.tinytim.core.IScope#remove(org.tmapi.core.Topic) + * @see org.tinytim.internal.api.IScope#remove(org.tmapi.core.Topic) */ public IScope remove(Topic theme) { if (!_set.contains(theme)) { @@ -137,14 +137,14 @@ } /* (non-Javadoc) - * @see org.tinytim.core.IScope#isUnconstrained() + * @see org.tinytim.internal.api.IScope#isUnconstrained() */ public boolean isUnconstrained() { return this == UCS; } /* (non-Javadoc) - * @see org.tinytim.core.IScope#size() + * @see org.tinytim.internal.api.IScope#size() */ public int size() { return _set.size(); Modified: tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java 2008-11-14 13:35:18 UTC (rev 189) @@ -49,14 +49,14 @@ } /* (non-Javadoc) - * @see org.tinytim.core.IScoped#getScopeObject() + * @see org.tinytim.internal.api.IScoped#getScopeObject() */ public IScope getScopeObject() { return _scope; } /* (non-Javadoc) - * @see org.tinytim.core.IScoped#setScopeObject(org.tinytim.core.IScope) + * @see org.tinytim.internal.api.IScoped#setScopeObject(org.tinytim.internal.api.IScope) */ public void setScopeObject(IScope scope) { if (_scope == scope) { @@ -67,14 +67,14 @@ } /* (non-Javadoc) - * @see org.tmapi.core.ScopedObject#getScope() + * @see org.tmapi.core.Scoped#getScope() */ public Set<Topic> getScope() { return _scope.asSet(); } /* (non-Javadoc) - * @see org.tmapi.Scoped#removeTheme(org.tmapi.core.Topic) + * @see org.tmapi.core.Scoped#addTheme(org.tmapi.core.Topic) */ public void addTheme(Topic theme) { if (theme == null) { @@ -84,7 +84,7 @@ } /* (non-Javadoc) - * @see org.tmapi.Scoped#removeTheme(org.tmapi.core.Topic) + * @see org.tmapi.core.Scoped#removeTheme(org.tmapi.core.Topic) */ public void removeTheme(Topic theme) { setScopeObject(_scope.remove(theme)); Modified: tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java 2008-11-14 13:35:18 UTC (rev 189) @@ -251,7 +251,7 @@ } /* (non-Javadoc) - * @see org.tmapi.core.Topic#getTopicNames() + * @see org.tmapi.core.Topic#getNames() */ public Set<Name> getNames() { return Collections.unmodifiableSet(_names); @@ -483,7 +483,7 @@ } /* (non-Javadoc) - * @see org.tmapi.core.TopicMapObject#remove() + * @see org.tmapi.core.Construct#remove() */ public void remove() throws TopicInUseException { if (!TopicUtils.isRemovable(this, true)) { @@ -492,7 +492,7 @@ if (_reified != null) { _reified.setReifier(null); } - _tm.removeTopic(this); + ((AbstractTopicMap) _tm).removeTopic(this); _sids.clear(); _slos = null; _types = null; @@ -523,5 +523,4 @@ return sb.toString(); } - } Modified: tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java 2008-11-14 13:35:18 UTC (rev 189) @@ -54,8 +54,8 @@ return _type; } - /* (non-Javadoc) - * @see org.tinytim.ITyped#setType(org.tmapi.core.Topic) + /* + * @see org.tmapi.core.Typed#setType(org.tmapi.core.Topic) */ public void setType(Topic type) { Check.typeNotNull(this, type); @@ -67,14 +67,14 @@ } /* (non-Javadoc) - * @see org.tmapi.core.IReifiable#getReifier() + * @see org.tmapi.core.Reifiable#getReifier() */ public Topic getReifier() { return _reifier; } /* (non-Javadoc) - * @see org.tinytim.IReifiable#setReifier(org.tmapi.core.Topic) + * @see org.tmapi.core.Reifiable#setReifier(org.tmapi.core.Topic) */ public void setReifier(Topic reifier) { if (_reifier == reifier) { @@ -91,7 +91,7 @@ } /* (non-Javadoc) - * @see org.tinytim.Construct#dispose() + * @see org.tinytim.core.ConstructImpl#dispose() */ @Override protected void dispose() { Modified: tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java 2008-11-14 13:35:18 UTC (rev 189) @@ -52,7 +52,7 @@ } /* (non-Javadoc) - * @see org.tinytim.IMovable#moveTo(java.lang.Object) + * @see org.tinytim.internal.api.IMovable#moveTo(org.tmapi.core.Construct) */ public void moveTo(Name newParent) { ((NameImpl) _parent).detachVariant(this); Added: tinytim/trunk/src/main/java/org/tinytim/core/value/BooleanLiteral.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/value/BooleanLiteral.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/value/BooleanLiteral.java 2008-11-14 13:35:18 UTC (rev 189) @@ -0,0 +1,110 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.core.value; + +import java.math.BigDecimal; +import java.math.BigInteger; + +import org.tinytim.internal.api.ILiteral; +import org.tinytim.voc.XSD; +import org.tmapi.core.Locator; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +final class BooleanLiteral implements ILiteral { + + public static final ILiteral TRUE = new BooleanLiteral(true); + public static final ILiteral FALSE = new BooleanLiteral(false); + + private final boolean _value; + + private BooleanLiteral(boolean value) { + _value = value; + } + + /* (non-Javadoc) + * @see org.tinytim.internal.api.ILiteral#decimalValue() + */ + public BigDecimal decimalValue() { + return _value == true ? BigDecimal.ONE : BigDecimal.ZERO; + } + + /* (non-Javadoc) + * @see org.tinytim.internal.api.ILiteral#floatValue() + */ + public float floatValue() { + return _value == true ? 1.0F : 0.0F; + } + + /* (non-Javadoc) + * @see org.tinytim.internal.api.ILiteral#getDatatype() + */ + public Locator getDatatype() { + return XSD.BOOLEAN; + } + + /* (non-Javadoc) + * @see org.tinytim.internal.api.ILiteral#getValue() + */ + public String getValue() { + return _value == true ? "true" : "false"; + } + + /* (non-Javadoc) + * @see org.tinytim.internal.api.ILiteral#intValue() + */ + public int intValue() { + return _value == true ? 1 : 0; + } + + /* (non-Javadoc) + * @see org.tinytim.internal.api.ILiteral#integerValue() + */ + public BigInteger integerValue() { + return _value == true ? BigInteger.ONE : BigInteger.ZERO; + } + + /* (non-Javadoc) + * @see org.tinytim.internal.api.ILiteral#longValue() + */ + public long longValue() { + return intValue(); + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + return (obj instanceof BooleanLiteral) && _value == ((BooleanLiteral) obj)._value; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return _value == true ? 1 : 0; + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/value/BooleanLiteral.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/core/value/DecimalLiteral.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/value/DecimalLiteral.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/core/value/DecimalLiteral.java 2008-11-14 13:35:18 UTC (rev 189) @@ -48,49 +48,49 @@ } /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#decimalValue() + * @see org.tinytim.internal.api.ILiteral#decimalValue() */ public BigDecimal decimalValue() { return _decimal; } /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#floatValue() + * @see org.tinytim.internal.api.ILiteral#floatValue() */ public float floatValue() { return _decimal.floatValue(); } /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#getDatatype() + * @see org.tinytim.internal.api.ILiteral#getDatatype() */ public Locator getDatatype() { return XSD.DECIMAL; } /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#getValue() + * @see org.tinytim.internal.api.ILiteral#getValue() */ public String getValue() { return _lexicalForm; } /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#intValue() + * @see org.tinytim.internal.api.ILiteral#intValue() */ public int intValue() { return _decimal.intValue(); } /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#integerValue() + * @see org.tinytim.internal.api.ILiteral#integerValue() */ public BigInteger integerValue() { return _decimal.toBigInteger(); } /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#longValue() + * @see org.tinytim.internal.api.ILiteral#longValue() */ public long longValue() { return _decimal.longValue(); Modified: tinytim/trunk/src/main/java/org/tinytim/core/value/IntegerLiteral.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/value/IntegerLiteral.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/core/value/IntegerLiteral.java 2008-11-14 13:35:18 UTC (rev 189) @@ -49,7 +49,7 @@ } /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#decimalValue() + * @see org.tinytim.internal.api.ILiteral#decimalValue() */ public BigDecimal decimalValue() { if (_decimal == null) { @@ -59,42 +59,42 @@ } /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#floatValue() + * @see org.tinytim.internal.api.ILiteral#floatValue() */ public float floatValue() { return _integer.floatValue(); } /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#getDatatype() + * @see org.tinytim.internal.api.ILiteral#getDatatype() */ public Locator getDatatype() { return XSD.INTEGER; } /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#getValue() + * @see org.tinytim.internal.api.ILiteral#getValue() */ public String getValue() { return _lexicalForm; } /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#intValue() + * @see org.tinytim.internal.api.ILiteral#intValue() */ public int intValue() { return _integer.intValue(); } /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#integerValue() + * @see org.tinytim.internal.api.ILiteral#integerValue() */ public BigInteger integerValue() { return _integer; } /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#longValue() + * @see org.tinytim.internal.api.ILiteral#longValue() */ public long longValue() { return _integer.longValue(); Modified: tinytim/trunk/src/main/java/org/tinytim/core/value/Literal.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/value/Literal.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/core/value/Literal.java 2008-11-14 13:35:18 UTC (rev 189) @@ -23,6 +23,7 @@ import org.tinytim.internal.api.ILocator; import org.tinytim.internal.utils.WeakObjectRegistry; import org.tinytim.voc.XSD; +import static org.tinytim.core.value.LiteralNormalizer.normalizeBoolean; import org.tmapi.core.Locator; @@ -53,14 +54,14 @@ } /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#getDatatype() + * @see org.tinytim.internal.api.ILiteral#getDatatype() */ public Locator getDatatype() { return _datatype; } /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#getValue() + * @see org.tinytim.internal.api.ILiteral#getValue() */ public String getValue() { return _value; @@ -90,6 +91,10 @@ if (XSD.STRING.equals(datatype)) { return get(value); } + if (XSD.BOOLEAN.equals(datatype)) { + return normalizeBoolean(value).equals("true") ? BooleanLiteral.TRUE + : BooleanLiteral.FALSE; + } return _OTHERS.get(new Literal(value, datatype)); } @@ -122,6 +127,9 @@ if (XSD.INTEGER.equals(datatype)) { return createInteger(value); } + if (XSD.BOOLEAN.equals(datatype)) { + return createBoolean(value); + } return _registerIfAbsent(_OTHERS, new Literal(value, datatype)); } @@ -191,6 +199,11 @@ return _registerIfAbsent(_OTHERS, new IntegerLiteral(value)); } + public static ILiteral createBoolean(String value) { + return normalizeBoolean(value).equals("true") ? BooleanLiteral.TRUE + : BooleanLiteral.FALSE; + } + public BigDecimal decimalValue() { return new BigDecimal(_value); } @@ -211,11 +224,17 @@ return Long.valueOf(_value); } + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ @Override public int hashCode() { return _value.hashCode(); } + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ @Override public boolean equals(Object obj) { if (this == obj) { Modified: tinytim/trunk/src/main/java/org/tinytim/core/value/LiteralNormalizer.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/value/LiteralNormalizer.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/core/value/LiteralNormalizer.java 2008-11-14 13:35:18 UTC (rev 189) @@ -42,15 +42,15 @@ * @return A normalized value. */ public static String normalize(final String value, final Locator datatype) { - if (XSD.BOOLEAN.equals(datatype)) { - return normalizeBoolean(value); - } - else if (XSD.INTEGER.equals(datatype)) { + if (XSD.INTEGER.equals(datatype)) { return normalizeInteger(value); } else if (XSD.DECIMAL.equals(datatype)) { return normalizeDecimal(value); } + else if (XSD.BOOLEAN.equals(datatype)) { + return normalizeBoolean(value); + } return value; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/value/LocatorImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/value/LocatorImpl.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/core/value/LocatorImpl.java 2008-11-14 13:35:18 UTC (rev 189) @@ -68,35 +68,50 @@ } /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#getDatatype() + * @see org.tinytim.internal.api.ILiteral#getDatatype() */ public Locator getDatatype() { return XSD.ANY_URI; } /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#getValue() + * @see org.tinytim.internal.api.ILiteral#getValue() */ public String getValue() { return _reference; } + /* (non-Javadoc) + * @see org.tinytim.internal.api.ILiteral#decimalValue() + */ public BigDecimal decimalValue() { throw new NumberFormatException(); } + /* (non-Javadoc) + * @see org.tinytim.internal.api.ILiteral#floatValue() + */ public float floatValue() { throw new NumberFormatException(); } + /* (non-Javadoc) + * @see org.tinytim.internal.api.ILiteral#integerValue() + */ public BigInteger integerValue() { throw new NumberFormatException(); } + /* (non-Javadoc) + * @see org.tinytim.internal.api.ILiteral#intValue() + */ public int intValue() { throw new NumberFormatException(); } + /* (non-Javadoc) + * @see org.tinytim.internal.api.ILiteral#longValue() + */ public long longValue() { throw new NumberFormatException(); } Modified: tinytim/trunk/src/main/java/org/tinytim/index/AbstractIndex.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/AbstractIndex.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/index/AbstractIndex.java 2008-11-14 13:35:18 UTC (rev 189) @@ -20,8 +20,7 @@ import org.tmapi.index.Index; /** - * Abstract base class for {@link org.tmapi.index.Index} implementation which - * are autoupdated. + * Abstract base class for {@link Index} implementations which are autoupdated. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ @@ -70,4 +69,9 @@ // noop. } + /** + * Clears the index. + */ + abstract void clear(); + } Deleted: tinytim/trunk/src/main/java/org/tinytim/index/IIndexManager.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/IIndexManager.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/index/IIndexManager.java 2008-11-14 13:35:18 UTC (rev 189) @@ -1,57 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.index; - -import org.tinytim.internal.api.IEventPublisherAware; -import org.tmapi.index.LiteralIndex; -import org.tmapi.index.ScopedIndex; -import org.tmapi.index.TypeInstanceIndex; - -/** - * The index manager provides access to the tinyTiM-specific indexes. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public interface IIndexManager extends IEventPublisherAware { - - /** - * Returns the {@link TypeInstanceIndex}. - * - * @return A {@link TypeInstanceIndex} instance. - */ - public TypeInstanceIndex getTypeInstanceIndex(); - - /** - * Returns the {@link ScopedIndex}. - * - * @return A {@link ScopedIndex} instance. - */ - public ScopedIndex getScopedIndex(); - - /** - * Returns the {@link LiteralIndex}. - * - * @return A {@link LiteralIndex} instance. - */ - public LiteralIndex getLiteralIndex(); - - /** - * Closes this index manager. - */ - public void close(); - -} Modified: tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java 2008-11-14 13:35:18 UTC (rev 189) @@ -16,6 +16,8 @@ package org.tinytim.index; import org.tinytim.internal.api.IEventPublisher; +import org.tinytim.internal.api.IIndexManager; + import org.tmapi.index.LiteralIndex; import org.tmapi.index.ScopedIndex; import org.tmapi.index.TypeInstanceIndex; @@ -40,7 +42,7 @@ } /* (non-Javadoc) - * @see org.tinytim.core.IEventPublisherAware#subscribe(org.tinytim.core.IEventPublisher) + * @see org.tinytim.internal.api.IEventPublisherAware#subscribe(org.tinytim.internal.api.IEventPublisher) */ public void subscribe(final IEventPublisher publisher) { _typeInstanceIndex.subscribe(publisher); @@ -49,7 +51,7 @@ } /* (non-Javadoc) - * @see org.tinytim.core.IEventPublisherAware#unsubscribe(org.tinytim.core.IEventPublisher) + * @see org.tinytim.internal.api.IEventPublisherAware#unsubscribe(org.tinytim.internal.api.IEventPublisher) */ public void unsubscribe(IEventPublisher publisher) { _typeInstanceIndex.unsubscribe(publisher); @@ -58,26 +60,29 @@ } /* (non-Javadoc) - * @see org.tinytim.index.IIndexManager#getTypeInstanceIndex() + * @see org.tinytim.internal.api.IIndexManager#getTypeInstanceIndex() */ public TypeInstanceIndex getTypeInstanceIndex() { return _typeInstanceIndex; } /* (non-Javadoc) - * @see org.tinytim.index.IIndexManager#getScopedIndex() + * @see org.tinytim.internal.api.IIndexManager#getScopedIndex() */ public ScopedIndex getScopedIndex() { return _scopedIndex; } /* (non-Javadoc) - * @see org.tinytim.index.IIndexManager#getLiteralIndex() + * @see org.tinytim.internal.api.IIndexManager#getLiteralIndex() */ public LiteralIndex getLiteralIndex() { return _literalIndex; } + /* (non-Javadoc) + * @see org.tinytim.internal.api.IIndexManager#close() + */ public void close() { _typeInstanceIndex.clear(); _scopedIndex.clear(); Modified: tinytim/trunk/src/main/java/org/tinytim/index/LiteralIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/LiteralIndexImpl.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/index/LiteralIndexImpl.java 2008-11-14 13:35:18 UTC (rev 189) @@ -42,21 +42,21 @@ */ public class LiteralIndexImpl extends AbstractIndex implements LiteralIndex { - private Map<ILiteral, List<Name>> _lit2Names; - private Map<ILiteral, List<Occurrence>> _lit2Occs; - private Map<ILiteral, List<Variant>> _lit2Variants; + private final Map<ILiteral, List<Name>> _lit2Names; + private final Map<ILiteral, List<Occurrence>> _lit2Occs; + private final Map<ILiteral, List<Variant>> _lit2Variants; public LiteralIndexImpl() { super(); + _lit2Names = CollectionFactory.createIdentityMap(); + _lit2Occs = CollectionFactory.createIdentityMap(); + _lit2Variants = CollectionFactory.createIdentityMap(); } /* (non-Javadoc) - * @see org.tinytim.core.IEventPublisherAware#subscribe(org.tinytim.core.IEventPublisher) + * @see org.tinytim.internal.api.IEventPublisherAware#subscribe(org.tinytim.internal.api.IEventPublisher) */ public void subscribe(IEventPublisher publisher) { - _lit2Names = CollectionFactory.createIdentityMap(); - _lit2Occs = CollectionFactory.createIdentityMap(); - _lit2Variants = CollectionFactory.createIdentityMap(); publisher.subscribe(Event.SET_LITERAL, new LiteralHandler()); IEventHandler handler = new AddLiteralAwareHandler(); publisher.subscribe(Event.ATTACHED_OCCURRENCE, handler); @@ -75,6 +75,12 @@ return _getNames(Literal.get(value)); } + /** + * + * + * @param literal + * @return + */ private Collection<Name> _getNames(ILiteral literal) { if (literal == null) { return Collections.<Name>emptySet(); @@ -108,6 +114,12 @@ return _getOccurrences(Literal.get(value, datatype)); } + /** + * + * + * @param literal + * @return + */ private Collection<Occurrence> _getOccurrences(ILiteral literal) { if (literal == null) { return Collections.<Occurrence>emptySet(); @@ -141,6 +153,12 @@ return _getVariants(Literal.get(value, datatype)); } + /** + * + * + * @param literal + * @return + */ private Collection<Variant> _getVariants(ILiteral literal) { if (literal == null) { return Collections.<Variant>emptySet(); @@ -150,6 +168,9 @@ : CollectionFactory.createList(variants); } + /* (non-Javadoc) + * @see org.tinytim.index.AbstractIndex#clear() + */ public void clear() { _lit2Names.clear(); _lit2Occs.clear(); Modified: tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndexImpl.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndexImpl.java 2008-11-14 13:35:18 UTC (rev 189) @@ -44,23 +44,23 @@ */ public class ScopedIndexImpl extends AbstractIndex implements ScopedIndex { - private Map<Topic, Set<Association>> _theme2Assocs; - private Map<Topic, Set<Occurrence>> _theme2Occs; - private Map<Topic, Set<Name>> _theme2Names; - private Map<Topic, Set<Variant>> _theme2Variants; + private final Map<Topic, Set<Association>> _theme2Assocs; + private final Map<Topic, Set<Occurrence>> _theme2Occs; + private final Map<Topic, Set<Name>> _theme2Names; + private final Map<Topic, Set<Variant>> _theme2Variants; public ScopedIndexImpl() { super(); + _theme2Assocs = CollectionFactory.createIdentityMap(); + _theme2Occs = CollectionFactory.createIdentityMap(); + _theme2Names = CollectionFactory.createIdentityMap(); + _theme2Variants = CollectionFactory.createIdentityMap(); } /* (non-Javadoc) * @see org.tinytim.core.IEventPublisherAware#subscribe(org.tinytim.core.IEventPublisher) */ public void subscribe(IEventPublisher publisher) { - _theme2Assocs = CollectionFactory.createIdentityMap(); - _theme2Occs = CollectionFactory.createIdentityMap(); - _theme2Names = CollectionFactory.createIdentityMap(); - _theme2Variants = CollectionFactory.createIdentityMap(); publisher.subscribe(Event.SET_SCOPE, new SetScopeHandler()); IEventHandler handler = new AddScopedHandler(); publisher.subscribe(Event.ADD_ASSOCIATION, handler); @@ -239,15 +239,14 @@ return themes; } + /* (non-Javadoc) + * @see org.tinytim.index.AbstractIndex#clear() + */ void clear() { _theme2Assocs.clear(); - _theme2Assocs = null; _theme2Occs.clear(); - _theme2Occs = null; _theme2Names.clear(); - _theme2Names = null; _theme2Variants.clear(); - _theme2Variants = null; } private void _unindex(Map<Topic, Set<Scoped>> map, Scoped scoped, IScope scope) { Modified: tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndexImpl.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndexImpl.java 2008-11-14 13:35:18 UTC (rev 189) @@ -42,25 +42,25 @@ */ public class TypeInstanceIndexImpl extends AbstractIndex implements TypeInstanceIndex { - private Map<Topic, Set<Topic>> _type2Topics; - private Map<Topic, List<Association>> _type2Assocs; - private Map<Topic, List<Role>> _type2Roles; - private Map<Topic, List<Occurrence>> _type2Occs; - private Map<Topic, List<Name>> _type2Names; + private final Map<Topic, Set<Topic>> _type2Topics; + private final Map<Topic, List<Association>> _type2Assocs; + private final Map<Topic, List<Role>> _type2Roles; + private final Map<Topic, List<Occurrence>> _type2Occs; + private final Map<Topic, List<Name>> _type2Names; public TypeInstanceIndexImpl() { super(); + _type2Topics = CollectionFactory.createIdentityMap(); + _type2Assocs = CollectionFactory.createIdentityMap(); + _type2Roles = CollectionFactory.createIdentityMap(); + _type2Occs = CollectionFactory.createIdentityMap(); + _type2Names = CollectionFactory.createIdentityMap(); } /* (non-Javadoc) * @see org.tinytim.core.IEventPublisherAware#subscribe(org.tinytim.core.IEventPublisher) */ public void subscribe(IEventPublisher publisher) { - _type2Topics = CollectionFactory.createIdentityMap(); - _type2Assocs = CollectionFactory.createIdentityMap(); - _type2Roles = CollectionFactory.createIdentityMap(); - _type2Occs = CollectionFactory.createIdentityMap(); - _type2Names = CollectionFactory.createIdentityMap(); IEventHandler handler = new TopicTypeHandler(); publisher.subscribe(Event.ADD_TYPE, handler); publisher.subscribe(Event.REMOVE_TYPE, handler); @@ -352,16 +352,14 @@ } } + /* (non-Javadoc) + * @see org.tinytim.index.AbstractIndex#clear() + */ void clear() { _type2Topics.clear(); - _type2Topics = null; _type2Assocs.clear(); - _type2Assocs = null; _type2Roles.clear(); - _type2Roles = null; _type2Occs.clear(); - _type2Occs = null; _type2Names.clear(); - _type2Names = null; } } Modified: tinytim/trunk/src/main/java/org/tinytim/internal/api/IConstant.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/internal/api/IConstant.java 2008-11-13 18:10:28 UTC (rev 188) +++ tinytim/trunk/src/main/java/org/tinytim/internal/api/IConstant.java 2008-11-14 13:35:18 UTC (rev 189) @@ -26,83 +26,83 @@ */ public interface IConstant { /** - * Initial size of the {@link MemoryTopicMap} topic set + * Initial size of the topic set */ public static final int TM_TOPIC_SIZE = 100; /** - * Initial size of the {@link MemoryTopicMap} association set + * Initial size of the association set */ public static final int TM_ASSOCIATION_SIZE = 100; /** - * Initial size of the {@link ConstructImpl} item identifier set. + * Initial size of the item identifier set. */ public static final int CONSTRUCT_IID_SIZE = 4; /** - * Initial size of the {@link TopicImpl} subject identifier set. + * Initial size of the subject identifier set. */ public static final int TOPIC_SID_SIZE = 4; /** - * Initial size of the {@link TopicImpl} subject locator set. + * Initial size of the subject locator set. */ public static final int TOPIC_SLO_SIZE = 2; /** - * Initial size of the {@link TopicImpl} types set. + * Initial size of the topic types set. */ public static final int TOPIC_TYPE_SIZE = 2; /** - * Initial size of the {@link TopicImpl} name set. + * Initial size of the name set. */ public static final int TOPIC_NAME_SIZE = 2; /** - * Initial size of the {@link TopicImpl} occurrence set. + * Initial size of the occurrence set. */ public static final int TOPIC_OCCURRENCE_SIZE = 2; /** - * Initial size ... [truncated message content] |
From: <lh...@us...> - 2008-11-19 13:47:50
|
Revision: 210 http://tinytim.svn.sourceforge.net/tinytim/?rev=210&view=rev Author: lheuer Date: 2008-11-19 13:47:44 +0000 (Wed, 19 Nov 2008) Log Message: ----------- - Fixed bug in LiteralNormalizer for decimals "9.3" was reported as illegal value - Added more tests for LiteralNormalizer Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/value/DecimalLiteral.java tinytim/trunk/src/main/java/org/tinytim/core/value/IntegerLiteral.java tinytim/trunk/src/main/java/org/tinytim/core/value/Literal.java tinytim/trunk/src/main/java/org/tinytim/core/value/LiteralNormalizer.java tinytim/trunk/src/test/java/org/tinytim/core/value/TestLiteralNormalizer.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/value/DecimalLiteral.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/value/DecimalLiteral.java 2008-11-19 13:45:23 UTC (rev 209) +++ tinytim/trunk/src/main/java/org/tinytim/core/value/DecimalLiteral.java 2008-11-19 13:47:44 UTC (rev 210) @@ -101,7 +101,7 @@ */ @Override public int hashCode() { - return _decimal.hashCode(); + return _lexicalForm.hashCode(); } /* (non-Javadoc) Modified: tinytim/trunk/src/main/java/org/tinytim/core/value/IntegerLiteral.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/value/IntegerLiteral.java 2008-11-19 13:45:23 UTC (rev 209) +++ tinytim/trunk/src/main/java/org/tinytim/core/value/IntegerLiteral.java 2008-11-19 13:47:44 UTC (rev 210) @@ -105,7 +105,7 @@ */ @Override public int hashCode() { - return _integer.hashCode(); + return _lexicalForm.hashCode(); } /* (non-Javadoc) Modified: tinytim/trunk/src/main/java/org/tinytim/core/value/Literal.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/value/Literal.java 2008-11-19 13:45:23 UTC (rev 209) +++ tinytim/trunk/src/main/java/org/tinytim/core/value/Literal.java 2008-11-19 13:47:44 UTC (rev 210) @@ -46,28 +46,14 @@ private final Locator _datatype; private Literal(final String value, final Locator datatype) { - if (value == null) { - throw new IllegalArgumentException("The value must not be null"); - } _value = LiteralNormalizer.normalize(value, datatype); _datatype = datatype; } - /* (non-Javadoc) - * @see org.tinytim.internal.api.ILiteral#getDatatype() - */ - public Locator getDatatype() { - return _datatype; - } - - /* (non-Javadoc) - * @see org.tinytim.internal.api.ILiteral#getValue() - */ - public String getValue() { - return _value; - } - public static synchronized ILiteral get(String value) { + if (value == null) { + throw new IllegalArgumentException("The value must not be null"); + } return _STRINGS.get(new Literal(value, XSD.STRING)); } @@ -108,7 +94,7 @@ return lit; } - public static synchronized ILiteral create(final String value, final Locator datatype) { + public static ILiteral create(final String value, final Locator datatype) { if (value == null) { throw new IllegalArgumentException("The value must not be null"); } @@ -133,7 +119,7 @@ return _registerIfAbsent(_OTHERS, new Literal(value, datatype)); } - public static synchronized ILiteral create(String value) { + public static ILiteral create(String value) { return _registerIfAbsent(_STRINGS, new Literal(value, XSD.STRING)); } @@ -164,35 +150,35 @@ return (ILocator) value; } - public static synchronized ILocator createIRI(String value) { + public static ILocator createIRI(String value) { if (value == null) { throw new IllegalArgumentException("The value must not be null"); } return _registerIfAbsent(_IRIS, new LocatorImpl(value)); } - public static synchronized ILiteral createDecimal(String value) { + public static ILiteral createDecimal(String value) { if (value == null) { throw new IllegalArgumentException("The value must not be null"); } return _registerIfAbsent(_OTHERS, new DecimalLiteral(value)); } - public static synchronized ILiteral createDecimal(BigDecimal value) { + public static ILiteral createDecimal(BigDecimal value) { if (value == null) { throw new IllegalArgumentException("The value must not be null"); } return _registerIfAbsent(_OTHERS, new DecimalLiteral(value)); } - public static synchronized ILiteral createInteger(String value) { + public static ILiteral createInteger(String value) { if (value == null) { throw new IllegalArgumentException("The value must not be null"); } return _registerIfAbsent(_OTHERS, new IntegerLiteral(value)); } - public static synchronized ILiteral createInteger(BigInteger value) { + public static ILiteral createInteger(BigInteger value) { if (value == null) { throw new IllegalArgumentException("The value must not be null"); } @@ -204,22 +190,51 @@ : BooleanLiteral.FALSE; } + /* (non-Javadoc) + * @see org.tinytim.internal.api.ILiteral#getDatatype() + */ + public Locator getDatatype() { + return _datatype; + } + + /* (non-Javadoc) + * @see org.tinytim.internal.api.ILiteral#getValue() + */ + public String getValue() { + return _value; + } + + /* (non-Javadoc) + * @see org.tinytim.internal.api.ILiteral#decimalValue() + */ public BigDecimal decimalValue() { return new BigDecimal(_value); } + /* (non-Javadoc) + * @see org.tinytim.internal.api.ILiteral#integerValue() + */ public BigInteger integerValue() { return new BigInteger(_value); } + /* (non-Javadoc) + * @see org.tinytim.internal.api.ILiteral#floatValue() + */ public float floatValue() { return Float.valueOf(_value); } + /* (non-Javadoc) + * @see org.tinytim.internal.api.ILiteral#intValue() + */ public int intValue() { return Integer.valueOf(_value); } + /* (non-Javadoc) + * @see org.tinytim.internal.api.ILiteral#longValue() + */ public long longValue() { return Long.valueOf(_value); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/value/LiteralNormalizer.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/value/LiteralNormalizer.java 2008-11-19 13:45:23 UTC (rev 209) +++ tinytim/trunk/src/main/java/org/tinytim/core/value/LiteralNormalizer.java 2008-11-19 13:47:44 UTC (rev 210) @@ -66,9 +66,9 @@ public static String normalizeInteger(final String value) { final String val = value.trim(); - int len = value.length(); + int len = val.length(); if (len == 0) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Illegal integer value: " + value); } int idx = 0; boolean negative = false; @@ -93,7 +93,7 @@ // Check if everything is a digit for (int i = 0; i < len; i++) { if (!Character.isDigit(normalized.charAt(i))) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Illegal integer value: " + value); } } return negative && normalized.charAt(0) != 0 ? '-' + normalized : normalized; @@ -101,9 +101,9 @@ public static String normalizeDecimal(final String value) { final String val = value.trim(); - int len = value.length(); + int len = val.length(); if (len == 0) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Illegal decimal value: " + value); } int idx = 0; boolean negative = false; @@ -142,11 +142,13 @@ while (len >= idx && val.charAt(len) == '0') { len--; } - if (len == idx || len < idx) { + if (len <= idx) { normalized.append('0'); } else { - while (idx < len) { + // idx points to the '.', increment it + idx++; + while (idx <= len) { char c = val.charAt(idx); if (!Character.isDigit(c)) { throw new IllegalArgumentException("Illegal decimal value: " + value); Modified: tinytim/trunk/src/test/java/org/tinytim/core/value/TestLiteralNormalizer.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/value/TestLiteralNormalizer.java 2008-11-19 13:45:23 UTC (rev 209) +++ tinytim/trunk/src/test/java/org/tinytim/core/value/TestLiteralNormalizer.java 2008-11-19 13:47:44 UTC (rev 210) @@ -46,6 +46,7 @@ assertEquals("1", LiteralNormalizer.normalizeInteger("00001")); assertEquals("-1", LiteralNormalizer.normalizeInteger("-1")); assertEquals("-1", LiteralNormalizer.normalizeInteger("-00001")); + assertEquals("-1", LiteralNormalizer.normalizeInteger(" -00001 ")); try { LiteralNormalizer.normalizeInteger("invalid"); fail("Expected an IllegalArgumentException"); @@ -57,6 +58,7 @@ public void testNormalizeDecimal() { assertEquals("0.0", LiteralNormalizer.normalizeDecimal("0")); + assertEquals("0.0", LiteralNormalizer.normalizeDecimal(" 0 ")); assertEquals("0.0", LiteralNormalizer.normalizeDecimal("-0")); assertEquals("0.0", LiteralNormalizer.normalizeDecimal("-0.0")); assertEquals("0.0", LiteralNormalizer.normalizeDecimal("+0.0")); @@ -65,6 +67,9 @@ assertEquals("10.0", LiteralNormalizer.normalizeDecimal("10")); assertEquals("-10.0", LiteralNormalizer.normalizeDecimal("-10.00")); assertEquals("10.0", LiteralNormalizer.normalizeDecimal("+10.00")); + assertEquals("9.3", LiteralNormalizer.normalizeDecimal("+9.3")); + assertEquals("9.3", LiteralNormalizer.normalizeDecimal("9.3")); + assertEquals("-9.3", LiteralNormalizer.normalizeDecimal("-9.3")); try { LiteralNormalizer.normalizeDecimal("invalid"); fail("Expected an IllegalArgumentException"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-11-27 14:14:23
|
Revision: 239 http://tinytim.svn.sourceforge.net/tinytim/?rev=239&view=rev Author: lheuer Date: 2008-11-27 14:14:16 +0000 (Thu, 27 Nov 2008) Log Message: ----------- Fixed bug #2353673 -- Locator.resolve returns new Locator objects Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/value/Literal.java tinytim/trunk/src/main/java/org/tinytim/core/value/LocatorImpl.java tinytim/trunk/src/test/java/org/tinytim/core/value/TestLiteral.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/value/Literal.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/value/Literal.java 2008-11-26 16:26:07 UTC (rev 238) +++ tinytim/trunk/src/main/java/org/tinytim/core/value/Literal.java 2008-11-27 14:14:16 UTC (rev 239) @@ -38,7 +38,6 @@ */ public final class Literal implements ILiteral { - private static final WeakObjectRegistry<LocatorImpl> _IRIS = new WeakObjectRegistry<LocatorImpl>(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); @@ -57,11 +56,11 @@ return _STRINGS.get(new Literal(value, XSD.STRING)); } - public static synchronized ILiteral getIRI(String value) { + public static ILiteral getIRI(String value) { if (value == null) { throw new IllegalArgumentException("The value must not be null"); } - return _IRIS.get(new LocatorImpl(value)); + return LocatorImpl.get(value); } public static synchronized ILiteral get(String value, Locator datatype) { @@ -154,7 +153,7 @@ if (value == null) { throw new IllegalArgumentException("The value must not be null"); } - return _registerIfAbsent(_IRIS, new LocatorImpl(value)); + return LocatorImpl.create(value); } public static ILiteral createDecimal(String value) { Modified: tinytim/trunk/src/main/java/org/tinytim/core/value/LocatorImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/value/LocatorImpl.java 2008-11-26 16:26:07 UTC (rev 238) +++ tinytim/trunk/src/main/java/org/tinytim/core/value/LocatorImpl.java 2008-11-27 14:14:16 UTC (rev 239) @@ -26,7 +26,10 @@ import java.net.URI; import java.net.URLDecoder; +import org.tinytim.internal.api.IConstant; +import org.tinytim.internal.api.ILiteral; import org.tinytim.internal.api.ILocator; +import org.tinytim.internal.utils.WeakObjectRegistry; import org.tinytim.voc.XSD; import org.tmapi.core.Locator; @@ -44,10 +47,11 @@ */ final class LocatorImpl implements ILocator { + private static final WeakObjectRegistry<ILocator> _IRIS = new WeakObjectRegistry<ILocator>(IConstant.LITERAL_IRI_SIZE); private final URI _uri; private final String _reference; - LocatorImpl(String reference) { + private LocatorImpl(String reference) { try { _reference = URLDecoder.decode(reference, "utf-8"); } @@ -127,7 +131,7 @@ * @see org.tmapi.core.Locator#resolve(java.lang.String) */ public Locator resolve(String reference) { - return new LocatorImpl(_uri.resolve(reference)); + return create(_uri.resolve(reference)); } /* (non-Javadoc) @@ -161,4 +165,28 @@ return _uri.toString(); } + static synchronized ILiteral get(String value) { + return _IRIS.get(new LocatorImpl(value)); + } + + private static synchronized ILocator create(URI value) { + ILocator loc = new LocatorImpl(value); + final ILocator existing = _IRIS.get(loc); + if (existing != null) { + return existing; + } + _IRIS.add(loc); + return loc; + } + + static synchronized ILocator create(String value) { + ILocator loc = new LocatorImpl(value); + final ILocator existing = _IRIS.get(loc); + if (existing != null) { + return existing; + } + _IRIS.add(loc); + return loc; + } + } Modified: tinytim/trunk/src/test/java/org/tinytim/core/value/TestLiteral.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/value/TestLiteral.java 2008-11-26 16:26:07 UTC (rev 238) +++ tinytim/trunk/src/test/java/org/tinytim/core/value/TestLiteral.java 2008-11-27 14:14:16 UTC (rev 239) @@ -28,6 +28,12 @@ */ public class TestLiteral extends TinyTimTestCase { + public void testLocatorResolve() { + Locator base = Literal.createIRI("http://www.semagia.com/"); + Locator loc1 = base.resolve("#iid"); + Locator loc2 = base.resolve("#iid"); + assertSame(loc1, loc2); + } public void testStringGet() { final String value = "tiny tiny tiny"; @@ -63,7 +69,7 @@ } public void testIRIEquality() { - final String value = "http://www.semagia.com/"; + final String value = "http://www.semagia.com/test-iri-eq"; assertNull(Literal.get(value, XSD.ANY_URI)); final Locator loc = _sys.createLocator(value); ILiteral lit1 = Literal.create(loc); @@ -72,7 +78,7 @@ } public void testIRIEquality2() { - final String value = "http://www.semagia.net/"; + final String value = "http://www.semagia.net/test-iri-eq2"; assertNull(Literal.get(value, XSD.ANY_URI)); final Locator loc = _sys.createLocator(value); ILiteral lit1 = Literal.create(loc); @@ -81,7 +87,7 @@ } public void testIRIEquality3() { - final String value = "http://www.semagia.de/"; + final String value = "http://www.semagia.de/test-iri-eq3"; assertNull(Literal.get(value, XSD.ANY_URI)); final Locator loc = _sys.createLocator(value); ILiteral lit1 = Literal.create(value, XSD.ANY_URI); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-03-11 15:00:29
|
Revision: 289 http://tinytim.svn.sourceforge.net/tinytim/?rev=289&view=rev Author: lheuer Date: 2009-03-11 15:00:12 +0000 (Wed, 11 Mar 2009) Log Message: ----------- - Added XTM10Utils tests - TMCL vocabulary - TMCL namespace added Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/utils/XTM10Utils.java tinytim/trunk/src/main/java/org/tinytim/voc/Namespace.java Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java tinytim/trunk/src/test/java/org/tinytim/utils/TestXTM10Utils.java Modified: tinytim/trunk/src/main/java/org/tinytim/utils/XTM10Utils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/XTM10Utils.java 2009-03-10 15:31:31 UTC (rev 288) +++ tinytim/trunk/src/main/java/org/tinytim/utils/XTM10Utils.java 2009-03-11 15:00:12 UTC (rev 289) @@ -31,6 +31,10 @@ */ public class XTM10Utils { + private XTM10Utils() { + // noop. + } + private static final Logger LOG = Logger.getLogger(XTM10Utils.class.getName()); /** Modified: tinytim/trunk/src/main/java/org/tinytim/voc/Namespace.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/Namespace.java 2009-03-10 15:31:31 UTC (rev 288) +++ tinytim/trunk/src/main/java/org/tinytim/voc/Namespace.java 2009-03-11 15:00:12 UTC (rev 289) @@ -48,6 +48,11 @@ public static final String TMDM_MODEL = "http://psi.topicmaps.org/iso13250/model/"; /** + * TMCL namespace (<tt>http://psi.topicmaps.org/tmcl/</tt>) + */ + public static final String TMCL = "http://psi.topicmaps.org/tmcl/"; + + /** * XTM 2.0 namespace (<tt>http://www.topicmaps.org/xtm/</tt>). */ public static final String XTM_20 = "http://www.topicmaps.org/xtm/"; Added: tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java 2009-03-11 15:00:12 UTC (rev 289) @@ -0,0 +1,127 @@ +/* + * Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.voc; + +import org.tmapi.core.Locator; + +/** + * Constants for TMCL PSIs. + * <p> + * These PSIs are not stable yet. + * </p> + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public final class TMCL extends Vocabulary { + + private TMCL() { + // noop. + } + + private static final String _BASE = Namespace.TMCL; + + // Topic types + + public static final Locator TOPIC_TYPE = _createLocator(_BASE + "topictype"); + + public static final Locator ASSOCIATION_TYPE = _createLocator(_BASE + "associationtype"); + + public static final Locator ROLE_TYPE = _createLocator(_BASE + "roletype"); + + public static final Locator OCCURRENCE_TYPE = _createLocator(_BASE + "occurrencetype"); + + public static final Locator NAME_TYPE = _createLocator(_BASE + "nametype"); + + public static final Locator SCOPE_TYPE = _createLocator(_BASE + "scopetype"); + + + // Role types + + public static final Locator TOPIC_TYPE_ROLE = _createLocator(_BASE + "topictype-role"); + + public static final Locator ASSOCIATION_TYPE_ROLE = _createLocator(_BASE + "associationtype-role"); + + public static final Locator ROLE_TYPE_ROLE = _createLocator(_BASE + "roletype-role"); + + public static final Locator OTHERROLE_TYPE_ROLE = _createLocator(_BASE + "roletype-role"); + + public static final Locator OCCURRENCE_TYPE_ROLE = _createLocator(_BASE + "occurrencetype-role"); + + public static final Locator NAME_TYPE_ROLE = _createLocator(_BASE + "nametype-role"); + + public static final Locator SCOPE_TYPE_ROLE = _createLocator(_BASE + "scopetype-role"); + + public static final Locator CONSTRAINT_ROLE = _createLocator(_BASE + "constraint-role"); + + + // Model topics + public static final Locator CONSTRAINT = _createLocator(_BASE + "constraint"); + + public static final Locator VALIDATION_EXPRESSION = _createLocator(_BASE + "validation-expression"); + + public static final Locator APPLIES_TO = _createLocator(_BASE + "applies-to"); + + public static final Locator CARD_MIN = _createLocator(_BASE + "card-min"); + + public static final Locator CARD_MAX = _createLocator(_BASE + "card-max"); + + //TODO: TMCL uses sometimes "regexp" and sometimes "reg-exp" + public static final Locator REGEXP = _createLocator(_BASE + "reg-exp"); + + public static final Locator DATATYPE = _createLocator(_BASE + "datatype"); + + + // Constraint types + public static final Locator TOPIC_TYPE_CONSTRAINT = _createLocator(_BASE + "topictype-constraint"); + + public static final Locator ASSOCIATION_TYPE_CONSTRAINT = _createLocator(_BASE + "associationtype-constraint"); + + public static final Locator ROLE_TYPE_CONSTRAINT = _createLocator(_BASE + "roletype-constraint"); + + public static final Locator OCCURRENCE_TYPE_CONSTRAINT = _createLocator(_BASE + "occurrencetype-constraint"); + + public static final Locator NAME_TYPE_CONSTRAINT = _createLocator(_BASE + "nametype-constraint"); + + public static final Locator ABSTRACT_TOPIC_TYPE_CONSTRAINT = _createLocator(_BASE + "abstract-topictype-constraint"); + + public static final Locator EXCLUSIVE_INSTANCE = _createLocator(_BASE + "exclusive-instance"); + + public static final Locator SUBJECT_IDENTIFIER_CONSTRAINT = _createLocator(_BASE + "subjectidentifier-constraint"); + + public static final Locator SUBJECT_LOCATOR_CONSTRAINT = _createLocator(_BASE + "subjectlocator-constraint"); + + public static final Locator NAME_CONSTRAINT = _createLocator(_BASE + "topicname-constraint"); + + public static final Locator NAME_TYPE_SCOPE_CONSTRAINT = _createLocator(_BASE + "nametypescope-constraint"); + + public static final Locator OCCURRENCE_TYPE_SCOPE_CONSTRAINT = _createLocator(_BASE + "occurrencetypescope-constraint"); + + public static final Locator OCCURRENCE_DATATYPE_CONSTRAINT = _createLocator(_BASE + "occurrencedatatype-constraint"); + + public static final Locator ASSOCIATION_TYPE_SCOPE_CONSTRAINT = _createLocator(_BASE + "associationtypescope-constraint"); + + public static final Locator ASSOCIATION_ROLE_CONSTRAINT = _createLocator(_BASE + "associationrole-constraint"); + + public static final Locator ROLE_PLAYER_CONSTRAINT = _createLocator(_BASE + "roleplayer-constraint"); + + public static final Locator OTHERROLE_CONSTRAINT = _createLocator(_BASE + "otherrole-constraint"); + + public static final Locator TOPIC_OCCURRENCE_CONSTRAINT = _createLocator(_BASE + "topicoccurrence-constraint"); + + public static final Locator UNIQUE_OCCURRENCE_CONSTRAINT = _createLocator(_BASE + "uniqueoccurrence-constraint"); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/test/java/org/tinytim/utils/TestXTM10Utils.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/utils/TestXTM10Utils.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/utils/TestXTM10Utils.java 2009-03-11 15:00:12 UTC (rev 289) @@ -0,0 +1,82 @@ +/* + * Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com). All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.utils; + +import org.tinytim.core.TinyTimTestCase; +import org.tmapi.core.Locator; +import org.tmapi.core.Name; +import org.tmapi.core.Reifiable; +import org.tmapi.core.Topic; + +/** + * Tests against the {@link XTM10Utils}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class TestXTM10Utils extends TinyTimTestCase { + + private void _testConvertReification(Reifiable reifiable) { + final Locator loc = _tm.createLocator("http://www.semagia.com/test"); + Topic t = _tm.createTopicBySubjectIdentifier(loc); + reifiable.addItemIdentifier(loc); + assertNull(reifiable.getReifier()); + assertNull(t.getReified()); + assertEquals(1, t.getSubjectIdentifiers().size()); + assertEquals(loc, t.getSubjectIdentifiers().iterator().next()); + assertEquals(1, reifiable.getItemIdentifiers().size()); + assertEquals(loc, reifiable.getItemIdentifiers().iterator().next()); + XTM10Utils.convertReification(_tm); + assertEquals(t, reifiable.getReifier()); + assertEquals(reifiable, t.getReified()); + assertEquals(0, t.getSubjectIdentifiers().size()); + assertEquals(0, reifiable.getItemIdentifiers().size()); + reifiable.setReifier(null); + t.remove(); + } + + public void testConvertReification() { + _testConvertReification(_tm); + _testConvertReification(createAssociation()); + _testConvertReification(createRole()); + _testConvertReification(createOccurrence()); + _testConvertReification(createName()); + _testConvertReification(createVariant()); + } + + public void testConvertReificationSkipReified() { + final Locator loc = _tm.createLocator("http://www.semagia.com/test"); + Topic t = _tm.createTopicBySubjectIdentifier(loc); + Name reifiedName = createName(); + reifiedName.setReifier(t); + assertEquals(t, reifiedName.getReifier()); + assertEquals(reifiedName, t.getReified()); + Name name = createName(); + name.addItemIdentifier(loc); + assertEquals(1, t.getSubjectIdentifiers().size()); + assertEquals(loc, t.getSubjectIdentifiers().iterator().next()); + assertEquals(1, name.getItemIdentifiers().size()); + assertEquals(loc, name.getItemIdentifiers().iterator().next()); + XTM10Utils.convertReification(_tm); + assertEquals(t, reifiedName.getReifier()); + assertEquals(reifiedName, t.getReified()); + assertEquals(1, t.getSubjectIdentifiers().size()); + assertEquals(loc, t.getSubjectIdentifiers().iterator().next()); + assertEquals(1, name.getItemIdentifiers().size()); + assertEquals(loc, name.getItemIdentifiers().iterator().next()); + } + +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/utils/TestXTM10Utils.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-03-26 09:24:59
|
Revision: 293 http://tinytim.svn.sourceforge.net/tinytim/?rev=293&view=rev Author: lheuer Date: 2009-03-26 09:24:44 +0000 (Thu, 26 Mar 2009) Log Message: ----------- Added utility class to fetch the super-/subtypes of a topic and to check if a topic is an instance of another topic (supertypes / subtypes are taken into account) Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/utils/TypeInstanceUtils.java tinytim/trunk/src/test/java/org/tinytim/utils/TestTypeInstanceUtils.java Added: tinytim/trunk/src/main/java/org/tinytim/utils/TypeInstanceUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/TypeInstanceUtils.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/TypeInstanceUtils.java 2009-03-26 09:24:44 UTC (rev 293) @@ -0,0 +1,224 @@ +/* + * Copyright 2009 Lars Heuer (heuer[at]semagia.com). All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.utils; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import org.tinytim.internal.api.IAssociation; +import org.tinytim.voc.TMDM; +import org.tmapi.core.Locator; +import org.tmapi.core.Role; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; +import org.tmapi.core.Typed; + +/** + * Utility functions to retrieve the supertypes / subtypes of a topic and + * to check if a topic is an instance of another topic. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class TypeInstanceUtils { + + private static final RolePlayerWalker _SUPERTYPES_WALKER = new RolePlayerWalker(TMDM.SUPERTYPE_SUBTYPE, TMDM.SUBTYPE, TMDM.SUPERTYPE); + private static final RolePlayerWalker _SUBTYPES_WALKER = new RolePlayerWalker(TMDM.SUPERTYPE_SUBTYPE, TMDM.SUPERTYPE, TMDM.SUBTYPE); + + private TypeInstanceUtils() { + // noop + } + + /** + * Returns if <tt>instance</tt> is an instance of <tt>type</tt>. + * <p> + * The typed construct is an instance of <tt>type</tt> if {@link Typed#getType()} + * is equal to the provided <tt>type</tt> or if <tt>type</tt> is a supertype + * of {@link Typed#getType()}. + * </p> + * + * @param instance The instance. + * @param type The type. + * @return <tt>true</tt> if the typed construct is an instance of <tt>type</tt>, + * otherwise <tt>false</tt>. + */ + public static boolean isInstanceOf(Typed instance, Topic type) { + if (instance == null) { + throw new IllegalArgumentException("The instance must not be null"); + } + if (type == null) { + throw new IllegalArgumentException("The type must not be null"); + } + return instance.getType().equals(type) + || _SUPERTYPES_WALKER.isAssociated(instance.getType(), type); + } + + /** + * Returns if <tt>instance</tt> is an instance of <tt>type</tt>. + * <p> + * The topic is an instance of <tt>type</tt> if {@link Topic#getTypes()} + * contains <tt>type</tt> or if one of the topics returned by {@link Topic#getTypes()} + * is a subtype of <tt>type</tt>. + * </p> + * + * @param instance The instance. + * @param type The type. + * @return <tt>true</tt> if the topic is an instance of <tt>type</tt>, + * otherwise <tt>false</tt>. + */ + public static boolean isInstanceOf(Topic instance, Topic type) { + if (instance == null) { + throw new IllegalArgumentException("The instance must not be null"); + } + if (type == null) { + throw new IllegalArgumentException("The type must not be null"); + } + Collection<Topic> types = instance.getTypes(); + if (types.contains(type)) { + return true; + } + for (Topic topicType: types) { + if (_SUPERTYPES_WALKER.isAssociated(topicType, type)) { + return true; + } + } + return false; + } + + /** + * Returns the supertypes of <tt>subtype</tt>. + * <p> + * If <tt>subtype</tt> does not participate in a supertype-subtype association, + * the returned collection is empty. + * </p> + * + * @param subtype The subtype. + * @return A (maybe empty) collection of supertypes. + */ + public static Collection<Topic> getSupertypes(Topic subtype) { + if (subtype == null) { + throw new IllegalArgumentException("The subtype must not be null"); + } + return _SUPERTYPES_WALKER.walk(subtype); + } + + /** + * Returns the subtypes of <tt>supertype</tt>. + * <p> + * If <tt>supertype</tt> does not participate in a supertype-subtype association, + * the returned collection is empty. + * </p> + * + * @param supertype The supertype. + * @return A (maybe empty) collection of subtypes. + */ + public static Collection<Topic> getSubtypes(Topic supertype) { + if (supertype == null) { + throw new IllegalArgumentException("The supertype must not be null"); + } + return _SUBTYPES_WALKER.walk(supertype); + } + + + private static class RolePlayerWalker { + + private final Locator _assocTypeLoc; + private final Locator _rolePlayingTypeLoc; + private final Locator _otherRoleTypeLoc; + + public RolePlayerWalker(Locator associationType, Locator rolePlayingType, Locator otherRoleType) { + _assocTypeLoc = associationType; + _rolePlayingTypeLoc = rolePlayingType; + _otherRoleTypeLoc = otherRoleType; + } + + /** + * Walks through the association players and reports those which are + * playing the counterpart role. + * + * @param start The starting point. + * @return A colleciton of topics. + */ + public Set<Topic> walk(Topic start) { + return _walk(start, null); + } + + /** + * Returns if <tt>start</tt> is associated with <tt>end</tt>. + * + * @param start The starting point. + * @param end The end point. + * @return <tt>true</tt> if the start topic is associated with the end topic. + */ + public boolean isAssociated(Topic start, Topic end) { + return _walk(start, end).contains(end); + } + + /** + * Walks through the players. + * + * @param start The starting topic, must not be <tt>null</tt>. + * @param end The end topic, maybe <tt>null</tt>. + * @return A collection of topics. + */ + public Set<Topic> _walk(Topic start, Topic end) { + final TopicMap tm = start.getTopicMap(); + final Topic assocType = tm.getTopicBySubjectIdentifier(_assocTypeLoc); + final Topic rolePlayingType = tm.getTopicBySubjectIdentifier(_rolePlayingTypeLoc); + final Topic otherRoleType = tm.getTopicBySubjectIdentifier(_otherRoleTypeLoc); + if (assocType == null + || rolePlayingType == null + || otherRoleType == null) { + return Collections.emptySet(); + } + Set<Topic> players = new HashSet<Topic>(); + _walk(start, players, end, assocType, rolePlayingType, otherRoleType); + return players; + } + + private void _walk(Topic start, Set<Topic> result, Topic goal, Topic assocType, Topic rolePlayingType, Topic otherRoleType) { + for (Role role: start.getRolesPlayed(rolePlayingType, assocType)) { + IAssociation parent = (IAssociation) role.getParent(); + if (!parent.getScopeObject().isUnconstrained()) { + continue; + } + Set<Role> roles = role.getParent().getRoles(); + if (roles.size() != 2) { + continue; + } + for (Role r: roles) { + if (!r.getType().equals(otherRoleType)) { + continue; + } + Topic player = r.getPlayer(); + if (goal != null && player.equals(goal)) { + result.add(goal); + // No need to walk further + return; + } + else if (!result.contains(player)) { + result.add(player); + _walk(player, result, goal, assocType, rolePlayingType, otherRoleType); + } + } + } + } + } + + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/TypeInstanceUtils.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/test/java/org/tinytim/utils/TestTypeInstanceUtils.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/utils/TestTypeInstanceUtils.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/utils/TestTypeInstanceUtils.java 2009-03-26 09:24:44 UTC (rev 293) @@ -0,0 +1,148 @@ +/* + * Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com). All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.utils; + +import java.util.Collection; + +import org.tinytim.core.TinyTimTestCase; +import org.tinytim.voc.TMDM; + +import org.tmapi.core.Association; +import org.tmapi.core.Topic; +import org.tmapi.core.Typed; + +/** + * Tests against the {@link TypeInstanceUtils}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class TestTypeInstanceUtils extends TinyTimTestCase { + + private void _testTypedInstanceOf(final Typed typed) { + assertNotNull(typed.getType()); + final Topic origType = typed.getType(); + final Topic newType = createTopic(); + assertTrue(TypeInstanceUtils.isInstanceOf(typed, origType)); + assertFalse(TypeInstanceUtils.isInstanceOf(typed, newType)); + typed.setType(newType); + assertFalse(TypeInstanceUtils.isInstanceOf(typed, origType)); + assertTrue(TypeInstanceUtils.isInstanceOf(typed, newType)); + final Topic supertype = createTopic(); + assertFalse(TypeInstanceUtils.isInstanceOf(typed, supertype)); + _makeSupertypeSubtype(newType, supertype); + assertTrue(TypeInstanceUtils.isInstanceOf(typed, supertype)); + final Topic supersupertype = createTopic(); + assertFalse(TypeInstanceUtils.isInstanceOf(typed, supersupertype)); + _makeSupertypeSubtype(supertype, supersupertype); + assertTrue(TypeInstanceUtils.isInstanceOf(typed, supersupertype)); + } + + private void _makeSupertypeSubtype(Topic subtype, Topic supertype) { + Association assoc = _tm.createAssociation(_tm.createTopicBySubjectIdentifier(TMDM.SUPERTYPE_SUBTYPE)); + assoc.createRole(_tm.createTopicBySubjectIdentifier(TMDM.SUPERTYPE), supertype); + assoc.createRole(_tm.createTopicBySubjectIdentifier(TMDM.SUBTYPE), subtype); + } + + public void testAssociation() { + _testTypedInstanceOf(createAssociation()); + } + + public void testRole() { + _testTypedInstanceOf(createRole()); + } + + public void testOccurrence() { + _testTypedInstanceOf(createOccurrence()); + } + + public void testName() { + _testTypedInstanceOf(createName()); + } + + /** + * Tests if a topic is an instance of itself. + */ + public void testIsInstanceOfSelf() { + final Topic topic = createTopic(); + assertFalse(TypeInstanceUtils.isInstanceOf(topic, topic)); + } + + /** + * Tests if a topic is an instance of the types returned by + * {@link Topic#getTypes()}. + */ + public void testIsInstanceOfTypes() { + final Topic topic = createTopic(); + final Topic type = createTopic(); + topic.addType(type); + assertTrue(topic.getTypes().contains(type)); + assertTrue(TypeInstanceUtils.isInstanceOf(topic, type)); + } + + public void testTopicIsInstanceOf() { + final Topic topic = createTopic(); + final Topic type1 = createTopic(); + final Topic type2 = createTopic(); + topic.addType(type1); + assertTrue(topic.getTypes().contains(type1)); + assertFalse(topic.getTypes().contains(type2)); + assertTrue(TypeInstanceUtils.isInstanceOf(topic, type1)); + assertFalse(TypeInstanceUtils.isInstanceOf(topic, type2)); + _makeSupertypeSubtype(type1, type2); + assertTrue(TypeInstanceUtils.isInstanceOf(topic, type2)); + final Topic type3 = createTopic(); + assertFalse(TypeInstanceUtils.isInstanceOf(topic, type3)); + _makeSupertypeSubtype(type2, type3); + assertTrue(TypeInstanceUtils.isInstanceOf(topic, type3)); + } + + public void testGetSupertypesSubtypes() { + final Topic sub = createTopic(); + final Topic super1 = createTopic(); + final Topic super2 = createTopic(); + Collection<Topic> supertypes = TypeInstanceUtils.getSupertypes(sub); + Collection<Topic> subtypes1 = TypeInstanceUtils.getSubtypes(super1); + Collection<Topic> subtypes2 = TypeInstanceUtils.getSubtypes(super2); + assertEquals(0, supertypes.size()); + assertEquals(0, subtypes1.size()); + assertEquals(0, subtypes2.size()); + // sub ako super1 + _makeSupertypeSubtype(sub, super1); + supertypes = TypeInstanceUtils.getSupertypes(sub); + subtypes1 = TypeInstanceUtils.getSubtypes(super1); + subtypes2 = TypeInstanceUtils.getSubtypes(super2); + assertEquals(1, supertypes.size()); + assertTrue(supertypes.contains(super1)); + assertEquals(1, subtypes1.size()); + assertTrue(subtypes1.contains(sub)); + assertEquals(0, subtypes2.size()); + // super1 ako super2 + _makeSupertypeSubtype(super1, super2); + supertypes = TypeInstanceUtils.getSupertypes(sub); + subtypes1 = TypeInstanceUtils.getSubtypes(super1); + subtypes2 = TypeInstanceUtils.getSubtypes(super2); + assertEquals(2, supertypes.size()); + assertTrue(supertypes.contains(super1)); + assertTrue(supertypes.contains(super2)); + assertEquals(1, subtypes1.size()); + assertTrue(subtypes1.contains(sub)); + assertEquals(2, subtypes2.size()); + assertTrue(subtypes2.contains(sub)); + assertTrue(subtypes2.contains(super1)); + } + +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/utils/TestTypeInstanceUtils.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-21 14:54:43
|
Revision: 316 http://tinytim.svn.sourceforge.net/tinytim/?rev=316&view=rev Author: lheuer Date: 2009-07-21 14:54:31 +0000 (Tue, 21 Jul 2009) Log Message: ----------- Solves #2824834 partially. Test testOntopiaIssue84VariantReifier3 fails :( Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/internal/utils/MergeUtils.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/SignatureGenerator.java tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java Modified: tinytim/trunk/src/main/java/org/tinytim/internal/utils/MergeUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/internal/utils/MergeUtils.java 2009-07-20 09:20:12 UTC (rev 315) +++ tinytim/trunk/src/main/java/org/tinytim/internal/utils/MergeUtils.java 2009-07-21 14:54:31 UTC (rev 316) @@ -105,7 +105,7 @@ assert sourceReifiable != target.getReified(); throw new ModelConstraintException(target, "The topics cannot be merged. They reify different Topic Maps constructs"); } - _moveItemIdentifiers(source, target); + moveItemIdentifiers(source, target); if (sourceReifiable != null) { sourceReifiable.setReifier(target); } @@ -226,7 +226,7 @@ * @param target The target Topic Maps construct. */ public static void handleExistingConstruct(Reifiable source, Reifiable target) { - _moveItemIdentifiers(source, target); + moveItemIdentifiers(source, target); if (source.getReifier() == null) { return; } @@ -310,7 +310,7 @@ * @param source The source to remove the item identifiers from. * @param target The target which get the item identifiers. */ - private static void _moveItemIdentifiers(Construct source, Construct target) { + public static void moveItemIdentifiers(Construct source, Construct target) { List<Locator> iids = CollectionFactory.createList(source.getItemIdentifiers()); for (Locator iid: iids) { source.removeItemIdentifier(iid); Modified: tinytim/trunk/src/main/java/org/tinytim/internal/utils/SignatureGenerator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/internal/utils/SignatureGenerator.java 2009-07-20 09:20:12 UTC (rev 315) +++ tinytim/trunk/src/main/java/org/tinytim/internal/utils/SignatureGenerator.java 2009-07-21 14:54:31 UTC (rev 316) @@ -18,6 +18,7 @@ import java.util.Arrays; import java.util.Collection; +import org.tinytim.internal.api.IConstruct; import org.tinytim.internal.api.ILiteralAware; import org.tinytim.internal.api.IScoped; @@ -51,6 +52,25 @@ // noop. } + public static int generateSignature(IConstruct construct) { + if (construct.isAssociation()) { + return generateSignature((Association) construct); + } + else if (construct.isOccurrence()) { + return generateSignature((Occurrence) construct); + } + else if (construct.isName()) { + return generateSignature((Name) construct); + } + else if (construct.isVariant()) { + return generateSignature((Variant) construct); + } + else if (construct.isRole()) { + return generateSignature((Role) construct); + } + throw new IllegalArgumentException("Only association, role, occurrence, name, and variant are supported"); + } + /** * Returns the signature of an association. * Modified: tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-07-20 09:20:12 UTC (rev 315) +++ tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-07-21 14:54:31 UTC (rev 316) @@ -16,6 +16,7 @@ package org.tinytim.mio; import java.util.List; +import java.util.Map; import org.tinytim.core.Scope; import org.tinytim.core.value.Literal; @@ -29,6 +30,8 @@ import org.tinytim.internal.api.ITopicMap; import org.tinytim.internal.api.IVariant; import org.tinytim.internal.utils.CollectionFactory; +import org.tinytim.internal.utils.MergeUtils; +import org.tinytim.internal.utils.SignatureGenerator; import org.tinytim.utils.TypeInstanceConverter; import org.tinytim.voc.TMDM; @@ -72,10 +75,12 @@ private static final int _CONSTRUCT_SIZE = 6; private static final int _STATE_SIZE = 10; private static final int _SCOPE_SIZE = 6; + private static final int _DELAYED_REIFICATION_SIZE = 2; private final IConstructFactory _factory; private final ITopicMap _tm; private final List<Topic> _scope; + private final Map<Reifiable, Topic> _delayedReification; private byte[] _stateStack; private int _stateSize; private IConstruct[] _constructStack; @@ -88,11 +93,13 @@ _tm = (ITopicMap) topicMap; _factory = _tm.getConstructFactory(); _scope = CollectionFactory.createList(_SCOPE_SIZE); + _delayedReification = CollectionFactory.createIdentityMap(_DELAYED_REIFICATION_SIZE); } /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#startTopicMap() */ + @Override public void startTopicMap() throws MIOException { _constructStack = new IConstruct[_CONSTRUCT_SIZE]; _stateStack = new byte[_STATE_SIZE]; @@ -104,6 +111,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#endTopicMap() */ + @Override public void endTopicMap() throws MIOException { TypeInstanceConverter.convertAssociationsToTypes(_tm); _constructStack = null; @@ -114,6 +122,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#startTopic(com.semagia.mio.IRef) */ + @Override public void startTopic(IRef identity) throws MIOException { _enterState(TOPIC, _createTopic(identity)); } @@ -121,6 +130,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#endTopic() */ + @Override public void endTopic() throws MIOException { _handleTopic((Topic) _leaveStatePopConstruct(TOPIC)); } @@ -128,6 +138,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#startAssociation() */ + @Override public void startAssociation() throws MIOException { _enterState(ASSOCIATION, _factory.createAssociation()); } @@ -135,13 +146,15 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#endAssociation() */ + @Override public void endAssociation() throws MIOException { - _leaveStatePopConstruct(ASSOCIATION); + _leaveStatePopReifiable(ASSOCIATION); } /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#startRole() */ + @Override public void startRole() throws MIOException { assert _state() == ASSOCIATION; _enterState(ROLE, _factory.createRole((Association) _peekConstruct())); @@ -150,6 +163,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#endRole() */ + @Override public void endRole() throws MIOException { _leaveStatePopConstruct(ROLE); } @@ -157,6 +171,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#startPlayer() */ + @Override public void startPlayer() throws MIOException { assert _state() == ROLE; _enterState(PLAYER); @@ -165,6 +180,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#endPlayer() */ + @Override public void endPlayer() throws MIOException { _leaveState(PLAYER); assert _state() == ROLE; @@ -173,6 +189,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#startOccurrence() */ + @Override public void startOccurrence() throws MIOException { _enterState(OCCURRENCE, _factory.createOccurrence(_peekTopic())); } @@ -180,13 +197,15 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#endOccurrence() */ + @Override public void endOccurrence() throws MIOException { - _leaveStatePopConstruct(OCCURRENCE); + _leaveStatePopReifiable(OCCURRENCE); } /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#startName() */ + @Override public void startName() throws MIOException { _enterState(NAME, _factory.createName(_peekTopic())); } @@ -194,16 +213,19 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#endName() */ + @Override public void endName() throws MIOException { IName name = (IName) _leaveStatePopConstruct(NAME); if (name.getType() == null) { name.setType(_tm.createTopicBySubjectIdentifier(TMDM.TOPIC_NAME)); } + _handleDelayedReifier(name); } /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#startVariant() */ + @Override public void startVariant() throws MIOException { assert _state() == NAME; _enterState(VARIANT, _factory.createVariant((IName) _peekConstruct())); @@ -212,6 +234,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#endVariant() */ + @Override public void endVariant() throws MIOException { IVariant variant = (IVariant) _leaveStatePopConstruct(VARIANT); IName name = (IName) _peekConstruct(); @@ -219,11 +242,13 @@ if (scope.isUnconstrained() || name.getScopeObject().equals(scope)) { _reportError("The variant has no scope"); } + _handleDelayedReifier(variant); } /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#startType() */ + @Override public void startType() throws MIOException { assert _peekConstruct() instanceof Typed; _enterState(TYPE); @@ -232,6 +257,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#endType() */ + @Override public void endType() throws MIOException { _leaveState(TYPE); assert _peekConstruct() instanceof Typed; @@ -240,6 +266,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#startScope() */ + @Override public void startScope() throws MIOException { assert _peekConstruct() instanceof Scoped; _enterState(SCOPE); @@ -248,6 +275,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#endScope() */ + @Override public void endScope() throws MIOException { _leaveState(SCOPE); ((IScoped) _peekConstruct()).setScopeObject(Scope.create(_scope)); @@ -257,6 +285,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#startTheme() */ + @Override public void startTheme() throws MIOException { assert _state() == SCOPE; _enterState(THEME); @@ -265,6 +294,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#endTheme() */ + @Override public void endTheme() throws MIOException { _leaveState(THEME); assert _state() == SCOPE; @@ -273,6 +303,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#subjectIdentifier(java.lang.String) */ + @Override public void subjectIdentifier(String subjectIdentifier) throws MIOException { Locator sid = _tm.createLocator(subjectIdentifier); ITopic topic = _peekTopic(); @@ -292,6 +323,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#subjectLocator(java.lang.String) */ + @Override public void subjectLocator(String subjectLocator) throws MIOException { Locator slo = _tm.createLocator(subjectLocator); ITopic topic = _peekTopic(); @@ -305,6 +337,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#itemIdentifier(java.lang.String) */ + @Override public void itemIdentifier(String itemIdentifier) throws MIOException { Locator iid = _tm.createLocator(itemIdentifier); IConstruct tmo = _peekConstruct(); @@ -326,6 +359,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#startIsa() */ + @Override public void startIsa() throws MIOException { assert _state() == TOPIC; _enterState(ISA); @@ -334,6 +368,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#endIsa() */ + @Override public void endIsa() throws MIOException { _leaveState(ISA); assert _state() == TOPIC; @@ -342,6 +377,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#startReifier() */ + @Override public void startReifier() throws MIOException { assert _peekConstruct() instanceof Reifiable; _enterState(REIFIER); @@ -350,6 +386,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#endReifier() */ + @Override public void endReifier() throws MIOException { _leaveState(REIFIER); assert _peekConstruct() instanceof Reifiable; @@ -358,6 +395,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#topicRef(com.semagia.mio.IRef) */ + @Override public void topicRef(IRef identity) throws MIOException { _handleTopic(_createTopic(identity)); } @@ -365,6 +403,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#value(java.lang.String) */ + @Override public void value(String value) throws MIOException { assert _state() == NAME; ((IName) _peekConstruct()).setValue(value); @@ -373,6 +412,7 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#value(java.lang.String, java.lang.String) */ + @Override public void value(String value, String datatype) throws MIOException { ((ILiteralAware) _peekConstruct()).setLiteral(Literal.create(value, datatype)); } @@ -436,6 +476,12 @@ return construct; } + private Reifiable _leaveStatePopReifiable(byte state) throws MIOException { + final Reifiable reifiable = (Reifiable) _leaveStatePopConstruct(state); + _handleDelayedReifier(reifiable); + return reifiable; + } + /** * Returns the Topic Maps construct on top of the stack. * @@ -446,6 +492,75 @@ } /** + * + * + * @param reifiable + * @throws MIOException + */ + private void _handleDelayedReifier(final Reifiable reifiable) throws MIOException { + Topic reifier = _delayedReification.remove(reifiable); + final IConstruct c = (IConstruct) reifiable; + if (reifier != null) { + _handleDelayedReifier(reifiable, reifier); + return; + } + List<? extends Reifiable> reifiables = null; + if (c.isAssociation()) { + reifiables = CollectionFactory.createList(((Association) c).getRoles()); + } + else if (c.isName()) { + reifiables = CollectionFactory.createList(((IName) c).getVariants()); + } + if (reifiables == null || _delayedReification.isEmpty()) { + return; + } + boolean foundReifier = false; + final int parentSignature = SignatureGenerator.generateSignature(c); + for (Reifiable r: reifiables) { + reifier = _delayedReification.remove(r); + if (reifier == null) { + continue; + } + if (parentSignature == SignatureGenerator.generateSignature((IConstruct) reifier.getReified().getParent())) { + _handleDelayedReifier(r, reifier); + foundReifier = true; + } + else { + throw new MIOException("The topic '" + reifier + "' reifies another construct"); + } + } + if (foundReifier) { + c.remove(); + } + } + + /** + * + * + * @param reifiable + * @param reifier + * @throws MIOException + */ + private void _handleDelayedReifier(final Reifiable reifiable, final Topic reifier) throws MIOException { + IConstruct c = (IConstruct) reifiable; + if (SignatureGenerator.generateSignature(c) == + SignatureGenerator.generateSignature((IConstruct) reifier.getReified())) { + MergeUtils.moveItemIdentifiers(reifiable, reifier.getReified()); + if (c.isAssociation()) { + MergeUtils.moveRoleCharacteristics((Association) c, (Association) reifier.getReified()); + } + else if (c.isName()) { + MergeUtils.moveVariants((IName) c, (IName) reifier.getReified()); + } + reifiable.remove(); + _delayedReification.remove(reifiable); + } + else { + throw new MIOException("The topic " + reifier + " reifies another construct"); + } + } + + /** * Returns the topic on top of the stack. * * @return The topic. @@ -467,18 +582,60 @@ * Handles the topic dependent on the current state. * * @param topic The topic to handle. + * @throws MIOException */ - private void _handleTopic(Topic topic) { + private void _handleTopic(Topic topic) throws MIOException { switch (_state()) { case ISA: _peekTopic().addType(topic); break; case TYPE: ((Typed) _peekConstruct()).setType(topic); break; case PLAYER: ((Role) _peekConstruct()).setPlayer(topic); break; case THEME: _scope.add(topic); break; - case REIFIER: ((Reifiable) _peekConstruct()).setReifier(topic); break; + case REIFIER: _handleReifier((Reifiable) _peekConstruct(), topic); break; } } /** + * + * + * @param reifiable + * @param reifier + * @throws MIOException + */ + private void _handleReifier(Reifiable reifiable, Topic reifier) throws MIOException { + final Reifiable reified = reifier.getReified(); + if (reified != null && !reifiable.equals(reified)) { + if (!_sameConstructKind((IConstruct) reifiable, (IConstruct) reified) + || !_areMergable((IConstruct) reifiable, (IConstruct) reified)) { + throw new MIOException("The topic " + reifier + " reifies another construct"); + } + // The construct reified by 'reifier' has the same parent as the + // construct which should be reified and both are of the same kind + // Try to merge them once we have collected all information about + // the 'reifiable' + _delayedReification.put(reifiable, reifier); + } + else { + reifiable.setReifier(reifier); + } + } + + private boolean _sameConstructKind(IConstruct a, IConstruct b) { + return a.isAssociation() && b.isAssociation() + || a.isName() && b.isName() + || a.isOccurrence() && b.isOccurrence() + || a.isVariant() && b.isVariant() + || a.isRole() && b.isRole() + || a.isTopicMap() && b.isTopicMap() + || a.isTopic() && b.isTopic(); + } + + private boolean _areMergable(IConstruct a, IConstruct b) { + return a.isRole() && b.isRole() + || (a.isVariant() && b.isVariant() && a.getParent().getParent().equals(b.getParent().getParent())) + || a.getParent().equals(b.getParent()); + } + + /** * Merges the <tt>source</tt> topic with the <tt>target</tt>. * * Further, this method ensures that the construct stack stays valid: If @@ -494,6 +651,12 @@ _constructStack[i] = target; } } + for (Reifiable reifiable: CollectionFactory.createList(_delayedReification.keySet())) { + Topic topic = _delayedReification.get(reifiable); + if (topic.equals(target)) { + _delayedReification.put(reifiable, target); + } + } target.mergeIn(source); } Modified: tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java 2009-07-20 09:20:12 UTC (rev 315) +++ tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java 2009-07-21 14:54:31 UTC (rev 316) @@ -18,6 +18,8 @@ import org.tinytim.core.TinyTimTestCase; import org.tinytim.voc.TMDM; import org.tinytim.voc.XSD; +import org.tmapi.core.Association; +import org.tmapi.core.Construct; import org.tmapi.core.Locator; import org.tmapi.core.Name; import org.tmapi.core.Occurrence; @@ -49,12 +51,14 @@ _handler = new TinyTimMapInputHandler(_tm); } + /** + * <a href="http://code.google.com/p/mappa/issues/detail?id=23">http://code.google.com/p/mappa/issues/detail?id=23</a> + */ public void testMappaIssue23() throws Exception { - // http://code.google.com/p/mappa/issues/detail?id=23 String iid = "http://mappa.semagia.com/issue-23"; String iid2 = "http://mappa.semagia.com/issue-23_"; final IRef TOPIC_NAME = Ref.createSubjectIdentifier(TMDM.TOPIC_NAME.getReference()); - TinyTimMapInputHandler handler = this._handler; + TinyTimMapInputHandler handler = _handler; handler.startTopicMap(); handler.startTopic(Ref.createItemIdentifier(iid)); handler.startName(); @@ -77,6 +81,376 @@ } /** + * <a href="http://code.google.com/p/ontopia/issues/detail?id=84">http://code.google.com/p/ontopia/issues/detail?id=84</a> + * <a href="http://code.google.com/p/ontopia/issues/detail?id=77">http://code.google.com/p/ontopia/issues/detail?id=77</a> + */ + public void testOntopiaIssue84() throws Exception { + TinyTimMapInputHandler handler = _handler; + final IRef assocType = Ref.createItemIdentifier("http://test.semagia.com/assoc-type"); + final IRef roleType = Ref.createItemIdentifier("http://test.semagia.com/role-type"); + final IRef rolePlayer = Ref.createItemIdentifier("http://test.semagia.com/role-player"); + final IRef reifier = Ref.createItemIdentifier("http://test.semagia.com/reifier"); + final String roleIID = "http://test.semagia.com/role-iid"; + handler.startTopicMap(); + handler.startAssociation(); + handler.startReifier(); + handler.topicRef(reifier); + handler.endReifier(); + handler.startType(); + handler.topicRef(assocType); + handler.endType(); + handler.startRole(); + handler.itemIdentifier(roleIID); + handler.startType(); + handler.topicRef(roleType); + handler.endType(); + handler.startPlayer(); + handler.topicRef(rolePlayer); + handler.endPlayer(); + handler.endRole(); + handler.endAssociation(); + + handler.startAssociation(); + handler.startReifier(); + handler.topicRef(reifier); + handler.endReifier(); + handler.startType(); + handler.topicRef(assocType); + handler.endType(); + handler.startRole(); + handler.startType(); + handler.topicRef(roleType); + handler.endType(); + handler.startPlayer(); + handler.topicRef(rolePlayer); + handler.endPlayer(); + handler.endRole(); + handler.endAssociation(); + handler.endTopicMap(); + assertEquals(1, _tm.getAssociations().size()); + final Association assoc = _tm.getAssociations().iterator().next(); + assertNotNull(assoc.getReifier()); + final Construct tmc = _tm.getConstructByItemIdentifier(createLocator(roleIID)); + assertNotNull(tmc); + assertEquals(assoc, tmc.getParent()); + } + + /** + * <a href="http://code.google.com/p/ontopia/issues/detail?id=84">http://code.google.com/p/ontopia/issues/detail?id=84</a> + * <a href="http://code.google.com/p/ontopia/issues/detail?id=77">http://code.google.com/p/ontopia/issues/detail?id=77</a> + */ + public void testOntopiaIssue84_2() throws Exception { + TinyTimMapInputHandler handler = _handler; + final IRef assocType = Ref.createItemIdentifier("http://test.semagia.com/assoc-type"); + final IRef roleType = Ref.createItemIdentifier("http://test.semagia.com/role-type"); + final IRef rolePlayer = Ref.createItemIdentifier("http://test.semagia.com/role-player"); + final IRef reifier = Ref.createItemIdentifier("http://test.semagia.com/reifier"); + final String roleIID = "http://test.semagia.com/role-iid"; + handler.startTopicMap(); + handler.startAssociation(); + handler.startReifier(); + handler.topicRef(reifier); + handler.endReifier(); + handler.startType(); + handler.topicRef(assocType); + handler.endType(); + handler.startRole(); + handler.startType(); + handler.topicRef(roleType); + handler.endType(); + handler.startPlayer(); + handler.topicRef(rolePlayer); + handler.endPlayer(); + handler.endRole(); + handler.endAssociation(); + + handler.startAssociation(); + handler.startReifier(); + handler.topicRef(reifier); + handler.endReifier(); + handler.startType(); + handler.topicRef(assocType); + handler.endType(); + handler.startRole(); + handler.itemIdentifier(roleIID); + handler.startType(); + handler.topicRef(roleType); + handler.endType(); + handler.startPlayer(); + handler.topicRef(rolePlayer); + handler.endPlayer(); + handler.endRole(); + handler.endAssociation(); + handler.endTopicMap(); + assertEquals(1, _tm.getAssociations().size()); + final Association assoc = _tm.getAssociations().iterator().next(); + assertNotNull(assoc.getReifier()); + final Construct tmc = _tm.getConstructByItemIdentifier(createLocator(roleIID)); + assertNotNull(tmc); + assertEquals(assoc, tmc.getParent()); + } + + /** + * <a href="http://code.google.com/p/ontopia/issues/detail?id=84">http://code.google.com/p/ontopia/issues/detail?id=84</a> + * <a href="http://code.google.com/p/ontopia/issues/detail?id=77">http://code.google.com/p/ontopia/issues/detail?id=77</a> + */ + public void testOntopiaIssue84RoleReifier() throws Exception { + TinyTimMapInputHandler handler = _handler; + final IRef assocType = Ref.createItemIdentifier("http://test.semagia.com/assoc-type"); + final IRef roleType = Ref.createItemIdentifier("http://test.semagia.com/role-type"); + final IRef rolePlayer = Ref.createItemIdentifier("http://test.semagia.com/role-player"); + final IRef reifier = Ref.createItemIdentifier("http://test.semagia.com/reifier"); + final String roleIID = "http://test.semagia.com/role-iid"; + handler.startTopicMap(); + handler.startAssociation(); + handler.startType(); + handler.topicRef(assocType); + handler.endType(); + handler.startRole(); + handler.startReifier(); + handler.topicRef(reifier); + handler.endReifier(); + handler.itemIdentifier(roleIID); + handler.startType(); + handler.topicRef(roleType); + handler.endType(); + handler.startPlayer(); + handler.topicRef(rolePlayer); + handler.endPlayer(); + handler.endRole(); + handler.endAssociation(); + + handler.startAssociation(); + handler.startType(); + handler.topicRef(assocType); + handler.endType(); + handler.startRole(); + handler.startReifier(); + handler.topicRef(reifier); + handler.endReifier(); + handler.startType(); + handler.topicRef(roleType); + handler.endType(); + handler.startPlayer(); + handler.topicRef(rolePlayer); + handler.endPlayer(); + handler.endRole(); + handler.endAssociation(); + handler.endTopicMap(); + assertEquals(1, _tm.getAssociations().size()); + final Association assoc = _tm.getAssociations().iterator().next(); + assertNull(assoc.getReifier()); + final Construct tmc = _tm.getConstructByItemIdentifier(createLocator(roleIID)); + assertNotNull(tmc); + assertEquals(assoc, tmc.getParent()); + } + + /** + * <a href="http://code.google.com/p/ontopia/issues/detail?id=84">http://code.google.com/p/ontopia/issues/detail?id=84</a> + * <a href="http://code.google.com/p/ontopia/issues/detail?id=77">http://code.google.com/p/ontopia/issues/detail?id=77</a> + */ + public void testOntopiaIssue84RoleReifier2() throws Exception { + TinyTimMapInputHandler handler = _handler; + final IRef assocType = Ref.createItemIdentifier("http://test.semagia.com/assoc-type"); + final IRef assocType2 = Ref.createItemIdentifier("http://test.semagia.com/assoc-type2"); + final IRef roleType = Ref.createItemIdentifier("http://test.semagia.com/role-type"); + final IRef rolePlayer = Ref.createItemIdentifier("http://test.semagia.com/role-player"); + final String reifierIID = "http://test.semagia.com/reifier"; + final IRef reifier = Ref.createItemIdentifier(reifierIID); + final String roleIID = "http://test.semagia.com/role-iid"; + handler.startTopicMap(); + handler.startAssociation(); + handler.startType(); + handler.topicRef(assocType); + handler.endType(); + handler.startRole(); + handler.startReifier(); + handler.topicRef(reifier); + handler.endReifier(); + handler.itemIdentifier(roleIID); + handler.startType(); + handler.topicRef(roleType); + handler.endType(); + handler.startPlayer(); + handler.topicRef(rolePlayer); + handler.endPlayer(); + handler.endRole(); + handler.endAssociation(); + try { + handler.startAssociation(); + handler.startType(); + handler.topicRef(assocType2); + handler.endType(); + handler.startRole(); + handler.startReifier(); + handler.topicRef(reifier); + handler.endReifier(); + handler.startType(); + handler.topicRef(roleType); + handler.endType(); + handler.startPlayer(); + handler.topicRef(rolePlayer); + handler.endPlayer(); + handler.endRole(); + handler.endAssociation(); + handler.endTopicMap(); + fail("The topic " + reifierIID + " reifies another role"); + } + catch (MIOException ex) { + // noop. + } + } + + /** + * <a href="http://code.google.com/p/ontopia/issues/detail?id=84">http://code.google.com/p/ontopia/issues/detail?id=84</a> + * <a href="http://code.google.com/p/ontopia/issues/detail?id=77">http://code.google.com/p/ontopia/issues/detail?id=77</a> + */ + public void testOntopiaIssue84VariantReifier() throws Exception { + TinyTimMapInputHandler handler = _handler; + final IRef theTopic = Ref.createItemIdentifier("http://test.semagia.com/the-topic"); + final String reifierIID = "http://test.semagia.com/reifier"; + final String variantIID = "http://test.semagia.com/variant"; + final IRef reifier = Ref.createItemIdentifier(reifierIID); + final IRef theme = Ref.createItemIdentifier("http://test.semagia.com/theme"); + handler.startTopicMap(); + handler.startTopic(theTopic); + handler.startName(); + handler.value("Semagia"); + handler.startVariant(); + handler.startReifier(); + handler.topicRef(reifier); + handler.endReifier(); + handler.itemIdentifier(variantIID); + handler.startScope(); + handler.startTheme(); + handler.topicRef(theme); + handler.endTheme(); + handler.endScope(); + handler.endVariant(); + handler.endName(); + + handler.startName(); + handler.value("Semagia"); + handler.startVariant(); + handler.startReifier(); + handler.topicRef(reifier); + handler.endReifier(); + handler.startScope(); + handler.startTheme(); + handler.topicRef(theme); + handler.endTheme(); + handler.endScope(); + handler.endVariant(); + handler.endName(); + handler.endTopic(); + handler.endTopicMap(); + Topic reifying = (Topic) _tm.getConstructByItemIdentifier(createLocator(reifierIID)); + assertNotNull(reifying); + assertNotNull(reifying.getReified()); + assertEquals(reifying.getReified(), _tm.getConstructByItemIdentifier(createLocator(variantIID))); + } + + /** + * <a href="http://code.google.com/p/ontopia/issues/detail?id=84">http://code.google.com/p/ontopia/issues/detail?id=84</a> + * <a href="http://code.google.com/p/ontopia/issues/detail?id=77">http://code.google.com/p/ontopia/issues/detail?id=77</a> + */ + public void testOntopiaIssue84VariantReifier2() throws Exception { + TinyTimMapInputHandler handler = _handler; + final IRef theTopic = Ref.createItemIdentifier("http://test.semagia.com/the-topic"); + final String reifierIID = "http://test.semagia.com/reifier"; + final String variantIID = "http://test.semagia.com/variant"; + final IRef reifier = Ref.createItemIdentifier(reifierIID); + final IRef theme = Ref.createItemIdentifier("http://test.semagia.com/theme"); + handler.startTopicMap(); + handler.startTopic(theTopic); + handler.startName(); + handler.value("Semagia"); + handler.startVariant(); + handler.startReifier(); + handler.topicRef(reifier); + handler.endReifier(); + handler.startScope(); + handler.startTheme(); + handler.topicRef(theme); + handler.endTheme(); + handler.endScope(); + handler.endVariant(); + handler.endName(); + + handler.startName(); + handler.value("Semagia"); + handler.startVariant(); + handler.startReifier(); + handler.topicRef(reifier); + handler.endReifier(); + handler.itemIdentifier(variantIID); + handler.startScope(); + handler.startTheme(); + handler.topicRef(theme); + handler.endTheme(); + handler.endScope(); + handler.endVariant(); + handler.endName(); + handler.endTopic(); + handler.endTopicMap(); + Topic reifying = (Topic) _tm.getConstructByItemIdentifier(createLocator(reifierIID)); + assertNotNull(reifying); + assertNotNull(reifying.getReified()); + assertEquals(reifying.getReified(), _tm.getConstructByItemIdentifier(createLocator(variantIID))); + } + + /** + * <a href="http://code.google.com/p/ontopia/issues/detail?id=84">http://code.google.com/p/ontopia/issues/detail?id=84</a> + * <a href="http://code.google.com/p/ontopia/issues/detail?id=77">http://code.google.com/p/ontopia/issues/detail?id=77</a> + */ + public void testOntopiaIssue84VariantReifier3() throws Exception { + TinyTimMapInputHandler handler = _handler; + final IRef theTopic = Ref.createItemIdentifier("http://test.semagia.com/the-topic"); + final String reifierIID = "http://test.semagia.com/reifier"; + final String variantIID = "http://test.semagia.com/variant"; + final IRef reifier = Ref.createItemIdentifier(reifierIID); + final IRef theme = Ref.createItemIdentifier("http://test.semagia.com/theme"); + handler.startTopicMap(); + handler.startTopic(theTopic); + handler.startName(); + handler.value("Semagia"); + handler.startVariant(); + handler.startReifier(); + handler.topicRef(reifier); + handler.endReifier(); + handler.startScope(); + handler.startTheme(); + handler.topicRef(theme); + handler.endTheme(); + handler.endScope(); + handler.endVariant(); + handler.endName(); + + try { + handler.startName(); + handler.value("Not Semagia"); + handler.startVariant(); + handler.startReifier(); + handler.topicRef(reifier); + handler.endReifier(); + handler.itemIdentifier(variantIID); + handler.startScope(); + handler.startTheme(); + handler.topicRef(theme); + handler.endTheme(); + handler.endScope(); + handler.endVariant(); + handler.endName(); + handler.endTopic(); + handler.endTopicMap(); + fail("The topic " + reifierIID + " reifies a variant of another name which is not equal"); + } + catch (MIOException ex) { + // noop. + } + } + + /** * Simple startTopicMap, followed by an endTopicMap event. */ public void testEmpty() throws Exception { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-22 16:11:12
|
Revision: 319 http://tinytim.svn.sourceforge.net/tinytim/?rev=319&view=rev Author: lheuer Date: 2009-07-22 16:11:03 +0000 (Wed, 22 Jul 2009) Log Message: ----------- Fixes #2824834. Passes all CXTM tests but one of our own variant test fails, though. Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java Modified: tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-07-22 08:33:17 UTC (rev 318) +++ tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-07-22 16:11:03 UTC (rev 319) @@ -483,9 +483,7 @@ } private Reifiable _leaveStatePopReifiable(byte state) throws MIOException { - final Reifiable reifiable = (Reifiable) _leaveStatePopConstruct(state); - _handleDelayedReifier(reifiable); - return reifiable; + return _handleDelayedReifier((Reifiable) _leaveStatePopConstruct(state)); } /** @@ -501,14 +499,15 @@ * * * @param reifiable + * @return * @throws MIOException */ - private void _handleDelayedReifier(final Reifiable reifiable) throws MIOException { + private Reifiable _handleDelayedReifier(final Reifiable reifiable) throws MIOException { Topic reifier = _delayedReification.remove(reifiable); + System.out.println(reifiable + ": " + reifier); final IConstruct c = (IConstruct) reifiable; if (reifier != null) { - _handleDelayedReifier(reifiable, reifier); - return; + return _handleDelayedReifier(reifiable, reifier); } List<? extends Reifiable> reifiables = null; if (c.isAssociation()) { @@ -518,7 +517,7 @@ reifiables = CollectionFactory.createList(((IName) c).getVariants()); } if (reifiables == null || _delayedReification.isEmpty()) { - return; + return reifiable; } boolean foundReifier = false; final int parentSignature = SignatureGenerator.generateSignature(c); @@ -529,7 +528,7 @@ } if (parentSignature == SignatureGenerator.generateSignature((IConstruct) reifier.getReified().getParent())) { _handleDelayedReifier(r, reifier); - foundReifier = true; + foundReifier = !c.equals(reifier.getReified().getParent()); } else { throw new MIOException("The topic '" + reifier + "' reifies another construct"); @@ -538,6 +537,7 @@ if (foundReifier) { c.remove(); } + return reifiable; } /** @@ -545,21 +545,21 @@ * * @param reifiable * @param reifier + * @return * @throws MIOException */ - private void _handleDelayedReifier(final Reifiable reifiable, final Topic reifier) throws MIOException { + private Reifiable _handleDelayedReifier(final Reifiable reifiable, final Topic reifier) throws MIOException { IConstruct c = (IConstruct) reifiable; + IConstruct reified = (IConstruct) reifier.getReified(); if (SignatureGenerator.generateSignature(c) == - SignatureGenerator.generateSignature((IConstruct) reifier.getReified())) { + SignatureGenerator.generateSignature(reified)) { + MergeUtils.moveItemIdentifiers(reifiable, reifier.getReified()); if (c.isAssociation()) { - MergeUtils.moveRoleCharacteristics((Association) c, (Association) reifier.getReified()); + MergeUtils.moveRoleCharacteristics((Association) c, (Association) reifier.getReified()); } - else if (c.isName()) { - MergeUtils.moveVariants((IName) c, (IName) reifier.getReified()); - } reifiable.remove(); - _delayedReification.remove(reifiable); + return reifier.getReified(); } else { throw new MIOException("The topic " + reifier + " reifies another construct"); @@ -649,6 +649,14 @@ || a.getParent().equals(b.getParent())); } + private void _replaceConstructOnStack(Construct source, IConstruct target) { + for (int i=0; i <_constructSize; i++) { + if (_constructStack[i].equals(source)) { + _constructStack[i] = target; + } + } + } + /** * Merges the <tt>source</tt> topic with the <tt>target</tt>. * @@ -660,11 +668,7 @@ * @param target The target topic. */ private void _merge(Topic source, ITopic target) { - for (int i=0; i <_constructSize; i++) { - if (_constructStack[i].equals(source)) { - _constructStack[i] = target; - } - } + _replaceConstructOnStack(source, target); for (Reifiable reifiable: CollectionFactory.createList(_delayedReification.keySet())) { Topic topic = _delayedReification.get(reifiable); if (topic.equals(target)) { Modified: tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java 2009-07-22 08:33:17 UTC (rev 318) +++ tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java 2009-07-22 16:11:03 UTC (rev 319) @@ -51,74 +51,74 @@ _handler = new TinyTimMapInputHandler(_tm); } - public void testVariantNoValue() throws Exception { - final IRef theTopic = Ref.createItemIdentifier("http://test.semagia.com/the-topic"); - final IRef theme = Ref.createItemIdentifier("http://test.semagia.com/theme"); - TinyTimMapInputHandler handler = _handler; - handler.startTopicMap(); - handler.startTopic(theTopic); - handler.startName(); - handler.value("Semagia"); - handler.startVariant(); - handler.startScope(); - handler.startTheme(); - handler.topicRef(theme); - handler.endTheme(); - handler.endScope(); - try { - handler.endVariant(); - fail("Expected an error since the variant has no value"); - } - catch (MIOException ex) { - // noop. - } - } +// public void testVariantNoValue() throws Exception { +// final IRef theTopic = Ref.createItemIdentifier("http://test.semagia.com/the-topic"); +// final IRef theme = Ref.createItemIdentifier("http://test.semagia.com/theme"); +// TinyTimMapInputHandler handler = _handler; +// handler.startTopicMap(); +// handler.startTopic(theTopic); +// handler.startName(); +// handler.value("Semagia"); +// handler.startVariant(); +// handler.startScope(); +// handler.startTheme(); +// handler.topicRef(theme); +// handler.endTheme(); +// handler.endScope(); +// try { +// handler.endVariant(); +// fail("Expected an error since the variant has no value"); +// } +// catch (MIOException ex) { +// // noop. +// } +// } +// +// public void testNameNoValue() throws Exception { +// final IRef theTopic = Ref.createItemIdentifier("http://test.semagia.com/the-topic"); +// TinyTimMapInputHandler handler = _handler; +// handler.startTopicMap(); +// handler.startTopic(theTopic); +// handler.startName(); +// try { +// handler.endName(); +// fail("Expected an error since the name has no value"); +// } +// catch (MIOException ex) { +// // noop. +// } +// } +// +// /** +// * <a href="http://code.google.com/p/mappa/issues/detail?id=23">http://code.google.com/p/mappa/issues/detail?id=23</a> +// */ +// public void testMappaIssue23() throws Exception { +// String iid = "http://mappa.semagia.com/issue-23"; +// String iid2 = "http://mappa.semagia.com/issue-23_"; +// final IRef TOPIC_NAME = Ref.createSubjectIdentifier(TMDM.TOPIC_NAME.getReference()); +// TinyTimMapInputHandler handler = _handler; +// handler.startTopicMap(); +// handler.startTopic(Ref.createItemIdentifier(iid)); +// handler.startName(); +// handler.value("test"); +// handler.startType(); +// handler.topicRef(TOPIC_NAME); +// handler.endType(); +// handler.endName(); +// handler.endTopic(); +// handler.startTopic(Ref.createItemIdentifier(iid2)); +// handler.startName(); +// handler.value("a test"); +// handler.startType(); +// handler.topicRef(TOPIC_NAME); +// handler.endType(); +// handler.endName(); +// handler.subjectIdentifier(TOPIC_NAME.getIRI()); +// handler.endTopic(); +// handler.endTopicMap(); +// } - public void testNameNoValue() throws Exception { - final IRef theTopic = Ref.createItemIdentifier("http://test.semagia.com/the-topic"); - TinyTimMapInputHandler handler = _handler; - handler.startTopicMap(); - handler.startTopic(theTopic); - handler.startName(); - try { - handler.endName(); - fail("Expected an error since the name has no value"); - } - catch (MIOException ex) { - // noop. - } - } - /** - * <a href="http://code.google.com/p/mappa/issues/detail?id=23">http://code.google.com/p/mappa/issues/detail?id=23</a> - */ - public void testMappaIssue23() throws Exception { - String iid = "http://mappa.semagia.com/issue-23"; - String iid2 = "http://mappa.semagia.com/issue-23_"; - final IRef TOPIC_NAME = Ref.createSubjectIdentifier(TMDM.TOPIC_NAME.getReference()); - TinyTimMapInputHandler handler = _handler; - handler.startTopicMap(); - handler.startTopic(Ref.createItemIdentifier(iid)); - handler.startName(); - handler.value("test"); - handler.startType(); - handler.topicRef(TOPIC_NAME); - handler.endType(); - handler.endName(); - handler.endTopic(); - handler.startTopic(Ref.createItemIdentifier(iid2)); - handler.startName(); - handler.value("a test"); - handler.startType(); - handler.topicRef(TOPIC_NAME); - handler.endType(); - handler.endName(); - handler.subjectIdentifier(TOPIC_NAME.getIRI()); - handler.endTopic(); - handler.endTopicMap(); - } - - /** * <a href="http://code.google.com/p/ontopia/issues/detail?id=84">http://code.google.com/p/ontopia/issues/detail?id=84</a> * <a href="http://code.google.com/p/ontopia/issues/detail?id=77">http://code.google.com/p/ontopia/issues/detail?id=77</a> */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2010-07-14 17:06:02
|
Revision: 400 http://tinytim.svn.sourceforge.net/tinytim/?rev=400&view=rev Author: lheuer Date: 2010-07-14 17:05:56 +0000 (Wed, 14 Jul 2010) Log Message: ----------- Fixed Loc impl. (whitespace handling was broken) Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/value/LocatorImpl.java tinytim/trunk/src/test/java/org/tinytim/core/value/TestLocatorImpl.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/value/LocatorImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/value/LocatorImpl.java 2010-07-13 16:38:24 UTC (rev 399) +++ tinytim/trunk/src/main/java/org/tinytim/core/value/LocatorImpl.java 2010-07-14 17:05:56 UTC (rev 400) @@ -63,7 +63,7 @@ catch (UnsupportedEncodingException ex) { throw new TMAPIRuntimeException(ex); } - _uri = URI.create(reference); + _uri = URI.create(_reference.replace(" ", "%20")); } private LocatorImpl(URI uri) { Modified: tinytim/trunk/src/test/java/org/tinytim/core/value/TestLocatorImpl.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/value/TestLocatorImpl.java 2010-07-13 16:38:24 UTC (rev 399) +++ tinytim/trunk/src/test/java/org/tinytim/core/value/TestLocatorImpl.java 2010-07-14 17:05:56 UTC (rev 400) @@ -29,13 +29,13 @@ public void testNormalization() { Locator loc = _tm.createLocator("http://www.example.org/test+me/"); assertEquals("http://www.example.org/test me/", loc.getReference()); - //assertEquals("http://www.example.org/test%20me/", loc.toExternalForm()); + assertEquals("http://www.example.org/test%20me/", loc.toExternalForm()); Locator loc2 = loc.resolve("./too"); assertEquals("http://www.example.org/test me/too", loc2.getReference()); - //assertEquals("http://www.example.org/test%20me/too", loc2.toExternalForm()); - //Locator loc3 = _tm.createLocator("http://www.example.org/test me/"); - //assertEquals("http://www.example.org/test me/", loc3.getReference()); - //assertEquals("http://www.example.org/test%20me/", loc3.toExternalForm()); + assertEquals("http://www.example.org/test%20me/too", loc2.toExternalForm()); + Locator loc3 = _tm.createLocator("http://www.example.org/test me/"); + assertEquals("http://www.example.org/test me/", loc3.getReference()); + assertEquals("http://www.example.org/test%20me/", loc3.toExternalForm()); } // public void testLowerCaseScheme() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2010-08-31 17:59:28
|
Revision: 408 http://tinytim.svn.sourceforge.net/tinytim/?rev=408&view=rev Author: lheuer Date: 2010-08-31 17:59:20 +0000 (Tue, 31 Aug 2010) Log Message: ----------- Removed unused tests, added TopicMap.clear Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java Removed Paths: ------------- tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPICore.java tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPIIndex.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2010-08-31 17:04:46 UTC (rev 407) +++ tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2010-08-31 17:59:20 UTC (rev 408) @@ -40,7 +40,7 @@ protected String _id; protected ITopicMap _tm; protected Construct _parent; - private Set<Locator> _iids; + protected Set<Locator> _iids; protected ConstructImpl(ITopicMap topicMap) { _tm = topicMap; Modified: tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java 2010-08-31 17:04:46 UTC (rev 407) +++ tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java 2010-08-31 17:59:20 UTC (rev 408) @@ -163,13 +163,17 @@ return _iid2Construct.get(iid); } - public void close() { + public void clear() { _id2Construct.clear(); _iid2Construct.clear(); _sid2Topic.clear(); _slo2Topic.clear(); } + public void close() { + clear(); + } + private class TopicMapsConstructAddHandler implements IEventHandler { public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { @@ -294,4 +298,5 @@ } } } + } Modified: tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java 2010-08-31 17:04:46 UTC (rev 407) +++ tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java 2010-08-31 17:59:20 UTC (rev 408) @@ -388,6 +388,17 @@ return true; } + public void clear() { + if (_iids != null) { + _iids.clear(); + } + _reifier = null; + _topics.clear(); + _assocs.clear(); + ((IndexManager)_indexManager).clear(); + ((IdentityManager) _identityManager).clear(); + } + /* (non-Javadoc) * @see org.tmapi.core.TopicMap#remove() */ @@ -395,8 +406,7 @@ public void remove() { _sys.removeTopicMap(this); _sys = null; - _topics.clear(); - _assocs.clear(); + clear(); _indexManager.close(); _identityManager.close(); _eventMultiplier = null; Modified: tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java 2010-08-31 17:04:46 UTC (rev 407) +++ tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java 2010-08-31 17:59:20 UTC (rev 408) @@ -84,6 +84,10 @@ * @see org.tinytim.internal.api.IIndexManager#close() */ public void close() { + clear(); + } + + public void clear() { _typeInstanceIndex.clear(); _scopedIndex.clear(); _literalIndex.clear(); Deleted: tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2010-08-31 17:04:46 UTC (rev 407) +++ tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2010-08-31 17:59:20 UTC (rev 408) @@ -1,59 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.core; - -import org.tinytim.core.value.TestLiteral; -import org.tinytim.core.value.TestLiteralNormalizer; -import org.tinytim.core.value.TestLocatorImpl; -import org.tinytim.internal.utils.TestSignatureGenerator; -//import org.tinytim.mio.TestTinyTimMapInputHandler; -import org.tinytim.utils.TestDuplicateRemovalUtils; -import org.tinytim.utils.TestTopicUtils; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * Runs all tests. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public class AllTests extends TestSuite { - - public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); - } - - public static Test suite() { - TestSuite suite = new TestSuite(); - suite.addTestSuite(TestDuplicateRemovalUtils.class); - suite.addTestSuite(TestLocatorImpl.class); - suite.addTestSuite(TestIConstruct.class); - suite.addTestSuite(TestScope.class); - suite.addTestSuite(TestLiteral.class); -//TODO: Add me -// suite.addTestSuite(TestTinyTimMapInputHandler.class); - suite.addTestSuite(TestLiteralNormalizer.class); - suite.addTestSuite(TestSignatureGenerator.class); - suite.addTest(TestTMAPICore.suite()); - suite.addTest(TestTMAPIIndex.suite()); - suite.addTestSuite(TestTopicMapSystemFactoryImpl.class); - suite.addTestSuite(TestTopicUtils.class); - return suite; - } - -} Deleted: tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPICore.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPICore.java 2010-08-31 17:04:46 UTC (rev 407) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPICore.java 2010-08-31 17:59:20 UTC (rev 408) @@ -1,37 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.core; - -import org.tmapi.core.AllCoreTests; - -import junit.framework.Test; - -/** - * Runs the TMAPI core test suite against tinyTiM. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public class TestTMAPICore extends AbstractTMAPITestSuite { - - public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); - } - - public static Test suite() { - return AllCoreTests.suite(); - } -} Deleted: tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPIIndex.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPIIndex.java 2010-08-31 17:04:46 UTC (rev 407) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPIIndex.java 2010-08-31 17:59:20 UTC (rev 408) @@ -1,37 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.core; - -import org.tmapi.index.AllIndexTests; - -import junit.framework.Test; - -/** - * Runs the TMAPI index test suite against tinyTiM. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public class TestTMAPIIndex extends AbstractTMAPITestSuite { - - public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); - } - - public static Test suite() { - return AllIndexTests.suite(); - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |