Replace custom functional interfaces with built in types
This commit is contained in:
parent
5bd873cd0e
commit
5d3426dc70
3 changed files with 6 additions and 28 deletions
|
@ -1,7 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.comm;
|
|
||||||
|
|
||||||
// TODO replace with Consumer when our min API level >= 24
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface BolusProgressIndicationConsumer {
|
|
||||||
void accept(double estimatedUnitsDelivered, int percentage);
|
|
||||||
}
|
|
|
@ -7,6 +7,8 @@ import org.joda.time.Duration;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
|
@ -270,7 +272,7 @@ public class OmnipodManager {
|
||||||
// Returns a SingleSubject that returns when the bolus has finished.
|
// Returns a SingleSubject that returns when the bolus has finished.
|
||||||
// When a bolus is cancelled, it will return after cancellation and report the estimated units delivered
|
// When a bolus is cancelled, it will return after cancellation and report the estimated units delivered
|
||||||
// Only throws OmnipodException[certainFailure=false]
|
// Only throws OmnipodException[certainFailure=false]
|
||||||
public synchronized BolusCommandResult bolus(Double units, boolean acknowledgementBeep, boolean completionBeep, BolusProgressIndicationConsumer progressIndicationConsumer) {
|
public synchronized BolusCommandResult bolus(Double units, boolean acknowledgementBeep, boolean completionBeep, BiConsumer<Double, Integer> progressIndicationConsumer) {
|
||||||
assertReadyForDelivery();
|
assertReadyForDelivery();
|
||||||
|
|
||||||
logStartingCommandExecution("bolus [units=" + units + ", acknowledgementBeep=" + acknowledgementBeep + ", completionBeep=" + completionBeep + "]");
|
logStartingCommandExecution("bolus [units=" + units + ", acknowledgementBeep=" + acknowledgementBeep + ", completionBeep=" + completionBeep + "]");
|
||||||
|
@ -486,9 +488,9 @@ public class OmnipodManager {
|
||||||
|
|
||||||
// Only works for commands with nonce resyncable message blocks
|
// Only works for commands with nonce resyncable message blocks
|
||||||
// FIXME method is too big, needs refactoring
|
// FIXME method is too big, needs refactoring
|
||||||
private StatusResponse executeAndVerify(VerifiableAction runnable) {
|
private StatusResponse executeAndVerify(Supplier<StatusResponse> supplier) {
|
||||||
try {
|
try {
|
||||||
return runnable.run();
|
return supplier.get();
|
||||||
} catch (Exception originalException) {
|
} catch (Exception originalException) {
|
||||||
if (isCertainFailure(originalException)) {
|
if (isCertainFailure(originalException)) {
|
||||||
throw originalException;
|
throw originalException;
|
||||||
|
@ -609,12 +611,6 @@ public class OmnipodManager {
|
||||||
UNCERTAIN_FAILURE
|
UNCERTAIN_FAILURE
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO replace with Consumer when our min API level >= 24
|
|
||||||
@FunctionalInterface
|
|
||||||
private interface StatusResponseConsumer {
|
|
||||||
void accept(StatusResponse statusResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ActiveBolusData {
|
private static class ActiveBolusData {
|
||||||
private final double units;
|
private final double units;
|
||||||
private volatile DateTime startDate;
|
private volatile DateTime startDate;
|
||||||
|
@ -654,10 +650,4 @@ public class OmnipodManager {
|
||||||
return (double) Math.round(estimatedUnits * roundingDivisor) / roundingDivisor;
|
return (double) Math.round(estimatedUnits * roundingDivisor) / roundingDivisor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Could be replaced with Supplier<StatusResponse> when min API level >= 24
|
|
||||||
@FunctionalInterface
|
|
||||||
private interface VerifiableAction {
|
|
||||||
StatusResponse run();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import org.joda.time.format.ISODateTimeFormat;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
|
@ -777,10 +778,4 @@ public abstract class PodStateManager {
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO replace with java.util.function.Supplier<T> when min API level >= 24
|
|
||||||
@FunctionalInterface
|
|
||||||
private interface Supplier<T> {
|
|
||||||
T get();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue