org.apache.wiki
Class PageSorter

java.lang.Object
  extended by org.apache.wiki.PageSorter
All Implemented Interfaces:
Comparator

public class PageSorter
extends Object
implements Comparator

Wrapper class for managing and using the PageNameComparator.

Note - this class is deliberately not null safe. Never call any of the methods with a null argument!


Field Summary
protected static String PROP_PAGE_NAME_COMPARATOR
           
 
Constructor Summary
PageSorter()
          Default constructor uses Java "natural" ordering.
PageSorter(Comparator<String> comparator)
          Construct with a particular comparator.
 
Method Summary
 int compare(Object o1, Object o2)
          Compare two page names (Object version).
 int compare(String pageName1, String pageName2)
          Compare two page names (String version).
 int compare(WikiPage page1, WikiPage page2)
          Compare two pages (WikiPage version).
 boolean equals(Object o)
           
 void initialize(Properties props)
          Called by WikiEngine to initialise this instance.
 void sort(List<String> nameList)
          Sorts the specified list into ascending order based on the PageNameComparator.
 void sort(String[] nameArray)
          Sorts the specified array into ascending order based on the PageNameComparator.
 void sortPages(List<Object> pageList)
          Sorts the specified list into ascending order based on the PageNameComparator.
 void sortPages(Object[] pageArray)
          Sorts the specified array into ascending order based on the PageNameComparator.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_PAGE_NAME_COMPARATOR

protected static final String PROP_PAGE_NAME_COMPARATOR
See Also:
Constant Field Values
Constructor Detail

PageSorter

public PageSorter()
Default constructor uses Java "natural" ordering.


PageSorter

public PageSorter(Comparator<String> comparator)
Construct with a particular comparator.

Parameters:
comparator - the Comparator to use
Method Detail

compare

public int compare(Object o1,
                   Object o2)
Compare two page names (Object version). Arguments must be either String or WikiPage.

Specified by:
compare in interface Comparator
Throws:
IllegalArgumentException - if incorrect argument types.
See Also:
Comparator.compare(java.lang.Object, java.lang.Object)

compare

public int compare(String pageName1,
                   String pageName2)
Compare two page names (String version).

Parameters:
pageName1 - the first page name
pageName2 - the second page name
Returns:
see java.util.Comparator
See Also:
Comparator.compare(java.lang.Object, java.lang.Object)

compare

public int compare(WikiPage page1,
                   WikiPage page2)
Compare two pages (WikiPage version). Compares them by name first. If the same name, compares their versions.

Parameters:
page1 - the first page
page2 - the second page
Returns:
see java.util.Comparator
See Also:
Comparator.compare(java.lang.Object, java.lang.Object)

equals

public boolean equals(Object o)
Specified by:
equals in interface Comparator
Overrides:
equals in class Object

initialize

public void initialize(Properties props)
Called by WikiEngine to initialise this instance. Tries to use class given by the PROP_PAGE_NAME_COMPARATOR property as the page name comparator. Uses a default comparator if this property is not set or there is any problem loading the specified class.

Parameters:
props - this WikiEngine's properties.

sort

public void sort(List<String> nameList)
Sorts the specified list into ascending order based on the PageNameComparator. The actual sort is done using Collections.sort().

Parameters:
nameList - the page names to be sorted

sort

public void sort(String[] nameArray)
Sorts the specified array into ascending order based on the PageNameComparator. The actual sort is done using Arrays.sort().

Parameters:
nameArray - the page names to be sorted

sortPages

public void sortPages(List<Object> pageList)
Sorts the specified list into ascending order based on the PageNameComparator. The actual sort is done using Collections.sort().

Parameters:
pageList - the pages to be sorted

sortPages

public void sortPages(Object[] pageArray)
Sorts the specified array into ascending order based on the PageNameComparator. The actual sort is done using Arrays.sort().

Parameters:
pageArray - the pages to be sorted


Copyright © {inceptionYear}-2014 The Apache Software Foundation. All rights reserved.