/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package web.component.impl.aws.model;

import com.amazonaws.services.ec2.model.AvailabilityZone;
import java.util.HashMap;
import java.util.Map;
import web.component.api.model.Zone;

/**
 *
 * @author Hiroshi
 */
public class ZoneImpl extends AWSModelBase implements Zone{

    private static final Map<String,Zone> existZones = new HashMap<>();
    
    private final AvailabilityZone elbZone = new AvailabilityZone();
    
    private ZoneImpl(Builder builder){
        
        elbZone.setZoneName(builder.name);
    }
    
    public AvailabilityZone asElbZone(){
        return elbZone;
    }
    
    @Override
    public String getName(){
        return elbZone.getZoneName();
    }
    
    @Override
    public String getRegionName(){
        return elbZone.getRegionName();    
    }
    
    @Override
    public String getState(){
        return elbZone.getState();    
    }
    
    @Override
    public boolean equals(Object toBeCompared){
        if(toBeCompared instanceof ZoneImpl)
            return this.getName().equals(((ZoneImpl)toBeCompared).getName());
        return false;
    }
    
    @Override
    public int hashCode(){
        //this is wrong, but don't know how to implement this method properly.
        return 31 * this.getName().hashCode();
    }

    @Override
    public String toString(){
        return "{ZoneName: " + getName() + "}";
    }
    
    public static class Builder {
        
        private String name;
        
        public Builder name(String name){
            this.name = name;
            return this;
        }
        
        public Zone build(){
            if(existZones.get(name) == null)
                existZones.put(name, new ZoneImpl(this));
            return existZones.get(name);
        }
    }
}

@@ -566,18 +566,18 @@
 tyZone e
-lb
+c2
 Zone = n
@@ -661,18 +661,18 @@
        e
-lb
+c2
 Zone.set
@@ -737,18 +737,18 @@
 Zone asE
-lb
+c2
 Zone()%7B%0A
@@ -759,26 +759,26 @@
     return e
-lb
+c2
 Zone;%0A    %7D%0A
@@ -833,34 +833,34 @@
         return e
-lb
+c2
 Zone.getZoneName
@@ -935,132 +935,728 @@
     
-return elbZone.getRegionName();    %0A    %7D%0A    %0A    @Override%0A    public String getState()%7B%0A        return elbZone.getState()
+%0A        String regionName = ec2Zone.getRegionName();%0A        %0A        if(regionName == null %7C%7C regionName.isEmpty())%7B%0A%0A            regionName = %22%22;%0A%0A            try%7B%0A                regionName = ec2().getEc2AvailabilitiZone(getName()).getRegionName();%0A                ec2Zone.setRegionName(regionName);%0A            %7Dcatch(RuntimeException e)%7B%0A                //do nothing.%0A            %7D%0A        %7D%0A        %0A        return regionName;    %0A    %7D%0A    %0A    @Override%0A    public String getState()%7B%0A        %0A        String state = %22Unknown state.%22;%0A        %0A        try%7B%0A            state = ec2().getEc2AvailabilitiZone(getName()).getState();%0A        %7Dcatch()%7B%0A            //do nothing.%0A        %7D%0A        %0A        return state
 ;   
@@ -1775,16 +1775,74 @@
 neImpl)%0A
+            ZoneImpl asZoneImpl = (ZoneImpl)toBeCompared;%0A
         
@@ -1852,21 +1852,16 @@
  return 
-this.
 getName(
@@ -1873,18 +1873,18 @@
 als(
-((
+as
 ZoneImpl
 )toB
@@ -1883,26 +1883,66 @@
 Impl
-)toBeCompared).get
+.getName()) && getRegionName().equals(asZoneImpl.getRegion
 Name
@@ -2123,16 +2123,42 @@
 1 * 
-this.get
+( getName().hashCode() + getRegion
 Name
@@ -2170,16 +2170,18 @@
 shCode()
+ )
 ;%0A    %7D%0A
@@ -2267,16 +2267,53 @@
 Name() +
+ %22, RegionName: %22 + getRegionName() +
  %22%7D%22;%0A  

Update ZoneImpl.java