Canonical discoverability writing.

This commit is contained in:
Graeme Connell
2021-09-03 17:21:04 -06:00
committed by gram-signal
parent 92f035bc2a
commit b4aabd799b
6 changed files with 117 additions and 14 deletions

View File

@@ -23,6 +23,8 @@ public class AttributeValues {
return AttributeValue.builder().n(Long.toString(value)).build();
}
public static AttributeValue fromBool(boolean value) { return AttributeValue.builder().bool(value).build(); }
public static AttributeValue fromInt(int value) {
return AttributeValue.builder().n(Integer.toString(value)).build();
}
@@ -43,6 +45,10 @@ public class AttributeValues {
return AttributeValue.builder().b(value).build();
}
private static boolean toBool(AttributeValue av) {
return av.bool();
}
private static int toInt(AttributeValue av) {
return Integer.parseInt(av.n());
}
@@ -67,6 +73,10 @@ public class AttributeValues {
return Optional.ofNullable(item.get(key));
}
public static boolean getBool(Map<String, AttributeValue> item, String key, boolean defaultValue) {
return AttributeValues.get(item, key).map(AttributeValues::toBool).orElse(defaultValue);
}
public static int getInt(Map<String, AttributeValue> item, String key, int defaultValue) {
return AttributeValues.get(item, key).map(AttributeValues::toInt).orElse(defaultValue);
}