/*
* [HolidaySort.java]
*
* Summary: Sort by date holiday occurs in a specified year.
*
* Copyright: (c) 2008-2017 Roedy Green, Canadian Mind Products, http://mindprod.com
*
* Licence: This software may be copied and used freely for any purpose but military.
* http://mindprod.com/contact/nonmil.html
*
* Requires: JDK 1.8+
*
* Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
*
* Version History:
* 1.0 2008-03-20 initial version
*/
package com.mindprod.holidays;
import java.util.Comparator;
/**
* Sort by date holiday occurs in a specified year.
*
* Defines an alternate sort order for HolInfo.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2008-03-20 initial version
* @since 2008
*/
class HolidaySort implements Comparator
{
/**
* whether we want dates holiday shifted to
*/
private final boolean shifted;
/**
* year of holidays
*/
private final int year;
/**
* constructor sort holidays in order for a given year.
*
* @param year which year of interest. Holidays change order in different years.
* @param shifted true if want to sort by shifted-date you get off work..
*/
HolidaySort( int year, boolean shifted )
{
this.year = year;
this.shifted = shifted;
}
/**
* Sort by date holiday occurs in a specified year.
* Defines an alternate sort order for HolInfo.
* Compare two HolInfo Objects.
* Informally, returns (a-b), or +ve if a is more positive than b.
*
* @param a first HolInfo to compare
* @param b second HolInfo to compare
*
* @return +ve if a>b, 0 if a==b, -ve if a<b
*/
public final int compare( HolInfo a, HolInfo b )
{
return a.when( year, shifted ) - ( b.when( year, shifted ) );
}
}