2 * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
\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
9 package org.opendaylight.groupbasedpolicy.renderer.oc;
\r
11 import java.util.regex.Pattern;
\r
13 import org.slf4j.Logger;
\r
14 import org.slf4j.LoggerFactory;
\r
16 public class Utils {
\r
18 static final Logger LOGGER = LoggerFactory.getLogger(Utils.class);
\r
21 * Invoked to format the UUID if UUID is not in correct format.
\r
24 * An instance of UUID string.
\r
26 * @return Correctly formated UUID string.
\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
40 * Invoked to check the UUID if UUID is not a valid hexa-decimal number.
\r
43 * An instance of UUID string.
\r
45 * @return boolean value.
\r
47 public static boolean isValidHexNumber(String uuid) {
\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
60 } catch (NumberFormatException ex) {
\r
61 LOGGER.error("Exception : " + ex);
\r
67 * Invoked to format the UUID/Name in correct format.
\r
70 * An instance of UUID/Name string.
\r
72 * @return Correctly formated UUID/name string.
\r
75 public static String uuidNameFormat(String value){
\r
76 String[] pattern = value.split("=");
\r
77 value = pattern[1].replace("]", "");
\r