From 2aa0fff801ee61256fd6c4e6743206a8e3a21c33 Mon Sep 17 00:00:00 2001 From: Jason King Date: Tue, 22 Nov 2011 16:11:32 +0000 Subject: [PATCH] Issue 695: Removed Size and Memory classes as can use ResourceCapacity directly --- .../tmrk/enterprisecloud/domain/Size.java | 84 ------------------- .../hardware/HardwareConfiguration.java | 11 +-- .../domain/hardware/Memory.java | 84 ------------------- .../domain/hardware/VirtualDisk.java | 12 +-- .../domain/internal/ResourceCapacity.java | 80 +++++++++--------- .../domain/hardware/DisksTest.java | 6 +- .../xml/VirtualMachineJAXBParsingTest.java | 10 +-- 7 files changed, 58 insertions(+), 229 deletions(-) delete mode 100644 sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Size.java delete mode 100644 sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/Memory.java diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Size.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Size.java deleted file mode 100644 index bc79dcf0f0..0000000000 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Size.java +++ /dev/null @@ -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 { - - @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 { - - @Override - public Size build() { - return new Size(value,unit); - } - - public Builder fromSize(Size in) { - return fromResource(in); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder fromResource(ResourceCapacity 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 - } -} \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/HardwareConfiguration.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/HardwareConfiguration.java index 4bf0c2a196..6a00f781a9 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/HardwareConfiguration.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/HardwareConfiguration.java @@ -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 { // TODO Links private Set actions = Sets.newLinkedHashSet(); private int processorCount; - private Memory memory; + private ResourceCapacity memory; private Set virtualDisks = Sets.newLinkedHashSet(); private Set virtualNics = Sets.newLinkedHashSet(); @@ -82,7 +83,7 @@ public class HardwareConfiguration extends BaseResource { /** * @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 { 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 { @XmlElement(name = "Nics", required = false) private Nics virtualNics = Nics.builder().build(); - public HardwareConfiguration(Set actions, int processorCount, @Nullable Memory memory, Set virtualDisks, Set virtualNics) { + public HardwareConfiguration(Set actions, int processorCount, @Nullable ResourceCapacity memory, Set virtualDisks, Set 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 { return processorCount; } - public Memory getMemory() { + public ResourceCapacity getMemory() { return memory; } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/Memory.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/Memory.java deleted file mode 100644 index 875216acad..0000000000 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/Memory.java +++ /dev/null @@ -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 { - - @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 { - - @Override - public Memory build() { - return new Memory(value,unit); - } - - public Builder fromMemory(Memory in) { - return fromResource(in); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder fromResource(ResourceCapacity 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 - } -} \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/VirtualDisk.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/VirtualDisk.java index 59ddbd648c..3256508801 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/VirtualDisk.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/VirtualDisk.java @@ -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; } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/ResourceCapacity.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/ResourceCapacity.java index a39fdf9de0..b00fca6fbf 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/ResourceCapacity.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/ResourceCapacity.java @@ -25,42 +25,42 @@ import javax.xml.bind.annotation.XmlElement; /** * @author Jason King */ -public class ResourceCapacity> { +public class ResourceCapacity { - public static > Builder builder() { - return new Builder(); + public static Builder builder() { + return new Builder(); } - public Builder toBuilder() { - return new Builder().fromResource(this); + public Builder toBuilder() { + return new Builder().fromResource(this); } - public static class Builder> { + 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 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 unit(String unit) { + public Builder unit(String unit) { this.unit = unit; return this; } - public ResourceCapacity build() { - return new ResourceCapacity(value, unit); + public ResourceCapacity build() { + return new ResourceCapacity(value, unit); } - public Builder fromResource(ResourceCapacity in) { + public Builder fromResource(ResourceCapacity in) { return value(in.getValue()).unit(in.getUnit()); } } @@ -91,36 +91,32 @@ public class ResourceCapacity> { 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+"]"; } } \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/DisksTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/DisksTest.java index a9cabd7d95..b3c6bc69c5 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/DisksTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/DisksTest.java @@ -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 virtualDisks = twoDisks.getVirtualDisks(); diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/VirtualMachineJAXBParsingTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/VirtualMachineJAXBParsingTest.java index 35cc8db05b..6497f54bc0 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/VirtualMachineJAXBParsingTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/VirtualMachineJAXBParsingTest.java @@ -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 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);