]> git.basschouten.com Git - openhab-addons.git/blob
d8224cb502cdb8d847e537ff9ea16891eaa79628
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.silvercrestwifisocket.internal.utils;
14
15 import java.util.regex.Matcher;
16 import java.util.regex.Pattern;
17
18 /**
19  * Utilitary static class to perform some validations.
20  *
21  * @author Jaime Vaz - Initial contribution
22  *
23  */
24 public final class ValidationUtils {
25
26     private ValidationUtils() {
27         // avoid instantiation.
28     }
29
30     public static final String MAC_PATTERN = "^([0-9A-Fa-f]{2}[:-]*){5}([0-9A-Fa-f]{2})$";
31
32     /**
33      * Validates if one Mac address is valid.
34      *
35      * @param mac the mac, with or without :
36      * @return true if is valid.
37      */
38     public static boolean isMacValid(final String mac) {
39         Pattern pattern = Pattern.compile(ValidationUtils.MAC_PATTERN);
40         Matcher matcher = pattern.matcher(mac);
41         return matcher.matches();
42     }
43
44     /**
45      * Validates if one Mac address is not valid.
46      *
47      * @param mac the mac, with or without :
48      * @return true if is not valid.
49      */
50     public static boolean isMacNotValid(final String macAddress) {
51         return !isMacValid(macAddress);
52     }
53 }