initial
This commit is contained in:
53
src/main/java/de/hottis/smarthomelib/ADataObject.java
Normal file
53
src/main/java/de/hottis/smarthomelib/ADataObject.java
Normal file
@ -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<String, Object> values;
|
||||
|
||||
public ADataObject(LocalDateTime timestamp, String name) {
|
||||
this.timestamp = timestamp;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setValues(Map<String, Object> values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
abstract public String getTableName();
|
||||
|
||||
public LocalDateTime getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public Map<String, Object> 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();
|
||||
}
|
||||
}
|
@ -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<String, Object> values = new HashMap<String, Object>();
|
||||
values.put(ENERGY_KEY, energy);
|
||||
values.put(POWER_KEY, power);
|
||||
setValues(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTableName() {
|
||||
return TABLE_NAME;
|
||||
}
|
||||
}
|
@ -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<String, Object> values = new HashMap<String, Object>();
|
||||
values.put(TEMPERATURE_KEY, temperature);
|
||||
setValues(values);
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return TABLE_NAME;
|
||||
}
|
||||
}
|
38
src/test/java/de/hottis/smarthomelib/AppTest.java
Normal file
38
src/test/java/de/hottis/smarthomelib/AppTest.java
Normal file
@ -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 );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user