From d2f203522c5384ad411bc9dad38c5f87b0e63abd Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Mon, 30 May 2016 12:45:00 +0200 Subject: Move byteToBoolean to TranslateUtils Change-Id: I7a8142bc2df7d566bc3edde7ceb42eb6b8815852 Signed-off-by: Marek Gradzki --- .../v3po/translate/v3po/util/TranslateUtils.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util') diff --git a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java index f14b2eb6d..b13dbb4fe 100644 --- a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java +++ b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java @@ -129,4 +129,20 @@ public final class TranslateUtils { public static byte booleanToByte(@Nullable final Boolean value) { return value != null && value ? (byte) 1 : (byte) 0; } + + /** + * Returns Boolean.TRUE if argument is 0, Boolean.FALSE otherwise. + * @param value byte value to be converted + * @return Boolean value + * @throws IllegalArgumentException if argument is neither 0 nor 1 + */ + @Nonnull + public static Boolean byteToBoolean(final byte value) { + if (value == 0) { + return Boolean.FALSE; + } else if (value == 1) { + return Boolean.TRUE; + } + throw new IllegalArgumentException(String.format("0 or 1 was expected but was %d", value)); + } } -- cgit 1.2.3-korg