blob: 06582497c0ba54fe012fa85e41aaf34b8b9d5d4e [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
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'Connor6de2e202015-05-21 14:30:41 -070016package org.onosproject.net.resource.link;
Toshio Koidec9051db2014-10-20 15:18:37 -070017
Sho SHIMIZU4fea4fd2015-05-07 11:50:23 -070018import org.onosproject.net.IndexedLambda;
19
Toshio Koidec9051db2014-10-20 15:18:37 -070020import java.util.Objects;
21
Sho SHIMIZU4fea4fd2015-05-07 11:50:23 -070022import static com.google.common.base.Preconditions.checkNotNull;
23
Toshio Koidec9051db2014-10-20 15:18:37 -070024/**
25 * Representation of lambda resource.
Sho SHIMIZU364cbac2015-10-29 15:47:35 -070026 *
27 * @deprecated in Emu Release
Toshio Koidec9051db2014-10-20 15:18:37 -070028 */
Sho SHIMIZU364cbac2015-10-29 15:47:35 -070029@Deprecated
Sho SHIMIZU1c221ad2015-07-02 10:08:08 -070030public final class LambdaResource implements LinkResource {
Toshio Koidec9051db2014-10-20 15:18:37 -070031
Sho SHIMIZU4fea4fd2015-05-07 11:50:23 -070032 private final IndexedLambda lambda;
Toshio Koidec9051db2014-10-20 15:18:37 -070033
34 /**
35 * Creates a new instance with given lambda.
36 *
Sho SHIMIZU4fea4fd2015-05-07 11:50:23 -070037 * @param lambda lambda to be assigned
Toshio Koidec9051db2014-10-20 15:18:37 -070038 */
Sho SHIMIZU4fea4fd2015-05-07 11:50:23 -070039 private LambdaResource(IndexedLambda lambda) {
40 this.lambda = checkNotNull(lambda);
Toshio Koidec9051db2014-10-20 15:18:37 -070041 }
42
Thomas Vachuska7d0032b2014-11-04 17:39:57 -080043 // Constructor for serialization
Sho SHIMIZU94b7ff42015-05-06 17:51:49 -070044 private LambdaResource() {
Sho SHIMIZU4fea4fd2015-05-07 11:50:23 -070045 this.lambda = null;
Thomas Vachuska7d0032b2014-11-04 17:39:57 -080046 }
47
Toshio Koidec9051db2014-10-20 15:18:37 -070048 /**
Sho SHIMIZU4fea4fd2015-05-07 11:50:23 -070049 * Creates a new instance with the given index of lambda.
Toshio Koidec9051db2014-10-20 15:18:37 -070050 *
Sho SHIMIZU4fea4fd2015-05-07 11:50:23 -070051 * @param lambda index value of lambda to be assigned
52 * @return {@link LambdaResource} instance with the given lambda
Toshio Koidec9051db2014-10-20 15:18:37 -070053 */
Sho SHIMIZU94b7ff42015-05-06 17:51:49 -070054 public static LambdaResource valueOf(int lambda) {
Sho SHIMIZU4fea4fd2015-05-07 11:50:23 -070055 return valueOf(new IndexedLambda(lambda));
56 }
57
58 /**
59 * Creates a new instance with the given lambda.
60 *
61 * @param lambda lambda to be assigned
62 * @return {@link LambdaResource} instance with the given lambda
63 */
64 public static LambdaResource valueOf(IndexedLambda lambda) {
Sho SHIMIZU94b7ff42015-05-06 17:51:49 -070065 return new LambdaResource(lambda);
Toshio Koidec9051db2014-10-20 15:18:37 -070066 }
67
68 /**
69 * Returns lambda as an int value.
Toshio Koide485b4782014-10-20 19:34:21 -070070 *
Toshio Koidec9051db2014-10-20 15:18:37 -070071 * @return lambda as an int value
72 */
73 public int toInt() {
Sho SHIMIZU4fea4fd2015-05-07 11:50:23 -070074 return (int) lambda.index();
Toshio Koidec9051db2014-10-20 15:18:37 -070075 }
76
77 @Override
78 public boolean equals(Object obj) {
Sho SHIMIZU94b7ff42015-05-06 17:51:49 -070079 if (obj instanceof LambdaResource) {
80 LambdaResource that = (LambdaResource) obj;
Toshio Koidec9051db2014-10-20 15:18:37 -070081 return Objects.equals(this.lambda, that.lambda);
82 }
83 return false;
84 }
85
86 @Override
87 public int hashCode() {
Sho SHIMIZU4fea4fd2015-05-07 11:50:23 -070088 return lambda.hashCode();
Toshio Koidec9051db2014-10-20 15:18:37 -070089 }
90
91 @Override
92 public String toString() {
93 return String.valueOf(this.lambda);
94 }
95
96}