/*
 * 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 java.util.HashMap;
import java.util.Map;
import web.component.api.model.Subnet;

/**
 *
 * @author Hiroshi
 */
public class SubnetImpl extends com.amazonaws.services.ec2.model.Subnet implements Subnet{

    private static final Map<String,Subnet> existSubnets = new HashMap<>();
    
    private SubnetImpl(String id){
        super.setSubnetId(id);
    }
    
    @Override
    public String getId() {
        return super.getSubnetId();
    }
    
    public static Subnet create(String id){
        if(existSubnets.get(id) == null)
            existSubnets.put(id, new SubnetImpl(id));
        return existSubnets.get(id);
    }
    
    @Override
    public boolean equals(Object toBeCompared){
        if(toBeCompared instanceof SubnetImpl)
            return this.getId().equals(((SubnetImpl)toBeCompared).getId());
        return false;
    }
    
    @Override
    public int hashCode(){
        //this is wrong, but don't know how to implement this method properly.
        return 31 * this.getId().hashCode();
    }
    
    @Override
    public String toString(){
        return "{SubnetID: " + getId() + "}";
    }
    
    @Override
    public void setSubnetId(String subnetId){
        throw new UnsupportedOperationException("Subnet id can not be modified.");
    }
}

@@ -367,56 +367,8 @@
 mpl 
-extends com.amazonaws.services.ec2.model.Subnet 
 impl
@@ -480,137 +480,178 @@
 ate 
-SubnetImpl(String id)%7B%0A        super.set
+final com.amazonaws.services.ec2.model.Subnet elbSubnet = new com.amazonaws.services.ec2.model.
 Subnet
-Id(id
+(
 );%0A    
-%7D
 %0A    
-%0A    @Override%0A    public String getId() %7B%0A        return super.g
+private SubnetImpl(Builder builder)%7B%0A        elbSubnet.s
 etSu
@@ -657,16 +657,26 @@
 ubnetId(
+builder.id
 );%0A    %7D
@@ -696,135 +696,141 @@
 lic 
-static Subnet create(String id)%7B%0A        if(existSubnets.get(id) == null)
+com.amazonaws.services.ec2.model.Subnet asElbSubnet()%7B%0A        return elbSubnet;
 %0A    
+%7D%0A
     
+%0A
     
-existSubnets.put(id, new SubnetImpl(id));
+@Override%0A    public String getId() %7B
 %0A   
@@ -846,26 +846,29 @@
 rn e
-xist
+lb
 Subnet
-s
 .get
-(id
+SubnetId(
 );%0A 
@@ -1367,35 +1367,96 @@
 ;%0A    %7D%0A
+%0A
     
-%0A    @Override%0A
+public static class Builder %7B%0A    %0A        private String id;%0A        %0A    
     publ
@@ -1462,125 +1462,287 @@
 lic 
-void setSubnetId(String subnetId)%7B%0A        throw new UnsupportedOperationException(%22Subnet id can not be modified.%22);
+Builder id(String id)%7B%0A            this.id = id;%0A            return this;%0A        %7D%0A        %0A        public Subnet build()%7B%0A            if(existSubnets.get(id) == null)%0A                existSubnets.put(id, new SubnetImpl(this));%0A            return existSubnets.get(id);%0A        %7D
 %0A   

Update SubnetImpl.java