org.apache.wicket.markup.head
Class PriorityFirstComparator

java.lang.Object
  extended by org.apache.wicket.markup.head.PriorityFirstComparator
All Implemented Interfaces:
Serializable, Comparator<ResourceAggregator.RecordedHeaderItem>

public class PriorityFirstComparator
extends Object
implements Comparator<ResourceAggregator.RecordedHeaderItem>, Serializable

Implements the default sorting algorithm for HeaderItems. PriorityHeaderItems are moved to the front, inverting the component order to convert the child-first into a parent-first order. If renderPageFirst is true, the head from the markup of a page is moved to the front of the header, directly after the priority header items.

Author:
papegaaij
See Also:
Serialized Form

Nested Class Summary
protected static class PriorityFirstComparator.HeaderItemType
           
 
Constructor Summary
PriorityFirstComparator(boolean renderPageFirst)
          Construct.
 
Method Summary
 int compare(ResourceAggregator.RecordedHeaderItem o1, ResourceAggregator.RecordedHeaderItem o2)
           
protected  int compareWithinGroup(ResourceAggregator.RecordedHeaderItem o1, ResourceAggregator.RecordedHeaderItem o2)
          Compares two header items that belong in the same group.
protected  PriorityFirstComparator.HeaderItemType getItemType(ResourceAggregator.RecordedHeaderItem item)
          Determines the type of the item: priority, page or component.
protected  int inversedComponentOrder(ResourceAggregator.RecordedHeaderItem o1, ResourceAggregator.RecordedHeaderItem o2)
          Compares two priority header items, converting the child-first order into parent-first.
 
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
 

Constructor Detail

PriorityFirstComparator

public PriorityFirstComparator(boolean renderPageFirst)
Construct.

Parameters:
renderPageFirst - when true, the header of the page is moved to the front.
Method Detail

compare

public int compare(ResourceAggregator.RecordedHeaderItem o1,
                   ResourceAggregator.RecordedHeaderItem o2)
Specified by:
compare in interface Comparator<ResourceAggregator.RecordedHeaderItem>

compareWithinGroup

protected int compareWithinGroup(ResourceAggregator.RecordedHeaderItem o1,
                                 ResourceAggregator.RecordedHeaderItem o2)
Compares two header items that belong in the same group.

Parameters:
o1 -
o2 -
Returns:
0 by default to preserve the order

inversedComponentOrder

protected int inversedComponentOrder(ResourceAggregator.RecordedHeaderItem o1,
                                     ResourceAggregator.RecordedHeaderItem o2)
Compares two priority header items, converting the child-first order into parent-first.

Parameters:
o1 -
o2 -
Returns:
-1, 0 or 1 if o1 needs to be rendered before, unchanged or after o2.

getItemType

protected PriorityFirstComparator.HeaderItemType getItemType(ResourceAggregator.RecordedHeaderItem item)
Determines the type of the item: priority, page or component.

Parameters:
item -
Returns:
the type of the item


Copyright © 2006-2013 Apache Software Foundation. All Rights Reserved.