Sho SHIMIZU
Committed by Gerrit Code Review

Populate IndexedLambda with LambdaResource

Change-Id: Id809f3a55b7c89bab2e4e99c0447ae97f27f5557
...@@ -26,10 +26,12 @@ public class IndexedLambda implements Lambda { ...@@ -26,10 +26,12 @@ public class IndexedLambda implements Lambda {
26 26
27 /** 27 /**
28 * Creates an instance representing the wavelength specified by the given index number. 28 * Creates an instance representing the wavelength specified by the given index number.
29 + * It is recommended to use {@link Lambda#indexedLambda(long)} unless you want to use the
30 + * concrete type, IndexedLambda, directly.
29 * 31 *
30 * @param index index number of wavelength 32 * @param index index number of wavelength
31 */ 33 */
32 - IndexedLambda(long index) { 34 + public IndexedLambda(long index) {
33 this.index = index; 35 this.index = index;
34 } 36 }
35 37
......
...@@ -45,13 +45,15 @@ public class OchSignal implements Lambda { ...@@ -45,13 +45,15 @@ public class OchSignal implements Lambda {
45 45
46 /** 46 /**
47 * Creates an instance with the specified arguments. 47 * Creates an instance with the specified arguments.
48 + * It it recommended to use {@link Lambda#ochSignal(GridType, ChannelSpacing, int, int)}
49 + * unless you want to use the concrete type, OchSignal, directly.
48 * 50 *
49 * @param gridType grid type 51 * @param gridType grid type
50 * @param channelSpacing channel spacing 52 * @param channelSpacing channel spacing
51 * @param spacingMultiplier channel spacing multiplier 53 * @param spacingMultiplier channel spacing multiplier
52 * @param slotGranularity slot width granularity 54 * @param slotGranularity slot width granularity
53 */ 55 */
54 - OchSignal(GridType gridType, ChannelSpacing channelSpacing, 56 + public OchSignal(GridType gridType, ChannelSpacing channelSpacing,
55 int spacingMultiplier, int slotGranularity) { 57 int spacingMultiplier, int slotGranularity) {
56 this.gridType = checkNotNull(gridType); 58 this.gridType = checkNotNull(gridType);
57 this.channelSpacing = checkNotNull(channelSpacing); 59 this.channelSpacing = checkNotNull(channelSpacing);
......
...@@ -15,36 +15,50 @@ ...@@ -15,36 +15,50 @@
15 */ 15 */
16 package org.onosproject.net.resource; 16 package org.onosproject.net.resource;
17 17
18 +import org.onosproject.net.IndexedLambda;
19 +
18 import java.util.Objects; 20 import java.util.Objects;
19 21
22 +import static com.google.common.base.Preconditions.checkNotNull;
23 +
20 /** 24 /**
21 * Representation of lambda resource. 25 * Representation of lambda resource.
22 */ 26 */
23 public final class LambdaResource extends LinkResource { 27 public final class LambdaResource extends LinkResource {
24 28
25 - private final int lambda; 29 + private final IndexedLambda lambda;
26 30
27 /** 31 /**
28 * Creates a new instance with given lambda. 32 * Creates a new instance with given lambda.
29 * 33 *
30 - * @param lambda lambda value to be assigned 34 + * @param lambda lambda to be assigned
31 */ 35 */
32 - private LambdaResource(int lambda) { 36 + private LambdaResource(IndexedLambda lambda) {
33 - this.lambda = lambda; 37 + this.lambda = checkNotNull(lambda);
34 } 38 }
35 39
36 // Constructor for serialization 40 // Constructor for serialization
37 private LambdaResource() { 41 private LambdaResource() {
38 - this.lambda = 0; 42 + this.lambda = null;
39 } 43 }
40 44
41 /** 45 /**
42 - * Creates a new instance with given lambda. 46 + * Creates a new instance with the given index of lambda.
43 * 47 *
44 - * @param lambda lambda value to be assigned 48 + * @param lambda index value of lambda to be assigned
45 - * @return {@link LambdaResource} instance with given lambda 49 + * @return {@link LambdaResource} instance with the given lambda
46 */ 50 */
47 public static LambdaResource valueOf(int lambda) { 51 public static LambdaResource valueOf(int lambda) {
52 + return valueOf(new IndexedLambda(lambda));
53 + }
54 +
55 + /**
56 + * Creates a new instance with the given lambda.
57 + *
58 + * @param lambda lambda to be assigned
59 + * @return {@link LambdaResource} instance with the given lambda
60 + */
61 + public static LambdaResource valueOf(IndexedLambda lambda) {
48 return new LambdaResource(lambda); 62 return new LambdaResource(lambda);
49 } 63 }
50 64
...@@ -54,7 +68,7 @@ public final class LambdaResource extends LinkResource { ...@@ -54,7 +68,7 @@ public final class LambdaResource extends LinkResource {
54 * @return lambda as an int value 68 * @return lambda as an int value
55 */ 69 */
56 public int toInt() { 70 public int toInt() {
57 - return lambda; 71 + return (int) lambda.index();
58 } 72 }
59 73
60 @Override 74 @Override
...@@ -68,7 +82,7 @@ public final class LambdaResource extends LinkResource { ...@@ -68,7 +82,7 @@ public final class LambdaResource extends LinkResource {
68 82
69 @Override 83 @Override
70 public int hashCode() { 84 public int hashCode() {
71 - return lambda; 85 + return lambda.hashCode();
72 } 86 }
73 87
74 @Override 88 @Override
......