/*
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.   
 */
package org.apache.wiki.pages;

import java.io.Serializable;
import java.util.Comparator;
import java.util.Date;

import org.apache.log4j.Logger;
import org.apache.wiki.WikiPage;

/**
 *  Compares the lastModified date of its arguments.  Both o1 and o2 MUST
 *  be WikiPage objects, or else you will receive a ClassCastException.
 *  <p>
 *  If the lastModified date is the same, then the next key is the page name.
 *  If the page name is also equal, then returns 0 for equality.
 */
// FIXME: Does not implement equals().
public class PageTimeComparator implements Comparator<WikiPage>, Serializable {
	
    private static final long serialVersionUID = 0L;

    private static final Logger log = Logger.getLogger( PageTimeComparator.class ); 

    /**
     *  {@inheritDoc}
     */
    public int compare( WikiPage w1, WikiPage w2 ) {
        if( w1 == null || w2 == null ) {
            log.error( "W1 or W2 is NULL in PageTimeComparator!");
            return 0; // FIXME: Is this correct?
        }

        Date w1LastMod = w1.getLastModified();
        Date w2LastMod = w2.getLastModified();

        if( w1LastMod == null ) {
            log.error( "NULL MODIFY DATE WITH " + w1.getName() );
            return 0;
        } else if( w2LastMod == null ) {
            log.error( "NULL MODIFY DATE WITH " + w2.getName() );
            return 0;
        }

        // This gets most recent on top
        int timecomparison = w2LastMod.compareTo( w1LastMod );

        if( timecomparison == 0 ) {
            return w1.compareTo( w2 );
        }

        return timecomparison;
    }

}

@@ -847,16 +847,82 @@
 pages;%0A%0A
+import org.apache.log4j.Logger;%0Aimport org.apache.wiki.WikiPage;%0A%0A
 import j
@@ -999,74 +999,8 @@
 e;%0A%0A
-import org.apache.log4j.Logger;%0Aimport org.apache.wiki.WikiPage;%0A%0A
 /**%0A
@@ -1304,47 +1304,8 @@
  */%0A
-// FIXME: Does not implement equals().%0A
 publ
@@ -1354,24 +1354,25 @@
 parator%3C
+ 
 WikiPage
 %3E, Seria
@@ -1363,16 +1363,17 @@
 WikiPage
+ 
 %3E, Seria
@@ -1585,16 +1585,22 @@
 compare(
+ final
  WikiPag
@@ -1604,16 +1604,22 @@
 Page w1,
+ final
  WikiPag
@@ -1799,24 +1799,30 @@
  %7D%0A%0A        
+final 
 Date w1LastM
@@ -1856,16 +1856,22 @@
         
+final 
 Date w2L
@@ -2212,16 +2212,22 @@
         
+final 
 int time

remove unnecessary FIXME: + intellij fixes