Added range type to subject-feature-definition/parameter
[groupbasedpolicy.git] / groupbasedpolicy / src / main / java / org / opendaylight / groupbasedpolicy / renderer / oc / Utils.java
1 /*\r
2  * Copyright (c) 2015 Juniper Networks, Inc.  All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 \r
9 package org.opendaylight.groupbasedpolicy.renderer.oc;\r
10 \r
11 import java.util.regex.Pattern;\r
12 \r
13 import org.slf4j.Logger;\r
14 import org.slf4j.LoggerFactory;\r
15 \r
16 public class Utils {\r
17 \r
18     static final Logger LOGGER = LoggerFactory.getLogger(Utils.class);\r
19 \r
20     /**\r
21      * Invoked to format the UUID if UUID is not in correct format.\r
22      *\r
23      * @param String\r
24      *            An instance of UUID string.\r
25      *\r
26      * @return Correctly formated UUID string.\r
27      */\r
28     public static String uuidFormater(String uuid) {\r
29         String uuidPattern = null;\r
30         String id1 = uuid.substring(0, 8);\r
31         String id2 = uuid.substring(8, 12);\r
32         String id3 = uuid.substring(12, 16);\r
33         String id4 = uuid.substring(16, 20);\r
34         String id5 = uuid.substring(20, 32);\r
35         uuidPattern = (id1 + "-" + id2 + "-" + id3 + "-" + id4 + "-" + id5);\r
36         return uuidPattern;\r
37     }\r
38 \r
39     /**\r
40      * Invoked to check the UUID if UUID is not a valid hexa-decimal number.\r
41      *\r
42      * @param String\r
43      *            An instance of UUID string.\r
44      *\r
45      * @return boolean value.\r
46      */\r
47     public static boolean isValidHexNumber(String uuid) {\r
48         try {\r
49             Pattern hex = Pattern.compile("^[0-9a-f]+$");\r
50             uuid = uuid.replaceAll("-", "");\r
51             boolean valid = hex.matcher(uuid).matches();\r
52             if (uuid.length() != 32) {\r
53                 return false;\r
54             }\r
55             if (valid) {\r
56                 return true;\r
57             } else {\r
58                 return false;\r
59             }\r
60         } catch (NumberFormatException ex) {\r
61             LOGGER.error("Exception :  " + ex);\r
62             return false;\r
63         }\r
64     }\r
65 \r
66     /**\r
67      * Invoked to format the UUID/Name in correct format.\r
68      *\r
69      * @param String\r
70      *            An instance of UUID/Name string.\r
71      *\r
72      * @return Correctly formated UUID/name string.\r
73      */\r
74 \r
75     public static String uuidNameFormat(String value){\r
76         String[] pattern = value.split("=");\r
77         value = pattern[1].replace("]", "");\r
78         return value;\r
79     }\r
80 }