Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.net.intent; |
| 18 | |
| 19 | import com.google.common.collect.Lists; |
| 20 | |
| 21 | import java.util.List; |
| 22 | import java.util.Objects; |
| 23 | import java.util.Optional; |
| 24 | |
| 25 | /** |
| 26 | * Operation context for installable Intent. |
| 27 | * |
| 28 | * @param <T> the type of installable Intent |
| 29 | */ |
| 30 | public 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) && |
Yuta HIGUCHI | fbd9ae9 | 2018-01-24 23:39:06 -0800 | [diff] [blame] | 106 | Objects.equals(intentInstallationContext, that.intentInstallationContext); |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public int hashCode() { |
| 111 | return Objects.hash(intentsToInstall, |
| 112 | intentsToUninstall, |
| 113 | intentInstallationContext); |
| 114 | } |
| 115 | } |