Sho SHIMIZU
Committed by Gerrit Code Review

Populate IndexedLambda with LambdaResource

Change-Id: Id809f3a55b7c89bab2e4e99c0447ae97f27f5557
......@@ -26,10 +26,12 @@ public class IndexedLambda implements Lambda {
/**
* 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;
}
......
......@@ -45,13 +45,15 @@ public class OchSignal implements Lambda {
/**
* 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);
......
......@@ -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 @@ public final class LambdaResource extends LinkResource {
* @return lambda as an int value
*/
public int toInt() {
return lambda;
return (int) lambda.index();
}
@Override
......@@ -68,7 +82,7 @@ public final class LambdaResource extends LinkResource {
@Override
public int hashCode() {
return lambda;
return lambda.hashCode();
}
@Override
......