Sho SHIMIZU
Committed by Sho Shimizu

Move inner classes to upper level

Rename as follows.
- ResourceId.Discrete -> DiscreteResourceId
- ResourceId.Continuous -> ContinuousResourceId
- Resource.Discrete -> DiscreteResource
- Resource.Continuous -> ContinuousResource

Change-Id: I80e59d1eec07128743bacc582a8725bd4d5489b4
......@@ -34,6 +34,7 @@ import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.TributarySlot;
import org.onosproject.net.newresource.ContinuousResource;
import org.onosproject.net.newresource.Resource;
import org.onosproject.net.newresource.ResourceService;
......@@ -112,10 +113,10 @@ public class ResourcesCommand extends AbstractShellCommand {
return;
}
if (resource instanceof Resource.Continuous) {
if (resource instanceof ContinuousResource) {
print("%s%s: %f", Strings.repeat(" ", level),
resource.last(),
((Resource.Continuous) resource).value());
((ContinuousResource) resource).value());
// Continuous resource is terminal node, stop here
return;
} else {
......@@ -144,7 +145,7 @@ public class ResourcesCommand extends AbstractShellCommand {
List<Resource> nonAggregatable = new ArrayList<>();
for (Resource r : children) {
if (r instanceof Resource.Continuous) {
if (r instanceof ContinuousResource) {
// non-aggregatable terminal node
nonAggregatable.add(r);
} else if (aggregatableTypes.contains(r.last().getClass())) {
......
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.newresource;
import com.google.common.annotations.Beta;
import java.util.Objects;
/**
* Represents a resource path which specifies a resource which can be measured
* as continuous value. Bandwidth of a link is an example of the resource.
* <p>
* Note: This class is exposed to the public, but intended to be used in the resource API
* implementation only. It is not for resource API user.
*/
@Beta
// TODO: consider how to restrict the visibility
public final class ContinuousResource extends Resource {
private final double value;
ContinuousResource(ResourceId id, double value) {
super(id);
this.value = value;
}
/**
* The user of this methods must receive the return value as Double or double.
* Otherwise, this methods throws an exception.
*
* @param <T> type of the return value
* @return the volume of this resource
*/
@SuppressWarnings("unchecked")
@Override
public <T> T volume() {
return (T) Double.valueOf(value);
}
@Override
public int hashCode() {
return Objects.hash(id(), value);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final ContinuousResource other = (ContinuousResource) obj;
return Objects.equals(this.id(), other.id())
&& Objects.equals(this.value, other.value);
}
/**
* Returns the value of the resource amount.
*
* @return the value of the resource amount
*/
// FIXME: overlapping a purpose with volume()
public double value() {
return value;
}
}
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.newresource;
import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableList;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* ResourceId for {@link ContinuousResource}
*
* Note: This class is exposed to the public, but intended to be used in the resource API
* implementation only. It is not for resource API user.
*/
@Beta
// TODO: consider how to restrict the visibility
public final class ContinuousResourceId extends ResourceId {
// for printing purpose only (used in toString() implementation)
private final String name;
ContinuousResourceId(ImmutableList<Object> components, String name) {
super(components);
this.name = checkNotNull(name);
}
@Override
public String toString() {
// due to performance consideration, the value might need to be stored in a field
return ImmutableList.builder()
.addAll(components.subList(0, components.size() - 1))
.add(name)
.build().toString();
}
}
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.newresource;
import com.google.common.annotations.Beta;
import java.util.Objects;
/**
* Represents a resource path which specifies a resource which can be measured
* as a discrete unit. A VLAN ID and a MPLS label of a link are examples of the resource.
* <p>
* Note: This class is exposed to the public, but intended to be used in the resource API
* implementation only. It is not for resource API user.
* </p>
*/
@Beta
// TODO: consider how to restrict the visibility
public final class DiscreteResource extends Resource {
protected DiscreteResource() {
super();
}
DiscreteResource(ResourceId id) {
super(id);
}
/**
* The user of this methods must receive the return value as the correct type.
* Otherwise, this methods throws an exception.
*
* @param <T> type of the return value
* @return the volume of this resource
*/
@SuppressWarnings("unchecked")
@Override
// TODO: consider receiving Class<T> as an argument. Which approach is convenient?
public <T> T volume() {
return (T) last();
}
@Override
public int hashCode() {
// the value returing from volume() is excluded due to optimization
return id().hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final DiscreteResource other = (DiscreteResource) obj;
// the value returing from volume() is excluded due to optimization
return Objects.equals(this.id(), other.id());
}
}
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.newresource;
import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableList;
/**
* ResourceId for {@link DiscreteResource}.
*
* Note: This class is exposed to the public, but intended to be used in the resource API
* implementation only. It is not for resource API user.
*/
@Beta
// TODO: consider how to restrict the visibility
public final class DiscreteResourceId extends ResourceId {
DiscreteResourceId(ImmutableList<Object> components) {
super(components);
}
DiscreteResourceId() {
super();
}
}
......@@ -21,7 +21,6 @@ import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.Preconditions.checkArgument;
......@@ -47,13 +46,13 @@ import static com.google.common.base.Preconditions.checkState;
@Beta
public abstract class Resource {
private final Discrete parent;
private final DiscreteResource parent;
private final ResourceId id;
public static final Discrete ROOT = new Discrete();
public static final DiscreteResource ROOT = new DiscreteResource();
public static Resource discrete(DeviceId device) {
return new Discrete(ResourceId.discrete(device));
return new DiscreteResource(ResourceId.discrete(device));
}
/**
......@@ -64,7 +63,7 @@ public abstract class Resource {
* @return resource path instance
*/
public static Resource discrete(DeviceId device, Object... components) {
return new Discrete(ResourceId.discrete(device, components));
return new DiscreteResource(ResourceId.discrete(device, components));
}
/**
......@@ -76,7 +75,7 @@ public abstract class Resource {
* @return resource path instance
*/
public static Resource discrete(DeviceId device, PortNumber port, Object... components) {
return new Discrete(ResourceId.discrete(device, port, components));
return new DiscreteResource(ResourceId.discrete(device, port, components));
}
/**
......@@ -93,7 +92,7 @@ public abstract class Resource {
checkArgument(components.length > 0,
"Length of components must be greater thant 0, but " + components.length);
return new Continuous(ResourceId.continuous(device, components), value);
return new ContinuousResource(ResourceId.continuous(device, components), value);
}
/**
......@@ -108,7 +107,7 @@ public abstract class Resource {
* @return resource path instance
*/
public static Resource continuous(double value, DeviceId device, PortNumber port, Object... components) {
return new Continuous(ResourceId.continuous(device, port, components), value);
return new ContinuousResource(ResourceId.continuous(device, port, components), value);
}
/**
......@@ -123,12 +122,12 @@ public abstract class Resource {
if (id.components.size() == 1) {
this.parent = ROOT;
} else {
this.parent = new Discrete(id.parent());
this.parent = new DiscreteResource(id.parent());
}
}
// for serialization
private Resource() {
protected Resource() {
this.parent = null;
this.id = ResourceId.ROOT;
}
......@@ -157,7 +156,7 @@ public abstract class Resource {
* @return the parent resource path of this instance.
* If there is no parent, empty instance will be returned.
*/
public Optional<Discrete> parent() {
public Optional<DiscreteResource> parent() {
return Optional.ofNullable(parent);
}
......@@ -169,9 +168,9 @@ public abstract class Resource {
* @return a child resource path
*/
public Resource child(Object child) {
checkState(this instanceof Discrete);
checkState(this instanceof DiscreteResource);
return new Discrete(id().child(child));
return new DiscreteResource(id().child(child));
}
/**
......@@ -183,9 +182,9 @@ public abstract class Resource {
* @return a child resource path
*/
public Resource child(Object child, double value) {
checkState(this instanceof Discrete);
checkState(this instanceof DiscreteResource);
return new Continuous(id.child(child), value);
return new ContinuousResource(id.child(child), value);
}
/**
......@@ -218,114 +217,4 @@ public abstract class Resource {
.toString();
}
/**
* Represents a resource path which specifies a resource which can be measured
* as a discrete unit. A VLAN ID and a MPLS label of a link are examples of the resource.
* <p>
* Note: This class is exposed to the public, but intended to be used in the resource API
* implementation only. It is not for resource API user.
* </p>
*/
@Beta
public static final class Discrete extends Resource {
private Discrete() {
super();
}
private Discrete(ResourceId id) {
super(id);
}
/**
* The user of this methods must receive the return value as the correct type.
* Otherwise, this methods throws an exception.
*
* @param <T> type of the return value
* @return the volume of this resource
*/
@SuppressWarnings("unchecked")
@Override
// TODO: consider receiving Class<T> as an argument. Which approach is convenient?
public <T> T volume() {
return (T) last();
}
@Override
public int hashCode() {
// the value returing from volume() is excluded due to optimization
return id().hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final Discrete other = (Discrete) obj;
// the value returing from volume() is excluded due to optimization
return Objects.equals(this.id(), other.id());
}
}
/**
* Represents a resource path which specifies a resource which can be measured
* as continuous value. Bandwidth of a link is an example of the resource.
* <p>
* Note: This class is exposed to the public, but intended to be used in the resource API
* implementation only. It is not for resource API user.
*/
@Beta
public static final class Continuous extends Resource {
private final double value;
private Continuous(ResourceId id, double value) {
super(id);
this.value = value;
}
/**
* The user of this methods must receive the return value as Double or double.
* Otherwise, this methods throws an exception.
*
* @param <T> type of the return value
* @return the volume of this resource
*/
@SuppressWarnings("unchecked")
@Override
public <T> T volume() {
return (T) Double.valueOf(value);
}
@Override
public int hashCode() {
return Objects.hash(id(), value);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final Continuous other = (Continuous) obj;
return Objects.equals(this.id(), other.id())
&& Objects.equals(this.value, other.value);
}
/**
* Returns the value of the resource amount.
*
* @return the value of the resource amount
*/
// FIXME: overlapping a purpose with volume()
public double value() {
return value;
}
}
}
......
......@@ -33,19 +33,19 @@ import static com.google.common.base.Preconditions.checkState;
*/
@Beta
public abstract class ResourceId {
static final ResourceId ROOT = new Discrete();
static final ResourceId ROOT = new DiscreteResourceId();
final ImmutableList<Object> components;
static ResourceId discrete(DeviceId device, Object... components) {
return new Discrete(ImmutableList.builder()
return new DiscreteResourceId(ImmutableList.builder()
.add(device)
.add(components)
.build());
}
static ResourceId discrete(DeviceId device, PortNumber port, Object... components) {
return new Discrete(ImmutableList.builder()
return new DiscreteResourceId(ImmutableList.builder()
.add(device)
.add(port)
.add(components)
......@@ -72,17 +72,17 @@ public abstract class ResourceId {
}
private static ResourceId continuous(ImmutableList.Builder<Object> parentComponents, Class<?> last) {
return new Continuous(parentComponents
return new ContinuousResourceId(parentComponents
.add(last.getCanonicalName())
.build(), last.getSimpleName());
}
private ResourceId(ImmutableList<Object> components) {
protected ResourceId(ImmutableList<Object> components) {
this.components = checkNotNull(components);
}
// for serializer
private ResourceId() {
protected ResourceId() {
this.components = ImmutableList.of();
}
......@@ -91,27 +91,27 @@ public abstract class ResourceId {
if (components.size() == 1) {
return ROOT;
} else {
return new Discrete(components.subList(0, components.size() - 1));
return new DiscreteResourceId(components.subList(0, components.size() - 1));
}
}
/**
* Returns a resource ID of a child of this resource based on the specified object.
* If the argument is an instance of {@link Class}, this method returns an instance of
* {@link Continuous}. Otherwise, it returns an instance of {@link Discrete}
* This method only work when the receiver is {@link Discrete}. Otherwise,
* {@link ContinuousResourceId}. Otherwise, it returns an instance of {@link DiscreteResourceId}
* This method only work when the receiver is {@link DiscreteResourceId}. Otherwise,
* this method throws an exception.
*
* @param child the last component of the child
* @return a child resource ID
*/
public ResourceId child(Object child) {
checkState(this instanceof Discrete);
checkState(this instanceof DiscreteResourceId);
if (child instanceof Class<?>) {
return continuous(ImmutableList.builder().addAll(components), (Class<?>) child);
} else {
return new Discrete(ImmutableList.builder()
return new DiscreteResourceId(ImmutableList.builder()
.addAll(components)
.add(child)
.build());
......@@ -140,44 +140,4 @@ public abstract class ResourceId {
return components.toString();
}
/**
* ResourceId for {@link Resource.Discrete}.
*
* Note: This class is exposed to the public, but intended to be used in the resource API
* implementation only. It is not for resource API user.
*/
public static final class Discrete extends ResourceId {
private Discrete(ImmutableList<Object> components) {
super(components);
}
private Discrete() {
super();
}
}
/**
* ResourceId for {@link Resource.Continuous}
*
* Note: This class is exposed to the public, but intended to be used in the resource API
* implementation only. It is not for resource API user.
*/
public static final class Continuous extends ResourceId {
// for printing purpose only (used in toString() implementation)
private final String name;
private Continuous(ImmutableList<Object> components, String name) {
super(components);
this.name = checkNotNull(name);
}
@Override
public String toString() {
// due to performance consideration, the value might need to be stored in a field
return ImmutableList.builder()
.addAll(components.subList(0, components.size() - 1))
.add(name)
.build().toString();
}
}
}
......
......@@ -172,6 +172,10 @@ import org.onosproject.net.intent.constraint.PartialFailureConstraint;
import org.onosproject.net.intent.constraint.WaypointConstraint;
import org.onosproject.net.link.DefaultLinkDescription;
import org.onosproject.net.meter.MeterId;
import org.onosproject.net.newresource.ContinuousResource;
import org.onosproject.net.newresource.ContinuousResourceId;
import org.onosproject.net.newresource.DiscreteResource;
import org.onosproject.net.newresource.DiscreteResourceId;
import org.onosproject.net.newresource.ResourceAllocation;
import org.onosproject.net.newresource.ResourceId;
import org.onosproject.net.newresource.Resource;
......@@ -434,11 +438,11 @@ public final class KryoNamespaces {
BandwidthResourceAllocation.class,
LambdaResourceAllocation.class,
Resource.class,
Resource.Discrete.class,
Resource.Continuous.class,
DiscreteResource.class,
ContinuousResource.class,
ResourceId.class,
ResourceId.Discrete.class,
ResourceId.Continuous.class,
DiscreteResourceId.class,
ContinuousResourceId.class,
ResourceAllocation.class,
// Constraints
LambdaConstraint.class,
......