de.topicmapslab.majortom.comparator
Class TopicByIdentityComparator

java.lang.Object
  extended by de.topicmapslab.majortom.comparator.TopicByIdentityComparator
All Implemented Interfaces:
java.util.Comparator<org.tmapi.core.Topic>

public class TopicByIdentityComparator
extends java.lang.Object
implements java.util.Comparator<org.tmapi.core.Topic>

Special comparator ordering topics by identity.

Author:
Sven Krosse

Field Summary
private  boolean ascending
           
private static TopicByIdentityComparator instanceAsc
           
private static TopicByIdentityComparator instanceDesc
           
 
Constructor Summary
private TopicByIdentityComparator(boolean ascending)
          constructor
 
Method Summary
private  java.lang.Integer compare(java.util.List<org.tmapi.core.Locator> list1, java.util.List<org.tmapi.core.Locator> list2)
          compares two lists of locators
 int compare(org.tmapi.core.Topic o1, org.tmapi.core.Topic o2)
          Compare two topic items in this order: If the at least one of the topic has a subject-identifier:
Return -1 if the reference of the first subject-identifier of the first topic is lexicographically higher or the second topic has no subject-identifier.
static TopicByIdentityComparator getInstance(boolean ascending)
          Returns the singleton instance of the comparator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Field Detail

instanceAsc

private static TopicByIdentityComparator instanceAsc

instanceDesc

private static TopicByIdentityComparator instanceDesc

ascending

private final boolean ascending
Constructor Detail

TopicByIdentityComparator

private TopicByIdentityComparator(boolean ascending)
constructor

Parameters:
ascending - sorting order ascending?
Method Detail

getInstance

public static TopicByIdentityComparator getInstance(boolean ascending)
Returns the singleton instance of the comparator

Parameters:
ascending - sorting order ascending?
Returns:
the instance the comparator instance

compare

public int compare(org.tmapi.core.Topic o1,
                   org.tmapi.core.Topic o2)
Compare two topic items in this order:

If the at least one of the topic has a subject-identifier:
Return -1 if the reference of the first subject-identifier of the first topic is lexicographically higher or the second topic has no subject-identifier.

Return 1 if the reference of the first subject-identifier of the first topic is lexicographically smaller or the first topic has no subject-identifier.

If the at least one of the topic has a subject-locator:
Return -1 if the reference of the first subject-locator of the first topic is lexicographically higher or the second topic has no subject-locator.

Return 1 if the reference of the first subject-locator of the first topic is lexicographically smaller or the first topic has no subject-locator.

If the at least one of the topic has a item-identifier:
Return -1 if the reference of the first item-identifier of the first topic is lexicographically higher or the second topic has no item-identifier.

Return 1 if the reference of the first item-identifier of the first topic is lexicographically smaller or the first topic has no item-identifier.

Return 0 if both topics has no subject-identifier, subject-locator or item-identifier.

Specified by:
compare in interface java.util.Comparator<org.tmapi.core.Topic>

compare

private java.lang.Integer compare(java.util.List<org.tmapi.core.Locator> list1,
                                  java.util.List<org.tmapi.core.Locator> list2)
compares two lists of locators

Parameters:
list1 - the first list
list2 - the second list return null of both lists are empty otherwise the locators are compared