ONOS-2297: Decouple ResourceRequest and ResourceAllocation
Note: This change may break backward compatibility for those defining a
sub-class of ResourceAllocation
Change-Id: I01807b4ebb0f9af8fa822828953965b5119975d7
diff --git a/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceAllocation.java b/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceAllocation.java
index de2f52f..74f6e10 100644
--- a/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceAllocation.java
+++ b/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceAllocation.java
@@ -19,31 +19,59 @@
import org.onosproject.net.resource.ResourceAllocation;
import org.onosproject.net.resource.ResourceType;
+import java.util.Objects;
+
/**
* Representation of allocated bandwidth resource.
*/
-public class BandwidthResourceAllocation extends BandwidthResourceRequest
- implements ResourceAllocation {
+public class BandwidthResourceAllocation implements ResourceAllocation {
+ private final BandwidthResource bandwidth;
+
+ /**
+ * Creates a new {@link BandwidthResourceRequest} with {@link BandwidthResource}
+ * object.
+ *
+ * @param bandwidth {@link BandwidthResource} object to be requested
+ */
+ public BandwidthResourceAllocation(BandwidthResource bandwidth) {
+ this.bandwidth = bandwidth;
+ }
+
+ /**
+ * Returns the bandwidth resource.
+ *
+ * @return the bandwidth resource
+ */
+ public BandwidthResource bandwidth() {
+ return bandwidth;
+ }
@Override
public ResourceType type() {
return ResourceType.BANDWIDTH;
}
- /**
- * Creates a new {@link BandwidthResourceAllocation} with {@link BandwidthResource}
- * object.
- *
- * @param bandwidth allocated bandwidth
- */
- public BandwidthResourceAllocation(BandwidthResource bandwidth) {
- super(bandwidth);
+ @Override
+ public int hashCode() {
+ return Objects.hash(bandwidth);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ final BandwidthResourceAllocation other = (BandwidthResourceAllocation) obj;
+ return Objects.equals(this.bandwidth, other.bandwidth());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
- .add("bandwidth", bandwidth())
+ .add("bandwidth", bandwidth)
.toString();
}
}