blob: afb0010f8bb1b05f77438e0cdab8079cf11e2fa9 [file] [log] [blame]
Thomas Vachuska1fb982f2014-10-22 14:09:17 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska1fb982f2014-10-22 14:09:17 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska1fb982f2014-10-22 14:09:17 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska1fb982f2014-10-22 14:09:17 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent;
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070017
Brian O'Connorfa81eae2014-10-30 13:20:05 -070018
19import java.util.Objects;
20
21import static com.google.common.base.MoreObjects.toStringHelper;
Sho SHIMIZUc647b1e2014-12-12 15:04:55 -080022import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorfa81eae2014-10-30 13:20:05 -070023
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070024/**
25 * Abstraction of an intent-related operation, e.g. add, remove, replace.
26 */
Ray Milkeyc8f481f2014-11-18 15:37:12 -080027public final class IntentOperation {
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070028
29 private final Type type;
30 private final IntentId intentId;
31 private final Intent intent;
Brian O'Connorea4d7d12015-01-28 16:37:46 -080032 //FIXME consider pulling the key out (we will hash based on key)
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070033
34 /**
35 * Operation type.
36 */
Brian O'Connorfa81eae2014-10-30 13:20:05 -070037 public enum Type {
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070038 /**
39 * Indicates that an intent should be added.
40 */
41 SUBMIT,
42
43 /**
44 * Indicates that an intent should be removed.
45 */
46 WITHDRAW,
47
48 /**
49 * Indicates that an intent should be replaced with another.
50 */
Brian O'Connorea4d7d12015-01-28 16:37:46 -080051 @Deprecated
Brian O'Connorfa81eae2014-10-30 13:20:05 -070052 REPLACE,
53
54 /**
55 * Indicates that an intent should be updated (i.e. recompiled/reinstalled).
56 */
Brian O'Connorea4d7d12015-01-28 16:37:46 -080057 @Deprecated
Brian O'Connorfa81eae2014-10-30 13:20:05 -070058 UPDATE,
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070059 }
60
61 /**
62 * Creates an intent operation.
63 *
Brian O'Connorfa81eae2014-10-30 13:20:05 -070064 * @param type operation type
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070065 * @param intentId identifier of the intent subject to the operation
Brian O'Connorfa81eae2014-10-30 13:20:05 -070066 * @param intent intent subject
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070067 */
68 IntentOperation(Type type, IntentId intentId, Intent intent) {
Sho SHIMIZUc647b1e2014-12-12 15:04:55 -080069 this.type = checkNotNull(type);
70 this.intentId = checkNotNull(intentId);
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070071 this.intent = intent;
72 }
73
74 /**
75 * Returns the type of the operation.
76 *
77 * @return operation type
78 */
79 public Type type() {
80 return type;
81 }
82
83 /**
84 * Returns the identifier of the intent to which this operation applies.
85 *
86 * @return intent identifier
87 */
88 public IntentId intentId() {
89 return intentId;
90 }
91
92 /**
93 * Returns the intent to which this operation applied. For remove,
94 * this can be null.
95 *
96 * @return intent that is the subject of the operation; null for remove
97 */
98 public Intent intent() {
99 return intent;
100 }
101
Brian O'Connorfa81eae2014-10-30 13:20:05 -0700102 @Override
103 public int hashCode() {
104 return Objects.hash(type, intentId, intent);
105 }
106
107 @Override
108 public boolean equals(Object obj) {
109 if (this == obj) {
110 return true;
111 }
112 if (obj == null || getClass() != obj.getClass()) {
113 return false;
114 }
115 final IntentOperation other = (IntentOperation) obj;
116 return Objects.equals(this.type, other.type) &&
117 Objects.equals(this.intentId, other.intentId) &&
118 Objects.equals(this.intent, other.intent);
119 }
120
121
122 @Override
123 public String toString() {
124 return toStringHelper(this)
125 .add("type", type)
126 .add("intentId", intentId)
127 .add("intent", intent)
128 .toString();
129 }
Thomas Vachuska1fb982f2014-10-22 14:09:17 -0700130}