class TopicNameComparator extends ScopedIFComparator<TopicNameIF> {

  @Override
  public int compare(TopicNameIF o1, TopicNameIF o2) {
    TopicMapIF tm = o1.getTopicMap();

    TopicIF t1 = o1.getType();
    TopicIF t2 = o2.getType();
    
    // check for default type
    TopicIF untypedname = tm.getTopicBySubjectIdentifier(PSI.getSAMNameType());
    if (untypedname == null) {
      t1 = null;
      t2 = null;
    } else {
      if (untypedname.equals(t1)) t1 = null;
      if (untypedname.equals(t2)) t2 = null;
    }

    // untyped should sort before typed
    if (t1 == null) {
      if (t2 != null) return -1;
    } else {
      if (t2 == null) return 1;
    }
    
    return super.compare(o1, o2);
  }

    TopicNameComparator(Collection<TopicIF> scope);

}