/*
 * 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.awselb.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 AvailabilityZone implements Zone{

    private static final Map<String,Zone> existZones = new HashMap<>();
    
    public static Zone create(String name){
        if(existZones.get(name) == null)
            existZones.put(name, new ZoneImpl(name));
        return existZones.get(name);
    }
    
    private ZoneImpl(String name){
        super.setZoneName(name);
    }
    
    @Override
    public String getName(){
        return super.getZoneName();
    }
    
    @Override
    public boolean equals(Object toBeCompared){
        if(toBeCompared instanceof ZoneImpl)
            return this.getName().equals(((ZoneImpl)toBeCompared).getName());
        return false;
    }
    
    @Override
    public void setZoneName(String zoneName){
        throw new UnsupportedOperationException("Zone name can not be modified.");
    }
    
    @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() + "}";
    }
}

@@ -421,33 +421,8 @@
 mpl 
-extends AvailabilityZone 
 impl
@@ -521,185 +521,72 @@
    p
-ublic static Zone create(String name)%7B%0A        if(existZones.get(name) == null)%0A            existZones.put(name, new ZoneImpl(name));%0A        return existZones.get(name
+rivate final AvailabilityZone elbZone = new AvailabilityZone(
 );%0A
-    %7D%0A
     
@@ -611,35 +611,50 @@
 mpl(
-String name)%7B%0A        super
+Builder builder)%7B%0A        %0A        elbZone
 .set
@@ -662,16 +662,24 @@
 oneName(
+builder.
 name);%0A 
@@ -750,13 +750,15 @@
 urn 
-super
+elbZone
 .get
@@ -1016,162 +1016,8 @@
 ide%0A
-    public void setZoneName(String zoneName)%7B%0A        throw new UnsupportedOperationException(%22Zone name can not be modified.%22);%0A    %7D%0A    %0A    @Override%0A
     
@@ -1270,10 +1270,401 @@
 ;%0A    %7D%0A
+    %0A    public static class Builder %7B%0A        %0A        private String name;%0A        %0A        public Builder name(String name)%7B%0A            this.name = name;%0A            return this;%0A        %7D%0A        %0A        public Zone build()%7B%0A            if(existZones.get(name) == null)%0A                existZones.put(name, new ZoneImpl(this));%0A            return existZones.get(name);%0A        %7D%0A    %7D%0A
 %7D%0A

Update ZoneImpl.java