blob: e36d7ec18341bd42b5b1aba4b6977bb6307250c0 [file] [log] [blame]
Yi Tsengc927a062017-05-02 15:02:37 -07001/*
2 * Copyright 2017-present 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
17package org.onosproject.net.intent;
18
19import com.google.common.collect.Lists;
20
21import java.util.List;
22import java.util.Objects;
23import java.util.Optional;
24
25/**
26 * Operation context for installable Intent.
27 *
28 * @param <T> the type of installable Intent
29 */
30public class IntentOperationContext<T extends Intent> {
31 private IntentInstallationContext intentInstallationContext;
32 private List<T> intentsToUninstall;
33 private List<T> intentsToInstall;
34
35 /**
36 * Creates an operation context.
37 *
38 * @param intentsToUninstall the Intents to uninstall
39 * @param intentsToInstall the Intents to install
40 * @param intentInstallationContext the high level Intent installation information
41 */
42 public IntentOperationContext(List<T> intentsToUninstall, List<T> intentsToInstall,
43 IntentInstallationContext intentInstallationContext) {
44 this.intentsToUninstall = Lists.newArrayList(intentsToUninstall);
45 this.intentsToInstall = Lists.newArrayList(intentsToInstall);
46 this.intentInstallationContext = intentInstallationContext;
47 }
48
49 /**
50 * Retrieves installable Intents to uninstall.
51 *
52 * @return the Intents to uninstall
53 */
54 public List<T> intentsToUninstall() {
55 return intentsToUninstall;
56 }
57
58 /**
59 * Retrieves installable Intents to install.
60 *
61 * @return the Intents to install
62 */
63 public List<T> intentsToInstall() {
64 return intentsToInstall;
65 }
66
67 /**
68 * Retrieves high level Intent installation information.
69 *
70 * @return the high level Intent installation information
71 */
72 public IntentInstallationContext intentInstallationContext() {
73 return intentInstallationContext;
74 }
75
76 /**
77 * Retrieves high level Intent data to uninstall.
78 *
79 * @return high level Intent data to uninstall
80 */
81 public Optional<IntentData> toUninstall() {
82 return intentInstallationContext.toUninstall();
83 }
84
85 /**
86 * Retrieves high level Intent data to install.
87 *
88 * @return high level Intent data to install
89 */
90 public Optional<IntentData> toInstall() {
91 return intentInstallationContext.toInstall();
92 }
93
94 @Override
95 public boolean equals(Object obj) {
96 if (this == obj) {
97 return true;
98 }
99 if (!(obj instanceof IntentOperationContext)) {
100 return false;
101 }
102
103 IntentOperationContext that = (IntentOperationContext) obj;
104 return Objects.equals(intentsToInstall, that.intentsToInstall) &&
105 Objects.equals(intentsToUninstall, that.intentsToUninstall) &&
106 Objects.equals(intentInstallationContext, intentInstallationContext);
107 }
108
109 @Override
110 public int hashCode() {
111 return Objects.hash(intentsToInstall,
112 intentsToUninstall,
113 intentInstallationContext);
114 }
115}