Issue 695: Removed Size and Memory classes as can use ResourceCapacity directly

This commit is contained in:
Jason King 2011-11-22 16:11:32 +00:00
parent c4f1fa040f
commit 2aa0fff801
7 changed files with 58 additions and 229 deletions

View File

@ -1,84 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.jclouds.tmrk.enterprisecloud.domain;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
/**
* @author Jason King
*/
public class Size extends ResourceCapacity<Size> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromSize(this);
}
public static class Builder extends ResourceCapacity.Builder<Size> {
@Override
public Size build() {
return new Size(value,unit);
}
public Builder fromSize(Size in) {
return fromResource(in);
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(ResourceCapacity<Size> in) {
return Builder.class.cast(super.fromResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder value(double value) {
return Builder.class.cast(super.value(value));
}
/**
* {@inheritDoc}
*/
@Override
public Builder unit(String unit) {
return Builder.class.cast(super.unit(unit));
}
}
public Size(double value, String unit) {
super(value, unit);
}
protected Size() {
//For JAXB
}
}

View File

@ -24,6 +24,7 @@ import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.Action;
import org.jclouds.tmrk.enterprisecloud.domain.Actions;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import org.jclouds.tmrk.enterprisecloud.domain.network.Nics;
import org.jclouds.tmrk.enterprisecloud.domain.network.VirtualNic;
@ -59,7 +60,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
// TODO Links
private Set<Action> actions = Sets.newLinkedHashSet();
private int processorCount;
private Memory memory;
private ResourceCapacity memory;
private Set<VirtualDisk> virtualDisks = Sets.newLinkedHashSet();
private Set<VirtualNic> virtualNics = Sets.newLinkedHashSet();
@ -82,7 +83,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
/**
* @see HardwareConfiguration#getMemory
*/
public Builder memory(Memory memory) {
public Builder memory(ResourceCapacity memory) {
this.memory = memory;
return this;
}
@ -157,7 +158,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
private int processorCount;
@XmlElement(name = "Memory", required = false)
private Memory memory;
private ResourceCapacity memory;
@XmlElement(name = "Disks", required = false)
private Disks virtualDisks = Disks.builder().build();
@ -165,7 +166,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
@XmlElement(name = "Nics", required = false)
private Nics virtualNics = Nics.builder().build();
public HardwareConfiguration(Set<Action> actions, int processorCount, @Nullable Memory memory, Set<VirtualDisk> virtualDisks, Set<VirtualNic> virtualNics) {
public HardwareConfiguration(Set<Action> actions, int processorCount, @Nullable ResourceCapacity memory, Set<VirtualDisk> virtualDisks, Set<VirtualNic> virtualNics) {
this.actions = Actions.builder().actions(checkNotNull(actions, "actions")).build();
this.virtualDisks = Disks.builder().disks(checkNotNull(virtualDisks,"virtualDisks")).build();
this.virtualNics = Nics.builder().nics(checkNotNull(virtualNics, "virtualNics")).build();
@ -185,7 +186,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
return processorCount;
}
public Memory getMemory() {
public ResourceCapacity getMemory() {
return memory;
}

View File

@ -1,84 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.jclouds.tmrk.enterprisecloud.domain.hardware;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
/**
* @author Jason King
*/
public class Memory extends ResourceCapacity<Memory> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromMemory(this);
}
public static class Builder extends ResourceCapacity.Builder<Memory> {
@Override
public Memory build() {
return new Memory(value,unit);
}
public Builder fromMemory(Memory in) {
return fromResource(in);
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(ResourceCapacity<Memory> in) {
return Builder.class.cast(super.fromResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder value(double value) {
return Builder.class.cast(super.value(value));
}
/**
* {@inheritDoc}
*/
@Override
public Builder unit(String unit) {
return Builder.class.cast(super.unit(unit));
}
}
public Memory(double value, String unit) {
super(value, unit);
}
protected Memory() {
//For JAXB
}
}

View File

@ -19,7 +19,7 @@
package org.jclouds.tmrk.enterprisecloud.domain.hardware;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.Size;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import javax.xml.bind.annotation.XmlElement;
@ -44,7 +44,7 @@ public class VirtualDisk {
public static class Builder {
private String name;
private Size size;
private ResourceCapacity size;
private int index;
/**
@ -58,7 +58,7 @@ public class VirtualDisk {
/**
* @see VirtualDisk#getSize
*/
public Builder size(Size size) {
public Builder size(ResourceCapacity size) {
this.size = size;
return this;
}
@ -86,12 +86,12 @@ public class VirtualDisk {
private String name;
@XmlElement(name = "Size", required = false)
private Size size;
private ResourceCapacity size;
@XmlElement(name = "Index", required = false)
private int index;
public VirtualDisk(@Nullable String name, @Nullable Size size, int index) {
public VirtualDisk(@Nullable String name, @Nullable ResourceCapacity size, int index) {
this.name = name;
this.size = size;
this.index = index;
@ -105,7 +105,7 @@ public class VirtualDisk {
return name;
}
public Size getSize() {
public ResourceCapacity getSize() {
return size;
}

View File

@ -25,42 +25,42 @@ import javax.xml.bind.annotation.XmlElement;
/**
* @author Jason King
*/
public class ResourceCapacity<T extends ResourceCapacity<T>> {
public class ResourceCapacity {
public static <T extends ResourceCapacity<T>> Builder<T> builder() {
return new Builder<T>();
public static Builder builder() {
return new Builder();
}
public Builder<T> toBuilder() {
return new Builder<T>().fromResource(this);
public Builder toBuilder() {
return new Builder().fromResource(this);
}
public static class Builder<T extends ResourceCapacity<T>> {
public static class Builder {
protected double value; //mandatory
protected String unit; //optional
/**
* @see ResourceCapacity#getValue
* @see org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity#getValue
*/
public Builder<T> value(double value) {
public Builder value(double value) {
this.value = value;
return this;
}
/**
* @see ResourceCapacity#getUnit
* @see org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity#getUnit
*/
public Builder<T> unit(String unit) {
public Builder unit(String unit) {
this.unit = unit;
return this;
}
public ResourceCapacity<T> build() {
return new ResourceCapacity<T>(value, unit);
public ResourceCapacity build() {
return new ResourceCapacity(value, unit);
}
public Builder<T> fromResource(ResourceCapacity<T> in) {
public Builder fromResource(ResourceCapacity in) {
return value(in.getValue()).unit(in.getUnit());
}
}
@ -91,36 +91,32 @@ public class ResourceCapacity<T extends ResourceCapacity<T>> {
return unit;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ResourceCapacity that = (ResourceCapacity) o;
if (Double.compare(that.value, value) != 0) return false;
if (unit != null ? !unit.equals(that.unit) : that.unit != null)
return false;
return true;
}
@Override
public int hashCode() {
int result;
long temp;
temp = value != +0.0d ? Double.doubleToLongBits(value) : 0L;
result = (int) (temp ^ (temp >>> 32));
result = 31 * result + (unit != null ? unit.hashCode() : 0);
return result;
}
@Override
public String toString() {
return String.format("[%s]",string());
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ResourceCapacity that = (ResourceCapacity) o;
if (Double.compare(that.value, value) != 0) return false;
if (unit != null ? !unit.equals(that.unit) : that.unit != null)
return false;
return true;
}
@Override
public int hashCode() {
int result;
long temp;
temp = value != +0.0d ? Double.doubleToLongBits(value) : 0L;
result = (int) (temp ^ (temp >>> 32));
result = 31 * result + (unit != null ? unit.hashCode() : 0);
return result;
}
protected String string() {
return "value="+value+", unit="+unit;
@Override
public String toString() {
return "[value="+value+", unit="+unit+"]";
}
}

View File

@ -18,7 +18,7 @@
*/
package org.jclouds.tmrk.enterprisecloud.domain.hardware;
import org.jclouds.tmrk.enterprisecloud.domain.Size;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@ -39,13 +39,13 @@ public class DisksTest {
@BeforeMethod()
public void setUp() throws URISyntaxException {
disk = VirtualDisk.builder().index(0).name("test disk").size(Size.builder().value(1).unit("GB").build()).build();
disk = VirtualDisk.builder().index(0).name("test disk").size(ResourceCapacity.builder().value(1).unit("GB").build()).build();
disks = Disks.builder().addDisk(disk).build();
}
@Test
public void testAddDisk() throws URISyntaxException {
VirtualDisk disk2 = VirtualDisk.builder().index(1).name("test disk 1").size(Size.builder().value(1).unit("GB").build()).build();
VirtualDisk disk2 = VirtualDisk.builder().index(1).name("test disk 1").size(ResourceCapacity.builder().value(1).unit("GB").build()).build();
Disks twoDisks = disks.toBuilder().addDisk(disk2).build();
Set<VirtualDisk> virtualDisks = twoDisks.getVirtualDisks();

View File

@ -35,18 +35,18 @@ import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.BaseRestClientTest;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.tmrk.enterprisecloud.domain.*;
import org.jclouds.tmrk.enterprisecloud.domain.Layout;
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
import org.jclouds.tmrk.enterprisecloud.domain.hardware.Memory;
import org.jclouds.tmrk.enterprisecloud.domain.hardware.VirtualDisk;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
import org.jclouds.tmrk.enterprisecloud.domain.network.DeviceNetwork;
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkReference;
import org.jclouds.tmrk.enterprisecloud.domain.network.VirtualNic;
import org.jclouds.tmrk.enterprisecloud.domain.software.OperatingSystem;
import org.jclouds.tmrk.enterprisecloud.domain.software.ToolsStatus;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine.VirtualMachineStatus;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine.VirtualMachineStatus;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineIpAddresses;
import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineAsyncClient;
import org.testng.Assert;
@ -151,7 +151,7 @@ public class VirtualMachineJAXBParsingTest extends BaseRestClientTest {
private void assertHardwareConfiguration(HardwareConfiguration hardwareConfiguration) throws Exception {
assertEquals(1,hardwareConfiguration.getActions().size());
assertEquals(1,hardwareConfiguration.getProcessorCount());
Memory memory = Memory.builder().value(384).unit("MB").build();
ResourceCapacity memory = ResourceCapacity.builder().value(384).unit("MB").build();
assertEquals(memory,hardwareConfiguration.getMemory());
assertDisks(hardwareConfiguration.getVirtualDisks());
assertNics(hardwareConfiguration.getVirtualNics());
@ -159,7 +159,7 @@ public class VirtualMachineJAXBParsingTest extends BaseRestClientTest {
private void assertDisks(Set<VirtualDisk> disks) {
VirtualDisk disk = VirtualDisk.builder().index(0).name("Hard Disk 1")
.size(Size.builder().value(10).unit("GB").build())
.size(ResourceCapacity.builder().value(10).unit("GB").build())
.build();
assertEquals(ImmutableSet.of(disk), disks);