android: Enum type for transport protocols added
authorTobias Brunner <tobias@strongswan.org>
Fri, 26 Apr 2013 15:10:20 +0000 (17:10 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 8 Jul 2013 16:49:27 +0000 (18:49 +0200)
src/frontends/android/src/org/strongswan/android/logic/imc/collectors/Protocol.java [new file with mode: 0644]

diff --git a/src/frontends/android/src/org/strongswan/android/logic/imc/collectors/Protocol.java b/src/frontends/android/src/org/strongswan/android/logic/imc/collectors/Protocol.java
new file mode 100644 (file)
index 0000000..7320652
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+package org.strongswan.android.logic.imc.collectors;
+
+public enum Protocol
+{
+       TCP((byte)6, "tcp", "tcp6"),
+       UDP((byte)17, "udp", "udp6");
+
+       private final byte mValue;
+       private String[] mNames;
+
+       private Protocol(byte value, String... names)
+       {
+               mValue = value;
+               mNames = names;
+       }
+
+       /**
+        * Get the numeric value of the protocol.
+        * @return numeric value
+        */
+       public byte getValue()
+       {
+               return mValue;
+       }
+
+       /**
+        * Get the protocol from the given protocol name, if found.
+        * @param name protocol name (e.g. "udp" or "tcp")
+        * @return enum entry or null
+        */
+       public static Protocol fromName(String name)
+       {
+               for (Protocol protocol : Protocol.values())
+               {
+                       for (String keyword : protocol.mNames)
+                       {
+                               if (keyword.equalsIgnoreCase(name))
+                               {
+                                       return protocol;
+                               }
+                       }
+               }
+               return null;
+       }
+}