Permalink
Browse files

Code duplication reduced in the LTTB implementations.

  • Loading branch information...
Fabrice Bacchella
Fabrice Bacchella committed Sep 29, 2018
1 parent 90a4c1a commit 45fb70ddc1a42d1f78368caafa90ebc05f904dc0
@@ -20,4 +20,26 @@ protected void setDataSetLine(DownSampler.DataSet sampled, int rank, long timest
sampled.values[rank] = value;
}
@Override
public DataSet downsize(long[] timestamps, double[] values) {
if (timestamps == null || values == null) {
throw new NullPointerException("Cannot cope with a null data input array.");
}
if (threshold <= 2) {
throw new IllegalArgumentException("What am I supposed to do with that?");
}
if (timestamps.length != values.length) {
throw new IllegalArgumentException("Unmatched size with input arrays");
}
int inputLength = timestamps.length;
if (inputLength <= threshold) {
return new DownSampler.DataSet(timestamps, values);
} else {
DownSampler.DataSet sampled = new DownSampler.DataSet(new long[threshold], new double[threshold]);
return downsizeImpl(sampled, timestamps, values);
}
}
protected abstract DataSet downsizeImpl(DataSet sampled, long[] timestamps, double[] values);
}
@@ -16,21 +16,8 @@ public LargestTriangleThreeBuckets(int threshold) {
}
@Override
public DataSet downsize(long[] timestamps, double[] values) {
DownSampler.DataSet sampled = new DownSampler.DataSet(new long[threshold], new double[threshold]);
if (timestamps == null || values == null) {
throw new NullPointerException("Cannot cope with a null data input array.");
}
if (threshold <= 2) {
throw new IllegalArgumentException("What am I supposed to do with that?");
}
if (timestamps.length != values.length) {
throw new IllegalArgumentException("Unmatched size with input arrays");
}
public DataSet downsizeImpl(DownSampler.DataSet sampled, long[] timestamps, double[] values) {
int inputLength = timestamps.length;
if (inputLength <= threshold) {
return new DownSampler.DataSet(timestamps, values);
}
int sampled_index = 0;
double every = (double)(inputLength - 2) / (double)(threshold - 2);
int a = 0, next_a = 0;
@@ -91,6 +78,6 @@ public DataSet downsize(long[] timestamps, double[] values) {
setDataSetLine(sampled, sampled_index++, timestamps[inputLength - 1], values[inputLength - 1]);
return sampled;
};
}
}
@@ -16,21 +16,8 @@ public LargestTriangleThreeBucketsTime(int threshold) {
}
@Override
public DataSet downsize(long[] timestamps, double[] values) {
DownSampler.DataSet sampled = new DownSampler.DataSet(new long[threshold], new double[threshold]);
if (timestamps == null || values == null) {
throw new NullPointerException("Cannot cope with a null data input array.");
}
if (threshold <= 2) {
throw new IllegalArgumentException("What am I supposed to do with that?");
}
if (timestamps.length != values.length) {
throw new IllegalArgumentException("Unmatched size with input arrays");
}
public DataSet downsizeImpl(DownSampler.DataSet sampled, long[] timestamps, double[] values) {
int inputLength = timestamps.length;
if (inputLength <= threshold) {
return new DownSampler.DataSet(timestamps, values);
}
int bucket_interval = (int)((timestamps[inputLength - 1] - timestamps[0]) / threshold);
int sampled_index = 0;
double every = (double)(inputLength - 2) / (double)(threshold - 2);
@@ -39,7 +26,6 @@ public DataSet downsize(long[] timestamps, double[] values) {
double max_area_point_value;
double max_area;
setDataSetLine(sampled, sampled_index++, timestamps[a], values[a]);
for (int i = 0; i < threshold - 2; i++) {

0 comments on commit 45fb70d

Please sign in to comment.