blob: 0fdf25ad1d7a178a6efa3ce99a6f02ad78a658e9 [file] [log] [blame]
Brian O'Connorb7baf712015-07-28 23:27:03 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.incubator.net.domain;
17
18import com.google.common.annotations.Beta;
Brian O'Connorce2d8b52015-07-29 16:24:13 -070019import com.google.common.base.MoreObjects;
Brian O'Connorb7baf712015-07-28 23:27:03 -070020import org.onlab.graph.Vertex;
21import org.onosproject.net.DeviceId;
22
23import static com.google.common.base.Preconditions.checkNotNull;
24
25/**
26 * Representation of the intent domain or a device that is part of the intent
27 * domain graph.
28 */
29@Beta
30public class DomainVertex implements Vertex {
31 // FIXME we will want to add a type enum or subclasses for the two different types
32
33 // A domain vertex is either an intent domain or a device:
Brian O'Connorce2d8b52015-07-29 16:24:13 -070034 private final IntentDomainId domainId;
Brian O'Connorb7baf712015-07-28 23:27:03 -070035 // ----- or -----
36 private final DeviceId deviceId;
37
38 // Serialization constructor
39 private DomainVertex() {
Brian O'Connorce2d8b52015-07-29 16:24:13 -070040 this.domainId = null;
Brian O'Connorb7baf712015-07-28 23:27:03 -070041 this.deviceId = null;
42 }
43
Brian O'Connorce2d8b52015-07-29 16:24:13 -070044 public DomainVertex(IntentDomainId id) {
45 this.domainId = checkNotNull(id, "Intent domain ID cannot be null.");
Brian O'Connorb7baf712015-07-28 23:27:03 -070046 this.deviceId = null;
47 }
48
Brian O'Connorce2d8b52015-07-29 16:24:13 -070049 public DomainVertex(DeviceId id) {
50 this.domainId = null;
Brian O'Connorb7baf712015-07-28 23:27:03 -070051 this.deviceId = checkNotNull(id, "Device ID cannot be null.");
52 }
Brian O'Connorce2d8b52015-07-29 16:24:13 -070053
54 @Override
55 public String toString() {
56 if (domainId != null) {
57 return MoreObjects.toStringHelper(this)
58 .add("domainId", domainId)
59 .toString();
60 } else if (deviceId != null) {
61 return MoreObjects.toStringHelper(this)
62 .add("deviceId", deviceId)
63 .toString();
64 } else {
65 return MoreObjects.toStringHelper(this)
66 .toString();
67 }
68 }
Brian O'Connorb7baf712015-07-28 23:27:03 -070069}