Issue 695: Added Size,VirtualDisk and Disks. Additional equals/hashcode methods and test

This commit is contained in:
Jason King 2011-11-17 14:29:57 +00:00
parent f7c9579019
commit e911aad122
8 changed files with 389 additions and 6 deletions

View File

@ -45,6 +45,23 @@ public class Actions {
return Collections.unmodifiableSet(actions);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Actions actions1 = (Actions) o;
if (!actions.equals(actions1.actions)) return false;
return true;
}
@Override
public int hashCode() {
return actions.hashCode();
}
public String toString() {
return "["+ actions.toString()+"]";
}

View File

@ -0,0 +1,69 @@
/**
* 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 com.google.common.collect.Sets;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
/**
* Wraps individual Disk elements.
* Needed because parsing is done with JAXB and it does not handle Generic collections
* @author Jason King
*/
@XmlRootElement(name = "Disks")
public class Disks {
private LinkedHashSet<VirtualDisk> disks = Sets.newLinkedHashSet();
@XmlElement(name = "Disk")
public void setVirtualDisk(VirtualDisk disk) {
this.disks.add(disk);
}
public Set<VirtualDisk> getVirtualDisks() {
return Collections.unmodifiableSet(disks);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Disks disks1 = (Disks) o;
if (!disks.equals(disks1.disks)) return false;
return true;
}
@Override
public int hashCode() {
return disks.hashCode();
}
public String toString() {
return "["+ disks.toString()+"]";
}
}

View File

@ -54,6 +54,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
private Actions actions;
private int processorCount;
private Memory memory;
private Disks disks;
/**
* @see HardwareConfiguration#getActions
@ -80,9 +81,17 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
return this;
}
/**
* @see HardwareConfiguration#getDisks
*/
public Builder disks(Disks disks) {
this.disks = disks;
return this;
}
@Override
public HardwareConfiguration build() {
return new HardwareConfiguration(actions, processorCount, memory);
return new HardwareConfiguration(actions, processorCount, memory, disks);
}
/**
@ -119,23 +128,29 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
public Builder fromHardwareConfiguration(HardwareConfiguration in) {
return fromResource(in).actions(in.getActions())
.processorCount(in.getProcessorCount());
.processorCount(in.getProcessorCount())
.memory(in.getMemory())
.disks(in.getDisks());
}
}
@XmlElement(name = "Actions", required = true)
@XmlElement(name = "Actions", required = false)
private Actions actions;
@XmlElement(name = "ProcessorCount", required = true)
private int processorCount;
@XmlElement(name = "Memory", required = true)
@XmlElement(name = "Memory", required = false)
private Memory memory;
public HardwareConfiguration(@Nullable Actions actions, int processorCount, @Nullable Memory memory) {
@XmlElement(name = "Disks", required = false)
private Disks disks;
public HardwareConfiguration(@Nullable Actions actions, int processorCount, @Nullable Memory memory, @Nullable Disks disks) {
this.actions = checkNotNull(actions, "actions");
this.processorCount = processorCount;
this.memory = memory;
this.disks = disks;
}
protected HardwareConfiguration() {
@ -154,6 +169,10 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
return memory;
}
public Disks getDisks() {
return disks;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
@ -182,6 +201,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
@Override
public String string() {
return super.string()+", actions="+actions+", processorCount="+processorCount+", memory="+memory;
return super.string()+", actions="+actions+", processorCount="+processorCount+
", memory="+memory+", disks="+disks;
}
}

View File

@ -45,6 +45,23 @@ public class Links {
return Collections.unmodifiableSet(links);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Links links1 = (Links) o;
if (!links.equals(links1.links)) return false;
return true;
}
@Override
public int hashCode() {
return links.hashCode();
}
public String toString() {
return "["+ links.toString()+"]";
}

View File

@ -0,0 +1,87 @@
/**
* 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;
import javax.xml.bind.annotation.XmlRootElement;
/**
* @author Jason King
*/
@XmlRootElement(name = "Size")
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

@ -45,6 +45,23 @@ public class Tasks {
return Collections.unmodifiableSet(tasks);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Tasks tasks1 = (Tasks) o;
if (!tasks.equals(tasks1.tasks)) return false;
return true;
}
@Override
public int hashCode() {
return tasks.hashCode();
}
public String toString() {
return "["+tasks.toString()+"]";
}

View File

@ -0,0 +1,144 @@
/**
* 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.javax.annotation.Nullable;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* @author Jason King
*/
@XmlRootElement(name = "Disk")
public class VirtualDisk {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
public Builder toBuilder() {
return new Builder().fromVirtualDisk(this);
}
public static class Builder {
private String name;
private Size size;
private int index;
/**
* @see VirtualDisk#getName
*/
public Builder name(String name) {
this.name = name;
return this;
}
/**
* @see VirtualDisk#getSize
*/
public Builder size(Size size) {
this.size = size;
return this;
}
/**
* @see VirtualDisk#getIndex
*/
public Builder index(int index) {
this.index = index;
return this;
}
public VirtualDisk build() {
return new VirtualDisk(name, size, index);
}
public Builder fromVirtualDisk(VirtualDisk in) {
return name(in.getName())
.size(in.getSize())
.index(in.getIndex());
}
}
@XmlElement(name = "Name", required = false)
private String name;
@XmlElement(name = "Size", required = false)
private Size size;
@XmlElement(name = "Index", required = false)
private int index;
public VirtualDisk(@Nullable String name, @Nullable Size size, int index) {
this.name = name;
this.size = size;
this.index = index;
}
protected VirtualDisk() {
//For JAXB
}
public String getName() {
return name;
}
public Size getSize() {
return size;
}
public int getIndex() {
return index;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
VirtualDisk disk = (VirtualDisk) o;
if (index != disk.index) return false;
if (name != null ? !name.equals(disk.name) : disk.name != null)
return false;
if (size != null ? !size.equals(disk.size) : disk.size != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (size != null ? size.hashCode() : 0);
result = 31 * result + index;
return result;
}
@Override
public String toString() {
return "[name="+name+", size="+size+", index="+index+"]";
}
}

View File

@ -140,6 +140,18 @@ public class VirtualMachineJAXBParsingTest extends BaseRestClientTest {
assertEquals(1,hardwareConfiguration.getProcessorCount());
Memory memory = Memory.builder().value(384).unit("MB").build();
assertEquals(memory,hardwareConfiguration.getMemory());
assertDisks(hardwareConfiguration.getDisks());
}
private void assertDisks(Disks disks) {
VirtualDisk disk = VirtualDisk.builder().index(0).name("Hard Disk 1")
.size(Size.builder().value(10).unit("GB").build())
.build();
Disks expectedDisks = new Disks();
expectedDisks.setVirtualDisk(disk);
assertEquals(expectedDisks,disks);
}
}