blob: 3eea0d5a68f36c018796f85e162690616f4360fc [file] [log] [blame]
Brian O'Connorcff03322015-02-03 15:28:59 -08001/*
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.net.intent;
17
18import com.google.common.collect.ImmutableList;
19import org.onosproject.store.Timestamp;
20
21import java.util.List;
22import java.util.Objects;
23
24/**
25 * A wrapper class that contains an intents, its state, and other metadata for
26 * internal use.
27 */
28public class IntentData { //FIXME need to make this "immutable"
29 // manager should be able to mutate a local copy while processing
30 private Intent intent;
31
32 private IntentState state;
33 private Timestamp version;
34
35 private List<Intent> installables;
36
37 public IntentData(Intent intent, IntentState state, Timestamp version) {
38 this.intent = intent;
39 this.state = state;
40 this.version = version;
41 }
42
43 // kryo constructor
44 protected IntentData() {
45 }
46
47 public Intent intent() {
48 return intent;
49 }
50
51 public IntentState state() {
52 return state;
53 }
54
Ray Milkey5b3717e2015-02-05 11:44:08 -080055 public Key key() {
Brian O'Connorcff03322015-02-03 15:28:59 -080056 return intent.key();
57 }
58
59 public void setState(IntentState newState) {
60 this.state = newState;
61 }
62
63 public void setInstallables(List<Intent> installables) {
64 this.installables = ImmutableList.copyOf(installables);
65 }
66
67 public List<Intent> installables() {
68 return installables;
69 }
70
71 @Override
72 public int hashCode() {
73 return Objects.hash(intent, version);
74 }
75
76 @Override
77 public boolean equals(Object obj) {
78 if (this == obj) {
79 return true;
80 }
81 if (obj == null || getClass() != obj.getClass()) {
82 return false;
83 }
84 final IntentData other = (IntentData) obj;
85 return Objects.equals(this.intent, other.intent)
86 && Objects.equals(this.version, other.version);
87 }
88}