From 9bee6745142eb0a6f9c43c7c05c7152fda352dce Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Wed, 14 Oct 2015 12:11:31 +0200 Subject: [PATCH] Add Product.fromCodes() and Product.toCodes(). --- .../src/de/schildbach/pte/dto/Product.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/enabler/src/de/schildbach/pte/dto/Product.java b/enabler/src/de/schildbach/pte/dto/Product.java index 625db2ac..8e9e2ecc 100644 --- a/enabler/src/de/schildbach/pte/dto/Product.java +++ b/enabler/src/de/schildbach/pte/dto/Product.java @@ -60,4 +60,27 @@ public enum Product else throw new IllegalArgumentException("unknown code: '" + code + "'"); } + + public static Set fromCodes(final char[] codes) + { + if (codes == null) + return null; + + final Set products = EnumSet.noneOf(Product.class); + for (int i = 0; i < codes.length; i++) + products.add(Product.fromCode(codes[i])); + return products; + } + + public static char[] toCodes(final Set products) + { + if (products == null) + return null; + + final char[] codes = new char[products.size()]; + int i = 0; + for (final Product product : products) + codes[i++] = product.code; + return codes; + } }