You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
|
Apr
(48) |
May
(21) |
Jun
(3) |
Jul
(10) |
Aug
(66) |
Sep
(11) |
Oct
(7) |
Nov
(73) |
Dec
(12) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2009 |
Jan
(3) |
Feb
(17) |
Mar
(19) |
Apr
(1) |
May
(4) |
Jun
|
Jul
(43) |
Aug
(18) |
Sep
(1) |
Oct
(1) |
Nov
(2) |
Dec
|
2010 |
Jan
(3) |
Feb
(7) |
Mar
(21) |
Apr
(2) |
May
(1) |
Jun
(1) |
Jul
(6) |
Aug
(6) |
Sep
(7) |
Oct
|
Nov
(1) |
Dec
|
2011 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
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-11 16:45:28
|
Revision: 118 http://tinytim.svn.sourceforge.net/tinytim/?rev=118&view=rev Author: lheuer Date: 2008-08-11 16:45:18 +0000 (Mon, 11 Aug 2008) Log Message: ----------- - Added IIntObjectMap factory methods to the CollectionFactory - Inlined implementations of IIntObjectMap Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java tinytim/trunk/src/main/java/org/tinytim/core/IScope.java tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java tinytim/trunk/src/main/java/org/tinytim/core/Scope.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 Removed Paths: ------------- tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-11 16:45:18 UTC (rev 118) @@ -25,7 +25,6 @@ import org.tinytim.utils.CollectionFactory; import org.tinytim.utils.IIntObjectMap; -import org.tinytim.utils.IntObjectMap; import org.tmapi.core.Association; import org.tmapi.core.Construct; import org.tmapi.core.Locator; @@ -179,7 +178,7 @@ */ private static void _copyCharacteristics(Topic topic, TopicImpl targetTopic, Map<Topic, Topic> mergeMap) { - IIntObjectMap<Reifiable> sigs = IntObjectMap.create(); + IIntObjectMap<Reifiable> sigs = CollectionFactory.createIntObjectMap(); for (Occurrence occ: targetTopic.getOccurrences()) { sigs.put(SignatureGenerator.generateSignature(occ), occ); } @@ -229,7 +228,7 @@ */ private static void _copyVariants(Name source, NameImpl target, Map<Topic, Topic> mergeMap) { - IIntObjectMap<Variant> sigs = IntObjectMap.create(); + IIntObjectMap<Variant> sigs = CollectionFactory.createIntObjectMap(); for (Variant variant: target.getVariants()) { sigs.put(SignatureGenerator.generateSignature(variant), variant); } @@ -324,7 +323,7 @@ private static void _copyAssociations(TopicMap source, TopicMapImpl target, Map<Topic, Topic> mergeMap) { Set<Association> assocs = target.getAssociations(); - IIntObjectMap<Association> sigs = IntObjectMap.create(assocs.size()); + IIntObjectMap<Association> sigs = CollectionFactory.createIntObjectMap(assocs.size()); for (Association assoc: assocs) { sigs.put(SignatureGenerator.generateSignature(assoc), assoc); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java 2008-08-11 16:45:18 UTC (rev 118) @@ -23,8 +23,8 @@ import java.util.ArrayList; import java.util.Collection; +import org.tinytim.utils.CollectionFactory; import org.tinytim.utils.IIntObjectMap; -import org.tinytim.utils.IntObjectMap; import org.tmapi.core.Association; import org.tmapi.core.Name; import org.tmapi.core.Occurrence; @@ -56,7 +56,7 @@ for (Topic topic: tm.getTopics()) { removeDuplicates(topic); } - IIntObjectMap<Association> sig2Assoc = IntObjectMap.create(); + IIntObjectMap<Association> sig2Assoc = CollectionFactory.createIntObjectMap(); TypeInstanceIndex typeInstanceIdx = tm.getIndexManager().getTypeInstanceIndex(); if (!typeInstanceIdx.isAutoUpdated()) { typeInstanceIdx.reindex(); @@ -99,7 +99,7 @@ * @param name The name from which the duplicates should be removed. */ public static void removeDuplicates(Name name) { - IIntObjectMap<Variant> sigs = IntObjectMap.create(); + IIntObjectMap<Variant> sigs = CollectionFactory.createIntObjectMap(); for (Variant variant: new ArrayList<Variant>(name.getVariants())) { int sig = SignatureGenerator.generateSignature(variant); Variant existing = sigs.get(sig); @@ -119,7 +119,7 @@ * @param occs */ private static void _removeDuplicateOccurrences(Collection<Occurrence> occs) { - IIntObjectMap<Occurrence> sigs = IntObjectMap.create(occs.size()); + IIntObjectMap<Occurrence> sigs = CollectionFactory.createIntObjectMap(occs.size()); Occurrence existing = null; for (Occurrence occ: new ArrayList<Occurrence>(occs)) { int sig = SignatureGenerator.generateSignature(occ); @@ -140,7 +140,7 @@ * @param names */ private static void _removeDuplicateNames(Collection<Name> names) { - IIntObjectMap<Name> sigs = IntObjectMap.create(names.size()); + IIntObjectMap<Name> sigs = CollectionFactory.createIntObjectMap(names.size()); Name existing = null; for (Name name: new ArrayList<Name>(names)) { removeDuplicates(name); @@ -163,7 +163,7 @@ * @param assoc The association to remove duplicate roles from. */ public static void removeDuplicates(Association assoc) { - IIntObjectMap<Role> sig2Role = IntObjectMap.create(); + IIntObjectMap<Role> sig2Role = CollectionFactory.createIntObjectMap(); Role existing = null; for (Role role: new ArrayList<Role>(assoc.getRoles())) { int sig = SignatureGenerator.generateSignature(role); Modified: tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java 2008-08-11 16:45:18 UTC (rev 118) @@ -26,7 +26,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public interface IConstruct extends Construct { Modified: tinytim/trunk/src/main/java/org/tinytim/core/IScope.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IScope.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/core/IScope.java 2008-08-11 16:45:18 UTC (rev 118) @@ -30,7 +30,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$ */ public interface IScope extends Iterable<Topic> { Modified: tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java 2008-08-11 16:45:18 UTC (rev 118) @@ -26,7 +26,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public interface IScoped extends Scoped, IConstruct { Modified: tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-11 16:45:18 UTC (rev 118) @@ -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.utils.IntObjectMap; import org.tmapi.core.Association; import org.tmapi.core.Construct; import org.tmapi.core.Locator; @@ -121,7 +121,7 @@ for(Topic type: source.getTypes()) { target.addType(type); } - IIntObjectMap<Reifiable> sigs = IntObjectMap.create(); + IIntObjectMap<Reifiable> sigs = CollectionFactory.createIntObjectMap(); for (Occurrence occ: target.getOccurrences()) { sigs.put(SignatureGenerator.generateSignature(occ), occ); } @@ -177,7 +177,7 @@ * @param target The association which takes the role characteristics. */ static void moveRoleCharacteristics(Association source, Association target) { - IIntObjectMap<Role> sigs = IntObjectMap.create(); + IIntObjectMap<Role> sigs = CollectionFactory.createIntObjectMap(); for (Role role: target.getRoles()) { sigs.put(SignatureGenerator.generateSignature(role), role); } @@ -195,7 +195,7 @@ * @param target The target to add the variants to. */ static void moveVariants(Name source, Name target) { - IIntObjectMap<Variant> sigs = IntObjectMap.create(); + IIntObjectMap<Variant> sigs = CollectionFactory.createIntObjectMap(); for (Variant var: target.getVariants()) { sigs.put(SignatureGenerator.generateSignature(var), var); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/Scope.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Scope.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/core/Scope.java 2008-08-11 16:45:18 UTC (rev 118) @@ -33,7 +33,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ final class Scope implements IScope { Modified: tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java 2008-08-11 16:45:18 UTC (rev 118) @@ -24,12 +24,11 @@ import java.util.Set; - /** * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class CollectionFactory { @@ -105,4 +104,12 @@ 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); + } + } Modified: tinytim/trunk/src/main/java/org/tinytim/utils/ICollectionFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/ICollectionFactory.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/utils/ICollectionFactory.java 2008-08-11 16:45:18 UTC (rev 118) @@ -33,6 +33,10 @@ */ interface ICollectionFactory { + <E> IIntObjectMap<E> createIntObjectMap(); + + <E> IIntObjectMap<E> createIntObjectMap(int size); + /** * Creates a {@link java.util.Set} with the specified initial <code>size</code>. * Modified: tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java 2008-08-11 16:45:18 UTC (rev 118) @@ -24,7 +24,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public interface IIntObjectMap<V> { Deleted: tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java 2008-08-11 16:45:18 UTC (rev 118) @@ -1,57 +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.utils; - -/** - * - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ - */ -public class IntObjectMap { - - private static final boolean _TROVE_AVAILABLE; - - static { - boolean available = false; - try { - // Probe if Trove is available. - Class.forName("gnu.trove.THashSet"); - available = true; - } - catch (Exception ex) { - - } - _TROVE_AVAILABLE = available; - } - - private IntObjectMap() { - // noop. - } - - public static <V> IIntObjectMap<V> create() { - return _TROVE_AVAILABLE ? new TroveIntObjectMap<V>() : new JavaIntObjectMap<V>(); - } - - public static <V> IIntObjectMap<V> create(int size) { - return _TROVE_AVAILABLE ? new TroveIntObjectMap<V>(size) : new JavaIntObjectMap<V>(size); - } -} Modified: tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java 2008-08-11 16:45:18 UTC (rev 118) @@ -38,6 +38,22 @@ final class JavaCollectionFactory implements ICollectionFactory { /* (non-Javadoc) + * @see org.tinytim.utils.ICollectionFactory#createIntObjectMap() + */ + @Override + public <E> IIntObjectMap<E> createIntObjectMap() { + return new JavaIntObjectMap<E>(); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.ICollectionFactory#createIntObjectMap(int) + */ + @Override + public <E> IIntObjectMap<E> createIntObjectMap(int size) { + return new JavaIntObjectMap<E>(size); + } + + /* (non-Javadoc) * @see org.tinytim.ICollectionFactory#createMap(int) */ public <K, V> Map<K, V> createMap(int size) { @@ -157,4 +173,36 @@ _map.clear(); } } + + private static final class JavaIntObjectMap<V> implements IIntObjectMap<V> { + + private final Map<Integer, V> _map; + + JavaIntObjectMap() { + _map = new HashMap<Integer, V>(); + } + + JavaIntObjectMap(int size) { + _map = new HashMap<Integer, V>(size); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.IIntObjectMap#get(int) + */ + public V get(int key) { + return _map.get(key); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.IIntObjectMap#put(int, java.lang.Object) + */ + public V put(int key, V value) { + return _map.put(Integer.valueOf(key), value); + } + + public void clear() { + _map.clear(); + } + + } } Deleted: tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java 2008-08-11 16:45:18 UTC (rev 118) @@ -1,62 +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.utils; - -import java.util.HashMap; -import java.util.Map; - -/** - * - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ - */ -final class JavaIntObjectMap<V> implements IIntObjectMap<V> { - - private final Map<Integer, V> _map; - - JavaIntObjectMap() { - _map = new HashMap<Integer, V>(); - } - - JavaIntObjectMap(int size) { - _map = new HashMap<Integer, V>(size); - } - - /* (non-Javadoc) - * @see org.tinytim.utils.IIntObjectMap#get(int) - */ - public V get(int key) { - return _map.get(key); - } - - /* (non-Javadoc) - * @see org.tinytim.utils.IIntObjectMap#put(int, java.lang.Object) - */ - public V put(int key, V value) { - return _map.put(Integer.valueOf(key), value); - } - - public void clear() { - _map.clear(); - } - -} Modified: tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java 2008-08-11 16:45:18 UTC (rev 118) @@ -22,6 +22,7 @@ import gnu.trove.THashMap; import gnu.trove.THashSet; +import gnu.trove.TIntObjectHashMap; import gnu.trove.TObjectIdentityHashingStrategy; import java.util.Map; @@ -37,6 +38,16 @@ */ final class TroveCollectionFactory implements ICollectionFactory { + @Override + public <E> IIntObjectMap<E> createIntObjectMap() { + return new TroveIntObjectMap<E>(); + } + + @Override + public <E> IIntObjectMap<E> createIntObjectMap(int size) { + return new TroveIntObjectMap<E>(size); + } + /* (non-Javadoc) * @see org.tinytim.ICollectionFactory#createMap(int) */ @@ -94,4 +105,35 @@ } + private static final class TroveIntObjectMap<V> implements IIntObjectMap<V> { + + private final TIntObjectHashMap<V> _map; + + TroveIntObjectMap() { + _map = new TIntObjectHashMap<V>(); + } + + TroveIntObjectMap(int size) { + _map = new TIntObjectHashMap<V>(size); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.IIntObjectMap#get(int) + */ + public V get(int key) { + return _map.get(key); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.IIntObjectMap#put(int, java.lang.Object) + */ + public V put(int key, V value) { + return _map.put(key, value); + } + + public void clear() { + _map.clear(); + } + + } } Deleted: tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java 2008-08-11 16:45:18 UTC (rev 118) @@ -1,61 +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.utils; - -import gnu.trove.TIntObjectHashMap; - -/** - * - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ - */ -final class TroveIntObjectMap<V> implements IIntObjectMap<V> { - - private final TIntObjectHashMap<V> _map; - - TroveIntObjectMap() { - _map = new TIntObjectHashMap<V>(); - } - - TroveIntObjectMap(int size) { - _map = new TIntObjectHashMap<V>(size); - } - - /* (non-Javadoc) - * @see org.tinytim.utils.IIntObjectMap#get(int) - */ - public V get(int key) { - return _map.get(key); - } - - /* (non-Javadoc) - * @see org.tinytim.utils.IIntObjectMap#put(int, java.lang.Object) - */ - public V put(int key, V value) { - return _map.put(key, value); - } - - public void clear() { - _map.clear(); - } - -} Modified: tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java 2008-08-11 16:45:18 UTC (rev 118) @@ -30,7 +30,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class WeakObjectRegistry<E> extends AbstractSet<E> { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-11 13:42:48
|
Revision: 117 http://tinytim.svn.sourceforge.net/tinytim/?rev=117&view=rev Author: lheuer Date: 2008-08-11 13:42:49 +0000 (Mon, 11 Aug 2008) Log Message: ----------- - Aligned C14N to tinyTiM 2 Modified Paths: -------------- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java Added Paths: ----------- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/LiteralCanonicalizer.java Modified: tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java =================================================================== --- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java 2008-08-11 13:01:22 UTC (rev 116) +++ tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java 2008-08-11 13:42:49 UTC (rev 117) @@ -28,9 +28,6 @@ import java.util.Collection; import java.util.Collections; import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.IdentityHashMap; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -38,29 +35,27 @@ import java.util.Set; import java.util.logging.Logger; -import org.tinytim.DuplicateRemovalUtils; -import org.tinytim.IConstruct; -import org.tinytim.IDatatypeAwareConstruct; -import org.tinytim.IReifiable; -import org.tinytim.ITyped; -import org.tinytim.TopicMapImpl; -import org.tinytim.index.ITypeInstanceIndex; +import org.tinytim.core.DuplicateRemovalUtils; +import org.tinytim.core.ILiteralAware; +import org.tinytim.core.TopicMapImpl; +import org.tinytim.utils.CollectionFactory; import org.tinytim.voc.TMDM; +import org.tinytim.voc.XSD; import org.tmapi.core.Association; -import org.tmapi.core.AssociationRole; -import org.tmapi.core.DuplicateSourceLocatorException; +import org.tmapi.core.Construct; +import org.tmapi.core.DatatypeAware; import org.tmapi.core.Locator; -import org.tmapi.core.MergeException; -import org.tmapi.core.ModelConstraintException; +import org.tmapi.core.Name; import org.tmapi.core.Occurrence; -import org.tmapi.core.ScopedObject; -import org.tmapi.core.TMAPIException; +import org.tmapi.core.Reifiable; +import org.tmapi.core.Role; +import org.tmapi.core.Scoped; import org.tmapi.core.Topic; import org.tmapi.core.TopicInUseException; import org.tmapi.core.TopicMap; -import org.tmapi.core.TopicMapObject; -import org.tmapi.core.TopicName; +import org.tmapi.core.Typed; import org.tmapi.core.Variant; +import org.tmapi.index.TypeInstanceIndex; import org.xml.sax.Attributes; import org.xml.sax.helpers.AttributesImpl; @@ -84,10 +79,7 @@ * </p> * <p> * The canonicalizer IS NOT a generic TMAPI-compatible implementation. It - * requires tinyTiM. The canonicalizer requires that the property - * {@link org.tinytim.Property#XTM10_REIFICATION} is set to <tt>false</tt> and - * that the property {@link org.tinytim.Property#INHERIT_NAME_SCOPE} is enabled - * (set to <tt>true</tt>). + * requires tinyTiM. * </p> * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ @@ -96,31 +88,29 @@ private static final Logger LOG = Logger.getLogger(Canonicalizer.class.getName()); - private static final String _XSD_ANY_URI = "http://www.w3.org/2001/XMLSchema#anyURI"; + private static final Role[] _EMPTY_ROLES = new Role[0]; - private static final AssociationRole[] _EMPTY_ROLES = new AssociationRole[0]; - private Topic _type; private Topic _instance; private Topic _typeInstance; private CXTMWriter _out; private final String _normBase; - private Map<TopicMapObject, Integer> _construct2Id; - private Map<Topic, List<AssociationRole>> _topic2Roles; - private Map<String, String> _locator2Norm; + private Map<Construct, Integer> _construct2Id; + private Map<Topic, List<Role>> _topic2Roles; + private Map<Locator, String> _locator2Norm; private Comparator<Topic> _topicComparator; private Comparator<Association> _assocComparator; - private Comparator<AssociationRole> _roleComparator; + private Comparator<Role> _roleComparator; private Comparator<Occurrence> _occComparator; - private Comparator<TopicName> _nameComparator; + private Comparator<Name> _nameComparator; private Comparator<Variant> _variantComparator; private Comparator<Set<Locator>> _locSetComparator; private Comparator<Locator> _locComparator; private Comparator<Set<Topic>> _scopeComparator; - private Map<Association, AssociationRole[]> _assoc2Roles; + private Map<Association, Role[]> _assoc2Roles; /** * Creates a canonicalizer. @@ -162,11 +152,11 @@ */ public void write(TopicMap topicMap) throws IOException { DuplicateRemovalUtils.removeDuplicates(topicMap); - _construct2Id = new IdentityHashMap<TopicMapObject, Integer>(); - _locator2Norm = new HashMap<String, String>(); - _assoc2Roles = new IdentityHashMap<Association, AssociationRole[]>(); - _topic2Roles = new IdentityHashMap<Topic, List<AssociationRole>>(); - ITypeInstanceIndex typeInstanceIndex = ((TopicMapImpl) topicMap).getIndexManager().getTypeInstanceIndex(); + _construct2Id = CollectionFactory.createIdentityMap(); + _locator2Norm = CollectionFactory.createIdentityMap(); + _assoc2Roles = CollectionFactory.createIdentityMap(); + _topic2Roles = CollectionFactory.createIdentityMap(); + TypeInstanceIndex typeInstanceIndex = ((TopicMapImpl) topicMap).getIndexManager().getTypeInstanceIndex(); if (!typeInstanceIndex.isAutoUpdated()) { typeInstanceIndex.reindex(); } @@ -176,7 +166,7 @@ _createIndex(topics, assocs); _out.startDocument(); AttributesImpl attrs = new AttributesImpl(); - _addReifier(attrs, (IReifiable)topicMap); + _addReifier(attrs, topicMap); _out.startElement("topicMap", attrs); _out.newline(); _writeItemIdentifiers(topicMap); @@ -208,8 +198,7 @@ * @param idx A (upto date) type instance index. * @return All topics which must be included into the output. */ - @SuppressWarnings("unchecked") - private Topic[] _fetchTopics(TopicMap topicMap, ITypeInstanceIndex idx) { + private Topic[] _fetchTopics(TopicMap topicMap, TypeInstanceIndex idx) { Collection<Topic> types = idx.getTopicTypes(); if (types.isEmpty()) { Set<Topic> topics = topicMap.getTopics(); @@ -255,8 +244,7 @@ * @param idx A (upto date) type instance index. * @return An unsorted array of associations which must be included into the output. */ - @SuppressWarnings("unchecked") - private Association[] _fetchAssociations(TopicMap tm, ITypeInstanceIndex idx) { + private Association[] _fetchAssociations(TopicMap tm, TypeInstanceIndex idx) { Collection<Topic> types = idx.getTopicTypes(); if (types.isEmpty()) { Set<Association> assocs = tm.getAssociations(); @@ -281,7 +269,6 @@ * @param topics An array of topics. * @param assocs An array of associations. */ - @SuppressWarnings("unchecked") private void _createIndex(Topic[] topics, Association[] assocs) { Arrays.sort(topics, _topicComparator); Topic topic = null; @@ -294,8 +281,8 @@ for (int i=0; i < assocs.length; i++) { assoc = assocs[i]; _construct2Id.put(assoc, Integer.valueOf(i+1)); - Set<AssociationRole> roles_ = assoc.getAssociationRoles(); - AssociationRole[] roles = roles_.toArray(new AssociationRole[roles_.size()]); + Set<Role> roles_ = assoc.getRoles(); + Role[] roles = roles_.toArray(new Role[roles_.size()]); Arrays.sort(roles, _roleComparator); _assoc2Roles.put(assoc, roles); for (int j=0; j < roles.length; j++) { @@ -310,8 +297,8 @@ * @param assoc The association to retrieve the roles from. * @return A (maybe empty) sorted array of roles. */ - private AssociationRole[] _getRoles(Association assoc) { - AssociationRole[] roles = _assoc2Roles.get(assoc); + private Role[] _getRoles(Association assoc) { + Role[] roles = _assoc2Roles.get(assoc); return roles != null ? roles : _EMPTY_ROLES; } @@ -321,10 +308,9 @@ * @param topic The topic to retrieve the names from. * @return A (maybe empty) sorted array of names. */ - @SuppressWarnings("unchecked") - private TopicName[] _getNames(Topic topic) { - Set<TopicName> names_ = topic.getTopicNames(); - TopicName[] names = names_.toArray(new TopicName[names_.size()]); + private Name[] _getNames(Topic topic) { + Set<Name> names_ = topic.getNames(); + Name[] names = names_.toArray(new Name[names_.size()]); Arrays.sort(names, _nameComparator); return names; } @@ -335,8 +321,7 @@ * @param name The name to retrieve the variants from. * @return A (maybe empty) sorted array of variants. */ - @SuppressWarnings("unchecked") - private Variant[] _getVariants(TopicName name) { + private Variant[] _getVariants(Name name) { Set<Variant> variants_ = name.getVariants(); Variant[] variants = variants_.toArray(new Variant[variants_.size()]); Arrays.sort(variants, _variantComparator); @@ -349,7 +334,6 @@ * @param topic The topic to retrieve the occurrences from. * @return A (maybe emtpy) sorted array of occurrences. */ - @SuppressWarnings("unchecked") private Occurrence[] _getOccurrences(Topic topic) { Set<Occurrence> occs_ = topic.getOccurrences(); Occurrence[] occs = occs_.toArray(new Occurrence[occs_.size()]); @@ -367,7 +351,7 @@ * @param tmo The Topic Maps construct to return the index of. * @return The index of the Topic Maps construct. */ - private int _indexOf(TopicMapObject tmo) { + private int _indexOf(Construct tmo) { return _construct2Id.get(tmo).intValue(); } @@ -377,7 +361,6 @@ * @param topic The topic to serialize. * @throws IOException If an error occurs. */ - @SuppressWarnings("unchecked") private void _writeTopic(Topic topic) throws IOException { AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute("", "number", null, null, "" +_indexOf(topic)); @@ -386,7 +369,7 @@ _writeLocatorSet("subjectIdentifiers", topic.getSubjectIdentifiers()); _writeLocatorSet("subjectLocators", topic.getSubjectLocators()); _writeItemIdentifiers(topic); - TopicName[] names = _getNames(topic); + Name[] names = _getNames(topic); for (int i=0; i < names.length; i++) { _writeName(names[i], i+1); } @@ -394,18 +377,18 @@ for (int i=0; i < occs.length; i++) { _writeOccurrence(occs[i], i+1); } - Set<AssociationRole> roles_ = new HashSet<AssociationRole>(topic.getRolesPlayed()); - List<AssociationRole> alienRoles = _topic2Roles.get(topic); + List<Role> roles_ = new ArrayList<Role>(topic.getRolesPlayed()); + List<Role> alienRoles = _topic2Roles.get(topic); if (alienRoles != null) { roles_.addAll(alienRoles); } - AssociationRole[] roles = roles_.toArray(new AssociationRole[roles_.size()]); + Role[] roles = roles_.toArray(new Role[roles_.size()]); Arrays.sort(roles, _roleComparator); AttributesImpl roleAttrs = new AttributesImpl(); StringBuilder sb = new StringBuilder(); for (int i=0; i < roles.length; i++) { sb.append("association.") - .append(_indexOf(roles[i].getAssociation())) + .append(_indexOf(roles[i].getParent())) .append(".role.") .append(_indexOf(roles[i])); roleAttrs.addAttribute("", "ref", null, null, sb.toString()); @@ -425,18 +408,17 @@ * @param assoc The association to serialize. * @throws IOException If an error occurs. */ - @SuppressWarnings("unchecked") private void _writeAssociation(Association assoc) throws IOException { _out.startElement("association", _attributes(assoc, _indexOf(assoc))); _out.newline(); - _writeType((ITyped) assoc); - for (AssociationRole role: _getRoles(assoc)) { + _writeType(assoc); + for (Role role: _getRoles(assoc)) { _out.startElement("role", _attributes(role, _indexOf(role))); _out.newline(); _out.startElement("player", _topicRef(role.getPlayer())); _out.endElement("player"); _out.newline(); - _writeType((ITyped) role); + _writeType(role); _writeItemIdentifiers(role); _out.endElement("role"); _out.newline(); @@ -456,8 +438,8 @@ private void _writeOccurrence(Occurrence occ, int pos) throws IOException { _out.startElement("occurrence", _attributes(occ, pos)); _out.newline(); - _writeDatatyped((IDatatypeAwareConstruct) occ); - _writeType((ITyped) occ); + _writeDatatyped(occ); + _writeType(occ); _writeScope(occ); _writeItemIdentifiers(occ); _out.endElement("occurrence"); @@ -470,19 +452,15 @@ * @param obj The construct to serialize. * @throws IOException If an error occurs. */ - private void _writeDatatyped(IDatatypeAwareConstruct obj) throws IOException { - String value = obj.getValue2(); - String datatype = obj.getDatatype().getReference(); - //TODO: Handle xsd:decimal, xsd:integer, xsd:date, xsd:dateTime xsd:anyType(?!?) - if (_XSD_ANY_URI.equals(datatype)) { - value = _normalizeLocator(value); - } + private void _writeDatatyped(DatatypeAware obj) throws IOException { + String value = XSD.ANY_URI.equals(obj.getDatatype()) ? _normalizeLocator(obj.locatorValue()) + : LiteralCanonicalizer.canonicalize((ILiteralAware) obj); _out.startElement("value"); _out.characters(value); _out.endElement("value"); _out.newline(); _out.startElement("datatype"); - _out.characters(_normalizeLocator(datatype)); + _out.characters(_normalizeLocator(obj.getDatatype())); _out.endElement("datatype"); _out.newline(); } @@ -493,14 +471,14 @@ * @param name The name to serialize. * @throws IOException If an error occurs. */ - private void _writeName(TopicName name, int pos) throws IOException { + private void _writeName(Name name, int pos) throws IOException { _out.startElement("name", _attributes(name, pos)); _out.newline(); _out.startElement("value"); _out.characters(name.getValue()); _out.endElement("value"); _out.newline(); - _writeType((ITyped) name); + _writeType(name); _writeScope(name); Variant[] variants = _getVariants(name); Variant variant = null; @@ -508,7 +486,7 @@ variant = variants[i]; _out.startElement("variant", _attributes(variant, i+1)); _out.newline(); - _writeDatatyped((IDatatypeAwareConstruct) variant); + _writeDatatyped(variant); _writeScope(variant); _writeItemIdentifiers(variant); _out.endElement("variant"); @@ -526,7 +504,7 @@ * serialized. * @throws IOException If an error occurs. */ - private void _writeType(ITyped typed) throws IOException { + private void _writeType(Typed typed) throws IOException { Topic type = typed.getType(); if (type == null) { _reportInvalid("The type of " + typed + " is null"); @@ -544,8 +522,7 @@ * @param scoped The scoped Topic Maps construct. * @throws IOException If an error occurs. */ - @SuppressWarnings("unchecked") - private void _writeScope(ScopedObject scoped) throws IOException { + private void _writeScope(Scoped scoped) throws IOException { Set<Topic> scope = scoped.getScope(); if (scope.isEmpty()) { return; @@ -573,7 +550,7 @@ */ private void _writeLocator(Locator loc) throws IOException { _out.startElement("locator"); - _out.characters(_normalizeLocator(loc.getReference())); + _out.characters(_normalizeLocator(loc)); _out.endElement("locator"); _out.newline(); } @@ -584,9 +561,8 @@ * @param tmo The Topic Maps construct to take the item identifiers from. * @throws IOException If an error occurs. */ - @SuppressWarnings("unchecked") - private void _writeItemIdentifiers(TopicMapObject tmo) throws IOException { - _writeLocatorSet("itemIdentifiers", tmo.getSourceLocators()); + private void _writeItemIdentifiers(Construct tmo) throws IOException { + _writeLocatorSet("itemIdentifiers", tmo.getItemIdentifiers()); } /** @@ -638,9 +614,9 @@ * @return Attributes which contain a reference to the reifier (if any) and * the number of the provided Topic Maps construct. */ - private Attributes _attributes(TopicMapObject reifiable, int i) { + private Attributes _attributes(Reifiable reifiable, int i) { AttributesImpl attrs = new AttributesImpl(); - _addReifier(attrs, (IReifiable)reifiable); + _addReifier(attrs, reifiable); attrs.addAttribute("", "number", null, null, "" + i); return attrs; } @@ -653,7 +629,7 @@ * @param attrs The attributes. * @param reifiable The reifiable Topic Maps construct. */ - private void _addReifier(AttributesImpl attrs, IReifiable reifiable) { + private void _addReifier(AttributesImpl attrs, Reifiable reifiable) { Topic reifier = reifiable.getReifier(); if (reifier != null) { attrs.addAttribute("", "reifier", null, null, "" + _indexOf(reifier)); @@ -666,28 +642,29 @@ * @param locator The locator to normalize. * @return A normalized representation of the locator. */ - private String _normalizeLocator(String locator) { + private String _normalizeLocator(final Locator locator) { String normLoc = _locator2Norm.get(locator); if (normLoc != null) { return normLoc; } - normLoc = locator; - if (locator.startsWith(_normBase)) { - normLoc = locator.substring(_normBase.length()); + final String ref = locator.getReference(); + normLoc = ref; + if (ref.startsWith(_normBase)) { + normLoc = ref.substring(_normBase.length()); } else { int i = 0; int slashPos = -1; - final int max = _normBase.length() < locator.length() ? _normBase.length() - : locator.length(); - while(i < max && _normBase.charAt(i) == locator.charAt(i)) { + final int max = _normBase.length() < ref.length() ? _normBase.length() + : ref.length(); + while(i < max && _normBase.charAt(i) == ref.charAt(i)) { if (_normBase.charAt(i) == '/') { slashPos = i; } i++; } if (slashPos > -1) { - normLoc = locator.substring(slashPos); + normLoc = ref.substring(slashPos); } } if (normLoc.startsWith("/")) { @@ -741,7 +718,6 @@ private final class TopicComparator implements Comparator<Topic> { - @SuppressWarnings("unchecked") public int compare(Topic o1, Topic o2) { if (o1 == o2) { return 0; @@ -758,7 +734,7 @@ if (res == 0) { res = _locSetComparator.compare(o1.getSubjectLocators(), o2.getSubjectLocators()); if (res == 0) { - res = _locSetComparator.compare(o1.getSourceLocators(), o2.getSourceLocators()); + res = _locSetComparator.compare(o1.getItemIdentifiers(), o2.getItemIdentifiers()); } } return res; @@ -791,7 +767,7 @@ * first argument is less than, equal to, or greater than the * second. */ - int compareType(ITyped o1, ITyped o2) { + int compareType(Typed o1, Typed o2) { return _topicComparator.compare(o1.getType(), o2.getType()); } /** @@ -804,8 +780,7 @@ * first argument is less than, equal to, or greater than the * second. */ - @SuppressWarnings("unchecked") - int compareScope(ScopedObject o1, ScopedObject o2) { + int compareScope(Scoped o1, Scoped o2) { return _scopeComparator.compare(o1.getScope(), o2.getScope()); } } @@ -824,8 +799,8 @@ * first argument is less than, equal to, or greater than the * second. */ - int _compareValueDatatype(IDatatypeAwareConstruct o1, IDatatypeAwareConstruct o2) { - int res = compareString(o1.getValue2(), o2.getValue2()); + int _compareValueDatatype(DatatypeAware o1, DatatypeAware o2) { + int res = compareString(o1.getValue(), o2.getValue()); if (res == 0) { res = compareString(o1.getDatatype().getReference(), o2.getDatatype().getReference()); } @@ -842,20 +817,19 @@ */ private final class AssociationComparator extends AbstractComparator<Association> { - private Comparator<Set<AssociationRole>> _roleSetComparator; + private Comparator<Set<Role>> _roleSetComparator; AssociationComparator() { _roleSetComparator = new RoleSetComparator(); } - @SuppressWarnings("unchecked") public int compare(Association o1, Association o2) { if (o1 == o2) { return 0; } - int res = compareType((ITyped) o1, (ITyped) o2); + int res = compareType(o1, o2); if (res == 0) { - res = _roleSetComparator.compare(o1.getAssociationRoles(), o2.getAssociationRoles()); + res = _roleSetComparator.compare(o1.getRoles(), o2.getRoles()); if (res == 0) { res = compareScope(o1, o2); } @@ -869,15 +843,15 @@ * is meant to be used for roles where the parent is known to be equal or * unequal. */ - private class RoleIgnoreParentComparator extends AbstractComparator<AssociationRole> { + private class RoleIgnoreParentComparator extends AbstractComparator<Role> { - public int compare(AssociationRole o1, AssociationRole o2) { + public int compare(Role o1, Role o2) { if (o1 == o2) { return 0; } int res = _topicComparator.compare(o1.getPlayer(), o2.getPlayer()); if (res == 0) { - res = compareType((ITyped) o1, (ITyped) o2); + res = compareType(o1, o2); } return res; } @@ -891,13 +865,13 @@ */ private final class RoleComparator extends RoleIgnoreParentComparator { - public int compare(AssociationRole o1, AssociationRole o2) { + public int compare(Role o1, Role o2) { if (o1 == o2) { return 0; } int res = super.compare(o1, o2); if (res == 0) { - res = _assocComparator.compare(o1.getAssociation(), o2.getAssociation()); + res = _assocComparator.compare(o1.getParent(), o2.getParent()); } return res; } @@ -917,9 +891,9 @@ if (o1 == o2) { return 0; } - int res = _compareValueDatatype((IDatatypeAwareConstruct) o1, (IDatatypeAwareConstruct) o2); + int res = _compareValueDatatype(o1, o2); if (res == 0) { - res = compareType((ITyped) o1, (ITyped) o2); + res = compareType(o1, o2); if (res == 0) { res = compareScope(o1, o2); } @@ -936,15 +910,15 @@ * 3. [scope] * 4. [parent] */ - private final class NameComparator extends AbstractComparator<TopicName> { + private final class NameComparator extends AbstractComparator<Name> { - public int compare(TopicName o1, TopicName o2) { + public int compare(Name o1, Name o2) { if (o1 == o2) { return 0; } int res = compareString(o1.getValue(), o2.getValue()); if (res == 0) { - res = compareType((ITyped) o1, (ITyped) o2); + res = compareType(o1, o2); if (res == 0) { res = compareScope(o1, o2); } @@ -966,7 +940,7 @@ if (o1 == o2) { return 0; } - int res = _compareValueDatatype((IDatatypeAwareConstruct) o1, (IDatatypeAwareConstruct) o2); + int res = _compareValueDatatype(o1, o2); if (res == 0) { res = compareScope(o1, o2); } @@ -1010,7 +984,7 @@ /** * Compares role sets. The parent of the roles is ignored! */ - private final class RoleSetComparator extends AbstractSetComparator<AssociationRole> { + private final class RoleSetComparator extends AbstractSetComparator<Role> { private RoleIgnoreParentComparator _roleCmp; @@ -1019,11 +993,11 @@ } @Override - int compareContent(Set<AssociationRole> o1, Set<AssociationRole> o2, + int compareContent(Set<Role> o1, Set<Role> o2, int size) { int res = 0; - AssociationRole[] roles1 = o1.toArray(new AssociationRole[size]); - AssociationRole[] roles2 = o2.toArray(new AssociationRole[size]); + Role[] roles1 = o1.toArray(new Role[size]); + Role[] roles2 = o2.toArray(new Role[size]); Arrays.sort(roles1, _roleCmp); Arrays.sort(roles2, _roleCmp); for (int i=0; i < size && res == 0; i++) { @@ -1082,7 +1056,7 @@ if (o1 == o2) { return 0; } - return _normalizeLocator(o1.getReference()).compareTo(_normalizeLocator(o2.getReference())); + return _normalizeLocator(o1).compareTo(_normalizeLocator(o2)); } } @@ -1093,7 +1067,6 @@ * of a topic, as associations. */ - @SuppressWarnings("unchecked") private final class TypeInstanceTopic implements Topic { private final Set<Locator> _sids; @@ -1106,47 +1079,58 @@ return _sids; } - public void addSourceLocator(Locator arg0) throws DuplicateSourceLocatorException, MergeException { } - public void addSubjectIdentifier(Locator arg0) throws MergeException {} - public void addSubjectLocator(Locator arg0) throws MergeException, ModelConstraintException {} + public void addItemIdentifier(Locator arg0) { } + public void addSubjectIdentifier(Locator arg0) {} + public void addSubjectLocator(Locator arg0) {} public void addType(Topic arg0) {} - public Occurrence createOccurrence(String arg0, Topic arg1, Collection arg2) { return null; } - public Occurrence createOccurrence(Locator arg0, Topic arg1, Collection arg2) { return null; } - public TopicName createTopicName(String arg0, Collection arg1) throws MergeException { return null; } - public TopicName createTopicName(String arg0, Topic arg1, Collection arg2) throws UnsupportedOperationException, MergeException { return null; } - public Set getOccurrences() { return Collections.emptySet(); } - public Set getReified() { return null; } - public Set getRolesPlayed() { return Collections.emptySet(); } - public Set getSubjectLocators() { return Collections.emptySet(); } - public Set getTopicNames() { return Collections.emptySet(); } - public Set getTypes() { return null; } - public void mergeIn(Topic arg0) throws MergeException { } + public Set<Occurrence> getOccurrences() { return Collections.emptySet(); } + public Reifiable getReified() { return null; } + public Set<Role> getRolesPlayed() { return Collections.emptySet(); } + public Set<Locator> getSubjectLocators() { return Collections.emptySet(); } + public Set<Name> getNames() { return Collections.emptySet(); } + public Set<Topic> getTypes() { return null; } + public void mergeIn(Topic arg0) { } public void remove() throws TopicInUseException { } public void removeSubjectIdentifier(Locator arg0) { } public void removeSubjectLocator(Locator arg0) { } public void removeType(Topic arg0) { } - public String getObjectId() { return null; } - public Set getSourceLocators() { return Collections.emptySet(); } + public String getId() { return null; } + public Set<Locator> getItemIdentifiers() { return Collections.emptySet(); } public TopicMap getTopicMap() { return null; } - public void removeSourceLocator(Locator arg0) { } + public void removeItemIdentifier(Locator arg0) { } + public Name createName(String value, Collection<Topic> scope) { return null; } + public Name createName(String value, Topic... scope) {return null;} + public Name createName(Topic type, String value, Collection<Topic> scope) { return null; } + public Name createName(Topic type, String value, Topic... scope) { return null; } + public Occurrence createOccurrence(Topic type, Locator value, Collection<Topic> scope) { return null;} + public Occurrence createOccurrence(Topic type, Locator value, Topic... scope) {return null;} + public Occurrence createOccurrence(Topic type, String value, Collection<Topic> scope) { return null; } + public Occurrence createOccurrence(Topic type, String value, Locator datatype, Collection<Topic> scope) { return null; } + public Occurrence createOccurrence(Topic type, String value, Locator datatype, Topic... scope) { return null; } + public Occurrence createOccurrence(Topic type, String value, Topic... scope) { return null; } + public Set<Name> getNames(Topic type) { return null; } + public Set<Occurrence> getOccurrences(Topic type) { return null;} + public TopicMap getParent() { return null; } + public Set<Role> getRolesPlayed(Topic type, Topic assocType) { return null; } + public Set<Role> getRolesPlayed(Topic type) { return null; } + } /** * Used to represent type-instance relationships which are modelled as * [type] property of topics. */ - @SuppressWarnings("unchecked") - private final class TypeInstanceAssociation implements Association, IReifiable, ITyped { + private final class TypeInstanceAssociation implements Association { - final Set<AssociationRole> _roles; + final Set<Role> _roles; TypeInstanceAssociation(Topic type, Topic instance) { - AssociationRole typeRole = new TypeInstanceRole(this, _type, type); - AssociationRole instanceRole = new TypeInstanceRole(this, _instance, instance); + Role typeRole = new TypeInstanceRole(this, _type, type); + Role instanceRole = new TypeInstanceRole(this, _instance, instance); _roles = new TypeInstanceRoleSet(typeRole, instanceRole); } - public Set<AssociationRole> getAssociationRoles() { + public Set<Role> getRoles() { return _roles; } @@ -1154,30 +1138,28 @@ return _typeInstance; } + public Set<Topic> getRoleTypes() { return null; } + public Set<Role> getRoles(Topic type) { return null; } public void setReifier(Topic reifier) { } public void addItemIdentifier(Locator itemIdentifier) { } public Set<Locator> getItemIdentifiers() { return Collections.emptySet(); } - public IConstruct getParent() { return null; } + public TopicMap getParent() { return null; } public void removeItemIdentifier(Locator itemIdentifier) { } - public AssociationRole createAssociationRole(Topic arg0, Topic arg1) { return null; } + public Role createRole(Topic arg0, Topic arg1) { return null; } public Topic getReifier() { return null; } - public void remove() throws TMAPIException {} + public void remove() {} public void setType(Topic arg0) {} - public void addScopingTopic(Topic arg0) {} - public Set getScope() { return Collections.emptySet(); } - public void removeScopingTopic(Topic arg0) {} - public void addSourceLocator(Locator arg0) throws DuplicateSourceLocatorException {} - public String getObjectId() { return null; } - public Set getSourceLocators() { return Collections.emptySet(); } + public void addTheme(Topic arg0) {} + public Set<Topic> getScope() { return Collections.emptySet(); } + public void removeTheme(Topic arg0) {} + public String getId() { return null; } public TopicMap getTopicMap() { return null; } - public void removeSourceLocator(Locator arg0) {} } /** * Immutable association role. */ - @SuppressWarnings("unchecked") - private class TypeInstanceRole implements AssociationRole , IReifiable, ITyped { + private class TypeInstanceRole implements Role { private final Topic _type; private final Topic _player; private final Association _parent; @@ -1186,9 +1168,9 @@ _type = type; _player = player; _parent = parent; - List<AssociationRole> roles = _topic2Roles.get(player); + List<Role> roles = _topic2Roles.get(player); if (roles == null) { - roles = new ArrayList<AssociationRole>(); + roles = new ArrayList<Role>(); _topic2Roles.put(player, roles); } roles.add(this); @@ -1205,35 +1187,32 @@ public void setReifier(Topic reifier) { } public void addItemIdentifier(Locator itemIdentifier) { } public Set<Locator> getItemIdentifiers() { return Collections.emptySet(); } - public IConstruct getParent() { return (IConstruct) _parent; } + public Association getParent() { return _parent; } public void removeItemIdentifier(Locator itemIdentifier) { } public Association getAssociation() { return _parent; } public Topic getReifier() { return null; } - public void remove() throws TMAPIException {} + public void remove() {} public void setPlayer(Topic arg0) {} public void setType(Topic arg0) {} - public void addSourceLocator(Locator arg0) throws DuplicateSourceLocatorException {} - public String getObjectId() { return null; } - public Set getSourceLocators() { return Collections.emptySet(); } + public String getId() { return null; } public TopicMap getTopicMap() { return null; } - public void removeSourceLocator(Locator arg0) {} } /** * Immutable 'set' of two roles. */ - private static class TypeInstanceRoleSet extends AbstractSet<AssociationRole> { + private static class TypeInstanceRoleSet extends AbstractSet<Role> { - private final AssociationRole _role1; - private final AssociationRole _role2; + private final Role _role1; + private final Role _role2; - TypeInstanceRoleSet(AssociationRole role1, AssociationRole role2) { + TypeInstanceRoleSet(Role role1, Role role2) { _role1 = role1; _role2 = role2; } @Override - public Iterator<AssociationRole> iterator() { + public Iterator<Role> iterator() { return new TypeInstanceRoleSetIterator(); } @@ -1242,7 +1221,7 @@ return 2; } - private class TypeInstanceRoleSetIterator implements Iterator<AssociationRole> { + private class TypeInstanceRoleSetIterator implements Iterator<Role> { private int _idx; @@ -1250,7 +1229,7 @@ return _idx < 2; } - public AssociationRole next() { + public Role next() { if (_idx > 1) { throw new NoSuchElementException(); } Added: tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/LiteralCanonicalizer.java =================================================================== --- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/LiteralCanonicalizer.java (rev 0) +++ tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/LiteralCanonicalizer.java 2008-08-11 13:42:49 UTC (rev 117) @@ -0,0 +1,57 @@ +/* + * 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.cxtm; + +import org.tinytim.core.ILiteral; +import org.tinytim.core.ILiteralAware; +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 LiteralCanonicalizer { + + private LiteralCanonicalizer () { + // noop. + } + + public static String canonicalize(final ILiteralAware obj) { + final ILiteral lit = obj.getLiteral(); + final String value = lit.getValue(); + final Locator datatype = lit.getDatatype(); + if (datatype == XSD.ANY_URI || datatype == XSD.STRING) { + return lit.getValue(); + } + else if (datatype == XSD.DECIMAL || datatype == XSD.INT || datatype == XSD.INTEGER) { + if (value.charAt(0) == '+') { + return value.substring(1); + } + return value; + } + return lit.getValue(); + } + + +} Property changes on: tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/LiteralCanonicalizer.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-08-11 13:01:23
|
Revision: 116 http://tinytim.svn.sourceforge.net/tinytim/?rev=116&view=rev Author: lheuer Date: 2008-08-11 13:01:22 +0000 (Mon, 11 Aug 2008) Log Message: ----------- made a copy Added Paths: ----------- tinytim-cxtm/tags/release-1_5_0beta/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-11 12:59:59
|
Revision: 115 http://tinytim.svn.sourceforge.net/tinytim/?rev=115&view=rev Author: lheuer Date: 2008-08-11 13:00:06 +0000 (Mon, 11 Aug 2008) Log Message: ----------- - Updated build file to tinyTiM 1.5beta Modified Paths: -------------- tinytim-cxtm/trunk/build.xml Modified: tinytim-cxtm/trunk/build.xml =================================================================== --- tinytim-cxtm/trunk/build.xml 2008-08-11 12:47:57 UTC (rev 114) +++ tinytim-cxtm/trunk/build.xml 2008-08-11 13:00:06 UTC (rev 115) @@ -29,7 +29,7 @@ <property name="lib.junit" value="${dir.lib}/junit-4.4.jar"/> <property name="lib.tmapi" value="${dir.lib}/tmapi-1_0SP1.jar"/> - <property name="lib.tinytim" value="${dir.lib}/tinytim-1.5.0alpha2.jar"/> + <property name="lib.tinytim" value="${dir.lib}/tinytim-1.5.0beta.jar"/> <target name="help"> <echo message="-------------------------"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-11 12:47:51
|
Revision: 114 http://tinytim.svn.sourceforge.net/tinytim/?rev=114&view=rev Author: lheuer Date: 2008-08-11 12:47:57 +0000 (Mon, 11 Aug 2008) Log Message: ----------- - Removed tinytim2 branches - Updated CHANGES.txt Modified Paths: -------------- tinytim-cxtm/trunk/CHANGES.txt Removed Paths: ------------- tinytim-cxtm/branches/tinytim2/ Modified: tinytim-cxtm/trunk/CHANGES.txt =================================================================== --- tinytim-cxtm/trunk/CHANGES.txt 2008-08-11 12:26:15 UTC (rev 113) +++ tinytim-cxtm/trunk/CHANGES.txt 2008-08-11 12:47:57 UTC (rev 114) @@ -2,7 +2,7 @@ Changes Log =========== -1.5.0 beta (08.08.2008) +1.5.0 beta (11.08.2008) ----------------------- * Fixed bug #1971341 (Item identifiers of roles are omitted) * Minor improvements This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-11 12:26:17
|
Revision: 113 http://tinytim.svn.sourceforge.net/tinytim/?rev=113&view=rev Author: lheuer Date: 2008-08-11 12:26:15 +0000 (Mon, 11 Aug 2008) Log Message: ----------- Updated test suite Modified Paths: -------------- tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java tinytim/trunk/src/test/java/org/tinytim/core/TestDuplicateRemovalUtils.java tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java tinytim/trunk/src/test/java/org/tinytim/core/TestTopicMapSystemFactoryImpl.java tinytim/trunk/src/test/java/org/tinytim/core/TestTopicUtils.java tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java Added Paths: ----------- tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java Modified: tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2008-08-11 12:21:38 UTC (rev 112) +++ tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2008-08-11 12:26:15 UTC (rev 113) @@ -39,6 +39,7 @@ TestSuite suite = new TestSuite(); suite.addTestSuite(TestDuplicateRemovalUtils.class); suite.addTestSuite(TestIRI.class); + suite.addTestSuite(TestScope.class); suite.addTestSuite(TestLiteral.class); suite.addTestSuite(TestItemIdentifierConstraint.class); suite.addTestSuite(TestSignatureGenerator.class); Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestDuplicateRemovalUtils.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestDuplicateRemovalUtils.java 2008-08-11 12:21:38 UTC (rev 112) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestDuplicateRemovalUtils.java 2008-08-11 12:26:15 UTC (rev 113) @@ -34,8 +34,8 @@ public class TestDuplicateRemovalUtils extends TinyTimTestCase { public void testTopicRemoveNames() { - Topic topic = _tm.createTopic(); - Topic nameType = _tm.createTopic(); + Topic topic = createTopic(); + Topic nameType = createTopic(); Name name1 = topic.createName(nameType, "tinyTiM"); Name name2 = topic.createName(nameType, "tinyTiM"); assertEquals(nameType, name1.getType()); @@ -52,12 +52,12 @@ } public void testTopicRemoveNames2() { - Topic topic = _tm.createTopic(); - Topic nameType = _tm.createTopic(); + Topic topic = createTopic(); + Topic nameType = createTopic(); Name name1 = topic.createName(nameType, "tinyTiM"); Name name2 = topic.createName(nameType, "tinyTiM"); - Locator iid1 = _tm.createLocator("http://example.org/iid-1"); - Locator iid2 = _tm.createLocator("http://example.org/iid-2"); + Locator iid1 = createLocator("http://example.org/iid-1"); + Locator iid2 = createLocator("http://example.org/iid-2"); name1.addItemIdentifier(iid1); name2.addItemIdentifier(iid2); assertEquals(2, topic.getNames().size()); @@ -73,10 +73,10 @@ } public void testTopicRemoveNames3() { - Topic topic = _tm.createTopic(); - Topic theme1 = _tm.createTopic(); - Topic theme2 = _tm.createTopic(); - Topic nameType = _tm.createTopic(); + Topic topic = createTopic(); + Topic theme1 = createTopic(); + Topic theme2 = createTopic(); + Topic nameType = createTopic(); Name name1 = topic.createName(nameType, "tinyTiM", theme1, theme2); Name name2 = topic.createName(nameType, "tinyTiM", theme2, theme1); assertEquals(2, name1.getScope().size()); @@ -91,9 +91,9 @@ } public void testRemoveRoles() { - Association assoc = _tm.createAssociation(_tm.createTopic()); - Topic type = _tm.createTopic(); - Topic player = _tm.createTopic(); + Association assoc = createAssociation(); + Topic type = createTopic(); + Topic player = createTopic(); assoc.createRole(type, player); assoc.createRole(type, player); assertEquals(2, player.getRolesPlayed().size()); Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java 2008-08-11 12:21:38 UTC (rev 112) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java 2008-08-11 12:26:15 UTC (rev 113) @@ -24,12 +24,8 @@ import org.tmapi.core.Construct; import org.tmapi.core.IdentityConstraintException; import org.tmapi.core.Locator; -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; /** * Tests if the TMDM item identifier constraint is respected. @@ -40,6 +36,40 @@ public class TestItemIdentifierConstraint extends TinyTimTestCase { /** + * The item identifier constraint test. + * + * @param tmo The Topic Maps construct to test. + */ + private void _testConstraint(Construct tmo) throws Exception { + assertTrue(tmo.getItemIdentifiers().isEmpty()); + 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 { + tmo.addItemIdentifier(iid); + fail("Topic Maps constructs with the same item identifier are not allowed"); + } + catch (IdentityConstraintException ex) { + // noop + } + tmo.addItemIdentifier(iid2); + assertTrue(tmo.getItemIdentifiers().contains(iid2)); + tmo.removeItemIdentifier(iid2); + assoc.removeItemIdentifier(iid); + assertFalse(assoc.getItemIdentifiers().contains(iid)); + tmo.addItemIdentifier(iid); + assertTrue(tmo.getItemIdentifiers().contains(iid)); + if (!(tmo instanceof TopicMap)) { + // Removal should 'free' the item identifier + tmo.remove(); + assoc.addItemIdentifier(iid); + assertTrue(assoc.getItemIdentifiers().contains(iid)); + } + } + + /** * Tests against a topic map. */ public void testTopicMap() throws Exception { @@ -50,11 +80,11 @@ * Tests againts a topic. */ public void testTopic() throws Exception { - Topic topic = _tm.createTopic(); - Locator iid = _tm.createLocator("http://sf.net/projects/tinytim"); + Topic topic = createTopic(); + Locator iid = createLocator("http://sf.net/projects/tinytim"); topic.addItemIdentifier(iid); assertTrue(topic.getItemIdentifiers().contains(iid)); - Topic topic2 = _tm.createTopic(); + Topic topic2 = createTopic(); try { topic2.addItemIdentifier(iid); } @@ -78,77 +108,35 @@ * Tests against an association. */ public void testAssociation() throws Exception { - _testConstraint(_tm.createAssociation(_tm.createTopic())); + _testConstraint(createAssociation()); } /** * Tests against a role. */ public void testRole() throws Exception { - Association assoc = _tm.createAssociation(_tm.createTopic()); - Role role = assoc.createRole(_tm.createTopic(), _tm.createTopic()); - _testConstraint(role); + _testConstraint(createRole()); } /** * Tests against an occurrence. */ public void testOccurrence() throws Exception { - Topic topic = _tm.createTopic(); - Occurrence occ = topic.createOccurrence(_tm.createTopic(), "tinyTiM"); - _testConstraint(occ); + _testConstraint(createOccurrence()); } /** * Tests against a name. */ public void testName() throws Exception { - Topic topic = _tm.createTopic(); - Name name = topic.createName("tinyTiM"); - _testConstraint(name); + _testConstraint(createName()); } /** * Tests against a variant. */ public void testVariant() throws Exception { - Topic topic = _tm.createTopic(); - Name name = topic.createName("tinyTiM"); - Variant variant = name.createVariant("tinyTiM", _tm.createTopic()); - _testConstraint(variant); + _testConstraint(createVariant()); } - /** - * The item identifier constraint test. - * - * @param tmo The Topic Maps construct to test. - */ - private void _testConstraint(Construct tmo) throws Exception { - assertTrue(tmo.getItemIdentifiers().isEmpty()); - Locator iid = _tm.createLocator("http://sf.net/projects/tinytim"); - tmo.addItemIdentifier(iid); - assertTrue(tmo.getItemIdentifiers().contains(iid)); - Association assoc = _tm.createAssociation(_tm.createTopic()); - try { - assoc.addItemIdentifier(iid); - fail("Topic Maps constructs with the same item identifier are not allowed"); - } - catch (IdentityConstraintException ex) { - // noop - } - tmo.removeItemIdentifier(iid); - assertFalse(tmo.getItemIdentifiers().contains(iid)); - assoc.addItemIdentifier(iid); - assertTrue(assoc.getItemIdentifiers().contains(iid)); - assoc.removeItemIdentifier(iid); - assertFalse(assoc.getItemIdentifiers().contains(iid)); - tmo.addItemIdentifier(iid); - assertTrue(tmo.getItemIdentifiers().contains(iid)); - if (!(tmo instanceof TopicMap)) { - // Removal should 'free' the item identifier - tmo.remove(); - assoc.addItemIdentifier(iid); - assertTrue(assoc.getItemIdentifiers().contains(iid)); - } - } } Added: tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java 2008-08-11 12:26:15 UTC (rev 113) @@ -0,0 +1,48 @@ +/* + * 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.Arrays; + +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 TestScope extends TinyTimTestCase { + + public void testUnconstrained() { + assertTrue(Scope.UCS.isUnconstrained()); + assertEquals(0, Scope.UCS.size()); + } + + public void testEquals() { + Topic theme1 = createTopic(); + Topic theme2 = createTopic(); + IScope scope1 = Scope.create(Arrays.asList(theme1, theme2)); + assertEquals(2, scope1.size()); + IScope scope2 = Scope.create(Arrays.asList(theme2, theme1)); + assertSame(scope1, scope2); + } +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java 2008-08-11 12:21:38 UTC (rev 112) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java 2008-08-11 12:26:15 UTC (rev 113) @@ -40,7 +40,7 @@ * signature. */ public void testAssociationBasic() { - Topic type = _tm.createTopic(); + Topic type = createTopic(); Association assoc = _tm.createAssociation(type); Association assoc2 = _tm.createAssociation(type); assertFalse(assoc.getId().equals(assoc2.getId())); @@ -53,8 +53,8 @@ * signature. */ public void testOccurrenceBasic() { - Topic topic = _tm.createTopic(); - Topic type = _tm.createTopic(); + Topic topic = createTopic(); + Topic type = createTopic(); Occurrence occ = topic.createOccurrence(type, "tinyTiM"); Occurrence occ2 = topic.createOccurrence(type, "tinyTiM"); assertFalse(occ.getId().equals(occ2.getId())); @@ -76,7 +76,7 @@ * signature. */ public void testNameBasic() { - Topic topic = _tm.createTopic(); + Topic topic = createTopic(); Name name = topic.createName("tinyTiM"); Name name2 = topic.createName("tinyTiM"); assertFalse(name.getId().equals(name2.getId())); @@ -116,8 +116,8 @@ * Tests if associations with the same type return the same signature. */ public void testAssociationTyped() { - Topic type1 = _tm.createTopic(); - Topic type2 = _tm.createTopic(); + Topic type1 = createTopic(); + Topic type2 = createTopic(); Association assoc = _tm.createAssociation(type1); int sigBefore = SignatureGenerator.generateSignature(assoc); assoc.setType(type2); @@ -130,9 +130,9 @@ } public void testRoles() { - Association assoc = _tm.createAssociation(_tm.createTopic()); - Topic type = _tm.createTopic(); - Topic player = _tm.createTopic(); + Association assoc = _tm.createAssociation(createTopic()); + Topic type = createTopic(); + Topic player = createTopic(); Role role1 = assoc.createRole(type, player); Role role2 = assoc.createRole(type, player); assertEquals(2, player.getRolesPlayed().size()); Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestTopicMapSystemFactoryImpl.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestTopicMapSystemFactoryImpl.java 2008-08-11 12:21:38 UTC (rev 112) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestTopicMapSystemFactoryImpl.java 2008-08-11 12:26:15 UTC (rev 113) @@ -20,13 +20,6 @@ */ package org.tinytim.core; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.tinytim.utils.ICollectionFactory; -import org.tinytim.utils.Property; import org.tinytim.utils.Feature; import org.tmapi.core.FeatureNotRecognizedException; import org.tmapi.core.FeatureNotSupportedException; @@ -110,81 +103,4 @@ } } - /** - * Tests if the collection factory property is set. - * - * @throws Exception - */ - public void testCollectionFactoryProperty() throws Exception { - boolean troveAvailable = false; - try { - Class.forName("gnu.trove.THashSet"); - troveAvailable = true; - } - catch (Exception ex) { - // noop. - } - if (troveAvailable) { - assertEquals("org.tinytim.core.TroveCollectionFactory", _sysFactory.getProperty(Property.COLLECTION_FACTORY)); - } - else { - assertEquals("org.tinytim.core.JavaCollectionFactory", _sysFactory.getProperty(Property.COLLECTION_FACTORY)); - assertTrue(((TopicMapSystemImpl) _sysFactory.newTopicMapSystem()).getCollectionFactory() instanceof JavaCollectionFactory); - } - } - - /** - * Tests if the TopicMapSystemFactory creates automatically a default - * CollectionFactory iff the class name in the property is invaild / - * not resolvable. - * - * @throws Exception - */ - public void testCollectionFactoryFallback() throws Exception { - _sysFactory.setProperty(Property.COLLECTION_FACTORY, "a.non.existent.CollectionFactory"); - TopicMapSystemImpl sys = (TopicMapSystemImpl) _sysFactory.newTopicMapSystem(); - assertTrue(sys.getCollectionFactory() instanceof JavaCollectionFactory); - } - - /** - * Sets the setting of a custom {@link ICollectionFactory}. - * - * @throws Exception - */ - public void testCustomCollectionFactory() throws Exception { - _sysFactory.setProperty(Property.COLLECTION_FACTORY, MyCollectionFactory.class.getName()); - TopicMapSystemImpl sys = (TopicMapSystemImpl) _sysFactory.newTopicMapSystem(); - assertTrue(sys.getCollectionFactory() instanceof MyCollectionFactory); - } - - /** - * {@link ICollectionFactory} implementation that uses the Java collections. - */ - public static final class MyCollectionFactory implements ICollectionFactory { - public <K, V> Map<K, V> createMap() { - return new HashMap<K, V>(); - } - public <K, V> Map<K, V> createMap(int size) { - return createMap(); - } - public <E> Set<E> createSet(int size) { - return createSet(); - } - public <E> Set<E> createSet() { - return new HashSet<E>(); - } - public <K, V> Map<K, V> createIdentityMap() { - return createMap(); - } - public <K, V> Map<K, V> createIdentityMap(int size) { - return createMap(size); - } - public <E> Set<E> createIdentitySet() { - return createSet(); - } - public <E> Set<E> createIdentitySet(int size) { - return createSet(size); - } - - } } Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestTopicUtils.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestTopicUtils.java 2008-08-11 12:21:38 UTC (rev 112) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestTopicUtils.java 2008-08-11 12:26:15 UTC (rev 113) @@ -36,16 +36,16 @@ * Tests if a topic is considered as 'removable'. */ public void testRemovable() { - Topic topic = _tm.createTopic(); + Topic topic = createTopic(); assertTrue(TopicUtils.isRemovable(topic)); Association assoc = _tm.createAssociation(topic); assertFalse(TopicUtils.isRemovable(topic)); - assoc.setType(_tm.createTopic()); + assoc.setType(createTopic()); assertTrue(TopicUtils.isRemovable(topic)); // Role played - Role role = assoc.createRole(_tm.createTopic(), topic); + Role role = assoc.createRole(createTopic(), topic); assertFalse(TopicUtils.isRemovable(topic)); - role.setPlayer(_tm.createTopic()); + role.setPlayer(createTopic()); assertTrue(TopicUtils.isRemovable(topic)); // Theme assoc.addTheme(topic); Modified: tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java 2008-08-11 12:21:38 UTC (rev 112) +++ tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java 2008-08-11 12:26:15 UTC (rev 113) @@ -29,6 +29,7 @@ import org.tmapi.core.Occurrence; import org.tmapi.core.Role; import org.tmapi.core.Topic; +import org.tmapi.core.TopicMapSystem; import org.tmapi.core.Variant; import junit.framework.TestCase; @@ -48,9 +49,17 @@ protected static final String _IRI = "http://www.semagia.com/tinyTiM/testTopicMap/"; protected Locator _base; protected TopicMapImpl _tm; - protected TopicMapSystemImpl _sys; + protected TopicMapSystem _sys; protected TopicMapSystemFactoryImpl _sysFactory; + public TinyTimTestCase() { + super(); + } + + public TinyTimTestCase(String name) { + super(name); + } + /** * Returns additional / non-default properties which should be set * to configure the {@link org.tmapi.core.TopicMapSystemFactory}. @@ -118,6 +127,10 @@ return createName().createVariant("Variant", createTopic()); } + protected Locator createLocator(final String reference) { + return _sys.createLocator(reference); + } + /* (non-Javadoc) * @see junit.framework.TestCase#setUp() */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-11 12:21:37
|
Revision: 112 http://tinytim.svn.sourceforge.net/tinytim/?rev=112&view=rev Author: lheuer Date: 2008-08-11 12:21:38 +0000 (Mon, 11 Aug 2008) Log Message: ----------- - Committed missing classes (Scope and the new CollectionFactory) Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/core/Scope.java tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java Added: tinytim/trunk/src/main/java/org/tinytim/core/Scope.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Scope.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/Scope.java 2008-08-11 12:21:38 UTC (rev 112) @@ -0,0 +1,154 @@ +/* + * 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.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.Set; + +import org.tinytim.utils.CollectionFactory; +import org.tinytim.utils.WeakObjectRegistry; +import org.tmapi.core.Topic; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +final class Scope implements IScope { + + public static final IScope UCS = new Scope(); + + private static final WeakObjectRegistry<IScope> _SCOPES = new WeakObjectRegistry<IScope>(); + + private final Set<Topic> _set; + + private Scope() { + _set = Collections.emptySet(); + } + + private Scope(Collection<Topic> themes) { + _set = CollectionFactory.createIdentitySet(themes.size()); + _set.addAll(themes); + } + + private Scope(Set<Topic> themes) { + _set = themes; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + return (obj instanceof Scope) && _set.equals(((Scope)obj)._set); + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return _set.hashCode(); + } + + public static synchronized IScope create(Collection<Topic> scope) { + if (scope.isEmpty()) { + return UCS; + } + Set<Topic> themes = CollectionFactory.createIdentitySet(scope.size()); + themes.addAll(scope); + IScope scope_ = new Scope(themes); + IScope existing = _SCOPES.get(scope_); + if (existing != null) { + return existing; + } + _SCOPES.add(scope_); + return scope_; + } + + /* (non-Javadoc) + * @see org.tinytim.core.IScope#asSet() + */ + public Set<Topic> asSet() { + return Collections.unmodifiableSet(_set); + } + + /* (non-Javadoc) + * @see org.tinytim.core.IScope#contains(org.tmapi.core.Topic) + */ + public boolean contains(Topic theme) { + return _set.contains(theme); + } + + /* (non-Javadoc) + * @see org.tinytim.core.IScope#add(org.tmapi.core.Topic) + */ + public IScope add(Topic theme) { + if (_set.contains(theme)) { + return this; + } + Collection<Topic> themes = CollectionFactory.createIdentitySet(_set.size()); + themes.addAll(_set); + themes.add(theme); + return create(themes); + } + + /* (non-Javadoc) + * @see org.tinytim.core.IScope#remove(org.tmapi.core.Topic) + */ + public IScope remove(Topic theme) { + if (!_set.contains(theme)) { + return this; + } + Collection<Topic> themes = CollectionFactory.createIdentitySet(_set.size()); + themes.addAll(_set); + themes.remove(theme); + return create(themes); + } + + /* (non-Javadoc) + * @see java.lang.Iterable#iterator() + */ + public Iterator<Topic> iterator(){ + return _set.iterator(); + } + + /* (non-Javadoc) + * @see org.tinytim.core.IScope#isUnconstrained() + */ + public boolean isUnconstrained() { + return this == UCS; + } + + /* (non-Javadoc) + * @see org.tinytim.core.IScope#size() + */ + public int size() { + return _set.size(); + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/Scope.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java 2008-08-11 12:21:38 UTC (rev 112) @@ -0,0 +1,108 @@ +/* + * 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.utils; + +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.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; + } + + /* (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(); + } + + /* (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); + } + + /* (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(); + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java 2008-08-11 12:21:38 UTC (rev 112) @@ -0,0 +1,36 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.utils; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface IIntObjectMap<V> { + + public V put(int key, V value); + + public V get(int key); + + public void clear(); +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java 2008-08-11 12:21:38 UTC (rev 112) @@ -0,0 +1,57 @@ +/* + * 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.utils; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class IntObjectMap { + + private static final boolean _TROVE_AVAILABLE; + + static { + boolean available = false; + try { + // Probe if Trove is available. + Class.forName("gnu.trove.THashSet"); + available = true; + } + catch (Exception ex) { + + } + _TROVE_AVAILABLE = available; + } + + private IntObjectMap() { + // noop. + } + + public static <V> IIntObjectMap<V> create() { + return _TROVE_AVAILABLE ? new TroveIntObjectMap<V>() : new JavaIntObjectMap<V>(); + } + + public static <V> IIntObjectMap<V> create(int size) { + return _TROVE_AVAILABLE ? new TroveIntObjectMap<V>(size) : new JavaIntObjectMap<V>(size); + } +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java 2008-08-11 12:21:38 UTC (rev 112) @@ -0,0 +1,160 @@ +/* + * 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.utils; + +import java.util.AbstractSet; +import java.util.HashMap; +import java.util.HashSet; +import java.util.IdentityHashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + + +/** + * {@link ICollectionFactory} which uses the standard Java collections. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +final class JavaCollectionFactory implements ICollectionFactory { + + /* (non-Javadoc) + * @see org.tinytim.ICollectionFactory#createMap(int) + */ + public <K, V> Map<K, V> createMap(int size) { + return new HashMap<K, V>(size); + } + + /* (non-Javadoc) + * @see org.tinytim.ICollectionFactory#createMap() + */ + public <K, V> Map<K, V> createMap() { + return new HashMap<K, V>(); + } + + /* (non-Javadoc) + * @see org.tinytim.core.ICollectionFactory#createIdentityMap() + */ + public <K, V> Map<K, V> createIdentityMap() { + return new IdentityHashMap<K,V>(); + } + + /* (non-Javadoc) + * @see org.tinytim.core.ICollectionFactory#createIdentityMap(int) + */ + public <K, V> Map<K, V> createIdentityMap(int size) { + return new IdentityHashMap<K,V>(size); + } + + /* (non-Javadoc) + * @see org.tinytim.ICollectionFactory#createSet(int) + */ + public <E> Set<E> createSet(int size) { + return new HashSet<E>(size); + } + + /* (non-Javadoc) + * @see org.tinytim.ICollectionFactory#createSet() + */ + public <E> Set<E> createSet() { + return new HashSet<E>(); + } + + /* (non-Javadoc) + * @see org.tinytim.core.ICollectionFactory#createIdentitySet() + */ + public <E> Set<E> createIdentitySet() { + return new IdentityHashSet<E>(); + } + + /* (non-Javadoc) + * @see org.tinytim.core.ICollectionFactory#createIdentitySet(int) + */ + public <E> Set<E> createIdentitySet(int size) { + return new IdentityHashSet<E>(size); + } + + /** + * {@link java.util.Set} implementation that compares its elements by + * identity. + */ + private static class IdentityHashSet<E> extends AbstractSet<E> { + + private final Map<E, Boolean> _map; + + public IdentityHashSet() { + _map = new IdentityHashMap<E, Boolean>(); + } + + public IdentityHashSet(int size) { + _map = new IdentityHashMap<E, Boolean>(size); + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#add(java.lang.Object) + */ + @Override + public boolean add(E obj) { + return _map.put(obj, Boolean.TRUE) == null; + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#remove(java.lang.Object) + */ + @Override + public boolean remove(Object obj) { + return _map.remove(obj) != null; + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#contains(java.lang.Object) + */ + @Override + public boolean contains(Object obj) { + return _map.containsKey(obj); + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#iterator() + */ + @Override + public Iterator<E> iterator() { + return _map.keySet().iterator(); + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#size() + */ + @Override + public int size() { + return _map.size(); + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#clear() + */ + @Override + public void clear() { + _map.clear(); + } + } +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java 2008-08-11 12:21:38 UTC (rev 112) @@ -0,0 +1,62 @@ +/* + * 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.utils; + +import java.util.HashMap; +import java.util.Map; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +final class JavaIntObjectMap<V> implements IIntObjectMap<V> { + + private final Map<Integer, V> _map; + + JavaIntObjectMap() { + _map = new HashMap<Integer, V>(); + } + + JavaIntObjectMap(int size) { + _map = new HashMap<Integer, V>(size); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.IIntObjectMap#get(int) + */ + public V get(int key) { + return _map.get(key); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.IIntObjectMap#put(int, java.lang.Object) + */ + public V put(int key, V value) { + return _map.put(Integer.valueOf(key), value); + } + + public void clear() { + _map.clear(); + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java 2008-08-11 12:21:38 UTC (rev 112) @@ -0,0 +1,97 @@ +/* + * 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.utils; + +import gnu.trove.THashMap; +import gnu.trove.THashSet; +import gnu.trove.TObjectIdentityHashingStrategy; + +import java.util.Map; +import java.util.Set; + + +/** + * {@link ICollectionFactory} which uses the + * <a href="http://sourceforge.net/projects/trove4j/">Trove library </a>. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +final class TroveCollectionFactory implements ICollectionFactory { + + /* (non-Javadoc) + * @see org.tinytim.ICollectionFactory#createMap(int) + */ + public <K, V> Map<K, V> createMap(int size) { + return new THashMap<K,V>(size); + } + + /* (non-Javadoc) + * @see org.tinytim.ICollectionFactory#createMap() + */ + public <K, V> Map<K, V> createMap() { + return new THashMap<K, V>(); + } + + /* (non-Javadoc) + * @see org.tinytim.core.ICollectionFactory#createIdentityMap() + */ + public <K, V> Map<K, V> createIdentityMap() { + return new THashMap<K, V>(new TObjectIdentityHashingStrategy<K>()); + } + + /* (non-Javadoc) + * @see org.tinytim.core.ICollectionFactory#createIdentityMap(int) + */ + public <K, V> Map<K, V> createIdentityMap(int size) { + return new THashMap<K, V>(size, new TObjectIdentityHashingStrategy<K>()); + } + + /* (non-Javadoc) + * @see org.tinytim.ICollectionFactory#createSet(int) + */ + public <E> Set<E> createSet(int size) { + return new THashSet<E>(size); + } + + /* (non-Javadoc) + * @see org.tinytim.ICollectionFactory#createSet() + */ + public <E> Set<E> createSet() { + return new THashSet<E>(); + } + + /* (non-Javadoc) + * @see org.tinytim.core.ICollectionFactory#createIdentitySet() + */ + public <E> Set<E> createIdentitySet() { + return new THashSet<E>(new TObjectIdentityHashingStrategy<E>()); + } + + /* (non-Javadoc) + * @see org.tinytim.core.ICollectionFactory#createIdentitySet(int) + */ + public <E> Set<E> createIdentitySet(int size) { + return new THashSet<E>(size, new TObjectIdentityHashingStrategy<E>()); + } + + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java 2008-08-11 12:21:38 UTC (rev 112) @@ -0,0 +1,61 @@ +/* + * 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.utils; + +import gnu.trove.TIntObjectHashMap; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +final class TroveIntObjectMap<V> implements IIntObjectMap<V> { + + private final TIntObjectHashMap<V> _map; + + TroveIntObjectMap() { + _map = new TIntObjectHashMap<V>(); + } + + TroveIntObjectMap(int size) { + _map = new TIntObjectHashMap<V>(size); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.IIntObjectMap#get(int) + */ + public V get(int key) { + return _map.get(key); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.IIntObjectMap#put(int, java.lang.Object) + */ + public V put(int key, V value) { + return _map.put(key, value); + } + + public void clear() { + _map.clear(); + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java 2008-08-11 12:21:38 UTC (rev 112) @@ -0,0 +1,105 @@ +/* + * 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.utils; + +import java.lang.ref.WeakReference; +import java.util.AbstractSet; +import java.util.Iterator; +import java.util.Map; +import java.util.WeakHashMap; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public final class WeakObjectRegistry<E> extends AbstractSet<E> { + + private final Map<E, WeakReference<E>> _obj2Ref; + + public WeakObjectRegistry() { + super(); + _obj2Ref = new WeakHashMap<E, WeakReference<E>>(); + } + + /** + * + * + * @param key + * @return + */ + public E get(Object key) { + WeakReference<E> weakRef = _obj2Ref.get(key); + return weakRef != null ? weakRef.get() : null; + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#add(java.lang.Object) + */ + @Override + public boolean add(E obj) { + WeakReference<E> ref = new WeakReference<E>(obj); + ref = _obj2Ref.put(obj, ref); + return ref != null && ref.get() != null; + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#remove(java.lang.Object) + */ + @Override + public boolean remove(Object obj) { + WeakReference<E> ref = _obj2Ref.remove(obj); + return ref != null && ref.get() != null; + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#clear() + */ + @Override + public void clear() { + _obj2Ref.clear(); + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#contains(java.lang.Object) + */ + @Override + public boolean contains(Object obj) { + return get(obj) != null; + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#iterator() + */ + @Override + public Iterator<E> iterator() { + return _obj2Ref.keySet().iterator(); + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#size() + */ + @Override + public int size() { + return _obj2Ref.size(); + } +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.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-08-11 12:19:04
|
Revision: 111 http://tinytim.svn.sourceforge.net/tinytim/?rev=111&view=rev Author: lheuer Date: 2008-08-11 12:18:58 +0000 (Mon, 11 Aug 2008) Log Message: ----------- - Introduced Scope as first class object - Introduced a constructor which takes a TopicMapImpl for association, role etc. - Removed CollectionFactory from the TopicMapImpl and TopicMapSystemFactoryImpl - Added a static CollectionFactory - Various modifications Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java tinytim/trunk/src/main/java/org/tinytim/core/Event.java tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java tinytim/trunk/src/main/java/org/tinytim/core/Literal.java tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java tinytim/trunk/src/main/java/org/tinytim/core/OccurrenceImpl.java tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemFactoryImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java tinytim/trunk/src/main/java/org/tinytim/index/AbstractIndex.java tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java tinytim/trunk/src/main/java/org/tinytim/index/LiteralIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/utils/ICollectionFactory.java Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java tinytim/trunk/src/main/java/org/tinytim/core/IScope.java tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java Removed Paths: ------------- tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java tinytim/trunk/src/main/java/org/tinytim/core/JavaCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/core/TroveCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/utils/Property.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-08-11 12:18:58 UTC (rev 111) @@ -21,7 +21,6 @@ package org.tinytim.core; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.Set; @@ -40,7 +39,12 @@ private Set<Role> _roles; - AssociationImpl(TopicMapImpl topicMap, Topic type, Collection<Topic> scope) { + AssociationImpl(TopicMapImpl tm) { + super(tm); + _roles = _makeSet(2); + } + + AssociationImpl(TopicMapImpl topicMap, Topic type, IScope scope) { super(topicMap, type, scope); _roles = _makeSet(2); } @@ -142,6 +146,14 @@ } /* (non-Javadoc) + * @see org.tinytim.core.ConstructImpl#isAssociation() + */ + @Override + public final boolean isAssociation() { + return true; + } + + /* (non-Javadoc) * @see org.tmapi.core.TopicMapObject#remove() */ public void remove() { Modified: tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-08-11 12:18:58 UTC (rev 111) @@ -23,6 +23,7 @@ import java.util.Collections; import java.util.Set; +import org.tinytim.utils.CollectionFactory; import org.tmapi.core.Construct; import org.tmapi.core.Locator; import org.tmapi.core.TopicMap; @@ -33,7 +34,7 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -abstract class ConstructImpl implements Construct { +abstract class ConstructImpl implements IConstruct { protected String _id; protected TopicMapImpl _tm; @@ -45,11 +46,11 @@ } protected <E> Set<E> _makeSet() { - return _tm.getCollectionFactory().createIdentitySet(); + return CollectionFactory.createIdentitySet(); } protected <E> Set<E> _makeSet(int size) { - return _tm.getCollectionFactory().createIdentitySet(size); + return CollectionFactory.createIdentitySet(size); } /* (non-Javadoc) @@ -135,7 +136,7 @@ * @param newValue The new value. */ protected void _fireEvent(Event evt, Object oldValue, Object newValue) { - if (_tm != null) { + if (_tm != null && _parent != null) { _tm.handleEvent(evt, this, oldValue, newValue); } } @@ -153,6 +154,55 @@ } /* (non-Javadoc) + * @see org.tinytim.core.IConstruct#isAssociation() + */ + public boolean isAssociation() { + return false; + } + + /* (non-Javadoc) + * @see org.tinytim.core.IConstruct#isName() + */ + public boolean isName() { + return false; + } + + /* (non-Javadoc) + * @see org.tinytim.core.IConstruct#isOccurrence() + */ + public boolean isOccurrence() { + return false; + } + + /* (non-Javadoc) + * @see org.tinytim.core.IConstruct#isRole() + */ + public boolean isRole() { + return false; + } + + /* (non-Javadoc) + * @see org.tinytim.core.IConstruct#isTopic() + */ + public boolean isTopic() { + return false; + } + + /* (non-Javadoc) + * @see org.tinytim.core.IConstruct#isTopicMap() + */ + public boolean isTopicMap() { + return false; + } + + /* (non-Javadoc) + * @see org.tinytim.core.IConstruct#isVariant() + */ + public boolean isVariant() { + return false; + } + + /* (non-Javadoc) * @see java.lang.Object#toString() */ @Override Modified: tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-11 12:18:58 UTC (rev 111) @@ -23,6 +23,9 @@ import java.util.Map; import java.util.Set; +import org.tinytim.utils.CollectionFactory; +import org.tinytim.utils.IIntObjectMap; +import org.tinytim.utils.IntObjectMap; import org.tmapi.core.Association; import org.tmapi.core.Construct; import org.tmapi.core.Locator; @@ -66,7 +69,7 @@ if (source == target) { return; } - Map<Topic, Topic> mergeMap = target.getCollectionFactory().createIdentityMap(); + Map<Topic, Topic> mergeMap = CollectionFactory.createIdentityMap(); Topic existing = null; Construct existingConstruct = null; for (Topic topic: source.getTopics()) { @@ -176,7 +179,7 @@ */ private static void _copyCharacteristics(Topic topic, TopicImpl targetTopic, Map<Topic, Topic> mergeMap) { - Map<Integer, Reifiable> sigs = ((TopicMapImpl) targetTopic.getTopicMap()).getCollectionFactory().createMap(); + IIntObjectMap<Reifiable> sigs = IntObjectMap.create(); for (Occurrence occ: targetTopic.getOccurrences()) { sigs.put(SignatureGenerator.generateSignature(occ), occ); } @@ -226,7 +229,7 @@ */ private static void _copyVariants(Name source, NameImpl target, Map<Topic, Topic> mergeMap) { - Map<Integer, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap(); + IIntObjectMap<Variant> sigs = IntObjectMap.create(); for (Variant variant: target.getVariants()) { sigs.put(SignatureGenerator.generateSignature(variant), variant); } @@ -288,7 +291,7 @@ */ private static Set<Topic>_copyScope(Scoped source, TopicMap tm, Map<Topic, Topic> mergeMap) { - Set<Topic> themes = ((TopicMapImpl) tm).getCollectionFactory().createIdentitySet(source.getScope().size()); + Set<Topic> themes = CollectionFactory.createIdentitySet(source.getScope().size()); Topic theme = null; for (Topic sourceTheme: source.getScope()) { theme = mergeMap.containsKey(sourceTheme) ? mergeMap.get(sourceTheme) @@ -321,7 +324,7 @@ private static void _copyAssociations(TopicMap source, TopicMapImpl target, Map<Topic, Topic> mergeMap) { Set<Association> assocs = target.getAssociations(); - Map<Integer, Association> sigs = target.getCollectionFactory().createMap(assocs.size()); + IIntObjectMap<Association> sigs = IntObjectMap.create(assocs.size()); for (Association assoc: assocs) { sigs.put(SignatureGenerator.generateSignature(assoc), assoc); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-08-11 12:18:58 UTC (rev 111) @@ -22,7 +22,6 @@ import java.math.BigDecimal; import java.math.BigInteger; -import java.util.Collection; import org.tinytim.voc.XSD; import org.tmapi.core.DatatypeAware; @@ -40,7 +39,11 @@ private ILiteral _literal; - DatatypeAwareConstruct(TopicMapImpl topicMap, Topic type, ILiteral literal, Collection<Topic> scope) { + DatatypeAwareConstruct(TopicMapImpl tm) { + super(tm); + } + + DatatypeAwareConstruct(TopicMapImpl topicMap, Topic type, ILiteral literal, IScope scope) { super(topicMap, type, scope); _literal = literal; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java 2008-08-11 12:18:58 UTC (rev 111) @@ -22,9 +22,9 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.Map; -import org.tinytim.utils.ICollectionFactory; +import org.tinytim.utils.IIntObjectMap; +import org.tinytim.utils.IntObjectMap; import org.tmapi.core.Association; import org.tmapi.core.Name; import org.tmapi.core.Occurrence; @@ -56,7 +56,7 @@ for (Topic topic: tm.getTopics()) { removeDuplicates(topic); } - Map<Integer, Association> sig2Assoc = tm.getCollectionFactory().createMap(); + IIntObjectMap<Association> sig2Assoc = IntObjectMap.create(); TypeInstanceIndex typeInstanceIdx = tm.getIndexManager().getTypeInstanceIndex(); if (!typeInstanceIdx.isAutoUpdated()) { typeInstanceIdx.reindex(); @@ -66,13 +66,12 @@ } } - private static void _removeDuplicateAssociations(Map<Integer, Association> sig2Assoc, Collection<Association> assocs) { + private static void _removeDuplicateAssociations(IIntObjectMap<Association> sig2Assoc, Collection<Association> assocs) { sig2Assoc.clear(); Association existing = null; - Integer sig = null; for (Association assoc: assocs) { removeDuplicates(assoc); - sig = SignatureGenerator.generateSignature(assoc); + int sig = SignatureGenerator.generateSignature(assoc); existing = sig2Assoc.get(sig); if (existing != null) { MergeUtils.moveRoleCharacteristics(assoc, existing); @@ -90,9 +89,8 @@ * @param topic The topic from which duplicates should be removed from. */ public static void removeDuplicates(Topic topic) { - ICollectionFactory collFactory = ((TopicMapImpl) topic.getTopicMap()).getCollectionFactory(); - _removeDuplicateOccurrences(topic.getOccurrences(), collFactory); - _removeDuplicateNames(topic.getNames(), collFactory); + _removeDuplicateOccurrences(topic.getOccurrences()); + _removeDuplicateNames(topic.getNames()); } /** @@ -101,10 +99,9 @@ * @param name The name from which the duplicates should be removed. */ public static void removeDuplicates(Name name) { - Map<Integer, Variant> sigs = ((TopicMapImpl) name.getTopicMap()).getCollectionFactory().createMap(); - Integer sig = null; + IIntObjectMap<Variant> sigs = IntObjectMap.create(); for (Variant variant: new ArrayList<Variant>(name.getVariants())) { - sig = SignatureGenerator.generateSignature(variant); + int sig = SignatureGenerator.generateSignature(variant); Variant existing = sigs.get(sig); if (existing != null) { MergeUtils.handleExistingConstruct(variant, existing); @@ -121,12 +118,11 @@ * * @param occs */ - private static void _removeDuplicateOccurrences(Collection<Occurrence> occs, ICollectionFactory collFactory) { - Map<Integer, Occurrence> sigs = collFactory.createMap(occs.size()); + private static void _removeDuplicateOccurrences(Collection<Occurrence> occs) { + IIntObjectMap<Occurrence> sigs = IntObjectMap.create(occs.size()); Occurrence existing = null; - Integer sig = null; for (Occurrence occ: new ArrayList<Occurrence>(occs)) { - sig = SignatureGenerator.generateSignature(occ); + int sig = SignatureGenerator.generateSignature(occ); existing = sigs.get(sig); if (existing != null) { MergeUtils.handleExistingConstruct(occ, existing); @@ -143,13 +139,12 @@ * * @param names */ - private static void _removeDuplicateNames(Collection<Name> names, ICollectionFactory collFactory) { - Map<Integer, Name> sigs = collFactory.createMap(names.size()); + private static void _removeDuplicateNames(Collection<Name> names) { + IIntObjectMap<Name> sigs = IntObjectMap.create(names.size()); Name existing = null; - Integer sig = null; for (Name name: new ArrayList<Name>(names)) { removeDuplicates(name); - sig = SignatureGenerator.generateSignature(name); + int sig = SignatureGenerator.generateSignature(name); existing = sigs.get(sig); if (existing != null) { MergeUtils.handleExistingConstruct(name, existing); @@ -168,11 +163,10 @@ * @param assoc The association to remove duplicate roles from. */ public static void removeDuplicates(Association assoc) { - Map<Integer, Role> sig2Role = ((TopicMapImpl) assoc.getTopicMap()).getCollectionFactory().createMap(); + IIntObjectMap<Role> sig2Role = IntObjectMap.create(); Role existing = null; - Integer sig = null; for (Role role: new ArrayList<Role>(assoc.getRoles())) { - sig = SignatureGenerator.generateSignature(role); + int sig = SignatureGenerator.generateSignature(role); existing = sig2Role.get(sig); if (existing != null) { MergeUtils.handleExistingConstruct(role, existing); Modified: tinytim/trunk/src/main/java/org/tinytim/core/Event.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Event.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/Event.java 2008-08-11 12:18:58 UTC (rev 111) @@ -121,14 +121,9 @@ SET_TYPE, /** - * Notification that a theme should be added to a {@link IScoped} construct. + * Notification that the scope is changed. */ - ADD_THEME, - /** - * Notification that a theme should be removed from a - * {@link IScoped} construct. - */ - REMOVE_THEME, + SET_SCOPE, /** * Notification that the player of a role should be set. Added: tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java 2008-08-11 12:18:58 UTC (rev 111) @@ -0,0 +1,41 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.core; + +import org.tmapi.core.Construct; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface IConstruct extends Construct { + + public boolean isTopicMap(); + public boolean isTopic(); + public boolean isAssociation(); + public boolean isRole(); + public boolean isOccurrence(); + public boolean isName(); + public boolean isVariant(); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java 2008-08-11 12:18:58 UTC (rev 111) @@ -20,8 +20,6 @@ */ package org.tinytim.core; -import org.tmapi.core.Construct; - /** * Event handler that is able to handle Topic Maps events. * @@ -44,6 +42,6 @@ * @param newValue The new value or <code>null</code> if the new value * is not available or should become <code>null</code>. */ - public void handleEvent(Event evt, Construct sender, Object oldValue, Object newValue); + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue); } Deleted: tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java 2008-08-11 12:18:58 UTC (rev 111) @@ -1,48 +0,0 @@ -/* - * This is tinyTiM, a tiny Topic Maps engine. - * - * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ -package org.tinytim.core; - -import org.tmapi.core.Association; -import org.tmapi.core.Name; -import org.tmapi.core.Occurrence; -import org.tmapi.core.Role; -import org.tmapi.core.Topic; -import org.tmapi.core.Variant; - -/** - * - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public interface IFactory { - - public Association createAssociation(); - - public Role createRole(Association parent); - - public Occurrence createOccurrence(Topic parent); - - public Name createName(Topic parent); - - public Variant createVariant(Name parent); - -} Modified: tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java 2008-08-11 12:18:58 UTC (rev 111) @@ -23,8 +23,9 @@ import org.tmapi.core.Locator; /** + * Marker interface which unifies the {@link org.tmapi.core.Locator} and + * tinyTiM's {@link ILiteral}. * - * * This interface is not meant to be used outside of the tinyTiM package. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> Added: tinytim/trunk/src/main/java/org/tinytim/core/IScope.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IScope.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/IScope.java 2008-08-11 12:18:58 UTC (rev 111) @@ -0,0 +1,49 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.core; + +import java.util.Set; + +import org.tmapi.core.Topic; + +/** + * Represents an immutable set of {@link org.tmapi.core.Topic}s. + * + * This interface is not meant to be used outside of the tinyTiM package. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface IScope extends Iterable<Topic> { + + public Set<Topic> asSet(); + + public boolean contains(Topic theme); + + public IScope add(Topic theme); + + public IScope remove(Topic theme); + + public boolean isUnconstrained(); + + public int size(); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/IScope.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java 2008-08-11 12:18:58 UTC (rev 111) @@ -0,0 +1,36 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.core; + +import org.tmapi.core.Scoped; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface IScoped extends Scoped, IConstruct { + + public IScope getScopeObject(); + + public void setScopeObject(IScope scope); +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-08-11 12:18:58 UTC (rev 111) @@ -31,13 +31,8 @@ final class IdGenerator { private static final AtomicLong _COUNTER = new AtomicLong(); - private static final IdGenerator _INSTANCE = new IdGenerator(); - public static IdGenerator getInstance() { - return _INSTANCE; - } - - public long nextId() { + public static long nextId() { return _COUNTER.getAndIncrement(); } } Modified: tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java 2008-08-11 12:18:58 UTC (rev 111) @@ -22,7 +22,7 @@ import java.util.Map; -import org.tinytim.utils.ICollectionFactory; +import org.tinytim.utils.CollectionFactory; import org.tmapi.core.Construct; import org.tmapi.core.IdentityConstraintException; import org.tmapi.core.Locator; @@ -41,15 +41,14 @@ private Map<Locator, Topic> _sid2Topic; private Map<Locator, Topic> _slo2Topic; - private Map<Locator, Construct> _iid2Construct; - private Map<String, Construct> _id2Construct; + private Map<Locator, IConstruct> _iid2Construct; + private Map<String, IConstruct> _id2Construct; IdentityManager(TopicMapImpl tm) { - ICollectionFactory collFactory = tm.getCollectionFactory(); - _id2Construct = collFactory.createIdentityMap(); - _sid2Topic = collFactory.createIdentityMap(); - _slo2Topic = collFactory.createIdentityMap(); - _iid2Construct = collFactory.createIdentityMap(); + _id2Construct = CollectionFactory.createIdentityMap(); + _sid2Topic = CollectionFactory.createIdentityMap(); + _slo2Topic = CollectionFactory.createIdentityMap(); + _iid2Construct = CollectionFactory.createIdentityMap(); _subscribe(tm); _register(tm); } @@ -95,10 +94,10 @@ * * @param construct The construct to register. */ - private void _register(Construct construct) { + private void _register(IConstruct construct) { ConstructImpl c = (ConstructImpl) construct; if (c._id == null) { - String id = "" + IdGenerator.getInstance().nextId(); + String id = "" + IdGenerator.nextId(); c._id = id.intern(); } if (!_id2Construct.containsKey(c._id)) { @@ -163,16 +162,16 @@ } private class TopicMapsConstructAddHandler implements IEventHandler { - public void handleEvent(Event evt, Construct sender, Object oldValue, + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { - _register((ConstructImpl)newValue); + _register((IConstruct)newValue); } } private class TopicMapsConstructRemoveHandler implements IEventHandler { - public void handleEvent(Event evt, Construct sender, Object oldValue, + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { - _unregister((ConstructImpl)oldValue); + _unregister((IConstruct)oldValue); } } @@ -181,19 +180,19 @@ * item identifier to the index. */ private class AddItemIdentifierHandler implements IEventHandler { - public void handleEvent(Event evt, Construct sender, Object oldValue, + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { Locator iid = (Locator) newValue; - Construct existing = _iid2Construct.get(iid); + IConstruct existing = _iid2Construct.get(iid); if (existing != null) { if (existing != sender) { - if (sender instanceof Topic && existing instanceof Topic) { + if (sender.isTopic() && existing.isTopic()) { throw new IdentityConstraintException((Topic) sender, (Topic) existing, iid, "A topic with the same item identifier '" + iid.getReference() + "' exists"); } throw new IdentityConstraintException(sender, existing, iid, "A Topic Maps construct with the same item identifier '" + iid.getReference() + "' exists"); } } - if (sender instanceof Topic) { + if (sender.isTopic()) { Topic existingTopic = _sid2Topic.get(iid); if (existingTopic != null && existingTopic != sender) { throw new IdentityConstraintException((Topic) sender, existingTopic, iid, "A topic with a subject identifier equals to the item identifier '" + iid.getReference() + "' exists"); @@ -207,7 +206,7 @@ * Removes an item identifier and its Topic Maps constructs from the index. */ private class RemoveItemIdentifierHandler implements IEventHandler { - public void handleEvent(Event evt, Construct sender, Object oldValue, + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { _iid2Construct.remove(oldValue); } @@ -218,16 +217,16 @@ * subject identifier to the index. */ private class AddSubjectIdentifierHandler implements IEventHandler { - public void handleEvent(Event evt, Construct sender, Object oldValue, + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { Topic topic = (Topic) sender; Locator sid = (Locator) newValue; - Construct existing = _sid2Topic.get(sid); + IConstruct existing = (IConstruct) _sid2Topic.get(sid); if (existing != null && existing != topic) { throw new IdentityConstraintException(topic, (Topic) existing, sid, "A topic with the same subject identifier '" + sid.getReference() + "' exists"); } existing = _iid2Construct.get(sid); - if (existing != null && existing instanceof Topic && existing != topic) { + if (existing != null && existing.isTopic() && existing != topic) { throw new IdentityConstraintException(topic, (Topic) existing, sid, "A topic with an item identifier equals to the subject identifier '" + sid.getReference() + "' exists"); } _sid2Topic.put(sid, topic); @@ -238,7 +237,7 @@ * Removes a subject identifier and its topic from the index. */ private class RemoveSubjectIdentifierHandler implements IEventHandler { - public void handleEvent(Event evt, Construct sender, Object oldValue, + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { _sid2Topic.remove(oldValue); } @@ -249,7 +248,7 @@ * subject locator to the index. */ private class AddSubjectLocatorHandler implements IEventHandler { - public void handleEvent(Event evt, Construct sender, Object oldValue, + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { Topic topic = (Topic) sender; Locator slo = (Locator) newValue; @@ -265,7 +264,7 @@ * Removes a subject locator and its topic from the index. */ private class RemoveSubjectLocatorHandler implements IEventHandler { - public void handleEvent(Event evt, Construct sender, Object oldValue, + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { _slo2Topic.remove(oldValue); } @@ -275,7 +274,7 @@ * Checks if setting the reifier is allowed. */ private static class ReifierConstraintHandler implements IEventHandler { - public void handleEvent(Event evt, Construct sender, Object oldValue, + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { if (newValue == null) { return; Deleted: tinytim/trunk/src/main/java/org/tinytim/core/JavaCollectionFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/JavaCollectionFactory.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/JavaCollectionFactory.java 2008-08-11 12:18:58 UTC (rev 111) @@ -1,161 +0,0 @@ -/* - * This is tinyTiM, a tiny Topic Maps engine. - * - * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ -package org.tinytim.core; - -import java.util.AbstractSet; -import java.util.HashMap; -import java.util.HashSet; -import java.util.IdentityHashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.tinytim.utils.ICollectionFactory; - -/** - * {@link ICollectionFactory} which uses the standard Java collections. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -final class JavaCollectionFactory implements ICollectionFactory { - - /* (non-Javadoc) - * @see org.tinytim.ICollectionFactory#createMap(int) - */ - public <K, V> Map<K, V> createMap(int size) { - return new HashMap<K, V>(size); - } - - /* (non-Javadoc) - * @see org.tinytim.ICollectionFactory#createMap() - */ - public <K, V> Map<K, V> createMap() { - return new HashMap<K, V>(); - } - - /* (non-Javadoc) - * @see org.tinytim.core.ICollectionFactory#createIdentityMap() - */ - public <K, V> Map<K, V> createIdentityMap() { - return new IdentityHashMap<K,V>(); - } - - /* (non-Javadoc) - * @see org.tinytim.core.ICollectionFactory#createIdentityMap(int) - */ - public <K, V> Map<K, V> createIdentityMap(int size) { - return new IdentityHashMap<K,V>(size); - } - - /* (non-Javadoc) - * @see org.tinytim.ICollectionFactory#createSet(int) - */ - public <E> Set<E> createSet(int size) { - return new HashSet<E>(size); - } - - /* (non-Javadoc) - * @see org.tinytim.ICollectionFactory#createSet() - */ - public <E> Set<E> createSet() { - return new HashSet<E>(); - } - - /* (non-Javadoc) - * @see org.tinytim.core.ICollectionFactory#createIdentitySet() - */ - public <E> Set<E> createIdentitySet() { - return new IdentityHashSet<E>(); - } - - /* (non-Javadoc) - * @see org.tinytim.core.ICollectionFactory#createIdentitySet(int) - */ - public <E> Set<E> createIdentitySet(int size) { - return new IdentityHashSet<E>(size); - } - - /** - * {@link java.util.Set} implementation that compares its elements by - * identity. - */ - private static class IdentityHashSet<E> extends AbstractSet<E> { - - private final Map<E, Boolean> _map; - - public IdentityHashSet() { - _map = new IdentityHashMap<E, Boolean>(); - } - - public IdentityHashSet(int size) { - _map = new IdentityHashMap<E, Boolean>(size); - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#add(java.lang.Object) - */ - @Override - public boolean add(E obj) { - return _map.put(obj, Boolean.TRUE) == null; - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#remove(java.lang.Object) - */ - @Override - public boolean remove(Object obj) { - return _map.remove(obj) != null; - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#contains(java.lang.Object) - */ - @Override - public boolean contains(Object obj) { - return _map.containsKey(obj); - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#iterator() - */ - @Override - public Iterator<E> iterator() { - return _map.keySet().iterator(); - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#size() - */ - @Override - public int size() { - return _map.size(); - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#clear() - */ - @Override - public void clear() { - _map.clear(); - } - } -} Modified: tinytim/trunk/src/main/java/org/tinytim/core/Literal.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Literal.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/Literal.java 2008-08-11 12:18:58 UTC (rev 111) @@ -20,14 +20,10 @@ */ package org.tinytim.core; -import java.lang.ref.WeakReference; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.AbstractSet; -import java.util.Iterator; -import java.util.Map; -import java.util.WeakHashMap; +import org.tinytim.utils.WeakObjectRegistry; import org.tinytim.voc.XSD; import org.tmapi.core.Locator; @@ -210,77 +206,4 @@ && this._datatype.equals(other._datatype); } - - private static class WeakObjectRegistry<E> extends AbstractSet<E> { - - private final Map<E, WeakReference<E>> _obj2Ref; - - public WeakObjectRegistry() { - super(); - _obj2Ref = new WeakHashMap<E, WeakReference<E>>(); - } - - /** - * - * - * @param key - * @return - */ - public E get(Object key) { - WeakReference<E> weakRef = _obj2Ref.get(key); - return weakRef != null ? weakRef.get() : null; - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#add(java.lang.Object) - */ - @Override - public boolean add(E obj) { - WeakReference<E> ref = new WeakReference<E>(obj); - ref = _obj2Ref.put(obj, ref); - return ref != null && ref.get() != null; - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#remove(java.lang.Object) - */ - @Override - public boolean remove(Object obj) { - WeakReference<E> ref = _obj2Ref.remove(obj); - return ref != null && ref.get() != null; - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#clear() - */ - @Override - public void clear() { - _obj2Ref.clear(); - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#contains(java.lang.Object) - */ - @Override - public boolean contains(Object obj) { - return get(obj) != null; - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#iterator() - */ - @Override - public Iterator<E> iterator() { - return _obj2Ref.keySet().iterator(); - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#size() - */ - @Override - public int size() { - return _obj2Ref.size(); - } - } - } Modified: tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-11 12:18:58 UTC (rev 111) @@ -23,9 +23,10 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.Map; import org.tinytim.index.IIndexManager; +import org.tinytim.utils.IIntObjectMap; +import org.tinytim.utils.IntObjectMap; import org.tmapi.core.Association; import org.tmapi.core.Construct; import org.tmapi.core.Locator; @@ -86,8 +87,7 @@ /** * @see #merge(Topic, Topic) */ - @SuppressWarnings("unchecked") - private static void _merge(TopicImpl source, TopicImpl target) { + private static void _merge(TopicImpl source, Topic target) { if (source == null || target == null) { throw new IllegalArgumentException("Neither the source topic nor the target topic must be null"); } @@ -121,7 +121,7 @@ for(Topic type: source.getTypes()) { target.addType(type); } - Map<Integer, Reifiable> sigs = ((TopicMapImpl) source.getTopicMap()).getCollectionFactory().createMap(); + IIntObjectMap<Reifiable> sigs = IntObjectMap.create(); for (Occurrence occ: target.getOccurrences()) { sigs.put(SignatureGenerator.generateSignature(occ), occ); } @@ -133,7 +133,7 @@ occ.remove(); } else { - ((IMovable<Topic>) occ).moveTo(target); + ((OccurrenceImpl) occ).moveTo(target); } } sigs.clear(); @@ -148,7 +148,7 @@ name.remove(); } else { - ((IMovable<Topic>) name).moveTo(target); + ((NameImpl) name).moveTo(target); } } sigs.clear(); @@ -177,7 +177,7 @@ * @param target The association which takes the role characteristics. */ static void moveRoleCharacteristics(Association source, Association target) { - Map<Integer, Role> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap(); + IIntObjectMap<Role> sigs = IntObjectMap.create(); for (Role role: target.getRoles()) { sigs.put(SignatureGenerator.generateSignature(role), role); } @@ -194,9 +194,8 @@ * @param source The name to take the variants from. * @param target The target to add the variants to. */ - @SuppressWarnings("unchecked") static void moveVariants(Name source, Name target) { - Map<Integer, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap(); + IIntObjectMap<Variant> sigs = IntObjectMap.create(); for (Variant var: target.getVariants()) { sigs.put(SignatureGenerator.generateSignature(var), var); } @@ -208,7 +207,7 @@ var.remove(); } else { - ((IMovable<Name>) var).moveTo(target); + ((VariantImpl) var).moveTo(target); } } } Modified: tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2008-08-11 12:18:58 UTC (rev 111) @@ -44,7 +44,11 @@ private Set<Variant> _variants; - NameImpl(TopicMapImpl topicMap, Topic type, ILiteral literal, Collection<Topic> scope) { + NameImpl(TopicMapImpl tm) { + super(tm); + } + + NameImpl(TopicMapImpl topicMap, Topic type, ILiteral literal, IScope scope) { super(topicMap, type, scope); _literal = literal; } @@ -151,7 +155,7 @@ if (scope_.isEmpty()) { throw new ModelConstraintException(this, "The variant's scope is not a true superset of the parent's scope"); } - Variant variant = new VariantImpl(_tm, literal, scope_); + Variant variant = new VariantImpl(_tm, literal, Scope.create(scope_)); addVariant(variant); return variant; } @@ -198,6 +202,14 @@ } /* (non-Javadoc) + * @see org.tinytim.core.ConstructImpl#isName() + */ + @Override + public final boolean isName() { + return true; + } + + /* (non-Javadoc) * @see org.tmapi.core.Construct#remove() */ public void remove() { Modified: tinytim/trunk/src/main/java/org/tinytim/core/OccurrenceImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/OccurrenceImpl.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/OccurrenceImpl.java 2008-08-11 12:18:58 UTC (rev 111) @@ -20,8 +20,6 @@ */ package org.tinytim.core; -import java.util.Collection; - import org.tmapi.core.Occurrence; import org.tmapi.core.Topic; @@ -34,7 +32,11 @@ final class OccurrenceImpl extends DatatypeAwareConstruct implements Occurrence, IMovable<Topic> { - OccurrenceImpl(TopicMapImpl topicMap, Topic type, ILiteral literal, Collection<Topic> scope) { + OccurrenceImpl(TopicMapImpl tm) { + super(tm); + } + + OccurrenceImpl(TopicMapImpl topicMap, Topic type, ILiteral literal, IScope scope) { super(topicMap, type, literal, scope); } @@ -55,6 +57,14 @@ } /* (non-Javadoc) + * @see org.tinytim.core.ConstructImpl#isOccurrence() + */ + @Override + public final boolean isOccurrence() { + return true; + } + + /* (non-Javadoc) * @see org.tmapi.core.Construct#remove() */ public void remove() { Modified: tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java 2008-08-11 12:18:58 UTC (rev 111) @@ -34,6 +34,10 @@ private Topic _player; + RoleImpl(TopicMapImpl tm) { + super(tm); + } + RoleImpl(TopicMapImpl tm, Topic type, Topic player) { super(tm, type); _player = player; @@ -74,6 +78,14 @@ } /* (non-Javadoc) + * @see org.tinytim.core.ConstructImpl#isRole() + */ + @Override + public final boolean isRole() { + return true; + } + + /* (non-Javadoc) * @see org.tmapi.core.Construct#remove() */ public void remove() { Modified: tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java 2008-08-11 12:18:58 UTC (rev 111) @@ -20,8 +20,6 @@ */ package org.tinytim.core; -import java.util.Collection; -import java.util.Collections; import java.util.Set; import org.tmapi.core.Topic; @@ -33,28 +31,45 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -abstract class ScopedImpl extends TypedImpl { +abstract class ScopedImpl extends TypedImpl implements IScoped { //NOTE: This class does NOT implement IScoped by intention! - private Set<Topic> _scope; + private IScope _scope; - ScopedImpl(TopicMapImpl topicMap, Topic type, Collection<Topic> scope) { + ScopedImpl(TopicMapImpl tm) { + super(tm); + _scope = Scope.UCS; + } + + ScopedImpl(TopicMapImpl topicMap, Topic type, IScope scope) { super(topicMap, type); - if (scope != null && !scope.isEmpty()) { - _scope = _makeSet(scope.size()); - for (Topic theme: scope) { - _scope.add(theme); - } + _scope = scope; + } + + /* (non-Javadoc) + * @see org.tinytim.core.IScoped#getScopeObject() + */ + public IScope getScopeObject() { + return _scope; + } + + /* (non-Javadoc) + * @see org.tinytim.core.IScoped#setScopeObject(org.tinytim.core.IScope) + */ + public void setScopeObject(IScope scope) { + if (_scope == scope) { + return; } + _fireEvent(Event.SET_SCOPE, _scope, scope); + _scope = scope; } /* (non-Javadoc) * @see org.tmapi.core.ScopedObject#getScope() */ public Set<Topic> getScope() { - return _scope == null ? Collections.<Topic>emptySet() - : Collections.unmodifiableSet(_scope); + return _scope.asSet(); } /* (non-Javadoc) @@ -64,25 +79,14 @@ if (theme == null) { throw new IllegalArgumentException("The theme must not be null"); } - if (_scope != null && _scope.contains(theme)) { - return; - } - _fireEvent(Event.ADD_THEME, null, theme); - if (_scope == null) { - _scope = _makeSet(); - } - _scope.add(theme); + setScopeObject(_scope.add(theme)); } /* (non-Javadoc) * @see org.tmapi.Scoped#removeTheme(org.tmapi.core.Topic) */ public void removeTheme(Topic theme) { - if (_scope == null || _scope.isEmpty()) { - return; - } - _fireEvent(Event.REMOVE_THEME, theme, null); - _scope.remove(theme); + setScopeObject(_scope.remove(theme)); } /* (non-Javadoc) Modified: tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java 2008-08-11 12:18:58 UTC (rev 111) @@ -22,7 +22,6 @@ import java.util.Arrays; import java.util.Collection; -import java.util.Set; import org.tmapi.core.Association; import org.tmapi.core.Name; @@ -166,17 +165,7 @@ * @return The signature. */ private static int _generateScopeSignature(final Scoped scoped) { - Set<Topic> scope = scoped.getScope(); - if (scope.isEmpty()) { - return 0; - } - int[] ids = new int[scope.size()]; - int i = 0; - for (Topic topic : scope) { - ids[i++] = _signature(topic); - } - Arrays.sort(ids); - return Arrays.hashCode(ids); + return System.identityHashCode(((IScoped) scoped).getScopeObject()); } private static int _signature(Topic topic) { Modified: tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java 2008-08-11 12:18:58 UTC (rev 111) @@ -193,7 +193,7 @@ if (scope == null) { throw new IllegalArgumentException("The scope must not be null"); } - Occurrence occ = new OccurrenceImpl(_tm, type, literal, scope); + Occurrence occ = new OccurrenceImpl(_tm, type, literal, Scope.create(scope)); addOccurrence(occ); return occ; } @@ -313,7 +313,7 @@ if (scope == null) { throw new IllegalArgumentException("The scope must not be null"); } - NameImpl name = new NameImpl(_tm, type, literal, scope); + NameImpl name = new NameImpl(_tm, type, literal, Scope.create(scope)); addName(name); return name; } @@ -461,6 +461,14 @@ } /* (non-Javadoc) + * @see org.tinytim.core.ConstructImpl#isTopic() + */ + @Override + public final boolean isTopic() { + return true; + } + + /* (non-Javadoc) * @see org.tmapi.core.TopicMapObject#remove() */ public void remove() throws TopicInUseException { Modified: tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java 2008-08-11 12:18:58 UTC (rev 111) @@ -30,7 +30,7 @@ import org.tinytim.index.IndexManager; import org.tinytim.index.IIndexManager; -import org.tinytim.utils.ICollectionFactory; +import org.tinytim.utils.CollectionFactory; import org.tinytim.voc.TMDM; import org.tmapi.core.Association; import org.tmapi.core.IdentityConstraintException; @@ -55,8 +55,6 @@ private IdentityManager _identityManager; private IndexManager _indexManager; - private ICollectionFactory _collectionFactory; - private IFactory _factory; private Locator _locator; private Set<Topic> _topics; private Set<Association> _assocs; @@ -70,23 +68,14 @@ super._tm = this; _sys = sys; _locator = locator; - _collectionFactory = _sys.getCollectionFactory(); - _topics = _collectionFactory.createIdentitySet(100); - _assocs = _collectionFactory.createIdentitySet(100); - _evtHandlers = _collectionFactory.createIdentityMap(); + _topics = CollectionFactory.createIdentitySet(100); + _assocs = CollectionFactory.createIdentitySet(100); + _evtHandlers = CollectionFactory.createIdentityMap(); _identityManager = new IdentityManager(this); - _indexManager = new IndexManager(this, _collectionFactory); + _indexManager = new IndexManager(this); _eventMultiplier = new EventMultiplier(this); } - ICollectionFactory getCollectionFactory() { - return _collectionFactory; - } - - public IFactory getFactory() { - return _factory; - } - Locator getLocator() { return _locator; } @@ -119,7 +108,7 @@ public Topic createTopic() { TopicImpl topic = new TopicImpl(this); addTopic(topic); - topic.addItemIdentifier(Literal.createIRI("urn:x-tinytim:" + IdGenerator.getInstance().nextId())); + topic.addItemIdentifier(Literal.createIRI("urn:x-tinytim:" + IdGenerator.nextId())); return topic; } @@ -244,7 +233,7 @@ if (scope == null) { throw new IllegalArgumentException("The scope must not be null"); } - AssociationImpl assoc = new AssociationImpl(this, type, scope); + AssociationImpl assoc = new AssociationImpl(this, type, Scope.create(scope)); addAssociation(assoc); return assoc; } @@ -328,15 +317,16 @@ /* (non-Javadoc) * @see org.tmapi.core.TopicMap#getIndex(java.lang.Class) */ - public Index getIndex(Class<? extends Index> indexInterface) { + @SuppressWarnings("unchecked") + public <I extends Index> I getIndex(Class<I> indexInterface) { if (indexInterface.getName().equals("org.tmapi.index.TypeInstanceIndex")) { - return _indexManager.getTypeInstanceIndex(); + return (I) _indexManager.getTypeInstanceIndex(); } if (indexInterface.getName().equals("org.tmapi.index.ScopedIndex")) { - return _indexManager.getScopedIndex(); + return (I) _indexManager.getScopedIndex(); } if (indexInterface.getName().equals("org.tmapi.index.LiteralIndex")) { - return _indexManager.getLiteralIndex(); + return (I) _indexManager.getLiteralIndex(); } throw new UnsupportedOperationException("Index '" + indexInterface.getName() + "' is unknown"); } @@ -356,6 +346,14 @@ } /* (non-Javadoc) + * @see org.tinytim.core.ConstructImpl#isTopicMap() + */ + @Override + public boolean isTopicMap() { + return true; + } + + /* (non-Javadoc) * @see org.tmapi.core.TopicMap#remove() */ public void remove() { @@ -373,9 +371,17 @@ } /* (non-Javadoc) + * @see org.tinytim.core.ConstructImpl#_fireEvent(org.tinytim.core.Event, java.lang.Object, java.lang.Object) + */ + @Override + protected final void _fireEvent(Event evt, Object oldValue, Object newValue) { + handleEvent(evt, this, oldValue, newValue); + } + + /* (non-Javadoc) * @see org.tinytim.IEventHandler#handleEvent(org.tinytim.Event, org.tinytim.IConstruct, java.lang.Object, java.lang.Object) */ - public void handleEvent(Event evt, Construct sender, Object oldValue, Object newValue) { + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { if (!_evtHandlers.containsKey(evt)) { _eventMultiplier.handleEvent(evt, sender, oldValue, newValue); return; @@ -421,25 +427,25 @@ _handler = handler; } - public void handleEvent(Event evt, Construct sender, Object oldValue, + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { switch (evt) { - case ADD_TOPIC: _topicAdd((Topic)newValue); break; - case ADD_ASSOCIATION: _associationAdd((Association)newValue); break; - case ADD_NAME: _nameAdd((Name)newValue); break; + case ADD_TOPIC: _topicAdd((TopicImpl)newValue); break; + case ADD_ASSOCIATION: _associationAdd((AssociationImpl)newValue); break; + case ADD_NAME: _nameAdd((NameImpl)newValue); break; case ADD_ROLE: case ADD_OCCURRENCE: - ... [truncated message content] |
From: <lh...@us...> - 2008-08-08 14:10:50
|
Revision: 110 http://tinytim.svn.sourceforge.net/tinytim/?rev=110&view=rev Author: lheuer Date: 2008-08-08 14:10:59 +0000 (Fri, 08 Aug 2008) Log Message: ----------- - Literal test cases with differnt values to avoid caching :/ - Introduced a Literal.get() to check caching Modified Paths: -------------- tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java 2008-08-08 14:03:53 UTC (rev 109) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java 2008-08-08 14:10:59 UTC (rev 110) @@ -42,44 +42,53 @@ } public void testStringEquality() { - final String value = "tinyTiM"; + final String value = "__tinyTiM__"; + assertNull(Literal.get(value)); ILiteral lit1 = Literal.create(value); ILiteral lit2 = Literal.create(value); assertSame(lit1, lit2); } public void testStringEquality2() { - final String value = "tinyTiM"; + final String value = "tinyTiM!"; + assertNull(Literal.get(value)); ILiteral lit1 = Literal.create(value); ILiteral lit2 = Literal.create(value, XSD.STRING); assertSame(lit1, lit2); } public void testStringEquality3() { - final String value = "tinyTiM"; + final String value = "tinyTiM?"; + assertNull(Literal.get(value)); ILiteral lit1 = Literal.create(value, XSD.STRING); ILiteral lit2 = Literal.create(value); assertSame(lit1, lit2); } public void testIRIEquality() { - final Locator value = _sys.createLocator("http://www.semagia.com/"); - ILiteral lit1 = Literal.create(value); - ILiteral lit2 = Literal.create(value); + final String value = "http://www.semagia.com/"; + assertNull(Literal.get(value, XSD.ANY_URI)); + final Locator loc = _sys.createLocator(value); + ILiteral lit1 = Literal.create(loc); + ILiteral lit2 = Literal.create(loc); assertSame(lit1, lit2); } public void testIRIEquality2() { - final Locator value = _sys.createLocator("http://www.semagia.com/"); - ILiteral lit1 = Literal.create(value); - ILiteral lit2 = Literal.create(value.getReference(), XSD.ANY_URI); + final String value = "http://www.semagia.net/"; + assertNull(Literal.get(value, XSD.ANY_URI)); + final Locator loc = _sys.createLocator(value); + ILiteral lit1 = Literal.create(loc); + ILiteral lit2 = Literal.create(value, XSD.ANY_URI); assertSame(lit1, lit2); } public void testIRIEquality3() { - final Locator value = _sys.createLocator("http://www.semagia.com/"); - ILiteral lit1 = Literal.create(value.getReference(), XSD.ANY_URI); - ILiteral lit2 = Literal.create(value); + final String value = "http://www.semagia.de/"; + assertNull(Literal.get(value, XSD.ANY_URI)); + final Locator loc = _sys.createLocator(value); + ILiteral lit1 = Literal.create(value, XSD.ANY_URI); + ILiteral lit2 = Literal.create(loc); assertSame(lit1, lit2); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-08 14:03:45
|
Revision: 109 http://tinytim.svn.sourceforge.net/tinytim/?rev=109&view=rev Author: lheuer Date: 2008-08-08 14:03:53 +0000 (Fri, 08 Aug 2008) Log Message: ----------- Updated test cases Modified Paths: -------------- tinytim/trunk/src/test/java/org/tinytim/core/TestIRI.java tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestIRI.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestIRI.java 2008-08-08 12:10:45 UTC (rev 108) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestIRI.java 2008-08-08 14:03:53 UTC (rev 109) @@ -26,7 +26,7 @@ * Tests against the locator implementation. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class TestIRI extends TinyTimTestCase { Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java 2008-08-08 12:10:45 UTC (rev 108) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java 2008-08-08 14:03:53 UTC (rev 109) @@ -27,10 +27,20 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class TestLiteral extends TinyTimTestCase { + + public void testStringGet() { + final String value = "tiny tiny tiny"; + ILiteral lit = Literal.get(value); + assertNull(lit); + lit = Literal.create(value); + assertNotNull(lit); + assertSame(lit, Literal.get(value)); + } + public void testStringEquality() { final String value = "tinyTiM"; ILiteral lit1 = Literal.create(value); Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java 2008-08-08 12:10:45 UTC (rev 108) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java 2008-08-08 14:03:53 UTC (rev 109) @@ -44,8 +44,8 @@ Association assoc = _tm.createAssociation(type); Association assoc2 = _tm.createAssociation(type); assertFalse(assoc.getId().equals(assoc2.getId())); - String sig = SignatureGenerator.generateSignature(assoc); - assertEquals(sig, SignatureGenerator.generateSignature(assoc2)); + assertEquals(SignatureGenerator.generateSignature(assoc), + SignatureGenerator.generateSignature(assoc2)); } /** @@ -58,8 +58,17 @@ Occurrence occ = topic.createOccurrence(type, "tinyTiM"); Occurrence occ2 = topic.createOccurrence(type, "tinyTiM"); assertFalse(occ.getId().equals(occ2.getId())); - String sig = SignatureGenerator.generateSignature(occ); - assertEquals(sig, SignatureGenerator.generateSignature(occ2)); + assertEquals(SignatureGenerator.generateSignature(occ), + SignatureGenerator.generateSignature(occ2)); + int occ1Sig = SignatureGenerator.generateSignature(occ); + int occ2Sig = SignatureGenerator.generateSignature(occ2); + assertEquals(occ1Sig, occ2Sig); + occ.setType(createTopic()); + int occ1Sig2 = SignatureGenerator.generateSignature(occ); + assertFalse(occ1Sig == occ1Sig2); + occ2.setType(occ.getType()); + int occ2Sig2 = SignatureGenerator.generateSignature(occ2); + assertEquals(occ1Sig2, occ2Sig2); } /** @@ -71,8 +80,15 @@ Name name = topic.createName("tinyTiM"); Name name2 = topic.createName("tinyTiM"); assertFalse(name.getId().equals(name2.getId())); - String sig = SignatureGenerator.generateSignature(name); - assertEquals(sig, SignatureGenerator.generateSignature(name2)); + int name1Sig = SignatureGenerator.generateSignature(name); + int name2Sig = SignatureGenerator.generateSignature(name2); + assertEquals(name1Sig, name2Sig); + name.setType(createTopic()); + int name1Sig2 = SignatureGenerator.generateSignature(name); + assertFalse(name1Sig == name1Sig2); + name2.setType(name.getType()); + int name2Sig2 = SignatureGenerator.generateSignature(name2); + assertEquals(name1Sig2, name2Sig2); } /** @@ -80,11 +96,20 @@ * signature. */ public void testVariantBasic() { - Topic topic = _tm.createTopic(); - Name name = topic.createName("tinyTiM"); - Variant variant = name.createVariant("tiny Topic Maps", _tm.createTopic()); - String sig = SignatureGenerator.generateSignature(variant); - assertEquals(sig, SignatureGenerator.generateSignature(variant)); + final Name name = createName(); + final Topic theme = createTopic(); + final Topic theme2 = createTopic(); + Variant variant = name.createVariant("tiny Topic Maps", theme); + Variant variant2 = name.createVariant("tiny Topic Maps", theme); + int var1Sig = SignatureGenerator.generateSignature(variant); + int var2Sig = SignatureGenerator.generateSignature(variant2); + assertEquals(var1Sig, var2Sig); + variant.addTheme(theme2); + int var1Sig2 = SignatureGenerator.generateSignature(variant); + assertFalse(var1Sig == var1Sig2); + variant2.addTheme(theme2); + int var2Sig2 = SignatureGenerator.generateSignature(variant2); + assertEquals(var1Sig2, var2Sig2); } /** @@ -94,10 +119,10 @@ Topic type1 = _tm.createTopic(); Topic type2 = _tm.createTopic(); Association assoc = _tm.createAssociation(type1); - String sigBefore = SignatureGenerator.generateSignature(assoc); + int sigBefore = SignatureGenerator.generateSignature(assoc); assoc.setType(type2); - String sigAfter = SignatureGenerator.generateSignature(assoc); - assertFalse(sigBefore.equals(sigAfter)); + int sigAfter = SignatureGenerator.generateSignature(assoc); + assertFalse(sigBefore == sigAfter); Association assoc2 = _tm.createAssociation(type1); assertEquals(sigBefore, SignatureGenerator.generateSignature(assoc2)); assoc2.setType(type2); @@ -112,7 +137,19 @@ Role role2 = assoc.createRole(type, player); assertEquals(2, player.getRolesPlayed().size()); assertEquals(2, assoc.getRoles().size()); - String sig = SignatureGenerator.generateSignature(role1); - assertEquals(sig, SignatureGenerator.generateSignature(role2)); + assertEquals(SignatureGenerator.generateSignature(role1), + SignatureGenerator.generateSignature(role2)); } + + public void testRoles2() { + Association assoc = createAssociation(); + Topic type = createTopic(); + Topic player = createTopic(); + Role role1 = assoc.createRole(type, player); + Role role2 = assoc.createRole(player, type); + assertEquals(2, assoc.getRoles().size()); + int role1Sig = SignatureGenerator.generateSignature(role1); + int role2Sig = SignatureGenerator.generateSignature(role2); + assertTrue(role1Sig != role2Sig); + } } Modified: tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java 2008-08-08 12:10:45 UTC (rev 108) +++ tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java 2008-08-08 14:03:53 UTC (rev 109) @@ -23,7 +23,13 @@ import java.util.Enumeration; import java.util.Properties; +import org.tmapi.core.Association; import org.tmapi.core.Locator; +import org.tmapi.core.Name; +import org.tmapi.core.Occurrence; +import org.tmapi.core.Role; +import org.tmapi.core.Topic; +import org.tmapi.core.Variant; import junit.framework.TestCase; @@ -56,6 +62,62 @@ return null; } + /** + * Creates a topic with a random item identifier. + * + * @return The topic. + */ + protected Topic createTopic() { + return _tm.createTopic(); + } + + /** + * Creates an association with a random type and no roles. + * + * @return The association. + */ + protected Association createAssociation() { + return _tm.createAssociation(createTopic()); + } + + /** + * Creates a role which is part of a random association with a random + * player and type. + * + * @return The role. + */ + protected Role createRole() { + return createAssociation().createRole(createTopic(), createTopic()); + } + + /** + * Creates an occurrence which is part of a random topic with a random type. + * + * @return The occurrence. + */ + protected Occurrence createOccurrence() { + return createTopic().createOccurrence(createTopic(), "Occurrence"); + } + + /** + * Creates a name which is part of a newly created topic using the default + * type name. + * + * @return The name. + */ + protected Name createName() { + return createTopic().createName("Name"); + } + + /** + * Creates a variant which is part of a newly created name. + * + * @return The variant. + */ + protected Variant createVariant() { + return createName().createVariant("Variant", createTopic()); + } + /* (non-Javadoc) * @see junit.framework.TestCase#setUp() */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-08 12:10:39
|
Revision: 108 http://tinytim.svn.sourceforge.net/tinytim/?rev=108&view=rev Author: lheuer Date: 2008-08-08 12:10:45 +0000 (Fri, 08 Aug 2008) Log Message: ----------- - Signatures are Integers now (previously Strings) - Added Literal.get(..) to retrieve either an existing Lit. or null Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java tinytim/trunk/src/main/java/org/tinytim/core/IFactory.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/IdGenerator.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/SignatureGenerator.java tinytim/trunk/src/main/java/org/tinytim/index/LiteralIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-08 12:10:45 UTC (rev 108) @@ -176,7 +176,7 @@ */ private static void _copyCharacteristics(Topic topic, TopicImpl targetTopic, Map<Topic, Topic> mergeMap) { - Map<String, Reifiable> sigs = ((TopicMapImpl) targetTopic.getTopicMap()).getCollectionFactory().createMap(); + Map<Integer, Reifiable> sigs = ((TopicMapImpl) targetTopic.getTopicMap()).getCollectionFactory().createMap(); for (Occurrence occ: targetTopic.getOccurrences()) { sigs.put(SignatureGenerator.generateSignature(occ), occ); } @@ -226,7 +226,7 @@ */ private static void _copyVariants(Name source, NameImpl target, Map<Topic, Topic> mergeMap) { - Map<String, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap(); + Map<Integer, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap(); for (Variant variant: target.getVariants()) { sigs.put(SignatureGenerator.generateSignature(variant), variant); } @@ -321,7 +321,7 @@ private static void _copyAssociations(TopicMap source, TopicMapImpl target, Map<Topic, Topic> mergeMap) { Set<Association> assocs = target.getAssociations(); - Map<String, Association> sigs = target.getCollectionFactory().createMap(assocs.size()); + Map<Integer, Association> sigs = target.getCollectionFactory().createMap(assocs.size()); for (Association assoc: assocs) { sigs.put(SignatureGenerator.generateSignature(assoc), assoc); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java 2008-08-08 12:10:45 UTC (rev 108) @@ -22,9 +22,9 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.Map; +import org.tinytim.utils.ICollectionFactory; import org.tmapi.core.Association; import org.tmapi.core.Name; import org.tmapi.core.Occurrence; @@ -56,7 +56,7 @@ for (Topic topic: tm.getTopics()) { removeDuplicates(topic); } - Map<String, Association> sig2Assoc = tm.getCollectionFactory().createMap(); + Map<Integer, Association> sig2Assoc = tm.getCollectionFactory().createMap(); TypeInstanceIndex typeInstanceIdx = tm.getIndexManager().getTypeInstanceIndex(); if (!typeInstanceIdx.isAutoUpdated()) { typeInstanceIdx.reindex(); @@ -64,13 +64,12 @@ for (Topic type: typeInstanceIdx.getAssociationTypes()) { _removeDuplicateAssociations(sig2Assoc, typeInstanceIdx.getAssociations(type)); } - _removeDuplicateAssociations(sig2Assoc, typeInstanceIdx.getAssociations(null)); } - private static void _removeDuplicateAssociations(Map<String, Association> sig2Assoc, Collection<Association> assocs) { + private static void _removeDuplicateAssociations(Map<Integer, Association> sig2Assoc, Collection<Association> assocs) { sig2Assoc.clear(); Association existing = null; - String sig = null; + Integer sig = null; for (Association assoc: assocs) { removeDuplicates(assoc); sig = SignatureGenerator.generateSignature(assoc); @@ -91,8 +90,9 @@ * @param topic The topic from which duplicates should be removed from. */ public static void removeDuplicates(Topic topic) { - _removeDuplicateOccurrences(topic.getOccurrences()); - _removeDuplicateNames(topic.getNames()); + ICollectionFactory collFactory = ((TopicMapImpl) topic.getTopicMap()).getCollectionFactory(); + _removeDuplicateOccurrences(topic.getOccurrences(), collFactory); + _removeDuplicateNames(topic.getNames(), collFactory); } /** @@ -101,9 +101,10 @@ * @param name The name from which the duplicates should be removed. */ public static void removeDuplicates(Name name) { - Map<String, Variant> sigs = new HashMap<String, Variant>(); + Map<Integer, Variant> sigs = ((TopicMapImpl) name.getTopicMap()).getCollectionFactory().createMap(); + Integer sig = null; for (Variant variant: new ArrayList<Variant>(name.getVariants())) { - String sig = SignatureGenerator.generateSignature(variant); + sig = SignatureGenerator.generateSignature(variant); Variant existing = sigs.get(sig); if (existing != null) { MergeUtils.handleExistingConstruct(variant, existing); @@ -120,11 +121,12 @@ * * @param occs */ - private static void _removeDuplicateOccurrences(Collection<Occurrence> occs) { - Map<String, Occurrence> sigs = new HashMap<String, Occurrence>(occs.size()); + private static void _removeDuplicateOccurrences(Collection<Occurrence> occs, ICollectionFactory collFactory) { + Map<Integer, Occurrence> sigs = collFactory.createMap(occs.size()); Occurrence existing = null; + Integer sig = null; for (Occurrence occ: new ArrayList<Occurrence>(occs)) { - String sig = SignatureGenerator.generateSignature(occ); + sig = SignatureGenerator.generateSignature(occ); existing = sigs.get(sig); if (existing != null) { MergeUtils.handleExistingConstruct(occ, existing); @@ -141,12 +143,13 @@ * * @param names */ - private static void _removeDuplicateNames(Collection<Name> names) { - Map<String, Name> sigs = new HashMap<String, Name>(names.size()); + private static void _removeDuplicateNames(Collection<Name> names, ICollectionFactory collFactory) { + Map<Integer, Name> sigs = collFactory.createMap(names.size()); Name existing = null; + Integer sig = null; for (Name name: new ArrayList<Name>(names)) { removeDuplicates(name); - String sig = SignatureGenerator.generateSignature(name); + sig = SignatureGenerator.generateSignature(name); existing = sigs.get(sig); if (existing != null) { MergeUtils.handleExistingConstruct(name, existing); @@ -165,9 +168,9 @@ * @param assoc The association to remove duplicate roles from. */ public static void removeDuplicates(Association assoc) { - Map<String, Role> sig2Role = ((TopicMapImpl) assoc.getTopicMap()).getCollectionFactory().createMap(); + Map<Integer, Role> sig2Role = ((TopicMapImpl) assoc.getTopicMap()).getCollectionFactory().createMap(); Role existing = null; - String sig = null; + Integer sig = null; for (Role role: new ArrayList<Role>(assoc.getRoles())) { sig = SignatureGenerator.generateSignature(role); existing = sig2Role.get(sig); Modified: tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java 2008-08-08 12:10:45 UTC (rev 108) @@ -31,7 +31,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public interface IFactory { Modified: tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java 2008-08-08 12:10:45 UTC (rev 108) @@ -31,7 +31,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$ */ public interface ILiteral { Modified: tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java 2008-08-08 12:10:45 UTC (rev 108) @@ -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$ */ public interface ILiteralAware { Modified: tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java 2008-08-08 12:10:45 UTC (rev 108) @@ -28,7 +28,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$ */ public interface ILocator extends ILiteral, Locator { Modified: tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-08-08 12:10:45 UTC (rev 108) @@ -26,7 +26,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ final class IdGenerator { Modified: tinytim/trunk/src/main/java/org/tinytim/core/Literal.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Literal.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/core/Literal.java 2008-08-08 12:10:45 UTC (rev 108) @@ -37,7 +37,7 @@ * 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:$ + * @version $Rev$ - $Date$ */ public final class Literal implements ILiteral { @@ -49,6 +49,9 @@ 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 = value; _datatype = datatype; } @@ -61,6 +64,34 @@ return _value; } + public static synchronized ILiteral get(String value) { + return _STRINGS.get(new Literal(value, XSD.STRING)); + } + + public static synchronized ILiteral getIRI(String value) { + if (value == null) { + throw new IllegalArgumentException("The value must not be null"); + } + return _IRIS.get(new IRI(value)); + } + + public static synchronized ILiteral get(String value, Locator datatype) { + if (value == null) { + throw new IllegalArgumentException("The value must not be null"); + } + if (datatype == null) { + throw new IllegalArgumentException("The datatype must not be null"); + } + if (XSD.ANY_URI.equals(datatype)) { + return getIRI(value); + } + if (XSD.STRING.equals(datatype)) { + return get(value); + } + return _LITERALS.get(new Literal(value, datatype)); + + } + public static synchronized ILiteral create(final String value, final Locator datatype) { if (value == null) { throw new IllegalArgumentException("The value must not be null"); @@ -84,9 +115,6 @@ } public static synchronized ILiteral create(String value) { - if (value == null) { - throw new IllegalArgumentException("The value must not be null"); - } ILiteral literal = new Literal(value, XSD.STRING); ILiteral existing = _STRINGS.get(literal); if (existing != null) { Modified: tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-08 12:10:45 UTC (rev 108) @@ -121,7 +121,7 @@ for(Topic type: source.getTypes()) { target.addType(type); } - Map<String, Reifiable> sigs = ((TopicMapImpl) source.getTopicMap()).getCollectionFactory().createMap(); + Map<Integer, Reifiable> sigs = ((TopicMapImpl) source.getTopicMap()).getCollectionFactory().createMap(); for (Occurrence occ: target.getOccurrences()) { sigs.put(SignatureGenerator.generateSignature(occ), occ); } @@ -177,7 +177,7 @@ * @param target The association which takes the role characteristics. */ static void moveRoleCharacteristics(Association source, Association target) { - Map<String, Role> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().<String, Role>createMap(); + Map<Integer, Role> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap(); for (Role role: target.getRoles()) { sigs.put(SignatureGenerator.generateSignature(role), role); } @@ -196,7 +196,7 @@ */ @SuppressWarnings("unchecked") static void moveVariants(Name source, Name target) { - Map<String, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().<String, Variant>createMap(); + Map<Integer, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap(); for (Variant var: target.getVariants()) { sigs.put(SignatureGenerator.generateSignature(var), var); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java 2008-08-08 12:10:45 UTC (rev 108) @@ -21,6 +21,7 @@ package org.tinytim.core; import java.util.Arrays; +import java.util.Collection; import java.util.Set; import org.tmapi.core.Association; @@ -61,24 +62,23 @@ * @param assoc The association to generate the signature for. * @return The association's signature. */ - public static String generateSignature(Association assoc) { - StringBuilder sb = new StringBuilder(); - sb.append(_generateTypeSignature(assoc)) - .append('s') - .append(_generateScopeSignature(assoc)) - .append('.'); - Set<Role> roles = assoc.getRoles(); - String[] roleSigs = new String[roles.size()]; + public static int generateSignature(Association assoc) { + return Arrays.hashCode(new int[] {_generateTypeSignature(assoc), + _generateScopeSignature(assoc), + _generateRolesSignature(assoc.getRoles())}); + } + + private static int _generateRolesSignature(final Collection<Role> roles) { + if (roles.isEmpty()) { + return 0; + } + int[] ids = new int[roles.size()]; int i = 0; for (Role role : roles) { - roleSigs[i++] = generateSignature(role); + ids[i++] = generateSignature(role); } - Arrays.sort(roleSigs); - for (String sig : roleSigs) { - sb.append(sig) - .append('.'); - } - return sb.toString(); + Arrays.sort(ids); + return Arrays.hashCode(ids); } /** @@ -87,12 +87,10 @@ * @param role The role to generate the signature for. * @return The role's signature. */ - public static String generateSignature(Role role) { - StringBuilder sb = new StringBuilder(); - sb.append(_generateTypeSignature(role)) - .append('p') - .append(role.getPlayer() == null ? "" : role.getPlayer().getId()); - return sb.toString(); + public static int generateSignature(final Role role) { + return Arrays.hashCode(new int[] { + _signature(role.getType()), _signature(role.getPlayer()) + }); } /** @@ -101,14 +99,12 @@ * @param occ The occurrence to create the signature for. * @return The signature of the occurrence. */ - public static String generateSignature(Occurrence occ) { - StringBuilder sb = new StringBuilder(); - sb.append(_generateTypeSignature(occ)) - .append('s') - .append(_generateScopeSignature(occ)) - .append('v') - .append(_generateDataSignature((ILiteralAware) occ)); - return sb.toString(); + public static int generateSignature(final Occurrence occ) { + return Arrays.hashCode(new int[] { + _generateTypeSignature(occ), + _generateScopeSignature(occ), + _generateDataSignature((ILiteralAware)occ) + }); } /** @@ -119,14 +115,12 @@ * @param name The name to generate the signature for. * @return A signature for the name. */ - public static String generateSignature(Name name) { - StringBuilder sb = new StringBuilder(); - sb.append(_generateTypeSignature(name)) - .append('s') - .append(_generateScopeSignature(name)) - .append('v') - .append(_generateDataSignature((ILiteralAware) name)); - return sb.toString(); + public static int generateSignature(final Name name) { + return Arrays.hashCode(new int[] { + _generateTypeSignature(name), + _generateScopeSignature(name), + _generateDataSignature((ILiteralAware)name) + }); } /** @@ -135,12 +129,11 @@ * @param variant The variant to generate the signature for. * @return A signature for the variant. */ - public static String generateSignature(Variant variant) { - StringBuilder sb = new StringBuilder(); - sb.append(_generateScopeSignature(variant)) - .append('v') - .append(_generateDataSignature((ILiteralAware)variant)); - return sb.toString(); + public static int generateSignature(final Variant variant) { + return Arrays.hashCode(new int[] { + _generateScopeSignature(variant), + _generateDataSignature((ILiteralAware)variant) + }); } /** @@ -149,7 +142,7 @@ * @param construct An occurrence or variant. * @return The signature. */ - private static int _generateDataSignature(ILiteralAware construct) { + private static int _generateDataSignature(final ILiteralAware construct) { return System.identityHashCode(construct.getLiteral()); } @@ -159,9 +152,8 @@ * @param typed The typed Topic Maps construct. * @return The signature. */ - private static String _generateTypeSignature(Typed typed) { - Topic type = typed.getType(); - return type == null ? "" : type.getId(); + private static int _generateTypeSignature(final Typed typed) { + return _signature(typed.getType()); } /** @@ -173,23 +165,22 @@ * @param scoped The scoped Topic Maps construct. * @return The signature. */ - private static String _generateScopeSignature(Scoped scoped) { + private static int _generateScopeSignature(final Scoped scoped) { Set<Topic> scope = scoped.getScope(); if (scope.isEmpty()) { - return ""; + return 0; } - String[] ids = new String[scope.size()]; + int[] ids = new int[scope.size()]; int i = 0; for (Topic topic : scope) { - ids[i++] = topic.getId(); + ids[i++] = _signature(topic); } Arrays.sort(ids); - StringBuilder sb = new StringBuilder(); - for (String id : ids) { - sb.append(id) - .append('.'); - } - return sb.toString(); + return Arrays.hashCode(ids); } + private static int _signature(Topic topic) { + return System.identityHashCode(topic); + } + } Modified: tinytim/trunk/src/main/java/org/tinytim/index/LiteralIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/LiteralIndexImpl.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/index/LiteralIndexImpl.java 2008-08-08 12:10:45 UTC (rev 108) @@ -45,7 +45,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class LiteralIndexImpl extends AbstractIndex implements LiteralIndex { @@ -73,10 +73,13 @@ * @see org.tmapi.index.LiteralIndex#getNames(java.lang.String) */ public Collection<Name> getNames(String value) { - return _getNames(Literal.create(value)); + return _getNames(Literal.get(value)); } private Collection<Name> _getNames(ILiteral literal) { + if (literal == null) { + return Collections.<Name>emptySet(); + } Collection<Name> names = _lit2Names.get(literal); return names == null ? Collections.<Name>emptySet() : new ArrayList<Name>(names); @@ -86,24 +89,30 @@ * @see org.tmapi.index.LiteralIndex#getOccurrences(java.lang.String) */ public Collection<Occurrence> getOccurrences(String value) { - return _getOccurrences(Literal.create(value)); + return _getOccurrences(Literal.get(value)); } /* (non-Javadoc) * @see org.tmapi.index.LiteralIndex#getOccurrences(org.tmapi.core.Locator) */ public Collection<Occurrence> getOccurrences(Locator value) { - return _getOccurrences(Literal.create(value)); + if (value == null) { + throw new IllegalArgumentException("The value must not be null"); + } + return _getOccurrences((ILiteral) value); } /* (non-Javadoc) * @see org.tmapi.index.LiteralIndex#getOccurrences(java.lang.String, org.tmapi.core.Locator) */ public Collection<Occurrence> getOccurrences(String value, Locator datatype) { - return _getOccurrences(Literal.create(value, datatype)); + return _getOccurrences(Literal.get(value, datatype)); } private Collection<Occurrence> _getOccurrences(ILiteral literal) { + if (literal == null) { + return Collections.<Occurrence>emptySet(); + } Collection<Occurrence> occs = _lit2Occs.get(literal); return occs == null ? Collections.<Occurrence>emptySet() : new ArrayList<Occurrence>(occs); @@ -113,24 +122,30 @@ * @see org.tmapi.index.LiteralIndex#getVariants(java.lang.String) */ public Collection<Variant> getVariants(String value) { - return _getVariants(Literal.create(value)); + return _getVariants(Literal.get(value)); } /* (non-Javadoc) * @see org.tmapi.index.LiteralIndex#getVariants(org.tmapi.core.Locator) */ public Collection<Variant> getVariants(Locator value) { - return _getVariants(Literal.create(value)); + if (value == null) { + throw new IllegalArgumentException("The value must not be null"); + } + return _getVariants((ILiteral) value); } /* (non-Javadoc) * @see org.tmapi.index.LiteralIndex#getVariants(java.lang.String, org.tmapi.core.Locator) */ public Collection<Variant> getVariants(String value, Locator datatype) { - return _getVariants(Literal.create(value, datatype)); + return _getVariants(Literal.get(value, datatype)); } private Collection<Variant> _getVariants(ILiteral literal) { + if (literal == null) { + return Collections.<Variant>emptySet(); + } Collection<Variant> variants = _lit2Variants.get(literal); return variants == null ? Collections.<Variant>emptySet() : new ArrayList<Variant>(variants); Modified: tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java 2008-08-08 12:10:45 UTC (rev 108) @@ -27,7 +27,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ abstract class Vocabulary { Modified: tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java 2008-08-08 12:10:45 UTC (rev 108) @@ -26,7 +26,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class XSD extends Vocabulary { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-07 15:08:25
|
Revision: 107 http://tinytim.svn.sourceforge.net/tinytim/?rev=107&view=rev Author: lheuer Date: 2008-08-07 15:08:28 +0000 (Thu, 07 Aug 2008) Log Message: ----------- - Imported new test suite Added Paths: ----------- tinytim/trunk/src/test/java/org/tinytim/core/ 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/TestDuplicateRemovalUtils.java tinytim/trunk/src/test/java/org/tinytim/core/TestIRI.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/TestSignatureGenerator.java tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPICore.java tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPIIndex.java tinytim/trunk/src/test/java/org/tinytim/core/TestTopicMapSystemFactoryImpl.java tinytim/trunk/src/test/java/org/tinytim/core/TestTopicUtils.java tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java Added: tinytim/trunk/src/test/java/org/tinytim/core/AbstractTMAPITestSuite.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/AbstractTMAPITestSuite.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/core/AbstractTMAPITestSuite.java 2008-08-07 15:08:28 UTC (rev 107) @@ -0,0 +1,36 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.core; + +import junit.framework.TestSuite; + +/** + * Base class for all TMAPI-related test cases. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public abstract class AbstractTMAPITestSuite extends TestSuite { + + static { + System.setProperty("org.tmapi.core.TopicMapSystemFactory", "org.tinytim.core.TopicMapSystemFactoryImpl"); + } +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/AbstractTMAPITestSuite.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2008-08-07 15:08:28 UTC (rev 107) @@ -0,0 +1,51 @@ +/* + * 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 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(TestIRI.class); + suite.addTestSuite(TestLiteral.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); + return suite; + } +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/test/java/org/tinytim/core/TestDuplicateRemovalUtils.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestDuplicateRemovalUtils.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestDuplicateRemovalUtils.java 2008-08-07 15:08:28 UTC (rev 107) @@ -0,0 +1,105 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.core; + +import org.tmapi.core.Association; +import org.tmapi.core.Locator; +import org.tmapi.core.Name; +import org.tmapi.core.Topic; + +/** + * Tests against the {@link DuplicateRemovalUtils}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public class TestDuplicateRemovalUtils extends TinyTimTestCase { + + public void testTopicRemoveNames() { + Topic topic = _tm.createTopic(); + Topic nameType = _tm.createTopic(); + Name name1 = topic.createName(nameType, "tinyTiM"); + Name name2 = topic.createName(nameType, "tinyTiM"); + assertEquals(nameType, name1.getType()); + assertTrue(name1.getScope().isEmpty()); + assertEquals(nameType, name2.getType()); + assertTrue(name2.getScope().isEmpty()); + assertEquals(2, topic.getNames().size()); + DuplicateRemovalUtils.removeDuplicates(topic); + assertEquals(1, topic.getNames().size()); + Name name = (Name) topic.getNames().iterator().next(); + assertEquals("tinyTiM", name.getValue()); + assertEquals(nameType, name.getType()); + assertTrue(name.getScope().isEmpty()); + } + + public void testTopicRemoveNames2() { + Topic topic = _tm.createTopic(); + Topic nameType = _tm.createTopic(); + Name name1 = topic.createName(nameType, "tinyTiM"); + Name name2 = topic.createName(nameType, "tinyTiM"); + Locator iid1 = _tm.createLocator("http://example.org/iid-1"); + Locator iid2 = _tm.createLocator("http://example.org/iid-2"); + name1.addItemIdentifier(iid1); + name2.addItemIdentifier(iid2); + assertEquals(2, topic.getNames().size()); + DuplicateRemovalUtils.removeDuplicates(topic); + assertEquals(1, topic.getNames().size()); + Name name = (Name) topic.getNames().iterator().next(); + assertEquals("tinyTiM", name.getValue()); + assertEquals(nameType, name.getType()); + assertTrue(name.getScope().isEmpty()); + assertEquals(2, name.getItemIdentifiers().size()); + assertTrue(name.getItemIdentifiers().contains(iid1)); + assertTrue(name.getItemIdentifiers().contains(iid2)); + } + + public void testTopicRemoveNames3() { + Topic topic = _tm.createTopic(); + Topic theme1 = _tm.createTopic(); + Topic theme2 = _tm.createTopic(); + Topic nameType = _tm.createTopic(); + Name name1 = topic.createName(nameType, "tinyTiM", theme1, theme2); + Name name2 = topic.createName(nameType, "tinyTiM", theme2, theme1); + assertEquals(2, name1.getScope().size()); + assertEquals(2, name2.getScope().size()); + assertEquals(2, topic.getNames().size()); + DuplicateRemovalUtils.removeDuplicates(topic); + assertEquals(1, topic.getNames().size()); + Name name = (Name) topic.getNames().iterator().next(); + assertEquals("tinyTiM", name.getValue()); + assertEquals(nameType, name.getType()); + assertEquals(2, name.getScope().size()); + } + + public void testRemoveRoles() { + Association assoc = _tm.createAssociation(_tm.createTopic()); + Topic type = _tm.createTopic(); + Topic player = _tm.createTopic(); + assoc.createRole(type, player); + assoc.createRole(type, player); + assertEquals(2, player.getRolesPlayed().size()); + assertEquals(2, assoc.getRoles().size()); + DuplicateRemovalUtils.removeDuplicates(assoc); + assertEquals(1, player.getRolesPlayed().size()); + assertEquals(1, assoc.getRoles().size()); + } +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestDuplicateRemovalUtils.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/test/java/org/tinytim/core/TestIRI.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestIRI.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestIRI.java 2008-08-07 15:08:28 UTC (rev 107) @@ -0,0 +1,51 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.core; + +import org.tmapi.core.Locator; + +/** + * Tests against the locator implementation. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class TestIRI extends TinyTimTestCase { + + 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()); + 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()); + } + + //TODO! +// public void testLowerCaseScheme() { +// 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()); +// } +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestIRI.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java 2008-08-07 15:08:28 UTC (rev 107) @@ -0,0 +1,154 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.core; + +import org.tmapi.core.Association; +import org.tmapi.core.Construct; +import org.tmapi.core.IdentityConstraintException; +import org.tmapi.core.Locator; +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; + +/** + * Tests if the TMDM item identifier constraint is respected. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public class TestItemIdentifierConstraint extends TinyTimTestCase { + + /** + * Tests against a topic map. + */ + public void testTopicMap() throws Exception { + _testConstraint(_tm); + } + + /** + * Tests againts a topic. + */ + public void testTopic() throws Exception { + Topic topic = _tm.createTopic(); + Locator iid = _tm.createLocator("http://sf.net/projects/tinytim"); + topic.addItemIdentifier(iid); + assertTrue(topic.getItemIdentifiers().contains(iid)); + Topic topic2 = _tm.createTopic(); + try { + topic2.addItemIdentifier(iid); + } + catch (IdentityConstraintException ex) { + // noop. + } + topic.removeItemIdentifier(iid); + assertFalse(topic.getItemIdentifiers().contains(iid)); + topic2.addItemIdentifier(iid); + assertTrue(topic2.getItemIdentifiers().contains(iid)); + topic2.removeItemIdentifier(iid); + topic.addItemIdentifier(iid); + assertTrue(topic.getItemIdentifiers().contains(iid)); + assertFalse(topic2.getItemIdentifiers().contains(iid)); + topic.remove(); + topic2.addItemIdentifier(iid); + assertTrue(topic2.getItemIdentifiers().contains(iid)); + } + + /** + * Tests against an association. + */ + public void testAssociation() throws Exception { + _testConstraint(_tm.createAssociation(_tm.createTopic())); + } + + /** + * Tests against a role. + */ + public void testRole() throws Exception { + Association assoc = _tm.createAssociation(_tm.createTopic()); + Role role = assoc.createRole(_tm.createTopic(), _tm.createTopic()); + _testConstraint(role); + } + + /** + * Tests against an occurrence. + */ + public void testOccurrence() throws Exception { + Topic topic = _tm.createTopic(); + Occurrence occ = topic.createOccurrence(_tm.createTopic(), "tinyTiM"); + _testConstraint(occ); + } + + /** + * Tests against a name. + */ + public void testName() throws Exception { + Topic topic = _tm.createTopic(); + Name name = topic.createName("tinyTiM"); + _testConstraint(name); + } + + /** + * Tests against a variant. + */ + public void testVariant() throws Exception { + Topic topic = _tm.createTopic(); + Name name = topic.createName("tinyTiM"); + Variant variant = name.createVariant("tinyTiM", _tm.createTopic()); + _testConstraint(variant); + } + + /** + * The item identifier constraint test. + * + * @param tmo The Topic Maps construct to test. + */ + private void _testConstraint(Construct tmo) throws Exception { + assertTrue(tmo.getItemIdentifiers().isEmpty()); + Locator iid = _tm.createLocator("http://sf.net/projects/tinytim"); + tmo.addItemIdentifier(iid); + assertTrue(tmo.getItemIdentifiers().contains(iid)); + Association assoc = _tm.createAssociation(_tm.createTopic()); + try { + assoc.addItemIdentifier(iid); + fail("Topic Maps constructs with the same item identifier are not allowed"); + } + catch (IdentityConstraintException ex) { + // noop + } + tmo.removeItemIdentifier(iid); + assertFalse(tmo.getItemIdentifiers().contains(iid)); + assoc.addItemIdentifier(iid); + assertTrue(assoc.getItemIdentifiers().contains(iid)); + assoc.removeItemIdentifier(iid); + assertFalse(assoc.getItemIdentifiers().contains(iid)); + tmo.addItemIdentifier(iid); + assertTrue(tmo.getItemIdentifiers().contains(iid)); + if (!(tmo instanceof TopicMap)) { + // Removal should 'free' the item identifier + tmo.remove(); + assoc.addItemIdentifier(iid); + assertTrue(assoc.getItemIdentifiers().contains(iid)); + } + } +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java 2008-08-07 15:08:28 UTC (rev 107) @@ -0,0 +1,75 @@ +/* + * 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; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class TestLiteral extends TinyTimTestCase { + + public void testStringEquality() { + final String value = "tinyTiM"; + ILiteral lit1 = Literal.create(value); + ILiteral lit2 = Literal.create(value); + assertSame(lit1, lit2); + } + + public void testStringEquality2() { + final String value = "tinyTiM"; + ILiteral lit1 = Literal.create(value); + ILiteral lit2 = Literal.create(value, XSD.STRING); + assertSame(lit1, lit2); + } + + public void testStringEquality3() { + final String value = "tinyTiM"; + ILiteral lit1 = Literal.create(value, XSD.STRING); + ILiteral lit2 = Literal.create(value); + assertSame(lit1, lit2); + } + + public void testIRIEquality() { + final Locator value = _sys.createLocator("http://www.semagia.com/"); + ILiteral lit1 = Literal.create(value); + ILiteral lit2 = Literal.create(value); + assertSame(lit1, lit2); + } + + public void testIRIEquality2() { + final Locator value = _sys.createLocator("http://www.semagia.com/"); + ILiteral lit1 = Literal.create(value); + ILiteral lit2 = Literal.create(value.getReference(), XSD.ANY_URI); + assertSame(lit1, lit2); + } + + public void testIRIEquality3() { + final Locator value = _sys.createLocator("http://www.semagia.com/"); + ILiteral lit1 = Literal.create(value.getReference(), XSD.ANY_URI); + ILiteral lit2 = Literal.create(value); + assertSame(lit1, lit2); + } +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java 2008-08-07 15:08:28 UTC (rev 107) @@ -0,0 +1,118 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.core; + +import org.tmapi.core.Association; +import org.tmapi.core.Name; +import org.tmapi.core.Occurrence; +import org.tmapi.core.Role; +import org.tmapi.core.Topic; +import org.tmapi.core.Variant; + +/** + * Tests against the {@link org.tinytim.SignatureGenerator}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public class TestSignatureGenerator extends TinyTimTestCase { + + /** + * Tests if an association with no initialized properties returns the same + * signature. + */ + public void testAssociationBasic() { + Topic type = _tm.createTopic(); + Association assoc = _tm.createAssociation(type); + Association assoc2 = _tm.createAssociation(type); + assertFalse(assoc.getId().equals(assoc2.getId())); + String sig = SignatureGenerator.generateSignature(assoc); + assertEquals(sig, SignatureGenerator.generateSignature(assoc2)); + } + + /** + * Tests if an occurrence with no initialized properties returns the same + * signature. + */ + public void testOccurrenceBasic() { + Topic topic = _tm.createTopic(); + Topic type = _tm.createTopic(); + Occurrence occ = topic.createOccurrence(type, "tinyTiM"); + Occurrence occ2 = topic.createOccurrence(type, "tinyTiM"); + assertFalse(occ.getId().equals(occ2.getId())); + String sig = SignatureGenerator.generateSignature(occ); + assertEquals(sig, SignatureGenerator.generateSignature(occ2)); + } + + /** + * Tests if a name with no initialized properties returns the same + * signature. + */ + public void testNameBasic() { + Topic topic = _tm.createTopic(); + Name name = topic.createName("tinyTiM"); + Name name2 = topic.createName("tinyTiM"); + assertFalse(name.getId().equals(name2.getId())); + String sig = SignatureGenerator.generateSignature(name); + assertEquals(sig, SignatureGenerator.generateSignature(name2)); + } + + /** + * Tests if a variant with no initialized properties returns the same + * signature. + */ + public void testVariantBasic() { + Topic topic = _tm.createTopic(); + Name name = topic.createName("tinyTiM"); + Variant variant = name.createVariant("tiny Topic Maps", _tm.createTopic()); + String sig = SignatureGenerator.generateSignature(variant); + assertEquals(sig, SignatureGenerator.generateSignature(variant)); + } + + /** + * Tests if associations with the same type return the same signature. + */ + public void testAssociationTyped() { + Topic type1 = _tm.createTopic(); + Topic type2 = _tm.createTopic(); + Association assoc = _tm.createAssociation(type1); + String sigBefore = SignatureGenerator.generateSignature(assoc); + assoc.setType(type2); + String sigAfter = SignatureGenerator.generateSignature(assoc); + assertFalse(sigBefore.equals(sigAfter)); + Association assoc2 = _tm.createAssociation(type1); + assertEquals(sigBefore, SignatureGenerator.generateSignature(assoc2)); + assoc2.setType(type2); + assertEquals(sigAfter, SignatureGenerator.generateSignature(assoc2)); + } + + public void testRoles() { + Association assoc = _tm.createAssociation(_tm.createTopic()); + Topic type = _tm.createTopic(); + Topic player = _tm.createTopic(); + Role role1 = assoc.createRole(type, player); + Role role2 = assoc.createRole(type, player); + assertEquals(2, player.getRolesPlayed().size()); + assertEquals(2, assoc.getRoles().size()); + String sig = SignatureGenerator.generateSignature(role1); + assertEquals(sig, SignatureGenerator.generateSignature(role2)); + } +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPICore.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPICore.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPICore.java 2008-08-07 15:08:28 UTC (rev 107) @@ -0,0 +1,42 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.core; + +import org.tmapi.core.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(); + } +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPICore.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPIIndex.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPIIndex.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPIIndex.java 2008-08-07 15:08:28 UTC (rev 107) @@ -0,0 +1,42 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.core; + +import org.tmapi.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(); + } +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPIIndex.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/test/java/org/tinytim/core/TestTopicMapSystemFactoryImpl.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestTopicMapSystemFactoryImpl.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestTopicMapSystemFactoryImpl.java 2008-08-07 15:08:28 UTC (rev 107) @@ -0,0 +1,190 @@ +/* + * 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.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.tinytim.utils.ICollectionFactory; +import org.tinytim.utils.Property; +import org.tinytim.utils.Feature; +import org.tmapi.core.FeatureNotRecognizedException; +import org.tmapi.core.FeatureNotSupportedException; + +/** + * Tests against the {@link org.tinytim.TopicMapSystemFactoryImpl}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public class TestTopicMapSystemFactoryImpl extends TinyTimTestCase { + + /** + * Tests the default feature values. + * + * @throws Exception + */ + public void testDefaultFeatureValues() throws Exception { + assertTrue(_sysFactory.getFeature(Feature.NOTATION_URI)); + assertTrue(_sysFactory.getFeature(Feature.XTM_1_1)); + assertFalse(_sysFactory.getFeature(Feature.XTM_1_0)); + assertFalse(_sysFactory.getFeature(Feature.READ_ONLY)); + assertFalse(_sysFactory.getFeature(Feature.AUTOMERGE)); + assertFalse(_sysFactory.getFeature(Feature.TNC)); + } + + + private void _setFeatureToAcceptedValue(String featureName, boolean value) throws Exception { + try { + _sysFactory.setFeature(featureName, value); + } + catch (FeatureNotSupportedException ex) { + fail("Unexpected exception while setting '" + featureName + "' to '" + value + "'"); + } + } + + private void _setFeatureToUnacceptedValue(String featureName, boolean value) throws Exception { + try { + _sysFactory.setFeature(featureName, value); + fail("Expected exception while setting '" + featureName + "' to '" + value + "'"); + } + catch (FeatureNotSupportedException ex) { + // noop. + } + } + + /** + * Tests if enabling / disabling of various features delivers the expected + * results. + * + * @throws Exception + */ + public void testSetFeatureValues() throws Exception { + _setFeatureToAcceptedValue(Feature.NOTATION_URI, true); + _setFeatureToUnacceptedValue(Feature.NOTATION_URI, false); + _setFeatureToAcceptedValue(Feature.XTM_1_0, false); + _setFeatureToUnacceptedValue(Feature.XTM_1_0, true); + _setFeatureToAcceptedValue(Feature.XTM_1_1, true); + _setFeatureToUnacceptedValue(Feature.XTM_1_1, false); + _setFeatureToAcceptedValue(Feature.READ_ONLY, false); + _setFeatureToUnacceptedValue(Feature.READ_ONLY, true); + _setFeatureToAcceptedValue(Feature.AUTOMERGE, false); + _setFeatureToUnacceptedValue(Feature.AUTOMERGE, true); + _setFeatureToAcceptedValue(Feature.TNC, false); + _setFeatureToUnacceptedValue(Feature.TNC, true); + } + + /** + * Tests if an unknown feature throws the expected exception. + * + * @throws Exception + */ + public void testUnrecognizedFeature() throws Exception { + try { + String unknownFeatureName = "http://www.semagia.com/tinyTiM/unknownTMAPIFeature"; + _sysFactory.setFeature(unknownFeatureName, true); + fail("Expected an exception while setting a unknown feature"); + } + catch (FeatureNotRecognizedException ex) { + // noop. + } + } + + /** + * Tests if the collection factory property is set. + * + * @throws Exception + */ + public void testCollectionFactoryProperty() throws Exception { + boolean troveAvailable = false; + try { + Class.forName("gnu.trove.THashSet"); + troveAvailable = true; + } + catch (Exception ex) { + // noop. + } + if (troveAvailable) { + assertEquals("org.tinytim.core.TroveCollectionFactory", _sysFactory.getProperty(Property.COLLECTION_FACTORY)); + } + else { + assertEquals("org.tinytim.core.JavaCollectionFactory", _sysFactory.getProperty(Property.COLLECTION_FACTORY)); + assertTrue(((TopicMapSystemImpl) _sysFactory.newTopicMapSystem()).getCollectionFactory() instanceof JavaCollectionFactory); + } + } + + /** + * Tests if the TopicMapSystemFactory creates automatically a default + * CollectionFactory iff the class name in the property is invaild / + * not resolvable. + * + * @throws Exception + */ + public void testCollectionFactoryFallback() throws Exception { + _sysFactory.setProperty(Property.COLLECTION_FACTORY, "a.non.existent.CollectionFactory"); + TopicMapSystemImpl sys = (TopicMapSystemImpl) _sysFactory.newTopicMapSystem(); + assertTrue(sys.getCollectionFactory() instanceof JavaCollectionFactory); + } + + /** + * Sets the setting of a custom {@link ICollectionFactory}. + * + * @throws Exception + */ + public void testCustomCollectionFactory() throws Exception { + _sysFactory.setProperty(Property.COLLECTION_FACTORY, MyCollectionFactory.class.getName()); + TopicMapSystemImpl sys = (TopicMapSystemImpl) _sysFactory.newTopicMapSystem(); + assertTrue(sys.getCollectionFactory() instanceof MyCollectionFactory); + } + + /** + * {@link ICollectionFactory} implementation that uses the Java collections. + */ + public static final class MyCollectionFactory implements ICollectionFactory { + public <K, V> Map<K, V> createMap() { + return new HashMap<K, V>(); + } + public <K, V> Map<K, V> createMap(int size) { + return createMap(); + } + public <E> Set<E> createSet(int size) { + return createSet(); + } + public <E> Set<E> createSet() { + return new HashSet<E>(); + } + public <K, V> Map<K, V> createIdentityMap() { + return createMap(); + } + public <K, V> Map<K, V> createIdentityMap(int size) { + return createMap(size); + } + public <E> Set<E> createIdentitySet() { + return createSet(); + } + public <E> Set<E> createIdentitySet(int size) { + return createSet(size); + } + + } +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestTopicMapSystemFactoryImpl.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/test/java/org/tinytim/core/TestTopicUtils.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestTopicUtils.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestTopicUtils.java 2008-08-07 15:08:28 UTC (rev 107) @@ -0,0 +1,64 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.core; + +import org.tmapi.core.Association; +import org.tmapi.core.Role; +import org.tmapi.core.Topic; + +/** + * Tests against the {@link TopicUtils}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public class TestTopicUtils extends TinyTimTestCase { + + /** + * Tests if a topic is considered as 'removable'. + */ + public void testRemovable() { + Topic topic = _tm.createTopic(); + assertTrue(TopicUtils.isRemovable(topic)); + Association assoc = _tm.createAssociation(topic); + assertFalse(TopicUtils.isRemovable(topic)); + assoc.setType(_tm.createTopic()); + assertTrue(TopicUtils.isRemovable(topic)); + // Role played + Role role = assoc.createRole(_tm.createTopic(), topic); + assertFalse(TopicUtils.isRemovable(topic)); + role.setPlayer(_tm.createTopic()); + assertTrue(TopicUtils.isRemovable(topic)); + // Theme + assoc.addTheme(topic); + assertFalse(TopicUtils.isRemovable(topic)); + assoc.removeTheme(topic); + assertTrue(TopicUtils.isRemovable(topic)); + // Reifier + assoc.setReifier(topic); + assertTrue(TopicUtils.isRemovable(topic)); + assertFalse(TopicUtils.isRemovable(topic, true)); + assoc.setReifier(null); + assertTrue(TopicUtils.isRemovable(topic)); + assertTrue(TopicUtils.isRemovable(topic, true)); + } + +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestTopicUtils.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java 2008-08-07 15:08:28 UTC (rev 107) @@ -0,0 +1,90 @@ +/* + * 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.Enumeration; +import java.util.Properties; + +import org.tmapi.core.Locator; + +import junit.framework.TestCase; + +/** + * Base class of all tinyTiM-specific test cases. + * + * This class sets up a default {@link org.tinytim.TopicMapSystemFactoryImpl}, + * a {@link org.tinytim.TopicMapSystemImpl}, and a + * {@link org.tinytim.TopicMapImpl}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public class TinyTimTestCase extends TestCase { + + protected static final String _IRI = "http://www.semagia.com/tinyTiM/testTopicMap/"; + protected Locator _base; + protected TopicMapImpl _tm; + protected TopicMapSystemImpl _sys; + protected TopicMapSystemFactoryImpl _sysFactory; + + /** + * Returns additional / non-default properties which should be set + * to configure the {@link org.tmapi.core.TopicMapSystemFactory}. + * + * @return Properties instance or <code>null</code> if no properties != + * default properties should be set. + */ + protected Properties getAdditionalProperties() { + return null; + } + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + _sysFactory = new TopicMapSystemFactoryImpl(); + Properties properties = getAdditionalProperties(); + if (properties != null) { + for (Enumeration<?> e = properties.propertyNames(); e.hasMoreElements();) { + String name = (String) e.nextElement(); + _sysFactory.setProperty(name, properties.getProperty(name)); + } + } + _sys = (TopicMapSystemImpl) _sysFactory.newTopicMapSystem(); + _base = _sys.createLocator(_IRI); + _tm = (TopicMapImpl) _sys.createTopicMap(_base); + } + + /* (non-Javadoc) + * @see junit.framework.TestCase#tearDown() + */ + @Override + protected void tearDown() throws Exception { + super.tearDown(); + _sysFactory = null; + _sys = null; + _tm = null; + _base = null; + } + +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.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-08-07 15:06:51
|
Revision: 106 http://tinytim.svn.sourceforge.net/tinytim/?rev=106&view=rev Author: lheuer Date: 2008-08-07 15:06:58 +0000 (Thu, 07 Aug 2008) Log Message: ----------- Removed old test suite Removed Paths: ------------- tinytim/trunk/src/test/java/org/tinytim/AbstractTMAPITestSuite.java tinytim/trunk/src/test/java/org/tinytim/AllTests.java tinytim/trunk/src/test/java/org/tinytim/TestConstruct.java tinytim/trunk/src/test/java/org/tinytim/TestDuplicateRemovalUtils.java tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java tinytim/trunk/src/test/java/org/tinytim/TestReifiable.java tinytim/trunk/src/test/java/org/tinytim/TestReificationUtils.java tinytim/trunk/src/test/java/org/tinytim/TestScoped.java tinytim/trunk/src/test/java/org/tinytim/TestSignatureGenerator.java tinytim/trunk/src/test/java/org/tinytim/TestTMAPICore.java tinytim/trunk/src/test/java/org/tinytim/TestTMAPIIndex.java tinytim/trunk/src/test/java/org/tinytim/TestTopic.java tinytim/trunk/src/test/java/org/tinytim/TestTopicMapMerge.java tinytim/trunk/src/test/java/org/tinytim/TestTopicMapSystemFactoryImpl.java tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java tinytim/trunk/src/test/java/org/tinytim/TestTopicMergeDetection.java tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java tinytim/trunk/src/test/java/org/tinytim/TestTyped.java tinytim/trunk/src/test/java/org/tinytim/TinyTimTestCase.java tinytim/trunk/src/test/java/org/tinytim/index/ Deleted: tinytim/trunk/src/test/java/org/tinytim/AbstractTMAPITestSuite.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/AbstractTMAPITestSuite.java 2008-08-07 14:42:58 UTC (rev 105) +++ tinytim/trunk/src/test/java/org/tinytim/AbstractTMAPITestSuite.java 2008-08-07 15:06:58 UTC (rev 106) @@ -1,36 +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; - -import junit.framework.TestSuite; - -/** - * Base class for all TMAPI-related test cases. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public abstract class AbstractTMAPITestSuite extends TestSuite { - - static { - System.setProperty("org.tmapi.core.TopicMapSystemFactory", "org.tinytim.TopicMapSystemFactoryImpl"); - } -} Deleted: tinytim/trunk/src/test/java/org/tinytim/AllTests.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/AllTests.java 2008-08-07 14:42:58 UTC (rev 105) +++ tinytim/trunk/src/test/java/org/tinytim/AllTests.java 2008-08-07 15:06:58 UTC (rev 106) @@ -1,62 +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; - -import org.tinytim.index.TestScopedIndex; -import org.tinytim.index.TestTypeInstanceIndex; - -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(TestConstruct.class); - suite.addTestSuite(TestDuplicateRemovalUtils.class); - suite.addTestSuite(TestItemIdentifierConstraint.class); - suite.addTestSuite(TestReifiable.class); - suite.addTestSuite(TestScoped.class); - suite.addTestSuite(TestTopic.class); - suite.addTestSuite(TestSignatureGenerator.class); - suite.addTest(TestTMAPICore.suite()); - suite.addTest(TestTMAPIIndex.suite()); - suite.addTestSuite(TestTopicMapMerge.class); - suite.addTestSuite(TestTopicMapSystemFactoryImpl.class); - suite.addTestSuite(TestTopicMerge.class); - suite.addTestSuite(TestTopicMergeDetection.class); - suite.addTestSuite(TestTopicUtils.class); - suite.addTestSuite(TestTyped.class); - suite.addTestSuite(TestScopedIndex.class); - suite.addTestSuite(TestTypeInstanceIndex.class); - return suite; - } -} Deleted: tinytim/trunk/src/test/java/org/tinytim/TestConstruct.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestConstruct.java 2008-08-07 14:42:58 UTC (rev 105) +++ tinytim/trunk/src/test/java/org/tinytim/TestConstruct.java 2008-08-07 15:06:58 UTC (rev 106) @@ -1,117 +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; - -import org.tmapi.core.Association; -import org.tmapi.core.AssociationRole; -import org.tmapi.core.Locator; -import org.tmapi.core.Occurrence; -import org.tmapi.core.Topic; -import org.tmapi.core.TopicName; -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$ - */ -public class TestConstruct extends TinyTimTestCase { - - /** - * Tests against the topic map. - */ - public void testTopicMap() { - _testConstruct((IConstruct) _tm); - } - - /** - * Tests against the topic. - */ - public void testTopic() { - _testConstruct((IConstruct) _tm.createTopic()); - } - - /** - * Tests against the association. - */ - public void testAssociation() { - _testConstruct((IConstruct) _tm.createAssociation()); - } - - /** - * Tests against the role. - */ - public void testRole() { - Association assoc = _tm.createAssociation(); - AssociationRole role = assoc.createAssociationRole(null, null); - _testConstruct((IConstruct) role); - } - - /** - * Tests against an occurrence. - */ - public void testOccurrence() { - Topic topic = _tm.createTopic(); - Occurrence occ = topic.createOccurrence("tinyTiM", null, null); - _testConstruct((IConstruct) occ); - } - - /** - * Tests against a name. - */ - public void testName() { - Topic topic = _tm.createTopic(); - TopicName name = topic.createTopicName("tinyTiM", null, null); - _testConstruct((IConstruct) name); - } - - /** - * Tests against a variant. - */ - public void testVariant() { - Topic topic = _tm.createTopic(); - TopicName name = topic.createTopicName("tinyTiM", null, null); - Variant variant = name.createVariant("tinyTiM", null); - _testConstruct((IConstruct) variant); - } - - /** - * Tests adding / removing item identifiers, retrieval by item identifier. - * - * @param construct The Topic Maps construct to test. - */ - private void _testConstruct(IConstruct construct) { - assertEquals(0, construct.getItemIdentifiers().size()); - Locator iid = _tm.createLocator("http://sf.net/projects/tinytim/#test"); - construct.addItemIdentifier(iid); - assertEquals(1, construct.getItemIdentifiers().size()); - assertTrue(construct.getItemIdentifiers().contains(iid)); - assertEquals(construct, _tm.getObjectByItemIdentifier(iid)); - construct.removeItemIdentifier(iid); - assertEquals(0, construct.getItemIdentifiers().size()); - assertFalse(construct.getItemIdentifiers().contains(iid)); - assertNull(_tm.getObjectByItemIdentifier(iid)); - - String id = construct.getObjectId(); - assertEquals(construct, _tm.getObjectById(id)); - } -} Deleted: tinytim/trunk/src/test/java/org/tinytim/TestDuplicateRemovalUtils.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestDuplicateRemovalUtils.java 2008-08-07 14:42:58 UTC (rev 105) +++ tinytim/trunk/src/test/java/org/tinytim/TestDuplicateRemovalUtils.java 2008-08-07 15:06:58 UTC (rev 106) @@ -1,107 +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; - -import java.util.Arrays; -import java.util.Collection; - -import org.tmapi.core.Association; -import org.tmapi.core.Locator; -import org.tmapi.core.Topic; -import org.tmapi.core.TopicName; - -/** - * Tests against the {@link DuplicateRemovalUtils}. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ - */ -public class TestDuplicateRemovalUtils extends TinyTimTestCase { - - public void testTopicRemoveNames() { - Topic topic = _tm.createTopic(); - TopicName name1 = topic.createTopicName("tinyTiM", null); - TopicName name2 = topic.createTopicName("tinyTiM", null); - assertNull(name1.getType()); - assertTrue(name1.getScope().isEmpty()); - assertNull(name2.getType()); - assertTrue(name2.getScope().isEmpty()); - assertEquals(2, topic.getTopicNames().size()); - DuplicateRemovalUtils.removeDuplicates(topic); - assertEquals(1, topic.getTopicNames().size()); - TopicName name = (TopicName) topic.getTopicNames().iterator().next(); - assertEquals("tinyTiM", name.getValue()); - assertNull(name.getType()); - assertTrue(name.getScope().isEmpty()); - } - - public void testTopicRemoveNames2() { - Topic topic = _tm.createTopic(); - TopicName name1 = topic.createTopicName("tinyTiM", null); - TopicName name2 = topic.createTopicName("tinyTiM", null); - Locator iid1 = _tm.createLocator("http://example.org/iid-1"); - Locator iid2 = _tm.createLocator("http://example.org/iid-2"); - name1.addSourceLocator(iid1); - name2.addSourceLocator(iid2); - assertEquals(2, topic.getTopicNames().size()); - DuplicateRemovalUtils.removeDuplicates(topic); - assertEquals(1, topic.getTopicNames().size()); - TopicName name = (TopicName) topic.getTopicNames().iterator().next(); - assertEquals("tinyTiM", name.getValue()); - assertNull(name.getType()); - assertTrue(name.getScope().isEmpty()); - assertEquals(2, name.getSourceLocators().size()); - assertTrue(name.getSourceLocators().contains(iid1)); - assertTrue(name.getSourceLocators().contains(iid2)); - } - - public void testTopicRemoveNames3() { - Topic topic = _tm.createTopic(); - Topic theme1 = _tm.createTopic(); - Topic theme2 = _tm.createTopic(); - Collection<Topic> scope1 = Arrays.asList(new Topic[] {theme1, theme2}); - Collection<Topic> scope2 = Arrays.asList(new Topic[] {theme2, theme1}); - TopicName name1 = topic.createTopicName("tinyTiM", scope1); - TopicName name2 = topic.createTopicName("tinyTiM", scope2); - assertEquals(2, name1.getScope().size()); - assertEquals(2, name2.getScope().size()); - assertEquals(2, topic.getTopicNames().size()); - DuplicateRemovalUtils.removeDuplicates(topic); - assertEquals(1, topic.getTopicNames().size()); - TopicName name = (TopicName) topic.getTopicNames().iterator().next(); - assertEquals("tinyTiM", name.getValue()); - assertNull(name.getType()); - assertEquals(2, name.getScope().size()); - } - - public void testRemoveRoles() { - Association assoc = _tm.createAssociation(); - Topic type = _tm.createTopic(); - Topic player = _tm.createTopic(); - assoc.createAssociationRole(player, type); - assoc.createAssociationRole(player, type); - assertEquals(2, player.getRolesPlayed().size()); - assertEquals(2, assoc.getAssociationRoles().size()); - DuplicateRemovalUtils.removeDuplicates(assoc); - assertEquals(1, player.getRolesPlayed().size()); - assertEquals(1, assoc.getAssociationRoles().size()); - } -} Deleted: tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java 2008-08-07 14:42:58 UTC (rev 105) +++ tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java 2008-08-07 15:06:58 UTC (rev 106) @@ -1,155 +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; - -import org.tmapi.core.Association; -import org.tmapi.core.AssociationRole; -import org.tmapi.core.DuplicateSourceLocatorException; -import org.tmapi.core.Locator; -import org.tmapi.core.Occurrence; -import org.tmapi.core.Topic; -import org.tmapi.core.TopicMap; -import org.tmapi.core.TopicMapObject; -import org.tmapi.core.TopicName; -import org.tmapi.core.TopicsMustMergeException; -import org.tmapi.core.Variant; - -/** - * Tests if the TMDM item identifier constraint is respected. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public class TestItemIdentifierConstraint extends TinyTimTestCase { - - /** - * Tests against a topic map. - */ - public void testTopicMap() throws Exception { - _testConstraint(_tm); - } - - /** - * Tests againts a topic. - */ - public void testTopic() throws Exception { - Topic topic = _tm.createTopic(); - Locator iid = _tm.createLocator("http://sf.net/projects/tinytim"); - topic.addSourceLocator(iid); - assertTrue(topic.getSourceLocators().contains(iid)); - Topic topic2 = _tm.createTopic(); - try { - topic2.addSourceLocator(iid); - } - catch (TopicsMustMergeException ex) { - // noop. - } - topic.removeSourceLocator(iid); - assertFalse(topic.getSourceLocators().contains(iid)); - topic2.addSourceLocator(iid); - assertTrue(topic2.getSourceLocators().contains(iid)); - topic2.removeSourceLocator(iid); - topic.addSourceLocator(iid); - assertTrue(topic.getSourceLocators().contains(iid)); - assertFalse(topic2.getSourceLocators().contains(iid)); - topic.remove(); - topic2.addSourceLocator(iid); - assertTrue(topic2.getSourceLocators().contains(iid)); - } - - /** - * Tests against an association. - */ - public void testAssociation() throws Exception { - _testConstraint(_tm.createAssociation()); - } - - /** - * Tests against a role. - */ - public void testRole() throws Exception { - Association assoc = _tm.createAssociation(); - AssociationRole role = assoc.createAssociationRole(_tm.createTopic(), _tm.createTopic()); - _testConstraint(role); - } - - /** - * Tests against an occurrence. - */ - public void testOccurrence() throws Exception { - Topic topic = _tm.createTopic(); - Occurrence occ = topic.createOccurrence("tinyTiM", null, null); - _testConstraint(occ); - } - - /** - * Tests against a name. - */ - public void testName() throws Exception { - Topic topic = _tm.createTopic(); - TopicName name = topic.createTopicName("tinyTiM", null, null); - _testConstraint(name); - } - - /** - * Tests against a variant. - */ - public void testVariant() throws Exception { - Topic topic = _tm.createTopic(); - TopicName name = topic.createTopicName("tinyTiM", null, null); - Variant variant = name.createVariant("tinyTiM", null); - _testConstraint(variant); - } - - /** - * The item identifier constraint test. - * - * @param tmo The Topic Maps construct to test. - */ - private void _testConstraint(TopicMapObject tmo) throws Exception { - assertTrue(tmo.getSourceLocators().isEmpty()); - Locator iid = _tm.createLocator("http://sf.net/projects/tinytim"); - tmo.addSourceLocator(iid); - assertTrue(tmo.getSourceLocators().contains(iid)); - Association assoc = _tm.createAssociation(); - try { - assoc.addSourceLocator(iid); - fail("Topic Maps constructs with the same item identifier are not allowed"); - } - catch (DuplicateSourceLocatorException ex) { - // noop - } - tmo.removeSourceLocator(iid); - assertFalse(tmo.getSourceLocators().contains(iid)); - assoc.addSourceLocator(iid); - assertTrue(assoc.getSourceLocators().contains(iid)); - assoc.removeSourceLocator(iid); - assertFalse(assoc.getSourceLocators().contains(iid)); - tmo.addSourceLocator(iid); - assertTrue(tmo.getSourceLocators().contains(iid)); - if (!(tmo instanceof TopicMap)) { - // Removal should 'free' the item identifier - tmo.remove(); - assoc.addSourceLocator(iid); - assertTrue(assoc.getSourceLocators().contains(iid)); - } - } -} Deleted: tinytim/trunk/src/test/java/org/tinytim/TestReifiable.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestReifiable.java 2008-08-07 14:42:58 UTC (rev 105) +++ tinytim/trunk/src/test/java/org/tinytim/TestReifiable.java 2008-08-07 15:06:58 UTC (rev 106) @@ -1,163 +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; - -import java.util.Properties; - -import org.tmapi.core.Association; -import org.tmapi.core.AssociationRole; -import org.tmapi.core.ModelConstraintException; -import org.tmapi.core.Occurrence; -import org.tmapi.core.Topic; -import org.tmapi.core.TopicMap; -import org.tmapi.core.TopicName; -import org.tmapi.core.Variant; - -/** - * Tests against the {@link org.tinytim.IReifiable} interface. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public class TestReifiable extends TinyTimTestCase { - - /* (non-Javadoc) - * @see org.tinytim.TinyTimTestCase#getAdditionalProperties() - */ - @Override - protected Properties getAdditionalProperties() { - Properties props = new Properties(); - props.setProperty(Property.XTM10_REIFICATION, "false"); - return props; - } - - /** - * Tests if a Topic Maps construct is an instance of IReifiable. - */ - public void testInstanceOf() { - assertTrue(((TopicMap)_tm) instanceof IReifiable); - Topic topic = _tm.createTopic(); - assertFalse(topic instanceof IReifiable); - Association assoc = _tm.createAssociation(); - assertTrue(assoc instanceof IReifiable); - AssociationRole role = assoc.createAssociationRole(_tm.createTopic(), _tm.createTopic()); - assertTrue(role instanceof IReifiable); - Occurrence occ = topic.createOccurrence("tinyTiM", null, null); - assertTrue(occ instanceof IReifiable); - TopicName name = topic.createTopicName("tinyTiM", null); - assertTrue(name instanceof IReifiable); - Variant variant = name.createVariant("tinyTiM", null); - assertTrue(variant instanceof IReifiable); - } - - /** - * Tests setting and getting the reifier of a topic map. - */ - public void testTopicMap() { - _testSetGet((IReifiable)_tm); - } - - /** - * Tests setting and getting the reifier of an association. - */ - public void testAssociation() { - _testSetGet((IReifiable)_tm.createAssociation()); - } - - /** - * Tests setting and getting the reifier of a role. - */ - public void testRole() { - Association assoc = _tm.createAssociation(); - AssociationRole role = assoc.createAssociationRole(_tm.createTopic(), _tm.createTopic()); - _testSetGet((IReifiable)role); - } - - /** - * Tests setting and getting the reifier of an occurrence. - */ - public void testOccurrence() { - Topic topic = _tm.createTopic(); - Occurrence occ = topic.createOccurrence("tinyTiM", null, null); - _testSetGet((IReifiable)occ); - } - - /** - * Tests setting and getting the reifier of a name. - */ - public void testName() { - Topic topic = _tm.createTopic(); - TopicName name = topic.createTopicName("tinyTiM", null, null); - _testSetGet((IReifiable)name); - } - - /** - * Tests setting and getting the reifier of a variant. - */ - public void testVariant() { - Topic topic = _tm.createTopic(); - TopicName name = topic.createTopicName("tinyTiM", null, null); - Variant variant = name.createVariant("tinyTiM", null); - _testSetGet((IReifiable)variant); - } - - /** - * Tests setting and getting the reifier of a reifiable Topic Maps construct. - * - * @param reifiable The Topic Maps construct to test. - */ - private void _testSetGet(IReifiable reifiable) { - assertNull(reifiable.getReifier()); - TopicImpl reifier = (TopicImpl) _tm.createTopic(); - assertEquals(0, reifier.getReified().size()); - reifiable.setReifier(reifier); - assertEquals(reifier, reifiable.getReifier()); - assertEquals(reifiable, reifier.getReifiedConstruct()); - assertEquals(1, reifier.getReified().size()); - assertTrue(reifier.getReified().contains(reifiable)); - reifiable.setReifier(null); - assertNull(reifiable.getReifier()); - assertNull(reifier.getReifiedConstruct()); - assertEquals(0, reifier.getReified().size()); - - TopicImpl reifier2 = (TopicImpl) _tm.createTopic(); - IReifiable assoc = (IReifiable) _tm.createAssociation(); - assoc.setReifier(reifier2); - assertEquals(reifier2, assoc.getReifier()); - assertEquals(assoc, reifier2.getReifiedConstruct()); - try { - reifiable.setReifier(reifier2); - fail("Expected an exception. The reifier reifies another Topic Maps construct"); - } - catch (ModelConstraintException ex) { - // noop. - } - assoc.setReifier(null); - assertNull(assoc.getReifier()); - assertNull(reifier2.getReifiedConstruct()); - reifiable.setReifier(reifier); - assertEquals(reifier, reifiable.getReifier()); - assertEquals(reifiable, reifier.getReifiedConstruct()); - reifiable.setReifier(reifier2); - assertEquals(reifier2, reifiable.getReifier()); - assertEquals(reifiable, reifier2.getReifiedConstruct()); - } -} Deleted: tinytim/trunk/src/test/java/org/tinytim/TestReificationUtils.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestReificationUtils.java 2008-08-07 14:42:58 UTC (rev 105) +++ tinytim/trunk/src/test/java/org/tinytim/TestReificationUtils.java 2008-08-07 15:06:58 UTC (rev 106) @@ -1,138 +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; - -import org.tmapi.core.Association; -import org.tmapi.core.AssociationRole; -import org.tmapi.core.Locator; -import org.tmapi.core.Occurrence; -import org.tmapi.core.Topic; -import org.tmapi.core.TopicMap; -import org.tmapi.core.TopicMapObject; -import org.tmapi.core.TopicName; -import org.tmapi.core.Variant; - -/** - * Tests against the {@link ReificationUtils}. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public class TestReificationUtils extends TinyTimTestCase { - - /** - * Tests reification of a topic map - */ - public void testTopicMap() throws Exception { - _testReification(_tm); - } - - /** - * Tests reification of a topic (which is not possible) - */ - public void testTopic() { - try { - ReificationUtils.getReifier(_tm.createTopic()); - fail("Topic cannot be reified"); - } - catch (IllegalArgumentException ex) { - // noop. - } - } - - /** - * Tests reification of an association. - */ - public void testAssociation() throws Exception { - _testReification(_tm.createAssociation()); - } - - /** - * Tests reification of a role. - */ - public void testRole() throws Exception { - Association assoc = _tm.createAssociation(); - AssociationRole role = assoc.createAssociationRole(_tm.createTopic(), _tm.createTopic()); - _testReification(role); - } - - /** - * Tests reification of an occurrence. - */ - public void testOccurrence() throws Exception { - Topic topic = _tm.createTopic(); - Occurrence occ = topic.createOccurrence("tinyTiM", null, null); - _testReification(occ); - } - - /** - * Tests reification of a name. - */ - public void testName() throws Exception { - Topic topic = _tm.createTopic(); - TopicName name = topic.createTopicName("tinyTiM", null, null); - _testReification(name); - } - - /** - * Tests reification of a variant. - */ - public void testVariant() throws Exception { - Topic topic = _tm.createTopic(); - TopicName name = topic.createTopicName("tinyTiM", null, null); - Variant variant = name.createVariant("tinyTiM", null); - _testReification(variant); - } - - /** - * The reification test. - * - * @param tmo The Topic Maps construct to test. - * @throws Exception - */ - private void _testReification(TopicMapObject tmo) throws Exception { - assertTrue(tmo.getSourceLocators().isEmpty()); - assertNull(ReificationUtils.getReifier(tmo)); - Locator loc = _tm.createLocator("http://sf.net/projects/tinytim/#example"); - Topic reifier = _tm.createTopic(); - assertTrue(reifier.getSubjectIdentifiers().isEmpty()); - assertEquals(0, ReificationUtils.getReified(reifier).size()); - reifier.addSubjectIdentifier(loc); - assertEquals(1, reifier.getSubjectIdentifiers().size()); - assertEquals(0, ReificationUtils.getReified(reifier).size()); - tmo.addSourceLocator(loc); - assertEquals(1, ReificationUtils.getReified(reifier).size()); - assertTrue(ReificationUtils.getReified(reifier).contains(tmo)); - assertEquals(reifier, ReificationUtils.getReifier(tmo)); - tmo.removeSourceLocator(loc); - assertEquals(0, ReificationUtils.getReified(reifier).size()); - assertFalse(ReificationUtils.getReified(reifier).contains(tmo)); - assertNull(ReificationUtils.getReifier(tmo)); - if (!(tmo instanceof TopicMap)) { - tmo.addSourceLocator(loc); - assertEquals(1, ReificationUtils.getReified(reifier).size()); - assertTrue(ReificationUtils.getReified(reifier).contains(tmo)); - assertEquals(reifier, ReificationUtils.getReifier(tmo)); - tmo.remove(); - assertEquals(0, ReificationUtils.getReified(reifier).size()); - } - } -} Deleted: tinytim/trunk/src/test/java/org/tinytim/TestScoped.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestScoped.java 2008-08-07 14:42:58 UTC (rev 105) +++ tinytim/trunk/src/test/java/org/tinytim/TestScoped.java 2008-08-07 15:06:58 UTC (rev 106) @@ -1,119 +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; - -import org.tmapi.core.Association; -import org.tmapi.core.AssociationRole; -import org.tmapi.core.Occurrence; -import org.tmapi.core.Topic; -import org.tmapi.core.TopicMap; -import org.tmapi.core.TopicName; -import org.tmapi.core.Variant; - -/** - * Tests against the {@link org.tinytim.IScoped} interface. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public class TestScoped extends TinyTimTestCase { - - /** - * Tests if a Topic Maps construct is an instance of IScoped. - */ - public void testInstanceOf() { - assertFalse(((TopicMap)_tm) instanceof IScoped); - Topic topic = _tm.createTopic(); - assertFalse(topic instanceof IScoped); - Association assoc = _tm.createAssociation(); - assertTrue(assoc instanceof IScoped); - AssociationRole role = assoc.createAssociationRole(_tm.createTopic(), _tm.createTopic()); - assertFalse(role instanceof IScoped); - Occurrence occ = topic.createOccurrence("tinyTiM", null, null); - assertTrue(occ instanceof IScoped); - TopicName name = topic.createTopicName("tinyTiM", null); - assertTrue(name instanceof IScoped); - Variant variant = name.createVariant("tinyTiM", null); - assertTrue(variant instanceof IScoped); - } - - /** - * Tests against an association. - */ - public void testAssociation() { - Association assoc = _tm.createAssociation(); - _testScoped((IScoped) assoc); - } - - /** - * Tests against an occurrence. - */ - public void testOccurrence() { - Topic topic = _tm.createTopic(); - Occurrence occ = topic.createOccurrence("tinyTiM", null, null); - _testScoped((IScoped) occ); - } - - /** - * Tests against a name. - */ - public void testName() { - Topic topic = _tm.createTopic(); - TopicName name = topic.createTopicName("tinyTiM", null, null); - _testScoped((IScoped) name); - } - - /** - * Tests against a variant. - */ - public void testVariant() { - Topic topic = _tm.createTopic(); - TopicName name = topic.createTopicName("tinyTiM", null, null); - Variant variant = name.createVariant("tinyTiM", null); - _testScoped((IScoped) variant); - } - - /** - * Tests adding / removing themes. - * - * @param scoped The scoped Topic Maps construct to test. - */ - private void _testScoped(IScoped scoped) { - //TODO: This may fail in the future for variants - assertEquals(0, scoped.getScope().size()); - Topic theme1 = _tm.createTopic(); - scoped.addTheme(theme1); - assertEquals(1, scoped.getScope().size()); - assertTrue(scoped.getScope().contains(theme1)); - Topic theme2 = _tm.createTopic(); - assertFalse(scoped.getScope().contains(theme2)); - scoped.addTheme(theme2); - assertEquals(2, scoped.getScope().size()); - assertTrue(scoped.getScope().contains(theme1)); - assertTrue(scoped.getScope().contains(theme2)); - scoped.removeTheme(theme2); - assertEquals(1, scoped.getScope().size()); - assertTrue(scoped.getScope().contains(theme1)); - assertFalse(scoped.getScope().contains(theme2)); - scoped.removeTheme(theme1); - assertEquals(0, scoped.getScope().size()); - } -} Deleted: tinytim/trunk/src/test/java/org/tinytim/TestSignatureGenerator.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestSignatureGenerator.java 2008-08-07 14:42:58 UTC (rev 105) +++ tinytim/trunk/src/test/java/org/tinytim/TestSignatureGenerator.java 2008-08-07 15:06:58 UTC (rev 106) @@ -1,129 +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; - -import org.tinytim.SignatureGenerator; -import org.tmapi.core.Association; -import org.tmapi.core.AssociationRole; -import org.tmapi.core.Occurrence; -import org.tmapi.core.Topic; -import org.tmapi.core.TopicName; -import org.tmapi.core.Variant; - -/** - * Tests against the {@link org.tinytim.SignatureGenerator}. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public class TestSignatureGenerator extends TinyTimTestCase { - - /** - * Tests if an association with no initialized properties returns the same - * signature. - */ - public void testAssociationBasic() { - Association assoc = _tm.createAssociation(); - Association assoc2 = _tm.createAssociation(); - assertFalse(assoc.getObjectId().equals(assoc2.getObjectId())); - String sig = SignatureGenerator.generateSignature(assoc); - assertEquals(sig, SignatureGenerator.generateSignature(assoc2)); - } - - /** - * Tests if a role with no initialized properties returns the same - * signature. - */ - public void testRoleBasic() { - Association assoc = _tm.createAssociation(); - AssociationRole role = assoc.createAssociationRole(null, null); - AssociationRole role2 = assoc.createAssociationRole(null, null); - assertFalse(role.getObjectId().equals(role2.getObjectId())); - String sig = SignatureGenerator.generateSignature(role); - assertEquals(sig, SignatureGenerator.generateSignature(role2)); - } - - /** - * Tests if an occurrence with no initialized properties returns the same - * signature. - */ - public void testOccurrenceBasic() { - Topic topic = _tm.createTopic(); - Occurrence occ = topic.createOccurrence((String) null, null, null); - Occurrence occ2 = topic.createOccurrence((String) null, null, null); - assertFalse(occ.getObjectId().equals(occ2.getObjectId())); - String sig = SignatureGenerator.generateSignature(occ); - assertEquals(sig, SignatureGenerator.generateSignature(occ2)); - } - - /** - * Tests if a name with no initialized properties returns the same - * signature. - */ - public void testNameBasic() { - Topic topic = _tm.createTopic(); - TopicName name = topic.createTopicName(null, null); - TopicName name2 = topic.createTopicName(null, null); - assertFalse(name.getObjectId().equals(name2.getObjectId())); - String sig = SignatureGenerator.generateSignature(name); - assertEquals(sig, SignatureGenerator.generateSignature(name2)); - } - - /** - * Tests if a variant with no initialized properties returns the same - * signature. - */ - public void testVariantBasic() { - Topic topic = _tm.createTopic(); - TopicName name = topic.createTopicName("tinyTiM", null); - Variant variant = name.createVariant("tiny Topic Maps", null); - String sig = SignatureGenerator.generateSignature(variant); - assertEquals(sig, SignatureGenerator.generateSignature(variant)); - } - - /** - * Tests if associations with the same type return the same signature. - */ - public void testAssociationTyped() { - Association assoc = _tm.createAssociation(); - String sigBefore = SignatureGenerator.generateSignature(assoc); - Topic type = _tm.createTopic(); - assoc.setType(type); - String sigAfter = SignatureGenerator.generateSignature(assoc); - assertFalse(sigBefore.equals(sigAfter)); - Association assoc2 = _tm.createAssociation(); - assertEquals(sigBefore, SignatureGenerator.generateSignature(assoc2)); - assoc2.setType(type); - assertEquals(sigAfter, SignatureGenerator.generateSignature(assoc2)); - } - - public void testRoles() { - Association assoc = _tm.createAssociation(); - Topic type = _tm.createTopic(); - Topic player = _tm.createTopic(); - AssociationRole role1 = assoc.createAssociationRole(player, type); - AssociationRole role2 = assoc.createAssociationRole(player, type); - assertEquals(2, player.getRolesPlayed().size()); - assertEquals(2, assoc.getAssociationRoles().size()); - String sig = SignatureGenerator.generateSignature(role1); - assertEquals(sig, SignatureGenerator.generateSignature(role2)); - } -} Deleted: tinytim/trunk/src/test/java/org/tinytim/TestTMAPICore.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestTMAPICore.java 2008-08-07 14:42:58 UTC (rev 105) +++ tinytim/trunk/src/test/java/org/tinytim/TestTMAPICore.java 2008-08-07 15:06:58 UTC (rev 106) @@ -1,42 +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; - -import org.tmapi.core.test.AllTMAPITests; - -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 AllTMAPITests.suite(); - } -} Deleted: tinytim/trunk/src/test/java/org/tinytim/TestTMAPIIndex.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestTMAPIIndex.java 2008-08-07 14:42:58 UTC (rev 105) +++ tinytim/trunk/src/test/java/org/tinytim/TestTMAPIIndex.java 2008-08-07 15:06:58 UTC (rev 106) @@ -1,42 +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; - -import org.tmapi.index.core.test.AllTMAPIIndexTests; - -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 AllTMAPIIndexTests.suite(); - } -} Deleted: tinytim/trunk/src/test/java/org/tinytim/TestTopic.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestTopic.java 2008-08-07 14:42:58 UTC (rev 105) +++ tinytim/trunk/src/test/java/org/tinytim/TestTopic.java 2008-08-07 15:06:58 UTC (rev 106) @@ -1,44 +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; - -import org.tmapi.core.Locator; -import org.tmapi.core.Topic; - -/** - * Tests against the {@link org.tmapi.core.Topic}. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ - */ -public class TestTopic extends TinyTimTestCase { - - public void testSubjectLocators() { - final Topic topic = _tm.createTopic(); - assertEquals(0, topic.getSubjectLocators().size()); - final Locator loc = _tm.createLocator("http://www.example.org/"); - topic.addSubjectLocator(loc); - assertEquals(1, topic.getSubjectLocators().size()); - assertTrue(topic.getSubjectLocators().contains(loc)); - topic.removeSubjectLocator(loc); - assertEquals(0, topic.getSubjectLocators().size()); - } -} Deleted: tinytim/trunk/src/test/java/org/tinytim/TestTopicMapMerge.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestTopicMapMerge.java 2008-08-07 14:42:58 UTC (rev 105) +++ tinytim/trunk/src/test/java/org/tinytim/TestTopicMapMerge.java 2008-08-07 15:06:58 UTC (rev 106) @@ -1,157 +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; - -import org.tmapi.core.Locator; -import org.tmapi.core.Topic; -import org.tmapi.core.TopicMap; - -/** - * Tests merging of topic maps. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public class TestTopicMapMerge extends TinyTimTestCase { - - private static final String _TM2_BASE = "http://www.sf.net/projects/tinytim/tm-2"; - - private TopicMap _tm2; - - /* (non-Javadoc) - * @see org.tinytim.TinyTimTestCase#setUp() - */ - @Override - protected void setUp() throws Exception { - super.setUp(); - _tm2 = _sys.createTopicMap(_TM2_BASE); - } - - /* (non-Javadoc) - * @see org.tinytim.TinyTimTestCase#tearDown() - */ - @Override - protected void tearDown() throws Exception { - super.tearDown(); - _tm2 = null; - } - - /** - * Tests merging of topics by equal item identifiers. - */ - public void testMergeSimple1() { - final String ref = "http://sf.net/projects/tinytim/loc"; - Topic topicA = _tm.createTopic(); - Locator iidA = _tm.createLocator(ref); - topicA.addSourceLocator(iidA); - Topic topicB = _tm2.createTopic(); - Locator iidB = _tm2.createLocator(ref); - topicB.addSourceLocator(iidB); - assertEquals(1, _tm.getTopics().size()); - assertEquals(1, _tm2.getTopics().size()); - - _tm.mergeIn(_tm2); - assertEquals(1, _tm.getTopics().size()); - assertEquals(topicA, _tm.getObjectByItemIdentifier(iidA)); - } - - /** - * Tests merging of topics by equal subject identifiers. - */ - public void testMergeSimple2() { - final String ref = "http://sf.net/projects/tinytim/loc"; - Topic topicA = _tm.createTopic(); - Locator sidA = _tm.createLocator(ref); - topicA.addSubjectIdentifier(sidA); - Topic topicB = _tm2.createTopic(); - Locator sidB = _tm2.createLocator(ref); - topicB.addSubjectIdentifier(sidB); - assertEquals(1, _tm.getTopics().size()); - assertEquals(1, _tm2.getTopics().size()); - - _tm.mergeIn(_tm2); - assertEquals(1, _tm.getTopics().size()); - assertEquals(topicA, _tm.getTopicBySubjectIdentifier(sidA)); - } - - /** - * Tests merging of topics by equal subject locators. - */ - public void testMergeSimple3() { - final String ref = "http://sf.net/projects/tinytim/loc"; - Topic topicA = _tm.createTopic(); - Locator sloA = _tm.createLocator(ref); - topicA.addSubjectLocator(sloA); - Topic topicB = _tm2.createTopic(); - Locator sloB = _tm2.createLocator(ref); - topicB.addSubjectLocator(sloB); - assertEquals(1, _tm.getTopics().size()); - assertEquals(1, _tm2.getTopics().size()); - - _tm.mergeIn(_tm2); - assertEquals(1, _tm.getTopics().size()); - assertEquals(topicA, _tm.getTopicBySubjectLocator(sloA)); - } - - /** - * Tests merging of topics by existing topic with item identifier equals - * to a topic's subject identifier from the other map. - */ - public void testMergeSimple4() { - final String ref = "http://sf.net/projects/tinytim/loc"; - Topic topicA = _tm.createTopic(); - Locator loc = _tm.createLocator(ref); - topicA.addSourceLocator(loc); - Topic topicB = _tm2.createTopic(); - Locator locB = _tm2.createLocator(ref); - topicB.addSubjectIdentifier(locB); - assertEquals(1, _tm.getTopics().size()); - assertEquals(1, _tm2.getTopics().size()); - assertEquals(topicA, _tm.getObjectByItemIdentifier(loc)); - assertNull(_tm.getTopicBySubjectIdentifier(loc)); - _tm.mergeIn(_tm2); - assertEquals(1, _tm.getTopics().size()); - assertEquals(topicA, _tm.getObjectByItemIdentifier(loc)); - assertEquals(topicA, _tm.getTopicBySubjectIdentifier(loc)); - } - - /** - * Tests merging of topics by existing topic with subject identifier equals - * to a topic's item identifier from the other map. - */ - public void testMergeSimple5() { - final String ref = "http://sf.net/projects/tinytim/loc"; - Topic topicA = _tm.createTopic(); - Locator loc = _tm.createLocator(ref); - topicA.addSubjectIdentifier(loc); - Topic topicB = _tm2.createTopic(); - Locator locB = _tm2.createLocator(ref); - topicB.addSourceLocator(locB); - assertEquals(1, _tm.getTopics().size()); - assertEquals(1, _tm2.getTopics().size()); - assertNull(_tm.getObjectByItemIdentifier(loc)); - assertEquals(topicA, _tm.getTopicBySubjectIdentifier(loc)); - _tm.mergeIn(_tm2); - assertEquals(1, _tm.getTopics().size()); - assertEquals(topicA, _tm.getObjectByItemIdentifier(loc)); - assertEquals(topicA, _tm.getTopicBySubjectIdentifier(loc)); - } -} Deleted: tinytim/trunk/src/test/java/org/tinytim/TestTopicMapSystemFactoryImpl.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestTopicMapSystemFactoryImpl.java 2008-08-07 14:42:58 UTC (rev 105) +++ tinytim/trunk/src/test/java/org/tinytim/TestTopicMapSystemFactoryImpl.java 2008-08-07 15:06:58 UTC (rev 106) @@ -1,179 +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; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.tinytim.ICollectionFactory; -import org.tinytim.JavaCollectionFactory; -import org.tinytim.Property; -import org.tinytim.TMAPIFeature; -import org.tinytim.TopicMapSystemImpl; -import org.tmapi.core.FeatureNotRecognizedException; -import org.tmapi.core.FeatureNotSupportedException; - -/** - * Tests against the {@link org.tinytim.TopicMapSystemFactoryImpl}. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public class TestTopicMapSystemFactoryImpl extends TinyTimTestCase { - - /** - * Tests the default feature values. - * - * @throws Exception - */ - public void testDefaultFeatureValues() throws Exception { - assertTrue(_sysFactory.getFeature(TMAPIFeature.NOTATION_URI)); - assertTrue(_sysFactory.getFeature(TMAPIFeature.XTM_1_1)); - assertFalse(_sysFactory.getFeature(TMAPIFeature.XTM_1_0)); - assertFalse(_sysFactory.getFeature(TMAPIFeature.READ_ONLY)); - assertFalse(_sysFactory.getFeature(TMAPIFeature.AUTOMERGE)); - assertFalse(_sysFactory.getFeature(TMAPIFeature.TNC)); - } - - - private void _setFeatureToAcceptedValue(String featureName, boolean value) throws Exception { - try { - _sysFactory.setFeature(featureName, value); - } - catch (FeatureNotSupportedException ex) { - fail("Unexpected exception while setting '" + featureName + "' to '" + value + "'"); - } - } - - private void _setFeatureToUnacceptedValue(String featureName, boolean value) throws Exception { - try { - _sysFactory.setFeature(featureName, value); - fail("Expected exception while setting '" + featureName + "' to '" + value + "'"); - } - catch (FeatureNotSupportedException ex) { - // noop. - } - } - - /** - * Tests if enabling / disabling of various features delivers the expected - * results. - * - * @throws Exception - */ - public void testSetFeatureValues() throws Exception { - _setFeatureToAcceptedValue(TMAPIFeature.NOTATION_URI, true); - _setFeatureToUnacceptedValue(TMAPIFeature.NOTATION_URI, false); - _setFeatureToAcceptedValue(TMAPIFeature.XTM_1_0, false); - _setFeatureToUnacceptedValue(TMAPIFeature.XTM_1_0, true); - _setFeatureToAcceptedValue(TMAPIFeature.XTM_1_1, true); - _setFeatureToUnacceptedValue(TMAPIFeature.XTM_1_1, false); - _setFeatureToAcceptedValue(TMAPIFeature.READ_ONLY, false); - _setFeatureToUnacceptedValue(TMAPIFeature.READ_ONLY, true); - _setFeatureToAcceptedValue(TMAPIFeature.AUTOMERGE, false); - _setFeatureToUnacceptedValue(TMAPIFeature.AUTOMERGE, true); - _setFeatureToAcceptedValue(TMAPIFeature.TNC, false); - _setFeatureToUnacceptedValue(TMAPIFeature.TNC, true); - } - - /** - * Tests if an unknown feature throws the expected exception. - * - * @throws Exception - */ - public void testUnrecognizedFeature() throws Exception { - try { - String unknownFeatureName = "http://www.semagia.com/tinyTiM/unknownTMAPIFeature"; - _sysFactory.setFeature(unknownFeatureName, true); - fail("Expected an exception while setting a unknown feature"); - } - catch (FeatureNotRecognizedException ex) { - // noop. - } - } - - /** - * Tests if the collection factory property is set. - * - * @throws Exception - */ - public void testCollectionFactoryProperty() throws Exception { - boolean troveAvailable = false; - try { - Class.forName("gnu.trove.THashSet"); - troveAvailable = true; - } - catch (Exception ex) { - // noop. - } - if (troveAvailable) { - assertEquals("org.tinytim.TroveCollectionFactory", _sysFactory.getProperty(Property.COLLECTION_FACTORY)); - } - else { - assertEquals("org.tinytim.JavaCollectionFactory", _sysFactory.getProperty(Property.COLLECTION_FACTORY)); - assertTrue(((TopicMapSystemImpl) _sysFactory.newTopicMapSystem()).getCollectionFactory() instanceof JavaCollectionFactory); - } - } - - /** - * Tests if the TopicMapSystemFactory creates automatically a default - * CollectionFactory iff the class name in the property is invaild / - * not resolvable. - * ... [truncated message content] |
From: <lh...@us...> - 2008-08-07 14:42:48
|
Revision: 105 http://tinytim.svn.sourceforge.net/tinytim/?rev=105&view=rev Author: lheuer Date: 2008-08-07 14:42:58 +0000 (Thu, 07 Aug 2008) Log Message: ----------- Added TMAPI 2.0 lic Added Paths: ----------- tinytim/trunk/lib/LICENSE.tmapi.txt Added: tinytim/trunk/lib/LICENSE.tmapi.txt =================================================================== --- tinytim/trunk/lib/LICENSE.tmapi.txt (rev 0) +++ tinytim/trunk/lib/LICENSE.tmapi.txt 2008-08-07 14:42:58 UTC (rev 105) @@ -0,0 +1,11 @@ +The Topic Maps API (TMAPI), created collectively by +the membership of the tmapi-discuss mailing list +<http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss>, +is hereby released into the public domain; and comes with +NO WARRANTY. + +No one owns TMAPI: you may use it freely in both commercial and +non-commercial applications, bundle it with your software +distribution, include it on a CD-ROM, list the source code in a +book, mirror the documentation at your own web site, or use it in +any other way you see fit. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-07 14:39:31
|
Revision: 104 http://tinytim.svn.sourceforge.net/tinytim/?rev=104&view=rev Author: lheuer Date: 2008-08-07 14:39:40 +0000 (Thu, 07 Aug 2008) Log Message: ----------- - Removed TMAPI 1.0 libs - Changed build properties - Changed TopicMapSystemFactory class name (META-INF) Modified Paths: -------------- tinytim/trunk/build.properties tinytim/trunk/src/main/resources/META-INF/services/org.tmapi.core.TopicMapSystemFactory Removed Paths: ------------- tinytim/trunk/lib/LICENSE.tmapi-test.txt tinytim/trunk/lib/LICENSE.tmapi.txt tinytim/trunk/lib/tmapi-1_0SP1.jar tinytim/trunk/lib/tmapi-test-1_0SP1.jar Modified: tinytim/trunk/build.properties =================================================================== --- tinytim/trunk/build.properties 2008-08-07 14:36:54 UTC (rev 103) +++ tinytim/trunk/build.properties 2008-08-07 14:39:40 UTC (rev 104) @@ -1,4 +1,4 @@ -version=1.5.0 -version_suffix=beta +version=2.0.0 +version_suffix=alpha1 debug=off optimize=on Deleted: tinytim/trunk/lib/LICENSE.tmapi-test.txt =================================================================== --- tinytim/trunk/lib/LICENSE.tmapi-test.txt 2008-08-07 14:36:54 UTC (rev 103) +++ tinytim/trunk/lib/LICENSE.tmapi-test.txt 2008-08-07 14:39:40 UTC (rev 104) @@ -1,21 +0,0 @@ -TMAPI 1.0 - - Version 1.0 of the Topic Maps API (TMAPI), created collectively by - the membership of the tmapi-discuss mailing list - (http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss), - is hereby released into the public domain. - - No one owns TMAPI: you may use it freely in both commercial and - non-commercial applications, bundle it with your software - distribution, include it on a CD-ROM, list the source code in a - book, mirror the documentation at your own web site, or use it in - any other way you see fit. - - Kal Ahmed (kal at techquila.com) - Lars Marius Garshol (larsga at users.sourceforge.net) - Geir Ove Gr\xF8nmo (grove at users.sourceforge.net) - Lars Heuer (lheuer at users.sourceforge.net) - Stefan Lischke (lischke2 at users.sourceforge.net) - Graham Moore (gra_moore at users.sourceforge.net) - - 08 April 2004 Deleted: tinytim/trunk/lib/LICENSE.tmapi.txt =================================================================== --- tinytim/trunk/lib/LICENSE.tmapi.txt 2008-08-07 14:36:54 UTC (rev 103) +++ tinytim/trunk/lib/LICENSE.tmapi.txt 2008-08-07 14:39:40 UTC (rev 104) @@ -1,21 +0,0 @@ -TMAPI 1.0 - - Version 1.0 of the Topic Maps API (TMAPI), created collectively by - the membership of the tmapi-discuss mailing list - (http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss), - is hereby released into the public domain. - - No one owns TMAPI: you may use it freely in both commercial and - non-commercial applications, bundle it with your software - distribution, include it on a CD-ROM, list the source code in a - book, mirror the documentation at your own web site, or use it in - any other way you see fit. - - Kal Ahmed (kal at techquila.com) - Lars Marius Garshol (larsga at users.sourceforge.net) - Geir Ove Gr\xF8nmo (grove at users.sourceforge.net) - Lars Heuer (lheuer at users.sourceforge.net) - Stefan Lischke (lischke2 at users.sourceforge.net) - Graham Moore (gra_moore at users.sourceforge.net) - - 08 April 2004 Modified: tinytim/trunk/src/main/resources/META-INF/services/org.tmapi.core.TopicMapSystemFactory =================================================================== --- tinytim/trunk/src/main/resources/META-INF/services/org.tmapi.core.TopicMapSystemFactory 2008-08-07 14:36:54 UTC (rev 103) +++ tinytim/trunk/src/main/resources/META-INF/services/org.tmapi.core.TopicMapSystemFactory 2008-08-07 14:39:40 UTC (rev 104) @@ -1 +1 @@ -org.tinytim.TopicMapSystemFactoryImpl +org.tinytim.core.TopicMapSystemFactoryImpl This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-07 14:36:47
|
Revision: 103 http://tinytim.svn.sourceforge.net/tinytim/?rev=103&view=rev Author: lheuer Date: 2008-08-07 14:36:54 +0000 (Thu, 07 Aug 2008) Log Message: ----------- Added Paths: ----------- 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 Removed Paths: ------------- tinytim/trunk/src/main/java/org/tinytim/AssociationImpl.java tinytim/trunk/src/main/java/org/tinytim/AssociationRoleImpl.java tinytim/trunk/src/main/java/org/tinytim/Construct.java tinytim/trunk/src/main/java/org/tinytim/CopyUtils.java tinytim/trunk/src/main/java/org/tinytim/DatatypeAwareConstruct.java tinytim/trunk/src/main/java/org/tinytim/DuplicateRemovalUtils.java tinytim/trunk/src/main/java/org/tinytim/Event.java tinytim/trunk/src/main/java/org/tinytim/ICollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/IConstruct.java tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java tinytim/trunk/src/main/java/org/tinytim/IEventHandler.java tinytim/trunk/src/main/java/org/tinytim/IEventPublisher.java tinytim/trunk/src/main/java/org/tinytim/IMovable.java tinytim/trunk/src/main/java/org/tinytim/IRI.java tinytim/trunk/src/main/java/org/tinytim/IReifiable.java tinytim/trunk/src/main/java/org/tinytim/IScoped.java tinytim/trunk/src/main/java/org/tinytim/ITyped.java tinytim/trunk/src/main/java/org/tinytim/IdentityManager.java tinytim/trunk/src/main/java/org/tinytim/JavaCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java tinytim/trunk/src/main/java/org/tinytim/OccurrenceImpl.java tinytim/trunk/src/main/java/org/tinytim/Property.java tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java tinytim/trunk/src/main/java/org/tinytim/Scoped.java tinytim/trunk/src/main/java/org/tinytim/SignatureGenerator.java tinytim/trunk/src/main/java/org/tinytim/TMAPIFeature.java tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java tinytim/trunk/src/main/java/org/tinytim/TopicMapSystemFactoryImpl.java tinytim/trunk/src/main/java/org/tinytim/TopicMapSystemImpl.java tinytim/trunk/src/main/java/org/tinytim/TopicNameImpl.java tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java tinytim/trunk/src/main/java/org/tinytim/TroveCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/TypeInstanceConverter.java tinytim/trunk/src/main/java/org/tinytim/Typed.java tinytim/trunk/src/main/java/org/tinytim/VariantImpl.java Deleted: tinytim/trunk/src/main/java/org/tinytim/AssociationImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/AssociationImpl.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/AssociationImpl.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,114 +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; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Set; - -import org.tmapi.core.Association; -import org.tmapi.core.AssociationRole; -import org.tmapi.core.TMAPIException; -import org.tmapi.core.Topic; - -/** - * {@link org.tmapi.core.Association} implementation. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public final class AssociationImpl extends Scoped implements Association, - IReifiable, ITyped, IScoped { - - private Set<AssociationRole> _roles; - - AssociationImpl(TopicMapImpl topicMap) { - super(topicMap, null, null); - _roles = topicMap.getCollectionFactory().createSet(2); - } - - /** - * Adds a role to this association. - * - * @param role The role to add. - */ - void addRole(AssociationRole role) { - AssociationRoleImpl r = (AssociationRoleImpl) role; - if (r._parent == this) { - return; - } - assert r._parent == null; - _fireEvent(Event.ADD_ROLE, null, r); - _roles.add(r); - r._parent = this; - TopicImpl player = (TopicImpl) r.getPlayer(); - if (player != null) { - player.addRolePlayed(r); - } - } - - /** - * Removes a role from this association. - * - * @param role The role to remove. - */ - void removeRole(AssociationRole role) { - AssociationRoleImpl r = (AssociationRoleImpl) role; - if (r._parent != this) { - return; - } - _fireEvent(Event.REMOVE_ROLE, r, null); - _roles.remove(role); - r._parent = null; - TopicImpl player = (TopicImpl) r.getPlayer(); - if (player != null) { - player.removeRolePlayed(r); - } - } - - /* (non-Javadoc) - * @see org.tmapi.core.Association#createAssociationRole(org.tmapi.core.Topic, org.tmapi.core.Topic) - */ - public AssociationRole createAssociationRole(Topic player, Topic type) { - AssociationRoleImpl role = new AssociationRoleImpl(_tm, type, player); - addRole(role); - return role; - } - - /* (non-Javadoc) - * @see org.tmapi.core.Association#getAssociationRoles() - */ - public Set<AssociationRole> getAssociationRoles() { - return Collections.unmodifiableSet(_roles); - } - - /* (non-Javadoc) - * @see org.tmapi.core.TopicMapObject#remove() - */ - public void remove() throws TMAPIException { - _tm.removeAssociation(this); - for (AssociationRole role: new ArrayList<AssociationRole>(_roles)) { - role.remove(); - } - _roles = null; - super.dispose(); - } -} Deleted: tinytim/trunk/src/main/java/org/tinytim/AssociationRoleImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/AssociationRoleImpl.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/AssociationRoleImpl.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,83 +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; - -import org.tmapi.core.Association; -import org.tmapi.core.AssociationRole; -import org.tmapi.core.TMAPIException; -import org.tmapi.core.Topic; - -/** - * {@link org.tmapi.core.AssociationRole} implementation. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public final class AssociationRoleImpl extends Typed implements AssociationRole, - ITyped { - - private Topic _player; - - AssociationRoleImpl(TopicMapImpl tm, Topic type, Topic player) { - super(tm, type); - _player = player; - } - - /* (non-Javadoc) - * @see org.tmapi.core.AssociationRole#getAssociation() - */ - public Association getAssociation() { - return (Association) _parent; - } - - /* (non-Javadoc) - * @see org.tmapi.core.AssociationRole#getPlayer() - */ - public Topic getPlayer() { - return _player; - } - - /* (non-Javadoc) - * @see org.tmapi.core.AssociationRole#setPlayer(org.tmapi.core.Topic) - */ - public void setPlayer(Topic player) { - if (_player == player) { - return; - } - _fireEvent(Event.SET_PLAYER, _player, player); - if (_player != null) { - ((TopicImpl)_player).removeRolePlayed(this); - } - _player = player; - if (player != null) { - ((TopicImpl) player).addRolePlayed(this); - } - } - - /* (non-Javadoc) - * @see org.tinytim.TopicMapObjectImpl#remove() - */ - public void remove() throws TMAPIException { - ((AssociationImpl) _parent).removeRole(this); - super.dispose(); - } - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/Construct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Construct.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/Construct.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,184 +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; - -import java.util.Collections; -import java.util.Set; - -import org.tmapi.core.DuplicateSourceLocatorException; -import org.tmapi.core.Locator; -import org.tmapi.core.TopicMap; - -/** - * Base class for all Topic Maps constructs. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -abstract class Construct implements IConstruct { - - protected String _id; - protected TopicMapImpl _tm; - protected IConstruct _parent; - private Set<Locator> _iids; - - Construct(TopicMapImpl topicMap) { - _tm = topicMap; - } - - /* (non-Javadoc) - * @see org.tinytim.IConstruct#getParent() - */ - public IConstruct getParent() { - return _parent; - } - - /* (non-Javadoc) - * @see org.tmapi.core.TopicMapObject#getObjectId() - */ - public String getObjectId() { - return _id; - } - - /* (non-Javadoc) - * @see org.tmapi.core.TopicMapObject#getSourceLocators() - */ - public Set<Locator> getSourceLocators() { - return getItemIdentifiers(); - } - - /* (non-Javadoc) - * @see org.tmapi.core.TopicMapObject#addSourceLocator(org.tmapi.core.Locator) - */ - public void addSourceLocator(Locator loc) - throws DuplicateSourceLocatorException { - addItemIdentifier(loc); - } - - /* (non-Javadoc) - * @see org.tmapi.core.TopicMapObject#removeSourceLocator(org.tmapi.core.Locator) - */ - public void removeSourceLocator(Locator loc) { - removeItemIdentifier(loc); - } - - /* (non-Javadoc) - * @see org.tmapi.core.TopicMapObject#getTopicMap() - */ - public TopicMap getTopicMap() { - return _tm; - } - - /* (non-Javadoc) - * @see org.tinytim.IConstruct#getItemIdentifiers() - */ - public Set<Locator> getItemIdentifiers() { - return _iids == null ? Collections.<Locator>emptySet() - : Collections.unmodifiableSet(_iids); - } - - /* (non-Javadoc) - * @see org.tinytim.IConstruct#addItemIdentifier(org.tmapi.core.Locator) - */ - public void addItemIdentifier(Locator itemIdentifier) { - if (_iids != null && _iids.contains(itemIdentifier)) { - return; - } - _fireEvent(Event.ADD_IID, null, itemIdentifier); - if (_iids == null) { - _iids = _tm.getCollectionFactory().createSet(); - } - _iids.add(itemIdentifier); - } - - /* (non-Javadoc) - * @see org.tinytim.IConstruct#removeItemIdentifier(org.tmapi.core.Locator) - */ - public void removeItemIdentifier(Locator itemIdentifier) { - if (_iids == null || !_iids.contains(itemIdentifier)) { - return; - } - _fireEvent(Event.REMOVE_IID, itemIdentifier, null); - _iids.remove(itemIdentifier); - } - - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public final boolean equals(Object obj) { - if (this == obj) { - return true; - } - return (obj instanceof Construct) && _id.equals(((Construct) obj)._id); - } - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public final int hashCode() { - return _id.hashCode(); - } - - /** - * Notifies the topic map about an event. - * - * If the topic map is <code>null</code>, no event is sent. - * - * @param evt The event. - * @param oldValue The old value. - * @param newValue The new value. - */ - protected void _fireEvent(Event evt, Object oldValue, Object newValue) { - if (_tm != null) { - _tm.handleEvent(evt, this, oldValue, newValue); - } - } - - /** - * Releases used resources. - * - * Should be called in the {@link org.tmapi.core.TopicMapObject#remove()} - * method. - */ - protected void dispose() { - _tm = null; - _parent = null; - _iids = null; - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - StringBuilder sb = new StringBuilder(super.toString()); - sb.append(" ").append(_id); - sb.append(" iids=["); - for (Locator iid: getItemIdentifiers()) { - sb.append(iid); - sb.append(','); - } - sb.append("]"); - return sb.toString(); - } -} Deleted: tinytim/trunk/src/main/java/org/tinytim/CopyUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/CopyUtils.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/CopyUtils.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,385 +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; - -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.tmapi.core.Association; -import org.tmapi.core.AssociationRole; -import org.tmapi.core.Locator; -import org.tmapi.core.Occurrence; -import org.tmapi.core.Topic; -import org.tmapi.core.TopicMap; -import org.tmapi.core.TopicMapObject; -import org.tmapi.core.TopicName; -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 { - - /** - * Copies the topics and associations from the <code>source</code> to the - * <code>target</code> 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((TopicMapImpl) source, (TopicMapImpl) target); - } - - /** - * @see #copy(TopicMap, TopicMap) - */ - @SuppressWarnings("unchecked") - private static void _copy(TopicMapImpl source, TopicMapImpl 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 = target.getCollectionFactory().createMap(); - Topic existing = null; - TopicMapObject existingConstruct = null; - for (Topic topic: source.getTopics()) { - for (Iterator<Locator> iter = topic.getSubjectLocators().iterator(); iter.hasNext();) { - existing = target.getTopicBySubjectLocator(iter.next()); - if (existing != null) { - _addMerge(topic, existing, mergeMap); - } - } - for (Iterator<Locator> iter = topic.getSubjectIdentifiers().iterator(); iter.hasNext();) { - Locator sid = iter.next(); - existing = target.getTopicBySubjectIdentifier(sid); - if (existing != null) { - _addMerge(topic, existing, mergeMap); - } - existingConstruct = target.getObjectByItemIdentifier(sid); - if (existingConstruct instanceof Topic) { - _addMerge(topic, (Topic) existingConstruct, mergeMap); - } - } - for (Iterator<Locator> iter = topic.getSourceLocators().iterator(); iter.hasNext();) { - Locator iid = iter.next(); - existingConstruct = target.getObjectByItemIdentifier(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 <code>topic</code> to the <code>target</code> 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, TopicMap target, - Map<Topic, Topic> mergeMap) { - Topic targetTopic = target.createTopic(); - _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 <code>source/code> to the <code>targetTopic</code>. - * - * @param topic The topic to take the identities from. - * @param targetTopic The topic which gets the identities. - */ - @SuppressWarnings("unchecked") - private static void _copyIdentities(Topic topic, Topic targetTopic) { - for(Iterator<Locator> iter = topic.getSubjectIdentifiers().iterator(); iter.hasNext();) { - targetTopic.addSubjectIdentifier(iter.next()); - } - for(Iterator<Locator> iter = topic.getSubjectLocators().iterator(); iter.hasNext();) { - targetTopic.addSubjectLocator(iter.next()); - } - _copyItemIdentifiers((IConstruct)topic, (IConstruct)targetTopic); - } - - /** - * Copies the types from the <code>topic</code> to the <code>targetTopic</code>. - * - * @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. - */ - @SuppressWarnings("unchecked") - private static void _copyTypes(Topic topic, Topic targetTopic, - Map<Topic, Topic> mergeMap) { - for (Iterator<Topic> iter = topic.getTypes().iterator(); iter.hasNext();) { - Topic type = iter.next(); - Topic targetType = mergeMap.get(type); - if (targetType == null) { - targetType = _copyTopic(type, targetTopic.getTopicMap(), mergeMap); - } - targetTopic.addType(targetType); - } - } - - /** - * Copies the occurrences and names from <code>topic</code> to the - * <code>targetTopic</code>. - * - * @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) { - Map<String, IReifiable> sigs = ((TopicMapImpl) targetTopic.getTopicMap()).getCollectionFactory().<String, IReifiable>createMap(); - for (Occurrence occ: targetTopic.getOccurrences()) { - sigs.put(SignatureGenerator.generateSignature(occ), (IReifiable)occ); - } - IReifiable existing = null; - for (Occurrence occ: ((TopicImpl) topic).getOccurrences()) { - Occurrence targetOcc = targetTopic.createOccurrence((String)null, null, null); - _copyType((ITyped)occ, (ITyped)targetOcc, mergeMap); - _copyScope((IScoped)occ, (IScoped)targetOcc, mergeMap); - if (occ.getValue() != null) { - targetOcc.setValue(occ.getValue()); - } - else if (occ.getResource() != null) { - targetOcc.setResource(occ.getResource()); - } - existing = sigs.get(SignatureGenerator.generateSignature(targetOcc)); - if (existing != null) { - MergeUtils.removeConstruct((IConstruct) targetOcc); - targetOcc = (Occurrence)existing; - } - _copyReifier((IReifiable) occ, (IReifiable) targetOcc, mergeMap); - _copyItemIdentifiers((IConstruct) occ, (IConstruct) targetOcc); - } - sigs.clear(); - for (TopicName name: targetTopic.getTopicNames()) { - sigs.put(SignatureGenerator.generateSignature(name), (IReifiable)name); - } - for (TopicName name: ((TopicImpl) topic).getTopicNames()) { - TopicName targetName = targetTopic.createTopicName(name.getValue(), null); - _copyType((ITyped) name, (ITyped) targetName, mergeMap); - _copyScope((IScoped) name, (IScoped) targetName, mergeMap); - existing = sigs.get(SignatureGenerator.generateSignature(targetName)); - if (existing != null) { - MergeUtils.removeConstruct((IConstruct)targetName); - targetName = (TopicName) existing; - } - _copyReifier((IReifiable) name, (IReifiable) targetName, mergeMap); - _copyItemIdentifiers((IConstruct) name, (IConstruct) targetName); - _copyVariants(name, targetName, mergeMap); - } - } - - /** - * Copies the variants from <code>source</code> to the <code>target</code>. - * - * @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(TopicName source, TopicName target, - Map<Topic, Topic> mergeMap) { - Map<String, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap(); - for (Variant variant: ((TopicNameImpl) target).getVariants()) { - sigs.put(SignatureGenerator.generateSignature(variant), variant); - } - Variant existing = null; - for (Variant variant: ((TopicNameImpl) source).getVariants()) { - Variant targetVar = target.createVariant((String) null, null); - _copyScope((IScoped) variant, (IScoped) targetVar, mergeMap); - if (variant.getValue() != null) { - targetVar.setValue(variant.getValue()); - } - else if (variant.getResource() != null) { - targetVar.setResource(variant.getResource()); - } - existing = sigs.get(SignatureGenerator.generateSignature(targetVar)); - if (existing != null) { - MergeUtils.removeConstruct((IConstruct) targetVar); - targetVar = existing; - } - _copyReifier((IReifiable) variant, (IReifiable) targetVar, mergeMap); - _copyItemIdentifiers((IConstruct) variant, (IConstruct) targetVar); - } - } - - /** - * Copies the reifier of <code>source</code> (if any) to the <code>target</code>. - * - * @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(IReifiable source, IReifiable target, - Map<Topic, Topic> mergeMap) { - Topic sourceReifier = source.getReifier(); - if (sourceReifier == null) { - return; - } - Topic reifier = mergeMap.containsKey(sourceReifier) ? mergeMap.get(sourceReifier) - : _copyTopic(sourceReifier, target.getTopicMap(), mergeMap); - target.setReifier(reifier); - } - - /** - * Copies the type of the <code>source</code> (if any) to the <code>target</code>. - * - * @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 void _copyType(ITyped source, ITyped target, - Map<Topic, Topic> mergeMap) { - Topic sourceType = source.getType(); - if (sourceType == null) { - return; - } - Topic type = mergeMap.containsKey(sourceType) ? mergeMap.get(sourceType) - : _copyTopic(sourceType, target.getTopicMap(), mergeMap); - target.setType(type); - } - - /** - * Copies all themes from the <code>source</code> scoped Topic Maps construct - * to the <code>target</code>. - * - * @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 void _copyScope(IScoped source, IScoped target, - Map<Topic, Topic> mergeMap) { - Topic theme = null; - for (Topic sourceTheme: source.getScope()) { - theme = mergeMap.containsKey(sourceTheme) ? mergeMap.get(sourceTheme) - : _copyTopic(sourceTheme, target.getTopicMap(), mergeMap); - target.addTheme(theme); - } - } - - /** - * Copies the item identifiers from <code>source</code> to <code>target</code>. - * - * @param source The source Topic Maps construct. - * @param target The target Topic Maps construct. - */ - private static void _copyItemIdentifiers(IConstruct source, IConstruct target) { - for(Locator iid: source.getItemIdentifiers()) { - target.addSourceLocator(iid); - } - } - - /** - * Copies the associations from the <code>source</code> topic map to the - * <code>target</code> 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. - */ - @SuppressWarnings("unchecked") - private static void _copyAssociations(TopicMapImpl source, - TopicMapImpl target, Map<Topic, Topic> mergeMap) { - Set<Association> assocs = target.getAssociations(); - Map<String, Association> sigs = target.getCollectionFactory().createMap(assocs.size()); - for (Association assoc: assocs) { - sigs.put(SignatureGenerator.generateSignature(assoc), assoc); - } - Association existing = null; - for (Association assoc: source.getAssociations()) { - Association targetAssoc = target.createAssociation(); - _copyType((ITyped) assoc, (ITyped) targetAssoc, mergeMap); - _copyScope((IScoped) assoc, (IScoped) targetAssoc, mergeMap); - for (Iterator<AssociationRole> iter = assoc.getAssociationRoles().iterator(); iter.hasNext();) { - AssociationRole role = iter.next(); - AssociationRole targetRole = targetAssoc.createAssociationRole(role.getPlayer(), role.getType()); - _copyItemIdentifiers((IConstruct)role, (IConstruct)targetRole); - _copyReifier((IReifiable) role, (IReifiable) targetRole, mergeMap); - } - existing = sigs.get(SignatureGenerator.generateSignature(targetAssoc)); - if (existing != null) { - MergeUtils.moveRoleCharacteristics(targetAssoc, existing); - MergeUtils.removeConstruct((IConstruct) targetAssoc); - targetAssoc = existing; - } - _copyReifier((IReifiable) assoc, (IReifiable) targetAssoc, mergeMap); - _copyItemIdentifiers((IConstruct) assoc, (IConstruct) targetAssoc); - } - } - - /** - * Adds a mapping from <code>source</code> to <code>target</code> into the - * <code>mergeMap</code>. - * - * If <code>source</code> has already a mapping to another target topic, - * <code>target</code> 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); - } - } - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/DatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/DatatypeAwareConstruct.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/DatatypeAwareConstruct.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,127 +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; - -import java.util.Collection; - -import org.tmapi.core.Locator; -import org.tmapi.core.Topic; - -/** - * Implementation of {@link org.tinytim.IDatatypeAwareConstruct}. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -abstract class DatatypeAwareConstruct extends Scoped implements - IDatatypeAwareConstruct { - - private static final String _XSD_BASE = "http://www.w3.org/2001/XMLSchema#"; - private static final Locator STRING = new IRI(_XSD_BASE + "string"); - private static final Locator ANY_URI = new IRI(_XSD_BASE + "anyURI"); - - private String _value; - private Locator _resource; - - DatatypeAwareConstruct(TopicMapImpl topicMap, Topic type, String value, Collection<Topic> scope) { - super(topicMap, type, scope); - _value = value; - } - - DatatypeAwareConstruct(TopicMapImpl topicMap, Topic type, Locator value, Collection<Topic> scope) { - super(topicMap, type, scope); - _resource = value; - } - - /* (non-Javadoc) - * @see org.tinytim.IDatatypeAwareConstruct#getValue2() - */ - public String getValue2() { - if (_value != null) { - return _value; - } - return _resource != null ? _resource.getReference() : ""; - } - - /** - * Sets the value (xsd:string) of this construct. - * - * Sideeffect: The resource is set to null. - * - * @param value Sets the value of this construct. - */ - public void setValue(String value) { - _fireEvent(Event.SET_VALUE, _value, value); - _resource = null; - _value = value; - } - - /** - * Returns the value of this construct. - * - * @return The value or <code>null</code>. - */ - public String getValue() { - return _value; - } - - /** - * Returns the locator (xsd:anyURI value) of this construct. - * - * @return The locator or <code>null</code>. - */ - public Locator getResource() { - return _resource; - } - - /** - * Sets the value (xsd:anyURI) of this construct. - * - * Side effect: The string value (if any) is set to <code>null</code>. - * - * @param value The locator. - */ - public void setResource(Locator value) { - _fireEvent(Event.SET_LOCATOR, _resource, value); - _value = null; - _resource = value; - } - - /* (non-Javadoc) - * @see org.tinytim.IDatatypeAwareConstruct#getDatatype() - */ - public Locator getDatatype() { - if (_value != null || _resource == null) { - return STRING; - } - return ANY_URI; - } - - /* (non-Javadoc) - * @see org.tinytim.Construct#dispose() - */ - @Override - protected void dispose() { - _value = null; - _resource = null; - super.dispose(); - } -} Deleted: tinytim/trunk/src/main/java/org/tinytim/DuplicateRemovalUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/DuplicateRemovalUtils.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/DuplicateRemovalUtils.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,209 +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; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.tinytim.index.ITypeInstanceIndex; -import org.tmapi.core.Association; -import org.tmapi.core.AssociationRole; -import org.tmapi.core.Occurrence; -import org.tmapi.core.Topic; -import org.tmapi.core.TopicMap; -import org.tmapi.core.TopicMapObject; -import org.tmapi.core.TopicName; -import org.tmapi.core.Variant; - -/** - * 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); - } - Map<String, Association> sig2Assoc = tm.getCollectionFactory().createMap(); - ITypeInstanceIndex typeInstanceIdx = tm.getIndexManager().getTypeInstanceIndex(); - if (!typeInstanceIdx.isAutoUpdated()) { - typeInstanceIdx.reindex(); - } - for (Topic type: typeInstanceIdx.getAssociationTypes()) { - _removeDuplicateAssociations(sig2Assoc, typeInstanceIdx.getAssociations(type)); - } - _removeDuplicateAssociations(sig2Assoc, typeInstanceIdx.getAssociations(null)); - } - - private static void _removeDuplicateAssociations(Map<String, Association> sig2Assoc, Collection<AssociationImpl> assocs) { - sig2Assoc.clear(); - Association existing = null; - String sig = null; - for (Association assoc: assocs) { - removeDuplicates(assoc); - sig = SignatureGenerator.generateSignature(assoc); - existing = sig2Assoc.get(sig); - if (existing != null) { - MergeUtils.moveRoleCharacteristics(assoc, existing); - _removeConstruct(assoc); - } - else { - sig2Assoc.put(sig, assoc); - } - } - } - - /** - * Removes duplicate occurrences and names from a topic. - * - * @param topic The topic from which duplicates should be removed from. - */ - @SuppressWarnings("unchecked") - public static void removeDuplicates(Topic topic) { - _removeDuplicateOccurrences(topic.getOccurrences()); - _removeDuplicateNames(topic.getTopicNames()); - } - - /** - * Removes duplicate variants from a name. - * - * @param name The name from which the duplicates should be removed. - */ - @SuppressWarnings("unchecked") - public static void removeDuplicates(TopicName name) { - Map<String, Variant> sigs = new HashMap<String, Variant>(); - for (Variant variant: new ArrayList<Variant>(name.getVariants())) { - String sig = SignatureGenerator.generateSignature(variant); - Variant existing = sigs.get(sig); - if (existing != null) { - _handleExistingConstruct(variant, existing); - _removeConstruct(variant); - } - else { - sigs.put(sig, variant); - } - } - } - - /** - * - * - * @param occs - */ - private static void _removeDuplicateOccurrences(Collection<Occurrence> occs) { - Map<String, Occurrence> sigs = new HashMap<String, Occurrence>(occs.size()); - Occurrence existing = null; - for (Occurrence occ: new ArrayList<Occurrence>(occs)) { - String sig = SignatureGenerator.generateSignature(occ); - existing = sigs.get(sig); - if (existing != null) { - _handleExistingConstruct(occ, existing); - _removeConstruct(occ); - } - else { - sigs.put(sig, occ); - } - } - } - - /** - * - * - * @param names - */ - private static void _removeDuplicateNames(Collection<TopicName> names) { - Map<String, TopicName> sigs = new HashMap<String, TopicName>(names.size()); - TopicName existing = null; - for (TopicName name: new ArrayList<TopicName>(names)) { - removeDuplicates(name); - String sig = SignatureGenerator.generateSignature(name); - existing = sigs.get(sig); - if (existing != null) { - _handleExistingConstruct(name, existing); - _moveVariants(name, existing); - _removeConstruct(name); - } - else { - sigs.put(sig, name); - } - } - } - - /** - * Removes duplicate roles from an association. - * - * @param assoc The association to remove duplicate roles from. - */ - @SuppressWarnings("unchecked") - public static void removeDuplicates(Association assoc) { - Map<String, AssociationRole> sig2Role = ((TopicMapImpl) assoc.getTopicMap()).getCollectionFactory().createMap(); - AssociationRole existing = null; - String sig = null; - for (AssociationRole role: new ArrayList<AssociationRole>(assoc.getAssociationRoles())) { - sig = SignatureGenerator.generateSignature(role); - existing = sig2Role.get(sig); - if (existing != null) { - _handleExistingConstruct(role, existing); - _removeConstruct(role); - } - else { - sig2Role.put(sig, role); - } - } - } - - /** - * @see {@link MergeUtils#moveVariants(TopicNameImpl, TopicNameImpl)} - */ - private static void _moveVariants(TopicName source, TopicName target) { - MergeUtils.moveVariants((TopicNameImpl)source, (TopicNameImpl)target); - } - - /** - * @see {@link MergeUtils#removeConstruct(IConstruct)} - */ - private static void _removeConstruct(TopicMapObject construct) { - MergeUtils.removeConstruct((IConstruct) construct); - } - - /** - * @see {@link MergeUtils#handleExistingConstruct(IReifiable, IReifiable)} - */ - private static void _handleExistingConstruct(TopicMapObject source, TopicMapObject target) { - MergeUtils.handleExistingConstruct((IReifiable) source, (IReifiable) target); - } - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/Event.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Event.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/Event.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,160 +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; - -/** - * Event constants. - * - * All events are sent before a change happens. This allows to check - * some constraints. - * - * 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$ - */ -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 a theme should be added to a {@link IScoped} construct. - */ - ADD_THEME, - /** - * Notification that a theme should be removed from a - * {@link IScoped} construct. - */ - REMOVE_THEME, - - /** - * Notification that the value of a name, an occurrence or variant - * should be set. - */ - SET_VALUE, - - /** - * 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 "resource" of an occurrence or variant should be - * set. - */ - SET_LOCATOR, //TODO: Remove this once we have a TMDM-compatible version - - MOVE_OCCURRENCE, - MOVE_NAME, - MOVE_VARIANT - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/ICollectionFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/ICollectionFactory.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/ICollectionFactory.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,72 +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; - -import java.util.Map; -import java.util.Set; - -/** - * Factory for collections. - * - * Implementations of this interface must provide a default constructor. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public interface ICollectionFactory { - - /** - * Creates a Set with the specified initial <code>size</code>. - * - * @param <E> - * @param size The initial capacity. - * @return - */ - <E> Set<E> createSet(int size); - - /** - * Creates a Set. - * - * @param <E> - * @return - */ - <E> Set<E> createSet(); - - /** - * Creates a Map. - * - * @param <K> - * @param <V> - * @return - */ - <K, V> Map<K, V> createMap(); - - /** - * Creates a Map with the specified initial <code>size</code>. - * - * @param <K> - * @param <V> - * @param size The initial capacity. - * @return - */ - <K, V> Map<K, V> createMap(int size); - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/IConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/IConstruct.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/IConstruct.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,66 +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; - -import java.util.Set; - -import org.tmapi.core.Locator; -import org.tmapi.core.TopicMapObject; - -/** - * The Topic Maps 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> - * @version $Rev$ - $Date$ - */ -public interface IConstruct extends TopicMapObject { - - /** - * Returns the parent of the Topic Maps construct. - * - * @return The parent of a Topic Maps construct or <code>null</code>. - */ - public IConstruct getParent(); - - /** - * Returns the item identifiers of the Topic Maps construct. - * - * @return A (maybe empty) immutable Set of item identifiers. - */ - public Set<Locator> getItemIdentifiers(); - - /** - * Adds an item identifier to the Topic Maps construct. - * - * @param itemIdentifier The item identifier to add. - */ - public void addItemIdentifier(Locator itemIdentifier); - - /** - * Removes an item identifier from the Topic Maps construct. - * - * @param itemIdentifier The item identifier to remove. - */ - public void removeItemIdentifier(Locator itemIdentifier); - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,54 +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; - -import org.tmapi.core.Locator; - -/** - * Indicates that a Topic Maps construct has a value and 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> - * @version $Rev$ - $Date$ - */ -public interface IDatatypeAwareConstruct extends IConstruct { - - /** - * The value of this Topic Maps construct. - * - * This method differs from TMAPI: This method MUST return the value OR the - * locator as string. This method should be removed if we have TMAPI 2.0 - * (maybe the whole interface should be removed). - * Currently, the {@link SignatureGenerator} needs it. - * - * @return The value. - */ - public String getValue2(); - - /** - * Returns the datatype of this Topic Maps construct. - * - * @return The datatype. - */ - public Locator getDatatype(); - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/IEventHandler.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/IEventHandler.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/IEventHandler.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,47 +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; - -/** - * Event handler that is able to handle Topic Maps events. - * - * 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 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/IEventPublisher.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/IEventPublisher.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/IEventPublisher.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,48 +0,0 @@ -/* - * This is tinyTiM, a tiny Topic Maps engine. - * - * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ -package org.tinytim; - -/** - * Publisher for Topic Maps events. - * - * 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 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/IMovable.java =================================================================== --- tinytim/trunk/src/main/java/org/t... [truncated message content] |
From: <lh...@us...> - 2008-08-07 14:28:46
|
Revision: 102 http://tinytim.svn.sourceforge.net/tinytim/?rev=102&view=rev Author: lheuer Date: 2008-08-07 14:28:52 +0000 (Thu, 07 Aug 2008) Log Message: ----------- - Imported current dev.status of tinyTiM 2. Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/utils/ tinytim/trunk/src/main/java/org/tinytim/utils/Feature.java tinytim/trunk/src/main/java/org/tinytim/utils/ICollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/utils/Property.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/XSD.java Added: tinytim/trunk/src/main/java/org/tinytim/utils/Feature.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/Feature.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/Feature.java 2008-08-07 14:28:52 UTC (rev 102) @@ -0,0 +1,92 @@ +/* + * 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.utils; + +/** + * This class provides access to the feature strings that TMAPI-compatible + * Topic Maps processors must recognize (but not necessarily support). + * + * Copied from the TMAPIX-project. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public final class Feature { + + private Feature() { + // noop. + } + + private static final String _FEATURE_BASE = "http://tmapi.org/features/"; + + /** + * An implementation which supports this feature can process locator + * addresses in URI notation as defined by RFC 2396. + * + * An implementation that supports URI notation locators MUST support + * the expansion of relative URIs that use a hierarchical URI scheme to + * fully specified URIs against a specified base URI, and MAY support + * the expansion of relative URIs that use other scheme-specific mechansims + * for relative URI expansion. + */ + public static final String NOTATION_URI= _FEATURE_BASE + "notation/URI"; + + /** + * An implementation which supports this feature supports the Topic Maps + * data model defined by the XTM 1.0 specification. + */ + public static final String XTM_1_0 = _FEATURE_BASE + "model/xtm1.0"; + + /** + * An implementation which supports this feature supports the + * <a href="http://www.isotopicmaps.org/sam/sam-model/">Topic Maps + * Data Model (TMDM) ISO/IEC 13250-2</a>. + */ + public static final String XTM_1_1 = _FEATURE_BASE + "model/xtm1.1"; + + /** + * An implementation which supports this feature MUST detect when two + * topic instances have topic names which match both in the scope of the + * name and the value of the name string, and, if XTM 1.1 is supported, + * the types are equal. Topics which have matching names must either be + * merged or a {@link org.tmapi.core.TopicsMustMergeException} must be + * raised, depending on the value of the + * <a href="http://tmapi.org/features/automerge">http://tmapi.org/features/automerge</a> + * feature. + */ + public static final String TNC = _FEATURE_BASE + "merge/byTopicName"; + + /** + * This feature indicates that the underlying + * {@link org.tmapi.core.TopicMapSystem} cannot be modified. + */ + public static final String READ_ONLY = _FEATURE_BASE + "readOnly"; + + /** + * If an implementation supports this feature, then whenever the + * implementation detects that two Topics should be merged (by one or more + * of the merge features defined under + * <a href="http://tmapi.org/features/merge/">http://tmapi.org/features/merge/</a>), + * then the implementation MUST merge the properties of these two Topics + * automatically and transparently to the API client. + */ + public static final String AUTOMERGE = _FEATURE_BASE + "automerge"; +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/Feature.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/ICollectionFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/ICollectionFactory.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/ICollectionFactory.java 2008-08-07 14:28:52 UTC (rev 102) @@ -0,0 +1,120 @@ +/* + * 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.utils; + +import java.util.Map; +import java.util.Set; + +/** + * Factory for collections. + * + * Implementations of this interface must provide a default constructor. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public interface ICollectionFactory { + + /** + * Creates a {@link java.util.Set} with the specified initial <code>size</code>. + * + * @param <E> + * @param size The initial capacity. + * @return + */ + <E> Set<E> createSet(int size); + + /** + * Creates a {@link java.util.Set}. + * + * @param <E> + * @return + */ + <E> Set<E> createSet(); + + /** + * Creates a {@link java.util.Set} with the specified initial <tt>size</tt>. + * + * This is almost equal to {@link #createSet(int)} but the implementation is + * allowed (but not required) to compare the elements by identity. + * + * @param <E> + * @param size The initial capacity. + * @return + */ + <E> Set<E> createIdentitySet(int size); + + /** + * Creates a {@link java.util.Set}. + * + * This is almost equal to {@link #createSet()} but the implementation is + * allowed (but not required) to compare the elements by identity. + * + * @param <E> + * @return + */ + <E> Set<E> createIdentitySet(); + + /** + * Creates a {@link java.util.Map}. + * + * @param <K> + * @param <V> + * @return + */ + <K, V> Map<K, V> createMap(); + + /** + * Creates a {@link java.util.Map} with the specified initial <tt>size</tt>. + * + * @param <K> + * @param <V> + * @param size The initial capacity. + * @return + */ + <K, V> Map<K, V> createMap(int size); + + /** + * Creates a {@link java.util.Map}. + * + * This is almost equal to {@link #createMap()} but the implementation is + * allowed (but not required) to compare the key elements by identity. + * + * @param <K> + * @param <V> + * @return + */ + <K, V> Map<K, V> createIdentityMap(); + + /** + * Creates a {@link java.util.Map} with the specified initial <tt>size</tt>. + * + * This is almost equal to {@link #createMap(int)} but the implementation is + * allowed (but not required) to compare the key elements by identity. + * + * @param <K> + * @param <V> + * @param size The initial capacity. + * @return + */ + <K, V> Map<K, V> createIdentityMap(int size); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/ICollectionFactory.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/Property.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/Property.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/Property.java 2008-08-07 14:28:52 UTC (rev 102) @@ -0,0 +1,45 @@ +/* + * 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.utils; + +/** + * Provides constants for all tinyTiM-specific TMAPI properties. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public final class Property { + + private Property() { + // noop. + } + + /** + * Property which indicates the {@link org.tinytim.ICollectionFactory} to use. + * + * The default value of this property depends on the environment: If + * the <a href="http://trove4j.sourceforge.net/">Trove4J</a> lib is found, + * that lib used, otherwise a collection factory which depends on the + * default Java collections. + */ + public static final String COLLECTION_FACTORY = "org.tinytim.util.ICollectionFactory"; + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/Property.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/TypeInstanceConverter.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/TypeInstanceConverter.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/TypeInstanceConverter.java 2008-08-07 14:28:52 UTC (rev 102) @@ -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.utils; + +import java.util.Collection; +import java.util.logging.Logger; + +import org.tinytim.core.TopicMapImpl; +import org.tinytim.voc.TMDM; +import org.tinytim.voc.XTM10; +import org.tmapi.core.Association; +import org.tmapi.core.Locator; +import org.tmapi.core.Role; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; +import org.tmapi.index.TypeInstanceIndex; + +/** + * This class provides functions that can be used to convert the type-instance + * relationships that are modelled as associations into the [types] property + * of {@link org.tmapi.core.Topic}s. + * + * Copied from the TMAPIX-project. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public final class TypeInstanceConverter { + + //TODO: Implement types -> associations + + private static final Logger LOG = Logger.getLogger(TypeInstanceConverter.class.getName()); + + private TypeInstanceConverter() { + // noop. + } + + /** + * Converts type-instance relationships (TMDM 1.0) and class-instance + * relationships into the [types] property of the {@link org.tmapi.core.Topic}. + * + * @see #convertTMDMAssociationsToTypes(TopicMap) + * @see #convertXTMAssociationsToTypes(TopicMap) + * + * @param topicMap The topic map to convert. + */ + public static void convertAssociationsToTypes(TopicMap topicMap) { + convertTMDMAssociationsToTypes(topicMap); + convertXTMAssociationsToTypes(topicMap); + } + + /** + * Converts class-instance relationships (XTM 1.0) into the [types] property + * of {@link org.tmapi.core.Topic}s. The associations are removed from the + * topic map. + * + * @param topicMap The topic map to convert. + */ + public static void convertXTMAssociationsToTypes(TopicMap topicMap) { + _associationsToTypes(topicMap, XTM10.CLASS_INSTANCE, + XTM10.CLASS, XTM10.INSTANCE); + } + + /** + * Converts type-instance relationships (TMDM 1.0) into the [types] property + * of {@link org.tmapi.core.Topic}s. The associations are removed from the + * topic map. + * + * @param topicMap The topic map to convert. + */ + public static void convertTMDMAssociationsToTypes(TopicMap topicMap) { + _associationsToTypes(topicMap, TMDM.TYPE_INSTANCE, + TMDM.TYPE, TMDM.INSTANCE); + } + + private static void _associationsToTypes(TopicMap topicMap, + Locator typeInstance_, Locator type_, Locator instance_) { + TopicMapImpl tm = (TopicMapImpl) topicMap; + Topic typeInstance = tm.getTopicBySubjectIdentifier(typeInstance_); + if (typeInstance == null) { + return; + } + Topic type = tm.getTopicBySubjectIdentifier(type_); + if (type == null) { + return; + } + Topic instance = tm.getTopicBySubjectIdentifier(instance_); + if (instance == null) { + return; + } + TypeInstanceIndex typeInstanceIdx = tm.getIndexManager().getTypeInstanceIndex(); + if (!typeInstanceIdx.isAutoUpdated()) { + typeInstanceIdx.reindex(); + } + for (Association assoc: typeInstanceIdx.getAssociations(typeInstance)) { + Topic[] pair = _getTypeInstancePair(assoc, type, instance); + if (pair == null) { + continue; + } + pair[1].addType(pair[0]); + assoc.remove(); + } + } + + private static void _info(Association assoc, String msg) { + LOG.info("The association (ID: '" + assoc.getId() + "') cannot be converted into a type property. Reason: " + msg); + } + + private static Topic[] _getTypeInstancePair(Association assoc, Topic type, Topic instance) { + Collection<Role> roles = assoc.getRoles(); + if (roles.size() != 2) { + _info(assoc, "Not a binary association."); + return null; + } + if (assoc.getReifier() != null) { + _info(assoc, "It is reified"); + return null; + } + if (!assoc.getItemIdentifiers().isEmpty()) { + _info(assoc, "It as item identifiers"); + return null; + } + if (!assoc.getScope().isEmpty()) { + _info(assoc, "The scope is not unconstrained"); + return null; + } + Topic[] pair = new Topic[2]; + for (Role role: roles) { + if (type.equals(role.getType())) { + pair[0] = role.getPlayer(); + } + else if (instance.equals(role.getType())) { + pair[1] = role.getPlayer(); + } + } + if (pair[0] == null) { + _info(assoc, "The type player is null."); + return null; + } + if (pair[1] == null) { + _info(assoc, "The instance player is null"); + return null; + } + return pair; + } +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/TypeInstanceConverter.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java 2008-08-07 14:26:19 UTC (rev 101) +++ tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java 2008-08-07 14:28:52 UTC (rev 102) @@ -20,67 +20,71 @@ */ package org.tinytim.voc; -import org.tinytim.IRI; import org.tmapi.core.Locator; /** * Constants for TMDM 1.0 (model) PSIs. * - * Copied from the Semagia MIO project. + * Copied with permission from the Semagia MIO project. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ -public final class TMDM { +public final class TMDM extends Vocabulary { + private TMDM() { + // noop. + } + private static final String _BASE = "http://psi.topicmaps.org/iso13250/model/"; /** * Core concept of type-instance relationships. * Used as association type. */ - public static final Locator TYPE_INSTANCE = new IRI(_BASE + "type-instance"); + public static final Locator TYPE_INSTANCE = _createLocator(_BASE + "type-instance"); /** * Core concept of type within a type-instance relationship. * Used as role type. */ - public static final Locator TYPE = new IRI(_BASE + "type"); + public static final Locator TYPE = _createLocator(_BASE + "type"); /** * Core concept of instance within a type-instance relationship. * Used as role type. */ - public static final Locator INSTANCE = new IRI(_BASE + "instance"); + public static final Locator INSTANCE = _createLocator(_BASE + "instance"); /** * Core concept of supertype-subtype relationship. * Used as association type. */ - public static final Locator SUPERTYPE_SUBTYPE = new IRI(_BASE + "supertype-subtype"); + public static final Locator SUPERTYPE_SUBTYPE = _createLocator(_BASE + "supertype-subtype"); /** * Core concept of supertype within a supertype-subtype relationship. * Used as role type. */ - public static final Locator SUPERTYPE = new IRI(_BASE + "supertype"); + public static final Locator SUPERTYPE = _createLocator(_BASE + "supertype"); /** * Core concept of subtype within a supertype-subtype relationship. * Used as role type. */ - public static final Locator SUBTYPE = new IRI(_BASE + "subtype"); + public static final Locator SUBTYPE = _createLocator(_BASE + "subtype"); /** * Core concept of a topic name. * Used as topic name type. */ - public static final Locator TOPIC_NAME = new IRI(_BASE + "topic-name"); + public static final Locator TOPIC_NAME = _createLocator(_BASE + "topic-name"); /** * Used to indicate that a variant can be used for sorting purposes. * Used as variant theme. */ - public static final Locator SORT = new IRI(_BASE + "sort"); + public static final Locator SORT = _createLocator(_BASE + "sort"); + } Added: tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java 2008-08-07 14:28:52 UTC (rev 102) @@ -0,0 +1,37 @@ +/* + * 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.voc; + +import org.tinytim.core.Literal; +import org.tmapi.core.Locator; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +abstract class Vocabulary { + + protected static Locator _createLocator(String reference) { + return Literal.createIRI(reference); + } +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java 2008-08-07 14:28:52 UTC (rev 102) @@ -0,0 +1,53 @@ +/* + * 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.voc; + +import org.tmapi.core.Locator; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public final class XSD extends Vocabulary { + + private XSD() { + // noop. + } + + private static final String _BASE = "http://www.w3.org/2001/XMLSchema#"; + + public final static Locator STRING = _createLocator(_BASE + "string"); + + public final static Locator ANY_URI = _createLocator(_BASE + "anyURI"); + + public final static Locator DECIMAL = _createLocator(_BASE + "decimal"); + + public final static Locator INTEGER = _createLocator(_BASE + "integer"); + + public final static Locator INT = _createLocator(_BASE + "int"); + + public final static Locator FLOAT = _createLocator(_BASE + "float"); + + public final static Locator LONG = _createLocator(_BASE + "long"); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java 2008-08-07 14:26:19 UTC (rev 101) +++ tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java 2008-08-07 14:28:52 UTC (rev 102) @@ -20,7 +20,6 @@ */ package org.tinytim.voc; -import org.tinytim.IRI; import org.tmapi.core.Locator; /** @@ -34,9 +33,9 @@ * Copied from the Semagia MIO project. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ -public final class XTM10 { +public final class XTM10 extends Vocabulary { private static final String _BASE = "http://www.topicmaps.org/xtm/1.0/core.xtm#"; @@ -45,61 +44,61 @@ * represents class-instance relationships between topics, and that is * semantically equivalent to the use of <instanceOf> subelements. */ - public static final Locator CLASS_INSTANCE = new IRI(_BASE + "class-instance"); + public static final Locator CLASS_INSTANCE = _createLocator(_BASE + "class-instance"); /** * The core concept of class; the role of class as played by one of the * members of a class-instance association. */ - public static final Locator CLASS = new IRI(_BASE + "class"); + public static final Locator CLASS = _createLocator(_BASE + "class"); /** * The core concept of instance; the role of instance as played by one of * the members of a class-instance association. */ - public static final Locator INSTANCE = new IRI(_BASE + "instance"); + public static final Locator INSTANCE = _createLocator(_BASE + "instance"); /** * The core concept of superclass-subclass; the class of association that * represents superclass-subclass relationships between topics. */ - public static final Locator SUPERCLASS_SUBCLASS = new IRI(_BASE + "superclass-subclass"); + public static final Locator SUPERCLASS_SUBCLASS = _createLocator(_BASE + "superclass-subclass"); /** * The core concept of superclass; the role of superclass as played by one * of the members of a superclass-subclass association. */ - public static final Locator SUPERCLASS = new IRI(_BASE + "superclass"); + public static final Locator SUPERCLASS = _createLocator(_BASE + "superclass"); /** * The core concept of subclass; the role of subclass as played by one of * the members of a superclass-subclass association. */ - public static final Locator SUBCLASS = new IRI(_BASE + "subclass"); + public static final Locator SUBCLASS = _createLocator(_BASE + "subclass"); /** * The core concept of association; the generic class to which all * associations belong unless otherwise specified. */ - public static final Locator ASSOCIATION = new IRI(_BASE + "association"); + public static final Locator ASSOCIATION = _createLocator(_BASE + "association"); /** * The core concept of occurrence; the generic class to which all * occurrences belong unless otherwise specified. */ - public static final Locator OCCURRENCE = new IRI(_BASE + "occurrence"); + public static final Locator OCCURRENCE = _createLocator(_BASE + "occurrence"); /** * Used to indicate that a variant can be used for sorting purposes. * Used as variant theme. */ - public static final Locator SORT = new IRI(_BASE + "sort"); + public static final Locator SORT = _createLocator(_BASE + "sort"); /** * Used to indicate that a variant can be used for displaying purposes. * Used as variant theme. */ - public static final Locator DISPLAY = new IRI(_BASE + "display"); + public static final Locator DISPLAY = _createLocator(_BASE + "display"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-07 14:26:12
|
Revision: 101 http://tinytim.svn.sourceforge.net/tinytim/?rev=101&view=rev Author: lheuer Date: 2008-08-07 14:26:19 +0000 (Thu, 07 Aug 2008) Log Message: ----------- Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/core/ tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java tinytim/trunk/src/main/java/org/tinytim/core/Event.java tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisher.java tinytim/trunk/src/main/java/org/tinytim/core/IFactory.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/IRI.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/JavaCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/core/Literal.java tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java tinytim/trunk/src/main/java/org/tinytim/core/OccurrenceImpl.java tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemFactoryImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicUtils.java tinytim/trunk/src/main/java/org/tinytim/core/TroveCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java Removed Paths: ------------- tinytim/trunk/src/main/java/org/tinytim/index/IIndex.java tinytim/trunk/src/main/java/org/tinytim/index/IIndexManager.java tinytim/trunk/src/main/java/org/tinytim/index/IScopedIndex.java tinytim/trunk/src/main/java/org/tinytim/index/ITypeInstanceIndex.java tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndex.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/ Added: tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,155 @@ +/* + * 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 java.util.Collections; +import java.util.Set; + +import org.tmapi.core.Association; +import org.tmapi.core.Role; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; + +/** + * {@link org.tmapi.core.Association} implementation. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +final class AssociationImpl extends ScopedImpl implements Association { + + private Set<Role> _roles; + + AssociationImpl(TopicMapImpl topicMap, Topic type, Collection<Topic> scope) { + super(topicMap, type, scope); + _roles = _makeSet(2); + } + + /* (non-Javadoc) + * @see org.tinytim.core.ConstructImpl#getParent() + */ + @Override + public TopicMap getParent() { + return _tm; + } + + /** + * Adds a role to this association. + * + * @param role The role to add. + */ + void addRole(Role role) { + RoleImpl r = (RoleImpl) role; + if (r._parent == this) { + return; + } + assert r._parent == null; + _fireEvent(Event.ADD_ROLE, null, r); + _roles.add(r); + r._parent = this; + TopicImpl player = (TopicImpl) r.getPlayer(); + if (player != null) { + player.addRolePlayed(r); + } + } + + /** + * Removes a role from this association. + * + * @param role The role to remove. + */ + void removeRole(Role role) { + RoleImpl r = (RoleImpl) role; + if (r._parent != this) { + return; + } + _fireEvent(Event.REMOVE_ROLE, r, null); + _roles.remove(role); + r._parent = null; + TopicImpl player = (TopicImpl) r.getPlayer(); + if (player != null) { + player.removeRolePlayed(r); + } + } + + /* (non-Javadoc) + * @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 IllegalArgumentException("The type must not be null"); + } + if (player == null) { + throw new IllegalArgumentException("The player must not be null"); + } + RoleImpl role = new RoleImpl(_tm, type, player); + addRole(role); + return role; + } + + /* (non-Javadoc) + * @see org.tmapi.core.Association#getRoles() + */ + public Set<Role> getRoles() { + return Collections.unmodifiableSet(_roles); + } + + /* (non-Javadoc) + * @see org.tmapi.core.Association#getRoleTypes() + */ + public Set<Topic> getRoleTypes() { + Set<Topic> roleTypes = _makeSet(_roles.size()); + for (Role role: _roles) { + roleTypes.add(role.getType()); + } + return roleTypes; + } + + /* (non-Javadoc) + * @see org.tmapi.core.Association#getRoles(org.tmapi.core.Topic) + */ + public Set<Role> getRoles(Topic type) { + if (type == null) { + throw new IllegalArgumentException("The type must not be null"); + } + Set<Role> roles = _makeSet(_roles.size()); + for (Role role: _roles) { + if (type == role.getType()) { + roles.add(role); + } + } + return roles; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapObject#remove() + */ + public void remove() { + _tm.removeAssociation(this); + for (Role role: new ArrayList<Role>(_roles)) { + role.remove(); + } + _roles = null; + super.dispose(); + } +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,170 @@ +/* + * 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.Collections; +import java.util.Set; + +import org.tmapi.core.Construct; +import org.tmapi.core.Locator; +import org.tmapi.core.TopicMap; + +/** + * Base class for all Topic Maps constructs. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +abstract class ConstructImpl implements Construct { + + protected String _id; + protected TopicMapImpl _tm; + protected Construct _parent; + private Set<Locator> _iids; + + ConstructImpl(TopicMapImpl topicMap) { + _tm = topicMap; + } + + protected <E> Set<E> _makeSet() { + return _tm.getCollectionFactory().createIdentitySet(); + } + + protected <E> Set<E> _makeSet(int size) { + return _tm.getCollectionFactory().createIdentitySet(size); + } + + /* (non-Javadoc) + * @see org.tmapi.core.Construct#getParent() + */ + public Construct getParent() { + return _parent; + } + + /* (non-Javadoc) + * @see org.tmapi.core.Construct#getId() + */ + public String getId() { + return _id; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapObject#getTopicMap() + */ + public TopicMap getTopicMap() { + return _tm; + } + + /* (non-Javadoc) + * @see org.tmapi.core.Construct#getItemIdentifiers() + */ + public Set<Locator> getItemIdentifiers() { + return _iids == null ? Collections.<Locator>emptySet() + : Collections.unmodifiableSet(_iids); + } + + /* (non-Javadoc) + * @see org.tmapi.core.Construct#addItemIdentifier(org.tmapi.core.Locator) + */ + public void addItemIdentifier(Locator itemIdentifier) { + if (itemIdentifier == null) { + throw new IllegalArgumentException("The item identifier must not be null"); + } + if (_iids != null && _iids.contains(itemIdentifier)) { + return; + } + _fireEvent(Event.ADD_IID, null, itemIdentifier); + if (_iids == null) { + _iids = _makeSet(); + } + _iids.add(itemIdentifier); + } + + /* (non-Javadoc) + * @see org.tmapi.core.Construct#removeItemIdentifier(org.tmapi.core.Locator) + */ + public void removeItemIdentifier(Locator itemIdentifier) { + if (_iids == null || !_iids.contains(itemIdentifier)) { + return; + } + _fireEvent(Event.REMOVE_IID, itemIdentifier, null); + _iids.remove(itemIdentifier); + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public final boolean equals(Object obj) { + return this == obj; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public final int hashCode() { + return _id.hashCode(); + } + + /** + * Notifies the topic map about an event. + * + * If the topic map is <code>null</code>, no event is sent. + * + * @param evt The event. + * @param oldValue The old value. + * @param newValue The new value. + */ + protected void _fireEvent(Event evt, Object oldValue, Object newValue) { + if (_tm != null) { + _tm.handleEvent(evt, this, oldValue, newValue); + } + } + + /** + * Releases used resources. + * + * Should be called in the {@link org.tmapi.core.TopicMapObject#remove()} + * method. + */ + protected void dispose() { + _tm = null; + _parent = null; + _iids = null; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(super.toString()); + sb.append(" ").append(_id); + sb.append(" iids=["); + for (Locator iid: getItemIdentifiers()) { + sb.append(iid); + sb.append(','); + } + sb.append("]"); + return sb.toString(); + } +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,374 @@ +/* + * 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.Map; +import java.util.Set; + +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 { + + /** + * 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, (TopicMapImpl) target); + } + + /** + * @see #copy(TopicMap, TopicMap) + */ + private static void _copy(TopicMap source, TopicMapImpl 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 = target.getCollectionFactory().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, TopicMap target, + Map<Topic, Topic> mergeMap) { + Topic targetTopic = target.createTopic(); + _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, 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) { + Map<String, Reifiable> sigs = ((TopicMapImpl) targetTopic.getTopicMap()).getCollectionFactory().createMap(); + 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) { + Map<String, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap(); + 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, 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, 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 = ((TopicMapImpl) tm).getCollectionFactory().createIdentitySet(source.getScope().size()); + Topic theme = null; + for (Topic sourceTheme: source.getScope()) { + theme = mergeMap.containsKey(sourceTheme) ? mergeMap.get(sourceTheme) + : _copyTopic(sourceTheme, 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, + TopicMapImpl target, Map<Topic, Topic> mergeMap) { + Set<Association> assocs = target.getAssociations(); + Map<String, Association> sigs = target.getCollectionFactory().createMap(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); + } + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,185 @@ +/* + * 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.math.BigDecimal; +import java.math.BigInteger; +import java.util.Collection; + +import org.tinytim.voc.XSD; +import org.tmapi.core.DatatypeAware; +import org.tmapi.core.Locator; +import org.tmapi.core.Topic; + +/** + * Implementation of {@link org.tinytim.IDatatypeAwareConstruct}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +abstract class DatatypeAwareConstruct extends ScopedImpl implements + DatatypeAware, ILiteralAware { + + private ILiteral _literal; + + DatatypeAwareConstruct(TopicMapImpl topicMap, Topic type, ILiteral literal, Collection<Topic> scope) { + super(topicMap, type, scope); + _literal = literal; + } + + /* (non-Javadoc) + * @see org.tinytim.core.ILiteralAware#getLiteral() + */ + public ILiteral getLiteral() { + return _literal; + } + + /* (non-Javadoc) + * @see org.tinytim.core.ILiteralAware#setLiteral(org.tinytim.core.ILiteral) + */ + public void setLiteral(ILiteral literal) { + assert literal != null; + _fireEvent(Event.SET_LITERAL, _literal, literal); + _literal = literal; + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#getValue() + */ + public String getValue() { + return _literal.getValue(); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#getDatatype() + */ + public Locator getDatatype() { + return _literal.getDatatype(); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#setValue(java.lang.String) + */ + public void setValue(String value) { + setLiteral(Literal.create(value)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#setValue(java.math.BigDecimal) + */ + public void setValue(BigDecimal value) { + setLiteral(Literal.create(value)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#setValue(java.math.BigInteger) + */ + public void setValue(BigInteger value) { + setLiteral(Literal.create(value)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#setValue(float) + */ + public void setValue(float value) { + setLiteral(Literal.create(value)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#setValue(int) + */ + public void setValue(int value) { + setLiteral(Literal.create(value)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#setValue(org.tmapi.core.Locator) + */ + public void setValue(Locator value) { + setLiteral(Literal.create(value)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#setValue(long) + */ + public void setValue(long value) { + setLiteral(Literal.create(value)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#setValue(java.lang.String, org.tmapi.core.Locator) + */ + public void setValue(String value, Locator datatype) { + setLiteral(Literal.create(value, datatype)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#decimalValue() + */ + public BigDecimal decimalValue() { + return _literal.decimalValue(); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#floatValue() + */ + public float floatValue() { + return _literal.floatValue(); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#integerValue() + */ + public BigInteger integerValue() { + return _literal.integerValue(); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#intValue() + */ + public int intValue() { + return _literal.intValue(); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#locatorValue() + */ + public Locator locatorValue() { + return XSD.ANY_URI.equals(_literal.getDatatype()) ? (Locator) _literal + : Literal.createIRI(_literal.getValue()); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#longValue() + */ + public long longValue() { + return _literal.longValue(); + } + + /* (non-Javadoc) + * @see org.tinytim.Construct#dispose() + */ + @Override + protected void dispose() { + _literal = null; + super.dispose(); + } +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,184 @@ +/* + * 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 java.util.HashMap; +import java.util.Map; + +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); + } + Map<String, Association> sig2Assoc = tm.getCollectionFactory().createMap(); + TypeInstanceIndex typeInstanceIdx = tm.getIndexManager().getTypeInstanceIndex(); + if (!typeInstanceIdx.isAutoUpdated()) { + typeInstanceIdx.reindex(); + } + for (Topic type: typeInstanceIdx.getAssociationTypes()) { + _removeDuplicateAssociations(sig2Assoc, typeInstanceIdx.getAssociations(type)); + } + _removeDuplicateAssociations(sig2Assoc, typeInstanceIdx.getAssociations(null)); + } + + private static void _removeDuplicateAssociations(Map<String, Association> sig2Assoc, Collection<Association> assocs) { + sig2Assoc.clear(); + Association existing = null; + String sig = null; + for (Association assoc: assocs) { + removeDuplicates(assoc); + 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) { + Map<String, Variant> sigs = new HashMap<String, Variant>(); + for (Variant variant: new ArrayList<Variant>(name.getVariants())) { + String 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) { + Map<String, Occurrence> sigs = new HashMap<String, Occurrence>(occs.size()); + Occurrence existing = null; + for (Occurrence occ: new ArrayList<Occurrence>(occs)) { + String 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) { + Map<String, Name> sigs = new HashMap<String, Name>(names.size()); + Name existing = null; + for (Name name: new ArrayList<Name>(names)) { + removeDuplicates(name); + String 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) { + Map<String, Role> sig2Role = ((TopicMapImpl) assoc.getTopicMap()).getCollectionFactory().createMap(); + Role existing = null; + String sig = null; + for (Role role: new ArrayList<Role>(assoc.getRoles())) { + sig = SignatureGenerator.generateSignature(role); + existing = sig2Role.get(sig); + if (existing != null) { + MergeUtils.handleExistingConstruct(role, existing); + role.remove(); + } + else { + sig2Role.put(sig, role); + } + } + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/Event.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Event.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/Event.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,154 @@ +/* + * 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; + +/** + * Event constants. + * + * All events are sent before a change happens. This allows to check + * some constraints. + * + * 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$ + */ +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 a theme should be added to a {@link IScoped} construct. + */ + ADD_THEME, + /** + * Notification that a theme should be removed from a + * {@link IScoped} construct. + */ + REMOVE_THEME, + + /** + * 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, + + MOVE_OCCURRENCE, + MOVE_NAME, + MOVE_VARIANT + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/Event.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,49 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.core; + +import org.tmapi.core.Construct; + +/** + * Event handler that is able to handle Topic Maps events. + * + * 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 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, Construct sender, Object oldValue, Object newValue); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisher.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisher.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisher.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,48 @@ +/* + * 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; + +/** + * Publisher for Topic Maps events. + * + * 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 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); +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisher.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,48 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.core; + +import org.tmapi.core.Association; +import org.tmapi.core.Name; +import org.tmapi.core.Occurrence; +import org.tmapi.core.Role; +import org.tmapi.core.Topic; +import org.tmapi.core.Variant; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface IFactory { + + public Association createAssociation(); + + public Role createRole(Association parent); + + public Occurrence createOccurrence(Topic parent); + + public Name createName(Topic parent); + + public Variant createVariant(Name parent); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,52 @@ +/* + * 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.math.BigDecimal; +import java.math.BigInteger; + +import org.tmapi.core.Locator; + +/** + * + * + * 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 ILiteral { + + public String getValue(); + + public Locator getDatatype(); + + public BigDecimal decimalValue(); + + public float floatValue(); + + public BigInteger integerValue(); + + public int intValue(); + + public long longValue(); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,37 @@ +/* + * 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; + +/** + * + * + * 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 ILiteralAware { + + public ILiteral getLiteral(); + + public void setLiteral(ILiteral literal); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,35 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.core; + +import org.tmapi.core.Locator; + +/** + * + * + * 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 ILocator extends ILiteral, Locator { + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/IMovable.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IMovable.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/IMovable.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,43 @@ +/* + * 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 ... [truncated message content] |
From: <lh...@us...> - 2008-08-07 14:13:36
|
Revision: 100 http://tinytim.svn.sourceforge.net/tinytim/?rev=100&view=rev Author: lheuer Date: 2008-08-07 14:13:46 +0000 (Thu, 07 Aug 2008) Log Message: ----------- Removed tmapi-2 branch, will move the code directly in the trunk Removed Paths: ------------- tinytim/branches/tmapi-2/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-07 14:09:49
|
Revision: 98 http://tinytim.svn.sourceforge.net/tinytim/?rev=98&view=rev Author: lheuer Date: 2008-08-07 13:14:50 +0000 (Thu, 07 Aug 2008) Log Message: ----------- - Again a test fix. :( Introduced a bug in the test while preparing tinyTiM 2 Modified Paths: -------------- tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java Modified: tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java 2008-08-06 14:18:42 UTC (rev 97) +++ tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java 2008-08-07 13:14:50 UTC (rev 98) @@ -202,7 +202,7 @@ TopicName name = (TopicName) topic1.getTopicNames().iterator().next(); Topic reifier = null; for (Topic topic: _tm.getTopics()) { - if (!topic.equals(topic1) && !topic.equals(type)) { + if (!topic.equals(topic1)) { reifier = topic; break; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-07 13:56:48
|
Revision: 99 http://tinytim.svn.sourceforge.net/tinytim/?rev=99&view=rev Author: lheuer Date: 2008-08-07 13:56:58 +0000 (Thu, 07 Aug 2008) Log Message: ----------- made a copy Added Paths: ----------- tinytim/tags/release-1_5_0beta/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-06 14:18:33
|
Revision: 97 http://tinytim.svn.sourceforge.net/tinytim/?rev=97&view=rev Author: lheuer Date: 2008-08-06 14:18:42 +0000 (Wed, 06 Aug 2008) Log Message: ----------- Prepared changes / version numbers for release Modified Paths: -------------- tinytim/trunk/CHANGES.txt tinytim/trunk/build.properties tinytim-cxtm/trunk/CHANGES.txt tinytim-cxtm/trunk/build.properties tinytim-mio/trunk/CHANGES.txt tinytim-mio/trunk/build.properties Modified: tinytim/trunk/CHANGES.txt =================================================================== --- tinytim/trunk/CHANGES.txt 2008-08-06 12:33:47 UTC (rev 96) +++ tinytim/trunk/CHANGES.txt 2008-08-06 14:18:42 UTC (rev 97) @@ -2,8 +2,8 @@ Changes Log =========== -1.5.0 beta1 (08.08.2008) -------------------------- +1.5.0 beta (08.08.2008) +----------------------- Bugfixes: --------- * Bug #1970502 (Locator impl does no reference unescaping) Modified: tinytim/trunk/build.properties =================================================================== --- tinytim/trunk/build.properties 2008-08-06 12:33:47 UTC (rev 96) +++ tinytim/trunk/build.properties 2008-08-06 14:18:42 UTC (rev 97) @@ -1,4 +1,4 @@ version=1.5.0 -version_suffix=alpha2 +version_suffix=beta debug=off optimize=on Modified: tinytim-cxtm/trunk/CHANGES.txt =================================================================== --- tinytim-cxtm/trunk/CHANGES.txt 2008-08-06 12:33:47 UTC (rev 96) +++ tinytim-cxtm/trunk/CHANGES.txt 2008-08-06 14:18:42 UTC (rev 97) @@ -2,9 +2,11 @@ Changes Log =========== -1.0.0 alpha3 (08.08.2008) -------------------------- +1.5.0 beta (08.08.2008) +----------------------- * Fixed bug #1971341 (Item identifiers of roles are omitted) +* Minor improvements +* Aligned version number to the tinyTiM's version scheme 1.0.0 alpha2 (16.05.2008) Modified: tinytim-cxtm/trunk/build.properties =================================================================== --- tinytim-cxtm/trunk/build.properties 2008-08-06 12:33:47 UTC (rev 96) +++ tinytim-cxtm/trunk/build.properties 2008-08-06 14:18:42 UTC (rev 97) @@ -1,4 +1,4 @@ -version=1.0.0 -version_suffix=alpha2-2008-05-15 +version=1.5.0 +version_suffix=beta debug=off optimize=on Modified: tinytim-mio/trunk/CHANGES.txt =================================================================== --- tinytim-mio/trunk/CHANGES.txt 2008-08-06 12:33:47 UTC (rev 96) +++ tinytim-mio/trunk/CHANGES.txt 2008-08-06 14:18:42 UTC (rev 97) @@ -2,7 +2,12 @@ Changes Log =========== +1.5.0 beta (08.08.2008) +----------------------- +* Moved the package from ``org.tinytim.io`` to ``org.tinytim.mio`` +* Aligned version number to the tinyTiM's version scheme + 1.0.0 alpha1 (08.05.2008) ------------------------- -- Initial tinyTiM I/O release +* Initial tinyTiM I/O release Modified: tinytim-mio/trunk/build.properties =================================================================== --- tinytim-mio/trunk/build.properties 2008-08-06 12:33:47 UTC (rev 96) +++ tinytim-mio/trunk/build.properties 2008-08-06 14:18:42 UTC (rev 97) @@ -1,4 +1,4 @@ -version=1.0.0 -version_suffix=alpha1 +version=1.5.0 +version_suffix=beta debug=off optimize=on This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-06 12:33:39
|
Revision: 96 http://tinytim.svn.sourceforge.net/tinytim/?rev=96&view=rev Author: lheuer Date: 2008-08-06 12:33:47 +0000 (Wed, 06 Aug 2008) Log Message: ----------- - Fixed test, topic must be unequal to two topics Modified Paths: -------------- tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java Modified: tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java 2008-08-05 13:28:39 UTC (rev 95) +++ tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java 2008-08-06 12:33:47 UTC (rev 96) @@ -202,8 +202,9 @@ TopicName name = (TopicName) topic1.getTopicNames().iterator().next(); Topic reifier = null; for (Topic topic: _tm.getTopics()) { - if (!topic.equals(topic1)) { + if (!topic.equals(topic1) && !topic.equals(type)) { reifier = topic; + break; } } assertEquals(reifier, name.getReifier()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-05 13:28:32
|
Revision: 95 http://tinytim.svn.sourceforge.net/tinytim/?rev=95&view=rev Author: lheuer Date: 2008-08-05 13:28:39 +0000 (Tue, 05 Aug 2008) Log Message: ----------- - Added test case for bug #2038853 (Subject locators are not removable) Modified Paths: -------------- tinytim/trunk/src/test/java/org/tinytim/AllTests.java Added Paths: ----------- tinytim/trunk/src/test/java/org/tinytim/TestTopic.java Modified: tinytim/trunk/src/test/java/org/tinytim/AllTests.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/AllTests.java 2008-08-05 12:46:53 UTC (rev 94) +++ tinytim/trunk/src/test/java/org/tinytim/AllTests.java 2008-08-05 13:28:39 UTC (rev 95) @@ -45,6 +45,7 @@ suite.addTestSuite(TestItemIdentifierConstraint.class); suite.addTestSuite(TestReifiable.class); suite.addTestSuite(TestScoped.class); + suite.addTestSuite(TestTopic.class); suite.addTestSuite(TestSignatureGenerator.class); suite.addTest(TestTMAPICore.suite()); suite.addTest(TestTMAPIIndex.suite()); Added: tinytim/trunk/src/test/java/org/tinytim/TestTopic.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestTopic.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/TestTopic.java 2008-08-05 13:28:39 UTC (rev 95) @@ -0,0 +1,44 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim; + +import org.tmapi.core.Locator; +import org.tmapi.core.Topic; + +/** + * Tests against the {@link org.tmapi.core.Topic}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class TestTopic extends TinyTimTestCase { + + public void testSubjectLocators() { + final Topic topic = _tm.createTopic(); + assertEquals(0, topic.getSubjectLocators().size()); + final Locator loc = _tm.createLocator("http://www.example.org/"); + topic.addSubjectLocator(loc); + assertEquals(1, topic.getSubjectLocators().size()); + assertTrue(topic.getSubjectLocators().contains(loc)); + topic.removeSubjectLocator(loc); + assertEquals(0, topic.getSubjectLocators().size()); + } +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/TestTopic.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. |