package brooklyn.location.basic;

import brooklyn.location.MachineManagementMixins.MachineMetadata;

public class BasicMachineMetadata implements MachineMetadata {

    final String id, name, primaryIp;
    final Boolean isRunning;
    final Object originalMetadata;
    
    public BasicMachineMetadata(String id, String name, String primaryIp, Boolean isRunning, Object originalMetadata) {
        super();
        this.id = id;
        this.name = name;
        this.primaryIp = primaryIp;
        this.isRunning = isRunning;
        this.originalMetadata = originalMetadata;
    }

    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getPrimaryIp() {
        return primaryIp;
    }

    public Boolean isRunning() {
        return isRunning;
    }

    public Object getOriginalMetadata() {
        return originalMetadata;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        result = prime * result + ((isRunning == null) ? 0 : isRunning.hashCode());
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        result = prime * result + ((originalMetadata == null) ? 0 : originalMetadata.hashCode());
        result = prime * result + ((primaryIp == null) ? 0 : primaryIp.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        BasicMachineMetadata other = (BasicMachineMetadata) obj;
        if (id == null) {
            if (other.id != null)
                return false;
        } else if (!id.equals(other.id))
            return false;
        if (isRunning == null) {
            if (other.isRunning != null)
                return false;
        } else if (!isRunning.equals(other.isRunning))
            return false;
        if (name == null) {
            if (other.name != null)
                return false;
        } else if (!name.equals(other.name))
            return false;
        if (originalMetadata == null) {
            if (other.originalMetadata != null)
                return false;
        } else if (!originalMetadata.equals(other.originalMetadata))
            return false;
        if (primaryIp == null) {
            if (other.primaryIp != null)
                return false;
        } else if (!primaryIp.equals(other.primaryIp))
            return false;
        return true;
    }

    @Override
    public String toString() {
        return "MachineMetadata[id=" + id + ", name=" + name + ", primaryIp=" + primaryIp + ", isRunning=" + isRunning + ", originalMetadata=" + originalMetadata + "]";
    }

    
}

@@ -94,16 +94,56 @@
 adata;%0A%0A
+import com.google.common.base.Objects;%0A%0A
 public c
@@ -1001,485 +1001,81 @@
     
-final int prime = 31;%0A        int result = 1;%0A        result = prime * result + ((id == null) ? 0 : id.hashCode());%0A        result = prime * result + ((isRunning == null) ? 0 : isRunning.hashCode());%0A        result = prime * result + ((name == null) ? 0 : name.hashCode());%0A        result = prime * result + ((originalMetadata == null) ? 0 : originalMetadata.hashCode());%0A        result = prime * result + ((primaryIp == null) ? 0 : primaryIp.hashCode());%0A        return result
+return Objects.hashCode(id, isRunning, name, originalMetadata, primaryIp)
 ;%0A  
@@ -1157,28 +1157,16 @@
  == obj)
-%0A           
  return 
@@ -1195,28 +1195,16 @@
 == null)
-%0A           
  return 
@@ -1251,28 +1251,16 @@
 Class())
-%0A           
  return 
@@ -1347,116 +1347,27 @@
 if (
-id == null) %7B%0A            if (other.id != null)%0A                return false;%0A        %7D else if (!id
+!Objects
 .equal
-s
 (
+id, 
 othe
@@ -1372,28 +1372,16 @@
 her.id))
-%0A           
  return 
@@ -1403,514 +1403,223 @@
 if (
-isRunning == null) %7B%0A            if (other.isRunning != null)%0A                return false;%0A        %7D else if (!isRunning.equals(other.isRunning))%0A            return false;%0A        if (name == null) %7B%0A            if (other.name != null)%0A                return false;%0A        %7D else if (!name.equals(other.name))%0A            return false;%0A        if (originalMetadata == null) %7B%0A            if (other.originalMetadata != null)%0A                return false;%0A        %7D else if (!originalMetadata
+!Objects.equal(name, other.name)) return false;%0A        if (!Objects.equal(primaryIp, other.primaryIp)) return false;%0A        if (!Objects.equal(isRunning, other.isRunning)) return false;%0A        if (!Objects
 .equal
-s
 (
-other.
 orig
@@ -1634,419 +1634,203 @@
 data
-))%0A            return false;%0A        if (primaryIp == null) %7B%0A            if (
+, 
 other.
-primaryIp != null)%0A                return false;%0A        %7D else if (!primaryIp.equals(other.primaryIp))%0A            return false;%0A        return true;%0A    %7D%0A%0A    @Override%0A    public String toString() %7B%0A        return %22MachineMetadata%5Bid=%22 + id + %22, name=%22 + name + %22, primaryIp=%22 + primaryIp + %22, isRunning=%22 + isRunning + %22, 
+originalMetadata)) return false;%0A        return true;%0A    %7D%0A%0A    @Override%0A    public String toString() %7B%0A        return Objects.toStringHelper(this).add(%22id%22, id).add(%22name%22, name).add(%22
 orig
@@ -1845,12 +1845,10 @@
 data
-=%22 +
+%22,
  ori
@@ -1864,22 +1864,28 @@
 data
- + %22%5D%22
+).toString()
 ;%0A    %7D%0A
 %0A   
@@ -1876,20 +1876,19 @@
 ng();%0A    %7D%0A
-%0A
     %0A%7D%0A

convert to preferred Objects toString/equals/hashcode