blob: c73199e34435cb8f086f295995663d941bfe5f36 [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;
32
33 /**
34 * Operation type.
35 */
Brian O'Connorfa81eae2014-10-30 13:20:05 -070036 public enum Type {
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070037 /**
38 * Indicates that an intent should be added.
39 */
40 SUBMIT,
41
42 /**
43 * Indicates that an intent should be removed.
44 */
45 WITHDRAW,
46
47 /**
48 * Indicates that an intent should be replaced with another.
49 */
Brian O'Connorfa81eae2014-10-30 13:20:05 -070050 REPLACE,
51
52 /**
53 * Indicates that an intent should be updated (i.e. recompiled/reinstalled).
54 */
55 UPDATE,
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070056 }
57
58 /**
59 * Creates an intent operation.
60 *
Brian O'Connorfa81eae2014-10-30 13:20:05 -070061 * @param type operation type
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070062 * @param intentId identifier of the intent subject to the operation
Brian O'Connorfa81eae2014-10-30 13:20:05 -070063 * @param intent intent subject
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070064 */
65 IntentOperation(Type type, IntentId intentId, Intent intent) {
Sho SHIMIZUc647b1e2014-12-12 15:04:55 -080066 this.type = checkNotNull(type);
67 this.intentId = checkNotNull(intentId);
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070068 this.intent = intent;
69 }
70
71 /**
72 * Returns the type of the operation.
73 *
74 * @return operation type
75 */
76 public Type type() {
77 return type;
78 }
79
80 /**
81 * Returns the identifier of the intent to which this operation applies.
82 *
83 * @return intent identifier
84 */
85 public IntentId intentId() {
86 return intentId;
87 }
88
89 /**
90 * Returns the intent to which this operation applied. For remove,
91 * this can be null.
92 *
93 * @return intent that is the subject of the operation; null for remove
94 */
95 public Intent intent() {
96 return intent;
97 }
98
Brian O'Connorfa81eae2014-10-30 13:20:05 -070099 @Override
100 public int hashCode() {
101 return Objects.hash(type, intentId, intent);
102 }
103
104 @Override
105 public boolean equals(Object obj) {
106 if (this == obj) {
107 return true;
108 }
109 if (obj == null || getClass() != obj.getClass()) {
110 return false;
111 }
112 final IntentOperation other = (IntentOperation) obj;
113 return Objects.equals(this.type, other.type) &&
114 Objects.equals(this.intentId, other.intentId) &&
115 Objects.equals(this.intent, other.intent);
116 }
117
118
119 @Override
120 public String toString() {
121 return toStringHelper(this)
122 .add("type", type)
123 .add("intentId", intentId)
124 .add("intent", intent)
125 .toString();
126 }
Thomas Vachuska1fb982f2014-10-22 14:09:17 -0700127}