diff options
author | Samuel Holland <samuel@sholland.org> | 2018-04-30 11:39:12 -0500 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2018-04-30 11:39:12 -0500 |
commit | 7eedf08d4bbe8d15a38cde777d92e72930ffa2e8 (patch) | |
tree | 12293719d001f3eef3a54244688279e62e2513a1 /app/src/main/java/com/wireguard/config/Attribute.java | |
parent | app: Sort dependencies (diff) | |
download | wireguard-android-7eedf08d4bbe8d15a38cde777d92e72930ffa2e8.tar.xz wireguard-android-7eedf08d4bbe8d15a38cde777d92e72930ffa2e8.zip |
global: Automatic code formatting
Signed-off-by: Samuel Holland <samuel@sholland.org>
Diffstat (limited to 'app/src/main/java/com/wireguard/config/Attribute.java')
-rw-r--r-- | app/src/main/java/com/wireguard/config/Attribute.java | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/app/src/main/java/com/wireguard/config/Attribute.java b/app/src/main/java/com/wireguard/config/Attribute.java index 5ecd21f4..2d8070ac 100644 --- a/app/src/main/java/com/wireguard/config/Attribute.java +++ b/app/src/main/java/com/wireguard/config/Attribute.java @@ -30,6 +30,7 @@ enum Attribute { private static final Map<String, Attribute> KEY_MAP; private static final Pattern SEPARATOR_PATTERN = Pattern.compile("\\s|="); + private static Method parseNumericAddressMethod; static { KEY_MAP = new HashMap<>(Attribute.values().length); @@ -38,6 +39,14 @@ enum Attribute { } } + static { + try { + parseNumericAddressMethod = InetAddress.class.getMethod("parseNumericAddress", new Class[]{String.class}); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + private final Pattern pattern; private final String token; @@ -46,44 +55,35 @@ enum Attribute { this.token = token; } - public static Attribute match(final CharSequence line) { - return KEY_MAP.get(SEPARATOR_PATTERN.split(line)[0]); - } - public static <T> String listToString(final List<T> list) { return TextUtils.join(", ", list); } - public static String[] stringToList(final String string) { - if (string == null) - return new String[0]; - return string.trim().split("\\s*,\\s*"); - } - - private static Method parseNumericAddressMethod; - static { - try { - parseNumericAddressMethod = InetAddress.class.getMethod("parseNumericAddress", new Class[]{String.class}); - } catch (Exception e) { - throw new RuntimeException(e); - } + public static Attribute match(final CharSequence line) { + return KEY_MAP.get(SEPARATOR_PATTERN.split(line)[0]); } public static InetAddress parseIPString(final String address) { if (address == null || address.isEmpty()) throw new IllegalArgumentException("Empty address"); try { - return (InetAddress)parseNumericAddressMethod.invoke(null, new Object[]{address}); + return (InetAddress) parseNumericAddressMethod.invoke(null, new Object[]{address}); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { if (e.getCause() instanceof IllegalArgumentException) - throw (IllegalArgumentException)e.getCause(); + throw (IllegalArgumentException) e.getCause(); else throw new IllegalArgumentException(e.getCause()); } } + public static String[] stringToList(final String string) { + if (string == null) + return new String[0]; + return string.trim().split("\\s*,\\s*"); + } + public String composeWith(final Object value) { return String.format("%s = %s%n", token, value); } |