de.topicmapslab.majortom.util
Class BestLabelUtils

java.lang.Object
  extended by de.topicmapslab.majortom.util.BestLabelUtils

public class BestLabelUtils
extends java.lang.Object

Author:
Sven Krosse

Field Summary
private static java.lang.String ID_PREFIX
           
protected static java.lang.String ITEMIDENTIFIER_PREFIX
           
protected static java.lang.String SUBJECTIDENTIFIER_PREFIX
           
protected static java.lang.String SUBJECTLOCATOR_PREFIX
           
 
Constructor Summary
BestLabelUtils()
           
 
Method Summary
static java.lang.String doReadBestIdentifier(de.topicmapslab.majortom.model.core.ITopic topic, boolean withPrefix)
          Returns the best and stable identifier of the topic.
static java.lang.String doReadBestLabel(de.topicmapslab.majortom.model.core.ITopic topic)
          Returns the best label for the current topic instance.
static java.lang.String doReadBestLabel(de.topicmapslab.majortom.model.core.ITopic topic, de.topicmapslab.majortom.model.core.ITopic theme, boolean strict)
          Returns the best label for the current topic instance.
private static java.util.Set<org.tmapi.core.Name> filterByDefaultNameType(de.topicmapslab.majortom.model.core.ITopic topic, java.util.Set<org.tmapi.core.Name> names)
          Method filter the given names by the default name type
private static java.lang.String readBestName(de.topicmapslab.majortom.model.core.ITopic topic, de.topicmapslab.majortom.model.core.ITopic theme, java.util.Set<org.tmapi.core.Name> names, boolean strict)
          Internal best label method only check name attributes.
private static java.lang.String readBestName(de.topicmapslab.majortom.model.core.ITopic topic, java.util.Set<org.tmapi.core.Name> names)
          Internal best label method only check name attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID_PREFIX

private static final java.lang.String ID_PREFIX
See Also:
Constant Field Values

SUBJECTIDENTIFIER_PREFIX

protected static final java.lang.String SUBJECTIDENTIFIER_PREFIX
See Also:
Constant Field Values

SUBJECTLOCATOR_PREFIX

protected static final java.lang.String SUBJECTLOCATOR_PREFIX
See Also:
Constant Field Values

ITEMIDENTIFIER_PREFIX

protected static final java.lang.String ITEMIDENTIFIER_PREFIX
See Also:
Constant Field Values
Constructor Detail

BestLabelUtils

public BestLabelUtils()
Method Detail

doReadBestLabel

public static java.lang.String doReadBestLabel(de.topicmapslab.majortom.model.core.ITopic topic)
                                        throws de.topicmapslab.majortom.model.exception.TopicMapStoreException
Returns the best label for the current topic instance. The best label will be identified satisfying the following rules in the given order.

1. Names of the default name type are weighted higher than names of other types.

2. Names with the unconstrained scope are weighted higher than other scoped names.

3. Names with a smaller number of scoping themes are weighted higher than others.

4. Names with a lexicographically smaller value are weighted higher than others.

5. If no names are existing, the subject-identifier with the lexicographically smallest reference are returned.

6. If no subject-identifiers are existing, the subject-locators with the lexicographically smallest reference are returned.

7. If no subject-locators are existing, the item-identifier with the lexicographically smallest reference are returned.

8. At least the ID of the topic will be returned.

Parameters:
topic - the topic
Throws:
de.topicmapslab.majortom.model.exception.TopicMapStoreException - thrown if operation fails
Since:
1.1.2

doReadBestLabel

public static java.lang.String doReadBestLabel(de.topicmapslab.majortom.model.core.ITopic topic,
                                               de.topicmapslab.majortom.model.core.ITopic theme,
                                               boolean strict)
                                        throws de.topicmapslab.majortom.model.exception.TopicMapStoreException
Returns the best label for the current topic instance. The best label will be identified satisfying the following rules in the given order.

1. Names of the default name type are weighted higher than names of other types.

2. Names with the unconstrained scope are weighted higher than other scoped names.

3. Names with a smaller number of scoping themes are weighted higher than others.

4. Names with a lexicographically smaller value are weighted higher than others.

5. If no names are existing, the subject-identifier with the lexicographically smallest reference are returned.

6. If no subject-identifiers are existing, the subject-locators with the lexicographically smallest reference are returned.

7. If no subject-locators are existing, the item-identifier with the lexicographically smallest reference are returned.

8. At least the ID of the topic will be returned.

Parameters:
topic - the topic
theme - the theme
strict - if there is no name with the given theme and strict is true, then null will be returned.
Throws:
de.topicmapslab.majortom.model.exception.TopicMapStoreException - thrown if operation fails
Since:
1.1.2

filterByDefaultNameType

private static java.util.Set<org.tmapi.core.Name> filterByDefaultNameType(de.topicmapslab.majortom.model.core.ITopic topic,
                                                                          java.util.Set<org.tmapi.core.Name> names)
Method filter the given names by the default name type

Parameters:
topic - the topic as parent of the names
names - the names
Returns:
the filtered names

readBestName

private static java.lang.String readBestName(de.topicmapslab.majortom.model.core.ITopic topic,
                                             de.topicmapslab.majortom.model.core.ITopic theme,
                                             java.util.Set<org.tmapi.core.Name> names,
                                             boolean strict)
                                      throws de.topicmapslab.majortom.model.exception.TopicMapStoreException
Internal best label method only check name attributes.

Parameters:
topic - the topic
theme - the theme
set - the non-empty set of names
strict - if there is no name with the given theme and strict is true, then null will be returned.
Returns:
the best name
Throws:
de.topicmapslab.majortom.model.exception.TopicMapStoreException - thrown if operation fails

readBestName

private static java.lang.String readBestName(de.topicmapslab.majortom.model.core.ITopic topic,
                                             java.util.Set<org.tmapi.core.Name> names)
                                      throws de.topicmapslab.majortom.model.exception.TopicMapStoreException
Internal best label method only check name attributes.

Parameters:
topic - the topic
set - the non-empty set of names
Returns:
the best name
Throws:
de.topicmapslab.majortom.model.exception.TopicMapStoreException - thrown if operation fails

doReadBestIdentifier

public static java.lang.String doReadBestIdentifier(de.topicmapslab.majortom.model.core.ITopic topic,
                                                    boolean withPrefix)
Returns the best and stable identifier of the topic. The best identifier will be extracted by following rules.

1. Identifiers are weighted by its types in the following order subject-identifier, subject-locator and item-identifier.

2. If there are more than one identifier of the same type, the shortest will be returned.

3. If there are more than one identifier with the same length, the lexicographically smallest will be returned.

Parameters:
topic - the topic
withPrefix - flag indicates if the returned identifier will be prefixed with its type. Subject-identifier( si:), subject-locator(sl:) or item-identifier(ii:).
Returns:
the best identifier or the id if the topic has no identifiers
Since:
1.2.0