Shashikanth VH | 8b1a5ef | 2016-12-26 14:37:43 +0530 | [diff] [blame] | 1 | /* |
| 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 | package org.onosproject.flowapi; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | |
| 20 | import java.util.ArrayList; |
| 21 | import java.util.List; |
| 22 | import java.util.Objects; |
| 23 | |
| 24 | /** |
| 25 | * Representation of Multi value flow container having custom rules. |
| 26 | */ |
| 27 | public final class ExtFlowContainer { |
| 28 | |
| 29 | private List<ExtFlowTypes> container = new ArrayList<>(); |
| 30 | private String deviceId; |
| 31 | |
| 32 | /** |
| 33 | * Creates an object of type ExtFlowContainer. |
| 34 | * |
| 35 | * @param container flow container |
| 36 | */ |
| 37 | public ExtFlowContainer(List<ExtFlowTypes> container) { |
| 38 | this.container = container; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Returns the ExtFlowContainer by setting its value. |
| 43 | * |
| 44 | * @param container flow container |
| 45 | * @return object of ExtFlowContainer |
| 46 | */ |
| 47 | public static ExtFlowContainer of(List<ExtFlowTypes> container) { |
| 48 | return new ExtFlowContainer(container); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Returns the list of ExtFlowTypes value. |
| 53 | * |
| 54 | * @return list of ExtFlowTypes |
| 55 | */ |
| 56 | public List<ExtFlowTypes> container() { |
| 57 | return container; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Returns the device Id. |
| 62 | * |
| 63 | * @return deviceId |
| 64 | */ |
| 65 | public String deviceId() { |
| 66 | return deviceId; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Adds the flow type to the container list. |
| 71 | * |
| 72 | * @param obj of ExtFlowTypes type |
| 73 | */ |
| 74 | public void add(ExtFlowTypes obj) { |
| 75 | container.add(obj); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Removes the flow type from the container list. |
| 80 | * |
| 81 | * @param obj of ExtFlowTypes type |
| 82 | */ |
| 83 | public void remove(ExtFlowTypes obj) { |
| 84 | container.remove(obj); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Sets the device Id to this container. |
| 89 | * |
| 90 | * @param deviceId to be set to this container |
| 91 | */ |
| 92 | public void setDeviceId(String deviceId) { |
| 93 | this.deviceId = deviceId; |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public int hashCode() { |
| 98 | return Objects.hash(container); |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public boolean equals(Object obj) { |
| 103 | if (this == obj) { |
| 104 | return true; |
| 105 | } |
| 106 | if (!(obj instanceof ExtFlowContainer)) { |
| 107 | return false; |
| 108 | } |
| 109 | final ExtFlowContainer other = (ExtFlowContainer) obj; |
| 110 | return Objects.equals(this.container, other.container) |
| 111 | && Objects.equals(this.deviceId, other.deviceId); |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public String toString() { |
| 116 | return MoreObjects.toStringHelper(this) |
| 117 | .add("container", container) |
| 118 | .add("deviceId", deviceId) |
| 119 | .toString(); |
| 120 | } |
| 121 | } |