Brian O'Connor | b7baf71 | 2015-07-28 23:27:03 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.incubator.net.domain; |
| 17 | |
| 18 | import com.google.common.annotations.Beta; |
Brian O'Connor | ce2d8b5 | 2015-07-29 16:24:13 -0700 | [diff] [blame^] | 19 | import com.google.common.base.MoreObjects; |
Brian O'Connor | b7baf71 | 2015-07-28 23:27:03 -0700 | [diff] [blame] | 20 | import org.onlab.graph.Vertex; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | |
| 23 | import 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 |
| 30 | public 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'Connor | ce2d8b5 | 2015-07-29 16:24:13 -0700 | [diff] [blame^] | 34 | private final IntentDomainId domainId; |
Brian O'Connor | b7baf71 | 2015-07-28 23:27:03 -0700 | [diff] [blame] | 35 | // ----- or ----- |
| 36 | private final DeviceId deviceId; |
| 37 | |
| 38 | // Serialization constructor |
| 39 | private DomainVertex() { |
Brian O'Connor | ce2d8b5 | 2015-07-29 16:24:13 -0700 | [diff] [blame^] | 40 | this.domainId = null; |
Brian O'Connor | b7baf71 | 2015-07-28 23:27:03 -0700 | [diff] [blame] | 41 | this.deviceId = null; |
| 42 | } |
| 43 | |
Brian O'Connor | ce2d8b5 | 2015-07-29 16:24:13 -0700 | [diff] [blame^] | 44 | public DomainVertex(IntentDomainId id) { |
| 45 | this.domainId = checkNotNull(id, "Intent domain ID cannot be null."); |
Brian O'Connor | b7baf71 | 2015-07-28 23:27:03 -0700 | [diff] [blame] | 46 | this.deviceId = null; |
| 47 | } |
| 48 | |
Brian O'Connor | ce2d8b5 | 2015-07-29 16:24:13 -0700 | [diff] [blame^] | 49 | public DomainVertex(DeviceId id) { |
| 50 | this.domainId = null; |
Brian O'Connor | b7baf71 | 2015-07-28 23:27:03 -0700 | [diff] [blame] | 51 | this.deviceId = checkNotNull(id, "Device ID cannot be null."); |
| 52 | } |
Brian O'Connor | ce2d8b5 | 2015-07-29 16:24:13 -0700 | [diff] [blame^] | 53 | |
| 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'Connor | b7baf71 | 2015-07-28 23:27:03 -0700 | [diff] [blame] | 69 | } |