1 | package com.hammurapi.extract; |
2 | |
3 | import java.util.concurrent.TimeUnit; |
4 | |
5 | public class GreaterEqual<T, V extends Comparable<V>, C> extends ComparisonPredicate<T, V, C> { |
6 | |
7 | public GreaterEqual( |
8 | double initialCost, |
9 | TimeUnit costUnit, |
10 | Extractor<T, V, C> leftExtractor, |
11 | Extractor<T, V, C> rightExtractor) { |
12 | super(initialCost, costUnit, leftExtractor, rightExtractor); |
13 | } |
14 | |
15 | @Override |
16 | public com.hammurapi.extract.ComparisonResult compareTo(Extractor<T, Boolean, C> otherPredicate) { |
17 | if (equals(otherPredicate)) { |
18 | return ComparisonResult.EQUAL_NM; |
19 | } |
20 | |
21 | /** |
22 | * TODO Implement comparisons. |
23 | * a * b ? c * d, * - can be <, <=, ==, !=, =>, > |
24 | * 36 permutations. Each permutation - compare a/b, c/d |
25 | */ |
26 | |
27 | // TODO if both parts are constants - comparison with True/False. |
28 | |
29 | return super.compareTo(otherPredicate); |
30 | } |
31 | |
32 | @Override |
33 | protected boolean compare(int n1, int n2) { |
34 | return n1>=n2; |
35 | } |
36 | |
37 | @Override |
38 | protected boolean compare(long n1, long n2) { |
39 | return n1>=n2; |
40 | } |
41 | |
42 | @Override |
43 | protected boolean compare(float n1, float n2) { |
44 | return n1>=n2; |
45 | } |
46 | |
47 | @Override |
48 | protected boolean compare(double n1, double n2) { |
49 | return n1>=n2; |
50 | } |
51 | |
52 | @SuppressWarnings({ "unchecked", "rawtypes" }) |
53 | @Override |
54 | protected boolean compare(Object o1, Object o2) { |
55 | if (o1 instanceof Comparable) { |
56 | return ((Comparable) o1).compareTo(o2)>=0; |
57 | } |
58 | throw new UnsupportedOperationException("Can't compare "+getClass().getName()+" on "+o1+" and "+o2); |
59 | } |
60 | |
61 | @Override |
62 | protected Extractor<T, Boolean, C> newInstance(Extractor<T, V, C> leftExtractor, Extractor<T, V, C> rightExtractor) { |
63 | return new GreaterEqual<T,V,C>(initialCost, costUnit, leftExtractor, rightExtractor); |
64 | } |
65 | } |