From f2bfc73b887f0d4501965e53b23a7c3954616fbb Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 12 Nov 2017 17:08:18 +0100 Subject: [PATCH] toString, equals. --- .../main/java/de/jotomo/ruffy/spi/CommandResult.java | 2 +- .../main/java/de/jotomo/ruffy/spi/history/Bolus.java | 6 ++++-- .../java/de/jotomo/ruffy/spi/history/PumpError.java | 4 +++- .../java/de/jotomo/ruffy/spi/history/PumpHistory.java | 2 +- .../jotomo/ruffy/spi/history/PumpHistoryRequest.java | 10 ++++++---- .../src/main/java/de/jotomo/ruffy/spi/history/Tbr.java | 6 ++++-- .../src/main/java/de/jotomo/ruffy/spi/history/Tdd.java | 6 ++++-- 7 files changed, 23 insertions(+), 13 deletions(-) diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/CommandResult.java b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/CommandResult.java index 6438fddd7c..98f0edc9f7 100644 --- a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/CommandResult.java +++ b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/CommandResult.java @@ -65,7 +65,7 @@ public class CommandResult { @Override public String toString() { return "CommandResult{" + - ", success=" + success + + "success=" + success + ", exception=" + exception + ", state=" + state + ", history=" + history + diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/Bolus.java b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/Bolus.java index 71ae8f2727..faed71c948 100644 --- a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/Bolus.java +++ b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/Bolus.java @@ -1,5 +1,7 @@ package de.jotomo.ruffy.spi.history; +import java.util.Date; + public class Bolus extends HistoryRecord { public final double amount; public final boolean isValid; @@ -20,7 +22,7 @@ public class Bolus extends HistoryRecord { if (timestamp != bolus.timestamp) return false; if (isValid != bolus.isValid) return false; - return Double.compare(bolus.amount, amount) == 0; + return Math.abs(bolus.amount - amount) <= 0.05; } @Override @@ -37,7 +39,7 @@ public class Bolus extends HistoryRecord { @Override public String toString() { return "Bolus{" + - "timestamp=" + timestamp + + "timestamp=" + timestamp + "(" + new Date(timestamp) + ")" + ", amount=" + amount + '}'; } diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/PumpError.java b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/PumpError.java index aa7a247faa..da2e3453c9 100644 --- a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/PumpError.java +++ b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/PumpError.java @@ -1,5 +1,7 @@ package de.jotomo.ruffy.spi.history; +import java.util.Date; + public class PumpError extends HistoryRecord { public final Integer warningCode; public final Integer errorCode; @@ -40,7 +42,7 @@ public class PumpError extends HistoryRecord { @Override public String toString() { return "PumpError{" + - "timestamp=" + timestamp + + "timestamp=" + timestamp + "(" + new Date(timestamp) + ")" + ", warningCode=" + warningCode + ", errorCode=" + errorCode + ", message='" + message + '\'' + diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/PumpHistory.java b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/PumpHistory.java index ed6b92e30f..6b2a17676a 100644 --- a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/PumpHistory.java +++ b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/PumpHistory.java @@ -41,7 +41,7 @@ public class PumpHistory { @Override public String toString() { return "PumpHistory{" + - ", bolusHistory=" + bolusHistory.size() + + "bolusHistory=" + bolusHistory.size() + ", tbrHistory=" + tbrHistory.size() + ", pumpErrorHistory=" + pumpErrorHistory.size() + ", tddHistory=" + tddHistory.size() + diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/PumpHistoryRequest.java b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/PumpHistoryRequest.java index 6c1bdaefe1..9478cdb399 100644 --- a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/PumpHistoryRequest.java +++ b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/PumpHistoryRequest.java @@ -1,5 +1,7 @@ package de.jotomo.ruffy.spi.history; +import java.util.Date; + /** What data a 'read history' request should return. */ public class PumpHistoryRequest { /* History to read: @@ -38,10 +40,10 @@ public class PumpHistoryRequest { @Override public String toString() { return "PumpHistoryRequest{" + - ", bolusHistory=" + bolusHistory + - ", tbrHistory=" + tbrHistory + - ", pumpErrorHistory=" + pumpErrorHistory + - ", tddHistory=" + tddHistory + + "bolusHistory=" + bolusHistory + (bolusHistory > 0 ? ("(" + new Date(bolusHistory) + ")") : "") + + ", tbrHistory=" + tbrHistory + (tbrHistory > 0 ? ("(" + new Date(tbrHistory) + ")") : "") + + ", pumpErrorHistory=" + pumpErrorHistory + (pumpErrorHistory > 0 ? ("(" + new Date(pumpErrorHistory) + ")") : "") + + ", tddHistory=" + tddHistory + (tddHistory > 0 ? ("(" + new Date(tddHistory) + ")") : "") + '}'; } } diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/Tbr.java b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/Tbr.java index 99eb78a81a..97936dcaef 100644 --- a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/Tbr.java +++ b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/Tbr.java @@ -1,7 +1,9 @@ package de.jotomo.ruffy.spi.history; -/** Note: the timestamp is the time the TBR **ended**, not started .*/ +import java.util.Date; + public class Tbr extends HistoryRecord { + /** Duration in minutes */ public final int duration; public final int percent; @@ -34,7 +36,7 @@ public class Tbr extends HistoryRecord { @Override public String toString() { return "Tbr{" + - "timestamp=" + timestamp + + "timestamp=" + timestamp + "(" + new Date(timestamp) + ")" + ", duration=" + duration + ", percent=" + percent + '}'; diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/Tdd.java b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/Tdd.java index 8c16bd43a7..d1d68ab7c2 100644 --- a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/Tdd.java +++ b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/history/Tdd.java @@ -1,5 +1,7 @@ package de.jotomo.ruffy.spi.history; +import java.util.Date; + /** Total daily dosage; amount of insulin delivered over a full day. */ public class Tdd extends HistoryRecord { public final double total; @@ -17,7 +19,7 @@ public class Tdd extends HistoryRecord { Tdd tdd = (Tdd) o; if (timestamp != tdd.timestamp) return false; - return Double.compare(tdd.total, total) == 0; + return Math.abs(tdd.total - total) <= 0.05; } @Override @@ -33,7 +35,7 @@ public class Tdd extends HistoryRecord { @Override public String toString() { return "Tdd{" + - "timestamp=" + timestamp + + "timestamp=" + timestamp + "(" + new Date(timestamp) + ")" + ", total=" + total + '}'; }