package com.quollwriter.data.comparators;

import java.util.*;

import com.quollwriter.data.*;


public class ChapterItemSorter implements Comparator<ChapterItem>
{

    public int compare (ChapterItem o1,
                        ChapterItem o2)
    {
/*
        if (o1.getKey () == null)
        {
            
            return 1;
            
        }

        if (o2.getKey () == null)
        {
            
            return 1;
            
        }
  */  
        if (o1.getPosition () == o2.getPosition ())
        {
            
            if ((o1.getKey () == null)
                ||
                (o1.getName () == null)
               )
            {
                
                return 1;
                
            }
    
            if ((o2.getKey () == null)
                ||
                (o2.getName () == null)
               )
            {
                
                return 1;
                
            }
            
            if ((o1 instanceof Scene)
                &&
                (o2 instanceof OutlineItem)
               )
            {
                
                return -1;
                        
            }

            if ((o2 instanceof Scene)
                &&
                (o1 instanceof OutlineItem)
               )
            {
                
                return 1;
                        
            }
            
            return o1.getName ().compareTo (o2.getName ());
            
            //return (int) (o1.getKey () - o2.getKey ());
            
        }

        return o1.getPosition () - o2.getPosition ();

    }

    public boolean equals (Object o)
    {

        return this == o;

    }

}

@@ -1393,32 +1393,44 @@
   %7D%0A            
+            
 %0A            ret
@@ -1422,30 +1422,32 @@
             
-return
+int nc =
  o1.getName 
@@ -1481,32 +1481,304 @@
 );%0A            %0A
+            if (nc == 0)%0A            %7B%0A                %0A                // Return the one created first.%0A                return o1.getDateCreated ().compareTo (o2.getDateCreated ());%0A                    %0A            %7D %0A                %0A            return nc;%0A            %0A
             //re

Tweak to make sorting work when two objects have same name.