From 81dfb547e7a96cc6c1aef5e50929beb0d6a1a7a4 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Wed, 22 Nov 2017 17:30:56 +0100 Subject: [PATCH] initial --- .classpath | 26 +++++++++ .gitignore | 1 + .project | 23 ++++++++ .settings/org.eclipse.jdt.core.prefs | 5 ++ .settings/org.eclipse.m2e.core.prefs | 4 ++ .vscode/settings.json | 3 ++ pom.xml | 32 +++++++++++ .../de/hottis/smarthomelib/ADataObject.java | 53 +++++++++++++++++++ .../ElectricEnergyDataObject.java | 24 +++++++++ .../smarthomelib/TemperatureDataObject.java | 21 ++++++++ .../java/de/hottis/smarthomelib/AppTest.java | 38 +++++++++++++ 11 files changed, 230 insertions(+) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 .settings/org.eclipse.m2e.core.prefs create mode 100644 .vscode/settings.json create mode 100644 pom.xml create mode 100644 src/main/java/de/hottis/smarthomelib/ADataObject.java create mode 100644 src/main/java/de/hottis/smarthomelib/ElectricEnergyDataObject.java create mode 100644 src/main/java/de/hottis/smarthomelib/TemperatureDataObject.java create mode 100644 src/test/java/de/hottis/smarthomelib/AppTest.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..af1430b --- /dev/null +++ b/.classpath @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb5a316 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target diff --git a/.project b/.project new file mode 100644 index 0000000..47cc580 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + SmarthomeLib + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..714351a --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e0f15db --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "automatic" +} \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..569c262 --- /dev/null +++ b/pom.xml @@ -0,0 +1,32 @@ + + 4.0.0 + de.hottis.smarthomelib + SmarthomeLib + jar + 1.0-SNAPSHOT + SmarthomeLib + http://maven.apache.org + + 1.8 + 1.8 + + + + junit + junit + 3.8.1 + test + + + org.apache.logging.log4j + log4j-core + 2.9.1 + + + org.apache.logging.log4j + log4j-api + 2.9.1 + + + diff --git a/src/main/java/de/hottis/smarthomelib/ADataObject.java b/src/main/java/de/hottis/smarthomelib/ADataObject.java new file mode 100644 index 0000000..b1a609d --- /dev/null +++ b/src/main/java/de/hottis/smarthomelib/ADataObject.java @@ -0,0 +1,53 @@ +package de.hottis.smarthomelib; + +import java.io.Serializable; +import java.time.LocalDateTime; +import java.util.Map; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public abstract class ADataObject implements Serializable { + private static final long serialVersionUID = 1L; + + final protected Logger logger = LogManager.getRootLogger(); + + private LocalDateTime timestamp; + private String name; + private Map values; + + public ADataObject(LocalDateTime timestamp, String name) { + this.timestamp = timestamp; + this.name = name; + } + + public void setValues(Map values) { + this.values = values; + } + + abstract public String getTableName(); + + public LocalDateTime getTimestamp() { + return timestamp; + } + + public Map getValues() { + return values; + } + + public String getName() { + return name; + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("<"); + sb.append(name); + sb.append(", "); + sb.append(timestamp); + sb.append(", "); + sb.append(values.toString()); + sb.append(">"); + return sb.toString(); + } +} diff --git a/src/main/java/de/hottis/smarthomelib/ElectricEnergyDataObject.java b/src/main/java/de/hottis/smarthomelib/ElectricEnergyDataObject.java new file mode 100644 index 0000000..4c97037 --- /dev/null +++ b/src/main/java/de/hottis/smarthomelib/ElectricEnergyDataObject.java @@ -0,0 +1,24 @@ +package de.hottis.smarthomelib; + +import java.time.LocalDateTime; +import java.util.HashMap; + +public class ElectricEnergyDataObject extends ADataObject { + private static final long serialVersionUID = 1L; + static final String ENERGY_KEY = "energy"; + static final String POWER_KEY = "power"; + static final String TABLE_NAME = "ElectricEnergy"; + + public ElectricEnergyDataObject(LocalDateTime timestamp, String name, double energy, double power) { + super(timestamp, name); + HashMap values = new HashMap(); + values.put(ENERGY_KEY, energy); + values.put(POWER_KEY, power); + setValues(values); + } + + @Override + public String getTableName() { + return TABLE_NAME; + } +} diff --git a/src/main/java/de/hottis/smarthomelib/TemperatureDataObject.java b/src/main/java/de/hottis/smarthomelib/TemperatureDataObject.java new file mode 100644 index 0000000..3d5160c --- /dev/null +++ b/src/main/java/de/hottis/smarthomelib/TemperatureDataObject.java @@ -0,0 +1,21 @@ +package de.hottis.smarthomelib; + +import java.time.LocalDateTime; +import java.util.HashMap; + +public class TemperatureDataObject extends ADataObject { + private static final long serialVersionUID = 1L; + static final String TEMPERATURE_KEY = "temperature"; + static final String TABLE_NAME = "Temperature"; + + public TemperatureDataObject(LocalDateTime timestamp, String name, double temperature) { + super(timestamp, name); + HashMap values = new HashMap(); + values.put(TEMPERATURE_KEY, temperature); + setValues(values); + } + + public String getTableName() { + return TABLE_NAME; + } +} diff --git a/src/test/java/de/hottis/smarthomelib/AppTest.java b/src/test/java/de/hottis/smarthomelib/AppTest.java new file mode 100644 index 0000000..47f9a6b --- /dev/null +++ b/src/test/java/de/hottis/smarthomelib/AppTest.java @@ -0,0 +1,38 @@ +package de.hottis.smarthomelib; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +}