de.topicmapslab.majortom.comparator
Class TopicByNameComparator

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

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

Topic comparator sort topics by its names of a specific type.

Author:
Sven Krosse

Field Summary
private  boolean ascending
           
private  org.tmapi.core.Topic nameType
           
 
Constructor Summary
TopicByNameComparator(org.tmapi.core.Topic nameType)
          constructor
TopicByNameComparator(org.tmapi.core.Topic nameType, boolean ascending)
          constructor
 
Method Summary
 int compare(org.tmapi.core.Topic topic, org.tmapi.core.Topic other)
          If topic and other have no names of the given type 0 will be returned.
 
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

nameType

private final org.tmapi.core.Topic nameType

ascending

private final boolean ascending
Constructor Detail

TopicByNameComparator

public TopicByNameComparator(org.tmapi.core.Topic nameType)
constructor

Parameters:
nameType - the name type

TopicByNameComparator

public TopicByNameComparator(org.tmapi.core.Topic nameType,
                             boolean ascending)
constructor

Parameters:
nameType - the name type
ascending - sorting order ascending?
Method Detail

compare

public int compare(org.tmapi.core.Topic topic,
                   org.tmapi.core.Topic other)
If topic and other have no names of the given type 0 will be returned. If topic has no names of the given type and other has at least one, -1(ASC) or 1(DESC) will be returned.If other has no names of the given type and topic has at least one, 1(ASC) or -1(DESC) will be returned. If both topics have at least one name of the given type, its values will be compared.

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