Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.resource; |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 17 | |
| 18 | import java.util.Objects; |
| 19 | |
| 20 | /** |
| 21 | * Representation of lambda resource. |
| 22 | */ |
| 23 | public final class Lambda extends LinkResource { |
| 24 | |
| 25 | private final int lambda; |
| 26 | |
| 27 | /** |
| 28 | * Creates a new instance with given lambda. |
| 29 | * |
| 30 | * @param lambda lambda value to be assigned |
| 31 | */ |
| 32 | private Lambda(int lambda) { |
| 33 | this.lambda = lambda; |
| 34 | } |
| 35 | |
Thomas Vachuska | 7d0032b | 2014-11-04 17:39:57 -0800 | [diff] [blame] | 36 | // Constructor for serialization |
| 37 | private Lambda() { |
| 38 | this.lambda = 0; |
| 39 | } |
| 40 | |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 41 | /** |
| 42 | * Creates a new instance with given lambda. |
| 43 | * |
| 44 | * @param lambda lambda value to be assigned |
| 45 | * @return {@link Lambda} instance with given lambda |
| 46 | */ |
| 47 | public static Lambda valueOf(int lambda) { |
| 48 | return new Lambda(lambda); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Returns lambda as an int value. |
Toshio Koide | 485b478 | 2014-10-20 19:34:21 -0700 | [diff] [blame] | 53 | * |
Toshio Koide | c9051db | 2014-10-20 15:18:37 -0700 | [diff] [blame] | 54 | * @return lambda as an int value |
| 55 | */ |
| 56 | public int toInt() { |
| 57 | return lambda; |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public boolean equals(Object obj) { |
| 62 | if (obj instanceof Lambda) { |
| 63 | Lambda that = (Lambda) obj; |
| 64 | return Objects.equals(this.lambda, that.lambda); |
| 65 | } |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public int hashCode() { |
| 71 | return Objects.hashCode(this.lambda); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public String toString() { |
| 76 | return String.valueOf(this.lambda); |
| 77 | } |
| 78 | |
| 79 | } |