1 package org.apache.helix.alerts;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Iterator;
23 import java.util.List;
24
25 public abstract class Operator {
26
27 public int minInputTupleLists;
28 public int maxInputTupleLists;
29 public int numOutputTupleLists = -1;
30 public boolean inputOutputTupleListsCountsEqual = false;
31
32 public Operator()
33 {
34
35 }
36
37 public Tuple<String> multiplyTuples(Tuple<String> tup1, Tuple<String> tup2)
38 {
39 if (tup1 == null) {
40 return tup2;
41 }
42 if (tup2 == null) {
43 return tup1;
44 }
45 Tuple<String>outputTup = new Tuple<String>();
46
47
48
49
50
51 Tuple<String>largerTup;
52 Tuple<String>smallerTup;
53 if (tup1.size() >= tup2.size()) {
54 largerTup = tup1;
55 smallerTup = tup2;
56 }
57 else {
58 largerTup = tup2;
59 smallerTup = tup1;
60 }
61 int gap = largerTup.size() - smallerTup.size();
62
63 for (int i=0; i< largerTup.size();i++) {
64 if (i < gap) {
65 outputTup.add(largerTup.getElement(i));
66 }
67 else {
68 double elementProduct = 0;
69 elementProduct = Double.parseDouble(largerTup.getElement(i)) *
70 Double.parseDouble(smallerTup.getElement(i-gap));
71 outputTup.add(String.valueOf(elementProduct));
72 }
73 }
74 return outputTup;
75 }
76
77 public Tuple<String> sumTuples(Tuple<String> tup1, Tuple<String> tup2)
78 {
79 if (tup1 == null) {
80 return tup2;
81 }
82 if (tup2 == null) {
83 return tup1;
84 }
85 Tuple<String>outputTup = new Tuple<String>();
86
87
88
89
90
91 Tuple<String>largerTup;
92 Tuple<String>smallerTup;
93 if (tup1.size() >= tup2.size()) {
94 largerTup = tup1;
95 smallerTup = tup2;
96 }
97 else {
98 largerTup = tup2;
99 smallerTup = tup1;
100 }
101 int gap = largerTup.size() - smallerTup.size();
102
103 for (int i=0; i< largerTup.size();i++) {
104 if (i < gap) {
105 outputTup.add(largerTup.getElement(i));
106 }
107 else {
108 double elementSum = 0;
109 elementSum = Double.parseDouble(largerTup.getElement(i)) +
110 Double.parseDouble(smallerTup.getElement(i-gap));
111 outputTup.add(String.valueOf(elementSum));
112 }
113 }
114 return outputTup;
115 }
116
117 public abstract List<Iterator<Tuple<String>>> execute(List<Iterator<Tuple<String>>> input);
118 }
119