From 6500727d6a0b579126f933aaff6477d005b3f7f0 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Fri, 26 Apr 2013 17:10:20 +0200 Subject: [PATCH] android: Enum type for transport protocols added --- .../logic/imc/collectors/Protocol.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/frontends/android/src/org/strongswan/android/logic/imc/collectors/Protocol.java 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 index 0000000000..7320652a1e --- /dev/null +++ b/src/frontends/android/src/org/strongswan/android/logic/imc/collectors/Protocol.java @@ -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 . + * + * 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; + } +} -- 2.47.3