001package com.hammurapi.extract; 002 003import java.util.concurrent.TimeUnit; 004 005public class GreaterEqual<T, V extends Comparable<V>, C> extends ComparisonPredicate<T, V, C> { 006 007 public GreaterEqual( 008 double initialCost, 009 TimeUnit costUnit, 010 Extractor<T, V, C> leftExtractor, 011 Extractor<T, V, C> rightExtractor) { 012 super(initialCost, costUnit, leftExtractor, rightExtractor); 013 } 014 015 @Override 016 public com.hammurapi.extract.ComparisonResult compareTo(Extractor<T, Boolean, C> otherPredicate) { 017 if (equals(otherPredicate)) { 018 return ComparisonResult.EQUAL_NM; 019 } 020 021 /** 022 * TODO Implement comparisons. 023 * a * b ? c * d, * - can be <, <=, ==, !=, =>, > 024 * 36 permutations. Each permutation - compare a/b, c/d 025 */ 026 027 // TODO if both parts are constants - comparison with True/False. 028 029 return super.compareTo(otherPredicate); 030 } 031 032 @Override 033 protected boolean compare(int n1, int n2) { 034 return n1>=n2; 035 } 036 037 @Override 038 protected boolean compare(long n1, long n2) { 039 return n1>=n2; 040 } 041 042 @Override 043 protected boolean compare(float n1, float n2) { 044 return n1>=n2; 045 } 046 047 @Override 048 protected boolean compare(double n1, double n2) { 049 return n1>=n2; 050 } 051 052 @SuppressWarnings({ "unchecked", "rawtypes" }) 053 @Override 054 protected boolean compare(Object o1, Object o2) { 055 if (o1 instanceof Comparable) { 056 return ((Comparable) o1).compareTo(o2)>=0; 057 } 058 throw new UnsupportedOperationException("Can't compare "+getClass().getName()+" on "+o1+" and "+o2); 059 } 060 061 @Override 062 protected Extractor<T, Boolean, C> newInstance(Extractor<T, V, C> leftExtractor, Extractor<T, V, C> rightExtractor) { 063 return new GreaterEqual<T,V,C>(initialCost, costUnit, leftExtractor, rightExtractor); 064 } 065}