aboutsummaryrefslogtreecommitdiff
path: root/src/uk/ac/ox/cs/pagoda/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/util')
-rw-r--r--src/uk/ac/ox/cs/pagoda/util/ExponentialInterpolation.java33
-rw-r--r--src/uk/ac/ox/cs/pagoda/util/tuples/TupleBuilder.java21
2 files changed, 50 insertions, 4 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/util/ExponentialInterpolation.java b/src/uk/ac/ox/cs/pagoda/util/ExponentialInterpolation.java
new file mode 100644
index 0000000..1d12169
--- /dev/null
+++ b/src/uk/ac/ox/cs/pagoda/util/ExponentialInterpolation.java
@@ -0,0 +1,33 @@
1package uk.ac.ox.cs.pagoda.util;
2
3/***
4 * Get an exponential function given two points.
5 */
6public class ExponentialInterpolation {
7
8 private final double base;
9 private final double multiplicativeFactor;
10
11 /***
12 * Compute the exponential function passing for the 2 given points.
13 *
14 * @param x1
15 * @param y1
16 * @param x2
17 * @param y2
18 */
19 public ExponentialInterpolation(double x1, double y1, double x2, double y2) {
20 base = Math.pow(y2/y1, 1 / (x2 - x1));
21 multiplicativeFactor = y1 / Math.pow(base, x1);
22 }
23
24 /***
25 * Compute value of the function in x.
26 *
27 * @param x
28 * @return
29 */
30 public double computeValue(double x) {
31 return multiplicativeFactor * Math.pow(base, x);
32 }
33}
diff --git a/src/uk/ac/ox/cs/pagoda/util/tuples/TupleBuilder.java b/src/uk/ac/ox/cs/pagoda/util/tuples/TupleBuilder.java
index ee2b74d..172e249 100644
--- a/src/uk/ac/ox/cs/pagoda/util/tuples/TupleBuilder.java
+++ b/src/uk/ac/ox/cs/pagoda/util/tuples/TupleBuilder.java
@@ -1,18 +1,31 @@
1package uk.ac.ox.cs.pagoda.util.tuples; 1package uk.ac.ox.cs.pagoda.util.tuples;
2 2
3import java.util.Collections;
4
3/** 5/**
4 * Allows to create an immutable <tt>Tuple</tt> in a non-atomic way. 6 * Allows to create an immutable <tt>Tuple</tt> in a non-atomic way.
5 * It can create only one <tt>Tuple</tt>. 7 * It can create only one <tt>Tuple</tt>.
6 * */ 8 * */
7public class TupleBuilder<T> { 9public class TupleBuilder<T> {
8 10
9 private Tuple tuple = new Tuple(); 11 private Tuple<T> tuple = new Tuple<T>();
10 12
11 private boolean building = true; 13 private boolean building = true;
12 14
13 public boolean append(T t) { 15 public TupleBuilder<T> append(T t) {
14 if(building) tuple.elements.add(t); 16 if(building) {
15 return building; 17 tuple.elements.add(t);
18 return this;
19 }
20 return null;
21 }
22
23 public TupleBuilder<T> append(T[] t) {
24 if(building) {
25 Collections.addAll(tuple.elements, t);
26 return this;
27 }
28 return null;
16 } 29 }
17 30
18 public Tuple<T> build() { 31 public Tuple<T> build() {