
net.java.dev.vcc.api.ManagedObjectId Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vcc-api Show documentation
Show all versions of vcc-api Show documentation
The API for control of virtual computers running on a virtual computer host
The newest version!
package net.java.dev.vcc.api;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
/**
* The unique ID of a {@link net.java.dev.vcc.api.ManagedObject} instance.
*
* @param The type of {@link net.java.dev.vcc.api.ManagedObject} that this ID is for.
*/
public abstract class ManagedObjectId implements Serializable {
/**
* The class of {@link ManagedObject} that this ID is for.
*/
private final Class managedObjectClass;
/**
* The URL of the {@link Datacenter} hosting the instance referenced by this ID.
*/
private final String datacenterUrl;
/**
* Constructs a new {@link net.java.dev.vcc.api.ManagedObjectId}.
*
* @param managedObjectClass The class of {@link ManagedObject} that this ID is for.
* @param datacenterUrl The URL of the {@link Datacenter} hosting the instance referenced by this ID.
*/
protected ManagedObjectId(Class managedObjectClass, String datacenterUrl) {
this.managedObjectClass = managedObjectClass;
this.datacenterUrl = datacenterUrl;
}
/**
* Gets the class of {@link ManagedObject} that this ID is for.
*
* @return The class of {@link ManagedObject} that this ID is for.
*/
public Class getManagedObjectClass() {
return managedObjectClass;
}
/**
* Getst the URL of the {@link Datacenter} hosting the instance referenced by this ID.
*
* @return The URL of the {@link Datacenter} hosting the instance referenced by this ID.
*/
public String getDatacenterUrl() {
return datacenterUrl;
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ManagedObjectId that = (ManagedObjectId) o;
if (!datacenterUrl.equals(that.datacenterUrl)) {
return false;
}
if (!managedObjectClass.equals(that.managedObjectClass)) {
return false;
}
return true;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
int result = managedObjectClass.hashCode();
result = 31 * result + datacenterUrl.hashCode();
return result;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append(datacenterUrl);
try {
sb.append(";class=");
sb.append(URLEncoder.encode(managedObjectClass.getSimpleName(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
// ignore, this cannot happen
}
return sb.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy