blob: 5a0077b958e64d79ccef4b5ec553489c6dc6541b [file] [log] [blame]
Sho SHIMIZU91210a72015-04-29 12:54:28 -07001/*
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 */
16package org.onosproject.net;
17
18import com.google.common.base.MoreObjects;
19
20/**
21 * Implementation of Lambda simply designated by an index number of wavelength.
22 */
23public class IndexedLambda implements Lambda {
24
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -070025 private final long index;
Sho SHIMIZU91210a72015-04-29 12:54:28 -070026
27 /**
28 * Creates an instance representing the wavelength specified by the given index number.
29 *
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -070030 * @param index index number of wavelength
Sho SHIMIZU91210a72015-04-29 12:54:28 -070031 */
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -070032 IndexedLambda(long index) {
33 this.index = index;
34 }
35
36 /**
37 * Returns the index number of lambda.
38 *
39 * @return the index number of lambda
40 */
41 public long index() {
42 return index;
Sho SHIMIZU91210a72015-04-29 12:54:28 -070043 }
44
45 @Override
46 public int hashCode() {
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -070047 return (int) (index ^ (index >>> 32));
Sho SHIMIZU91210a72015-04-29 12:54:28 -070048 }
49
50 @Override
51 public boolean equals(Object obj) {
52 if (this == obj) {
53 return true;
54 }
55 if (!(obj instanceof IndexedLambda)) {
56 return false;
57 }
58
59 final IndexedLambda that = (IndexedLambda) obj;
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -070060 return this.index == that.index;
Sho SHIMIZU91210a72015-04-29 12:54:28 -070061 }
62
63 @Override
64 public String toString() {
65 return MoreObjects.toStringHelper(this)
Sho SHIMIZU2e7ac842015-05-05 15:45:38 -070066 .add("lambda", index)
Sho SHIMIZU91210a72015-04-29 12:54:28 -070067 .toString();
68 }
69}