mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-13 00:08:49 +00:00
Add Product.fromCodes() and Product.toCodes().
This commit is contained in:
parent
0994d31443
commit
9bee674514
1 changed files with 23 additions and 0 deletions
|
@ -60,4 +60,27 @@ public enum Product
|
||||||
else
|
else
|
||||||
throw new IllegalArgumentException("unknown code: '" + code + "'");
|
throw new IllegalArgumentException("unknown code: '" + code + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Set<Product> fromCodes(final char[] codes)
|
||||||
|
{
|
||||||
|
if (codes == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
final Set<Product> 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<Product> 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue