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