/*
 * Copyright (c) 2011, Patrik Dufresne. All rights reserved.
 * Patrik Dufresne PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.planimod.core.comparators;

import java.util.Comparator;

import org.apache.commons.collections.ComparatorUtils;
import org.apache.commons.collections.Transformer;

import com.planimod.core.AbstractCalendarEvent;
import com.planimod.core.ProductionEvent;

public class ProductionEventComparators {

	@SuppressWarnings("unchecked")
	public static Comparator<AbstractCalendarEvent> byDate() {
		return ComparatorUtils.transformedComparator(ComparatorUtils
				.nullLowComparator(ComparatorUtils.naturalComparator()),
				new Transformer() {
					@Override
					public Object transform(Object arg0) {
						return ((ProductionEvent) arg0).getShift()
								.getStartDate();
					}
				});
	}

	@SuppressWarnings("unchecked")
	public static Comparator<? super ProductionEvent> byProductRefId() {
		return ComparatorUtils
				.transformedComparator(ComparatorUtils
						.nullLowComparator(new HumanNaturalComparator()),
						new Transformer() {
							@Override
							public Object transform(Object arg0) {
								return ((ProductionEvent) arg0).getProduct()
										.getRefId();
							}
						});
	}

	/**
	 * Compare Production event using the familly.
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static Comparator<? super ProductionEvent> byRefIdFamilyName() {
		return ComparatorUtils.nullHighComparator(ComparatorUtils
				.transformedComparator(ProductComparators.byRefIdFamilyName(),
						new Transformer() {
							@Override
							public Object transform(Object arg0) {
								return ((ProductionEvent) arg0).getProduct();
							}
						}));
	}

}
