2 * Copyright (c) 2017 Red Hat, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netvirt.qosservice;
10 import com.google.common.base.Optional;
11 import com.google.common.base.Preconditions;
12 import java.util.regex.Pattern;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
16 * Utility for {@link Uuid}.
17 * This class is ThreadSafe.
18 * @author Michael Vorburger.ch
22 private Pattern uuidPattern;
24 Optional<Uuid> newUuidIfValidPattern(String possibleUuid) {
25 Preconditions.checkNotNull(possibleUuid, "possibleUuid == null");
27 if (uuidPattern == null) {
28 // Thread safe because it really doesn't matter even if we were to do this initialization more than once
29 if (Uuid.PATTERN_CONSTANTS.size() != 1) {
30 throw new IllegalStateException("Uuid.PATTERN_CONSTANTS.size() != 1");
32 uuidPattern = Pattern.compile(Uuid.PATTERN_CONSTANTS.get(0));
35 if (uuidPattern.matcher(possibleUuid).matches()) {
36 return Optional.of(new Uuid(possibleUuid));
38 return Optional.absent();