diff --git a/src/main/java/de/dmi3y/behaiv/kernel/Kernel.java b/src/main/java/de/dmi3y/behaiv/kernel/Kernel.java index d261798..ec414f5 100644 --- a/src/main/java/de/dmi3y/behaiv/kernel/Kernel.java +++ b/src/main/java/de/dmi3y/behaiv/kernel/Kernel.java @@ -11,6 +11,7 @@ import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; +import java.util.List; public abstract class Kernel { @@ -32,12 +33,12 @@ public void setId(String id) { //list, label - protected ArrayList, String>> data = new ArrayList<>(); + protected List, String>> data = new ArrayList<>(); public abstract boolean isEmpty(); - public abstract void fit(ArrayList, String>> data); + public abstract void fit(List, String>> data); public void fit() { fit(this.data); @@ -51,18 +52,18 @@ public boolean readyToPredict() { return data.size() > treshold; } - public void update(ArrayList, String>> data) { + public void update(List, String>> data) { } public boolean isPartialFitAllowed() { return partialFitAllowed; } - public void updateSingle(ArrayList features, String label) { + public void updateSingle(List features, String label) { data.add(new Pair<>(features, label)); } - public abstract String predictOne(ArrayList features); + public abstract String predictOne(List features); public boolean isAlwaysKeepData() { return alwaysKeepData; @@ -80,7 +81,7 @@ public void save(BehaivStorage storage) throws IOException { } public void restore(BehaivStorage storage) throws IOException { - final TypeReference, String>>> typeReference = new TypeReference, String>>>() { + final TypeReference, String>>> typeReference = new TypeReference, String>>>() { }; try (final BufferedReader reader = new BufferedReader(new FileReader(storage.getDataFile(id)))) { final String content = reader.readLine(); diff --git a/src/main/java/de/dmi3y/behaiv/kernel/LogisticRegressionKernel.java b/src/main/java/de/dmi3y/behaiv/kernel/LogisticRegressionKernel.java index 2ae1cb6..5205d25 100644 --- a/src/main/java/de/dmi3y/behaiv/kernel/LogisticRegressionKernel.java +++ b/src/main/java/de/dmi3y/behaiv/kernel/LogisticRegressionKernel.java @@ -40,7 +40,7 @@ public boolean isEmpty() { @Override - public void fit(ArrayList, String>> data) { + public void fit(List, String>> data) { this.data = data; labels = toDistinctListOfPairValues(data); if (readyToPredict()) { @@ -86,12 +86,12 @@ public boolean readyToPredict() { } @Override - public void updateSingle(ArrayList features, String label) { + public void updateSingle(List features, String label) { super.updateSingle(features, label); } @Override - public String predictOne(ArrayList features) { + public String predictOne(List features) { final double[] doubles = ArrayUtils.toPrimitive(features.toArray(new Double[0])); @@ -153,7 +153,7 @@ public void restore(BehaivStorage storage) throws IOException { } try (final BufferedReader reader = new BufferedReader(new FileReader(storage.getNetworkMetadataFile(id)))) { - final TypeReference> typeReference = new TypeReference>() { + final TypeReference> typeReference = new TypeReference>() { }; final String labelsData = reader.readLine(); if (labelsData == null) { diff --git a/src/main/java/de/dmi3y/behaiv/provider/Provider.java b/src/main/java/de/dmi3y/behaiv/provider/Provider.java index e6320d7..aecd8d6 100644 --- a/src/main/java/de/dmi3y/behaiv/provider/Provider.java +++ b/src/main/java/de/dmi3y/behaiv/provider/Provider.java @@ -10,10 +10,10 @@ */ public interface Provider { - public List availableFeatures(); + List availableFeatures(); - public Observable> subscribeFeatures(); + Observable> subscribeFeatures(); - public Single> getFeature(); + Single> getFeature(); } diff --git a/src/main/java/de/dmi3y/behaiv/provider/ProviderCallback.java b/src/main/java/de/dmi3y/behaiv/provider/ProviderCallback.java index 465747e..9ad9836 100644 --- a/src/main/java/de/dmi3y/behaiv/provider/ProviderCallback.java +++ b/src/main/java/de/dmi3y/behaiv/provider/ProviderCallback.java @@ -6,5 +6,5 @@ public interface ProviderCallback { - public void onFeaturesCaptured(List> features); + void onFeaturesCaptured(List> features); } diff --git a/src/main/java/de/dmi3y/behaiv/storage/BehaivStorage.java b/src/main/java/de/dmi3y/behaiv/storage/BehaivStorage.java index e80bdd3..c8ee5b1 100644 --- a/src/main/java/de/dmi3y/behaiv/storage/BehaivStorage.java +++ b/src/main/java/de/dmi3y/behaiv/storage/BehaivStorage.java @@ -5,12 +5,12 @@ public interface BehaivStorage { - public boolean containsNetworkFile(String id); + boolean containsNetworkFile(String id); - public File getDataFile(String id) throws IOException; + File getDataFile(String id) throws IOException; - public File getNetworkFile(String id) throws IOException; + File getNetworkFile(String id) throws IOException; - public File getNetworkMetadataFile(String id) throws IOException; + File getNetworkMetadataFile(String id) throws IOException; } diff --git a/src/main/java/de/dmi3y/behaiv/tools/DataMappingUtils.java b/src/main/java/de/dmi3y/behaiv/tools/DataMappingUtils.java index 1a963f2..a66f278 100644 --- a/src/main/java/de/dmi3y/behaiv/tools/DataMappingUtils.java +++ b/src/main/java/de/dmi3y/behaiv/tools/DataMappingUtils.java @@ -15,9 +15,9 @@ private DataMappingUtils() { } - public static List toDistinctListOfPairValues(List, String>> data) { + public static List toDistinctListOfPairValues(List, String>> data) { Set setOfValues = new HashSet<>(); - for(Pair, String> arrayListStringPair : data ) { + for(Pair, String> arrayListStringPair : data ) { setOfValues.add(arrayListStringPair.getValue()); } return new ArrayList<>(setOfValues); @@ -31,10 +31,10 @@ public static ArrayList toListOfPairKeys(List> feat return doubleArrayList; } - public static double[][] toInput2dArray(List, String>> data) { + public static double[][] toInput2dArray(List, String>> data) { double[][] input2dArray = new double[data.size()][]; int i = 0; - for(Pair, String> dataPair : data) { + for(Pair, String> dataPair : data) { double[] doubleArray = ArrayUtils.toPrimitive(dataPair.getKey().toArray(new Double[0])); input2dArray[i] = doubleArray; i++; diff --git a/src/test/java/de/dmi3y/behaiv/LibraryTest.java b/src/test/java/de/dmi3y/behaiv/LibraryTest.java index 4f2084f..cd00e28 100644 --- a/src/test/java/de/dmi3y/behaiv/LibraryTest.java +++ b/src/test/java/de/dmi3y/behaiv/LibraryTest.java @@ -11,6 +11,7 @@ import org.junit.Test; import java.util.ArrayList; +import java.util.List; import static de.dmi3y.behaiv.kernel.KernelTest.WORK; import static org.junit.Assert.assertEquals; @@ -19,7 +20,7 @@ public class LibraryTest { Behaiv behaiv; private TestSleepProvider positionProvider; private TestSleepProvider timeProvider; - private ArrayList, String>> data; + private List, String>> data; public static final String WORK_SCREEN = "WORK_SCREEN"; @@ -35,8 +36,8 @@ public void setUp() throws Exception { @Test public void behaivTest_basicTestFlow_predictsJob() throws Exception { - for (Pair, String> fToL : data) { - ArrayList features = fToL.getKey(); + for (Pair, String> fToL : data) { + List features = fToL.getKey(); timeProvider.next(new Double[]{features.get(0)}); positionProvider.next(new Double[]{features.get(1), features.get(2)}); capture(fToL.getValue()); diff --git a/src/test/java/de/dmi3y/behaiv/kernel/KernelTest.java b/src/test/java/de/dmi3y/behaiv/kernel/KernelTest.java index 116f186..78cde5f 100644 --- a/src/test/java/de/dmi3y/behaiv/kernel/KernelTest.java +++ b/src/test/java/de/dmi3y/behaiv/kernel/KernelTest.java @@ -10,6 +10,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.List; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -39,8 +40,8 @@ public void setUp() throws Exception { @Test public void setTreshold() { dummyKernel.setTreshold(1L); - dummyKernel.data.add(new Pair, String>(null, null)); - dummyKernel.data.add(new Pair, String>(null, null)); + dummyKernel.data.add(new Pair, String>(null, null)); + dummyKernel.data.add(new Pair, String>(null, null)); boolean readyToPredict = dummyKernel.readyToPredict(); assertTrue(readyToPredict); dummyKernel.setTreshold(10L); @@ -66,9 +67,9 @@ public void kernel_saveAndRestore_expectNormalFlow() throws IOException { } - public static ArrayList, String>> getTrainingData() { - ArrayList list = new ArrayList<>(); - ArrayList, String>> data = new ArrayList<>(); + public static List, String>> getTrainingData() { + List list = new ArrayList<>(); + List, String>> data = new ArrayList<>(); list.add((5 * 60 + 00.0) / (24 * 60)); diff --git a/src/test/java/de/dmi3y/behaiv/kernel/LogisticRegressionKernelTest.java b/src/test/java/de/dmi3y/behaiv/kernel/LogisticRegressionKernelTest.java index 0a77410..1a6fdf4 100644 --- a/src/test/java/de/dmi3y/behaiv/kernel/LogisticRegressionKernelTest.java +++ b/src/test/java/de/dmi3y/behaiv/kernel/LogisticRegressionKernelTest.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import java.util.Random; import static de.dmi3y.behaiv.kernel.KernelTest.HOME; @@ -34,7 +35,7 @@ public void setUp() throws Exception { @Test public void predictOne() { - ArrayList, String>> data = KernelTest.getTrainingData(); + List, String>> data = KernelTest.getTrainingData(); Kernel testKernel = new LogisticRegressionKernel("testId"); testKernel.fit(data); ArrayList predictList = new ArrayList<>(); @@ -58,7 +59,7 @@ public void predictOne() { @Test public void storeResults() throws IOException, ClassNotFoundException { - ArrayList, String>> data = KernelTest.getTrainingData(); + List, String>> data = KernelTest.getTrainingData(); Kernel kernel = new LogisticRegressionKernel("testId"); kernel.setId("storeTest"); kernel.fit(data); @@ -84,7 +85,7 @@ public void storeResults() throws IOException, ClassNotFoundException { @Test public void storeResults_addAdditionalLabel_shouldFail() throws IOException, ClassNotFoundException { - ArrayList, String>> data = KernelTest.getTrainingData(); + List, String>> data = KernelTest.getTrainingData(); Kernel kernel = new LogisticRegressionKernel("testId"); kernel.setAlwaysKeepData(false); kernel.setId("storeTest"); @@ -142,7 +143,7 @@ public void storeResults_saveWhenDataIsNull_expectException() throws IOException @Test public void storeResults_saveDataAndThenTheta_expectNormalFlow() throws IOException, ClassNotFoundException { - ArrayList, String>> data = KernelTest.getTrainingData(); + List, String>> data = KernelTest.getTrainingData(); LogisticRegressionKernel kernel = new LogisticRegressionKernel("storeTest", new Random()); kernel.data = data; kernel.labels = Arrays.asList("time", "lat", "lon", "headphones"); diff --git a/src/test/java/de/dmi3y/behaiv/tools/DataMappingUtilsTest.java b/src/test/java/de/dmi3y/behaiv/tools/DataMappingUtilsTest.java index adf4ab3..09e218e 100644 --- a/src/test/java/de/dmi3y/behaiv/tools/DataMappingUtilsTest.java +++ b/src/test/java/de/dmi3y/behaiv/tools/DataMappingUtilsTest.java @@ -15,7 +15,7 @@ public class DataMappingUtilsTest { @Test public void toDistinctListOfPairValues_withInputData_returnsExpectedDistinctListOfPairValues() { - List, String>> mockData = Arrays.asList( + List, String>> mockData = Arrays.asList( getMockPairListDoubleStringData(), getMockPairListDoubleStringData() ); List actual = DataMappingUtils.toDistinctListOfPairValues(mockData); @@ -25,7 +25,7 @@ public void toDistinctListOfPairValues_withInputData_returnsExpectedDistinctList @Test public void toDistinctListOfPairValues_withEmptyListOfInputData_returnsEmptyList() { - List actual = DataMappingUtils.toDistinctListOfPairValues(Collections., String>>emptyList()); + List actual = DataMappingUtils.toDistinctListOfPairValues(Collections., String>>emptyList()); assertThat(actual, notNullValue()); assertTrue(actual.isEmpty()); } @@ -67,7 +67,7 @@ public void toInput2dArray_withInputData_returnsExpected2dArray() { @Test public void toInput2dArray_withEmptyListOfInputData_returnsEmpty2dArray() { - double[][] actual = DataMappingUtils.toInput2dArray(Collections., String>>emptyList()); + double[][] actual = DataMappingUtils.toInput2dArray(Collections., String>>emptyList()); assertThat(actual.length, is(0)); } @@ -81,8 +81,8 @@ private Pair getMockPairDoubleStringData() { return new Pair<>(20d, "Fish"); } - private Pair, String> getMockPairListDoubleStringData() { - ArrayList myDoubleList = new ArrayList<>(); + private Pair, String> getMockPairListDoubleStringData() { + List myDoubleList = new ArrayList<>(); myDoubleList.add(20d); return new Pair<>(myDoubleList, "Potato"); }