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