Populate IndexedLambda with LambdaResource
Change-Id: Id809f3a55b7c89bab2e4e99c0447ae97f27f5557
diff --git a/core/api/src/main/java/org/onosproject/net/IndexedLambda.java b/core/api/src/main/java/org/onosproject/net/IndexedLambda.java
index cb7e1ae..6b5fa65 100644
--- a/core/api/src/main/java/org/onosproject/net/IndexedLambda.java
+++ b/core/api/src/main/java/org/onosproject/net/IndexedLambda.java
@@ -26,10 +26,12 @@
/**
* Creates an instance representing the wavelength specified by the given index number.
+ * It is recommended to use {@link Lambda#indexedLambda(long)} unless you want to use the
+ * concrete type, IndexedLambda, directly.
*
* @param index index number of wavelength
*/
- IndexedLambda(long index) {
+ public IndexedLambda(long index) {
this.index = index;
}
diff --git a/core/api/src/main/java/org/onosproject/net/OchSignal.java b/core/api/src/main/java/org/onosproject/net/OchSignal.java
index 3f6c14f..e629b5e 100644
--- a/core/api/src/main/java/org/onosproject/net/OchSignal.java
+++ b/core/api/src/main/java/org/onosproject/net/OchSignal.java
@@ -45,13 +45,15 @@
/**
* Creates an instance with the specified arguments.
+ * It it recommended to use {@link Lambda#ochSignal(GridType, ChannelSpacing, int, int)}
+ * unless you want to use the concrete type, OchSignal, directly.
*
* @param gridType grid type
* @param channelSpacing channel spacing
* @param spacingMultiplier channel spacing multiplier
* @param slotGranularity slot width granularity
*/
- OchSignal(GridType gridType, ChannelSpacing channelSpacing,
+ public OchSignal(GridType gridType, ChannelSpacing channelSpacing,
int spacingMultiplier, int slotGranularity) {
this.gridType = checkNotNull(gridType);
this.channelSpacing = checkNotNull(channelSpacing);
diff --git a/core/api/src/main/java/org/onosproject/net/resource/LambdaResource.java b/core/api/src/main/java/org/onosproject/net/resource/LambdaResource.java
index aa14f70..e4df34e 100644
--- a/core/api/src/main/java/org/onosproject/net/resource/LambdaResource.java
+++ b/core/api/src/main/java/org/onosproject/net/resource/LambdaResource.java
@@ -15,36 +15,50 @@
*/
package org.onosproject.net.resource;
+import org.onosproject.net.IndexedLambda;
+
import java.util.Objects;
+import static com.google.common.base.Preconditions.checkNotNull;
+
/**
* Representation of lambda resource.
*/
public final class LambdaResource extends LinkResource {
- private final int lambda;
+ private final IndexedLambda lambda;
/**
* Creates a new instance with given lambda.
*
- * @param lambda lambda value to be assigned
+ * @param lambda lambda to be assigned
*/
- private LambdaResource(int lambda) {
- this.lambda = lambda;
+ private LambdaResource(IndexedLambda lambda) {
+ this.lambda = checkNotNull(lambda);
}
// Constructor for serialization
private LambdaResource() {
- this.lambda = 0;
+ this.lambda = null;
}
/**
- * Creates a new instance with given lambda.
+ * Creates a new instance with the given index of lambda.
*
- * @param lambda lambda value to be assigned
- * @return {@link LambdaResource} instance with given lambda
+ * @param lambda index value of lambda to be assigned
+ * @return {@link LambdaResource} instance with the given lambda
*/
public static LambdaResource valueOf(int lambda) {
+ return valueOf(new IndexedLambda(lambda));
+ }
+
+ /**
+ * Creates a new instance with the given lambda.
+ *
+ * @param lambda lambda to be assigned
+ * @return {@link LambdaResource} instance with the given lambda
+ */
+ public static LambdaResource valueOf(IndexedLambda lambda) {
return new LambdaResource(lambda);
}
@@ -54,7 +68,7 @@
* @return lambda as an int value
*/
public int toInt() {
- return lambda;
+ return (int) lambda.index();
}
@Override
@@ -68,7 +82,7 @@
@Override
public int hashCode() {
- return lambda;
+ return lambda.hashCode();
}
@Override