alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
alshabib | bc37196 | 2015-07-09 22:26:21 -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 | */ |
alshabib | 10c810b | 2015-08-18 16:59:04 -0700 | [diff] [blame] | 16 | package org.onosproject.net.meter; |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 17 | |
| 18 | import com.google.common.base.MoreObjects; |
alshabib | e1248b6 | 2015-08-20 17:21:55 -0700 | [diff] [blame] | 19 | import com.google.common.base.Objects; |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 20 | |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 21 | /** |
| 22 | * Representation of an operation on the meter table. |
| 23 | */ |
| 24 | public class MeterOperation { |
| 25 | |
alshabib | eadfc8e | 2015-08-18 15:40:46 -0700 | [diff] [blame] | 26 | |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 27 | /** |
| 28 | * Tyoe of meter operation. |
| 29 | */ |
| 30 | public enum Type { |
| 31 | ADD, |
| 32 | REMOVE, |
| 33 | MODIFY |
| 34 | } |
| 35 | |
| 36 | private final Meter meter; |
| 37 | private final Type type; |
| 38 | |
| 39 | |
alshabib | e1248b6 | 2015-08-20 17:21:55 -0700 | [diff] [blame] | 40 | public MeterOperation(Meter meter, Type type) { |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 41 | this.meter = meter; |
| 42 | this.type = type; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Returns the type of operation. |
| 47 | * |
| 48 | * @return type |
| 49 | */ |
| 50 | public Type type() { |
| 51 | return type; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Returns the meter. |
| 56 | * |
| 57 | * @return a meter |
| 58 | */ |
| 59 | public Meter meter() { |
| 60 | return meter; |
| 61 | } |
| 62 | |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 63 | @Override |
| 64 | public String toString() { |
| 65 | return MoreObjects.toStringHelper(this) |
| 66 | .add("meter", meter) |
| 67 | .add("type", type) |
| 68 | .toString(); |
| 69 | } |
alshabib | e1248b6 | 2015-08-20 17:21:55 -0700 | [diff] [blame] | 70 | |
| 71 | @Override |
| 72 | public boolean equals(Object o) { |
| 73 | if (this == o) { |
| 74 | return true; |
| 75 | } |
| 76 | if (o == null || getClass() != o.getClass()) { |
| 77 | return false; |
| 78 | } |
| 79 | MeterOperation that = (MeterOperation) o; |
| 80 | return Objects.equal(meter, that.meter) && |
| 81 | Objects.equal(type, that.type); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public int hashCode() { |
| 86 | return Objects.hashCode(meter, type); |
| 87 | } |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 88 | } |