Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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.net; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | |
| 20 | /** |
| 21 | * Implementation of Lambda simply designated by an index number of wavelength. |
| 22 | */ |
| 23 | public class IndexedLambda implements Lambda { |
| 24 | |
Sho SHIMIZU | 2e7ac84 | 2015-05-05 15:45:38 -0700 | [diff] [blame] | 25 | private final long index; |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Creates an instance representing the wavelength specified by the given index number. |
Sho SHIMIZU | 4fea4fd | 2015-05-07 11:50:23 -0700 | [diff] [blame] | 29 | * It is recommended to use {@link Lambda#indexedLambda(long)} unless you want to use the |
| 30 | * concrete type, IndexedLambda, directly. |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 31 | * |
Sho SHIMIZU | 2e7ac84 | 2015-05-05 15:45:38 -0700 | [diff] [blame] | 32 | * @param index index number of wavelength |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 33 | */ |
Sho SHIMIZU | 4fea4fd | 2015-05-07 11:50:23 -0700 | [diff] [blame] | 34 | public IndexedLambda(long index) { |
Sho SHIMIZU | 2e7ac84 | 2015-05-05 15:45:38 -0700 | [diff] [blame] | 35 | this.index = index; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Returns the index number of lambda. |
| 40 | * |
| 41 | * @return the index number of lambda |
| 42 | */ |
| 43 | public long index() { |
| 44 | return index; |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public int hashCode() { |
Sho SHIMIZU | a5b5c3e | 2015-05-07 12:04:49 -0700 | [diff] [blame] | 49 | return Long.hashCode(index); |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public boolean equals(Object obj) { |
| 54 | if (this == obj) { |
| 55 | return true; |
| 56 | } |
| 57 | if (!(obj instanceof IndexedLambda)) { |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | final IndexedLambda that = (IndexedLambda) obj; |
Sho SHIMIZU | 2e7ac84 | 2015-05-05 15:45:38 -0700 | [diff] [blame] | 62 | return this.index == that.index; |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public String toString() { |
| 67 | return MoreObjects.toStringHelper(this) |
Sho SHIMIZU | 2e7ac84 | 2015-05-05 15:45:38 -0700 | [diff] [blame] | 68 | .add("lambda", index) |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 69 | .toString(); |
| 70 | } |
| 71 | } |