Thomas Vachuska | 1fb982f | 2014-10-22 14:09:17 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 1fb982f | 2014-10-22 14:09:17 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 1fb982f | 2014-10-22 14:09:17 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 1fb982f | 2014-10-22 14:09:17 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent; |
Thomas Vachuska | 1fb982f | 2014-10-22 14:09:17 -0700 | [diff] [blame] | 17 | |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 18 | |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 19 | import com.google.common.annotations.Beta; |
| 20 | |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 21 | import java.util.Objects; |
| 22 | |
| 23 | import static com.google.common.base.MoreObjects.toStringHelper; |
Sho SHIMIZU | c647b1e | 2014-12-12 15:04:55 -0800 | [diff] [blame] | 24 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 25 | |
Thomas Vachuska | 1fb982f | 2014-10-22 14:09:17 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Abstraction of an intent-related operation, e.g. add, remove, replace. |
| 28 | */ |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 29 | @Beta |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 30 | public final class IntentOperation { |
Thomas Vachuska | 1fb982f | 2014-10-22 14:09:17 -0700 | [diff] [blame] | 31 | |
| 32 | private final Type type; |
Thomas Vachuska | 1fb982f | 2014-10-22 14:09:17 -0700 | [diff] [blame] | 33 | private final Intent intent; |
| 34 | |
| 35 | /** |
| 36 | * Operation type. |
| 37 | */ |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 38 | public enum Type { |
Thomas Vachuska | 1fb982f | 2014-10-22 14:09:17 -0700 | [diff] [blame] | 39 | /** |
| 40 | * Indicates that an intent should be added. |
| 41 | */ |
| 42 | SUBMIT, |
| 43 | |
| 44 | /** |
| 45 | * Indicates that an intent should be removed. |
| 46 | */ |
| 47 | WITHDRAW, |
Thomas Vachuska | 1fb982f | 2014-10-22 14:09:17 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Creates an intent operation. |
| 52 | * |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 53 | * @param type operation type |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 54 | * @param intent intent subject |
Thomas Vachuska | 1fb982f | 2014-10-22 14:09:17 -0700 | [diff] [blame] | 55 | */ |
Brian O'Connor | cff0332 | 2015-02-03 15:28:59 -0800 | [diff] [blame] | 56 | public IntentOperation(Type type, Intent intent) { |
Sho SHIMIZU | c647b1e | 2014-12-12 15:04:55 -0800 | [diff] [blame] | 57 | this.type = checkNotNull(type); |
Thomas Vachuska | 1fb982f | 2014-10-22 14:09:17 -0700 | [diff] [blame] | 58 | this.intent = intent; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Returns the type of the operation. |
| 63 | * |
| 64 | * @return operation type |
| 65 | */ |
| 66 | public Type type() { |
| 67 | return type; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Returns the identifier of the intent to which this operation applies. |
| 72 | * |
| 73 | * @return intent identifier |
| 74 | */ |
| 75 | public IntentId intentId() { |
Brian O'Connor | cff0332 | 2015-02-03 15:28:59 -0800 | [diff] [blame] | 76 | return intent.id(); |
| 77 | } |
| 78 | |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 79 | /** |
| 80 | * Returns the key for this intent. |
| 81 | * |
| 82 | * @return key value |
| 83 | */ |
| 84 | public Key key() { |
Brian O'Connor | cff0332 | 2015-02-03 15:28:59 -0800 | [diff] [blame] | 85 | return intent.key(); |
Thomas Vachuska | 1fb982f | 2014-10-22 14:09:17 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Returns the intent to which this operation applied. For remove, |
| 90 | * this can be null. |
| 91 | * |
| 92 | * @return intent that is the subject of the operation; null for remove |
| 93 | */ |
| 94 | public Intent intent() { |
| 95 | return intent; |
| 96 | } |
| 97 | |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 98 | @Override |
| 99 | public int hashCode() { |
Brian O'Connor | cff0332 | 2015-02-03 15:28:59 -0800 | [diff] [blame] | 100 | return Objects.hash(type, intent); |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public boolean equals(Object obj) { |
| 105 | if (this == obj) { |
| 106 | return true; |
| 107 | } |
| 108 | if (obj == null || getClass() != obj.getClass()) { |
| 109 | return false; |
| 110 | } |
| 111 | final IntentOperation other = (IntentOperation) obj; |
| 112 | return Objects.equals(this.type, other.type) && |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 113 | Objects.equals(this.intent, other.intent); |
| 114 | } |
| 115 | |
| 116 | |
| 117 | @Override |
| 118 | public String toString() { |
| 119 | return toStringHelper(this) |
| 120 | .add("type", type) |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 121 | .add("intent", intent) |
| 122 | .toString(); |
| 123 | } |
Thomas Vachuska | 1fb982f | 2014-10-22 14:09:17 -0700 | [diff] [blame] | 124 | } |