AndroidAPS/app/src/main/java/info/nightscout/androidaps/interfaces/Constraint.java

48 lines
943 B
Java
Raw Normal View History

package info.nightscout.androidaps.interfaces;
2018-03-19 13:11:25 +01:00
import java.util.ArrayList;
import java.util.List;
/**
* Created by mike on 19.03.2018.
*/
2018-03-19 17:38:48 +01:00
public class Constraint<T> {
T value;
2018-03-19 13:11:25 +01:00
List<String> reasons = new ArrayList<>();
2018-03-19 17:38:48 +01:00
public Constraint(T value) {
this.value = value;
}
public T get() {
return value;
}
public Constraint<T> set(T value) {
this.value = value;
return this;
}
public Constraint<T> set(T value, String reason) {
this.value = value;
reason(reason);
return this;
}
2018-03-19 13:11:25 +01:00
public Constraint reason(String reason) {
reasons.add(reason);
return this;
}
public String getReasons() {
StringBuilder sb = new StringBuilder();
int count = 0;
for (String r: reasons) {
if (count++ != 0) sb.append("\n");
sb.append(r);
}
return sb.toString();
}
}