Bump upstreams for Silicon
[neutron.git] / neutron-spi / src / main / java / org / opendaylight / neutron / spi / NeutronID.java
1 /*
2  * Copyright (c) 2015 IBM Corporation and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.neutron.spi;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.base.Preconditions;
13 import java.io.Serializable;
14 import java.util.regex.Pattern;
15 import javax.xml.bind.annotation.XmlAccessType;
16 import javax.xml.bind.annotation.XmlAccessorType;
17 import javax.xml.bind.annotation.XmlElement;
18 import javax.xml.bind.annotation.XmlRootElement;
19
20 @XmlRootElement
21 @XmlAccessorType(XmlAccessType.NONE)
22 public class NeutronID implements Serializable {
23     private static final long serialVersionUID = 1L;
24     private static final String UUID_PATTERN_REGEX =
25             "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$";
26     private static final Pattern UUID_PATTERN = Pattern.compile(UUID_PATTERN_REGEX);
27
28     // See OpenStack Network API v2.0 Reference for description of
29     // annotated attributes
30
31     @XmlElement(name = "id")
32     String uuid;
33
34     private static void checkUuidPattern(String uuid) {
35         Preconditions.checkArgument(
36                 UUID_PATTERN.matcher(requireNonNull(uuid, "Supplied value may not be null")).matches(),
37                 "Supplied value \"%s\" does not match uuid pattern \"%s\"", uuid, UUID_PATTERN_REGEX);
38     }
39
40     public NeutronID() {
41     }
42
43     public NeutronID(String uuid) {
44         checkUuidPattern(uuid);
45         this.uuid = uuid;
46     }
47
48     public String getID() {
49         return uuid;
50     }
51
52     public void setID(String newUuid) {
53         checkUuidPattern(newUuid);
54         this.uuid = newUuid;
55     }
56
57     @Override
58     public String toString() {
59         return "NeutronID{" + "id='" + uuid + '\'' + "}";
60     }
61 }