161cf45515be3d1d359315205b58113a914253ac
[onosfw.git] /
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  */
16 package org.onosproject.net.resource.link;
17
18 import com.google.common.base.MoreObjects;
19 import org.onosproject.net.resource.ResourceAllocation;
20 import org.onosproject.net.resource.ResourceType;
21
22 import java.util.Objects;
23
24 /**
25  * Representation of allocated lambda resource.
26  */
27 public class LambdaResourceAllocation implements ResourceAllocation {
28     private final LambdaResource lambda;
29
30     @Override
31     public ResourceType type() {
32         return ResourceType.LAMBDA;
33     }
34
35     /**
36      * Creates a new {@link LambdaResourceAllocation} with {@link LambdaResource}
37      * object.
38      *
39      * @param lambda allocated lambda
40      */
41     public LambdaResourceAllocation(LambdaResource lambda) {
42         this.lambda = lambda;
43     }
44
45     /**
46      * Returns the lambda resource.
47      *
48      * @return the lambda resource
49      */
50     public LambdaResource lambda() {
51         return lambda;
52     }
53
54     @Override
55     public int hashCode() {
56         return Objects.hashCode(lambda);
57     }
58
59     @Override
60     public boolean equals(Object obj) {
61         if (this == obj) {
62             return true;
63         }
64         if (obj == null || getClass() != obj.getClass()) {
65             return false;
66         }
67         final LambdaResourceAllocation other = (LambdaResourceAllocation) obj;
68         return Objects.equals(this.lambda, other.lambda);
69     }
70
71     @Override
72     public String toString() {
73         return MoreObjects.toStringHelper(this)
74                 .add("lambda", lambda)
75                 .toString();
76     }
77 }