package com.hammurapi.extract;

import java.util.concurrent.TimeUnit;

public class GreaterEqual<T, V extends Comparable<V>, C> extends ComparisonPredicate<T, V, C> {

	public GreaterEqual(
			double initialCost, 
			TimeUnit costUnit,
			Extractor<T, V, C> leftExtractor, 
			Extractor<T, V, C> rightExtractor) {
		super(initialCost, costUnit, leftExtractor, rightExtractor);
	}

	@Override
	public com.hammurapi.extract.ComparisonResult compareTo(Extractor<T, Boolean, C> otherPredicate) {
		if (equals(otherPredicate)) {
			return ComparisonResult.EQUAL_NM;
		}
		
		/**
		 * TODO Implement comparisons.
		 * a * b ? c * d, * - can be <, <=, ==, !=, =>, >
		 * 36 permutations. Each permutation - compare a/b, c/d 
		 */
				
		// TODO if both parts are constants - comparison with True/False.
		
		return super.compareTo(otherPredicate);
	}

	@Override
	protected boolean compare(int n1, int n2) {
		return n1>=n2;
	}
	
	@Override
	protected boolean compare(long n1, long n2) {
		return n1>=n2;
	}

	@Override
	protected boolean compare(float n1, float n2) {
		return n1>=n2;
	}

	@Override
	protected boolean compare(double n1, double n2) {
		return n1>=n2;
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	protected boolean compare(Object o1, Object o2) {
		if (o1 instanceof Comparable) {
			return ((Comparable) o1).compareTo(o2)>=0;
		}
 		throw new UnsupportedOperationException("Can't compare "+getClass().getName()+" on "+o1+" and "+o2);
	}

	@Override
	protected Extractor<T, Boolean, C> newInstance(Extractor<T, V, C> leftExtractor, Extractor<T, V, C> rightExtractor) {
		return new GreaterEqual<T,V,C>(initialCost, costUnit, leftExtractor, rightExtractor);
	}
}
