@Test public void responseCodesFlyweightAllowsIdentityComparisons(){ int value = 34343; ResponseCode a = ResponseCode.forCode(value); ResponseCode b = ResponseCode.forCode(value); assertTrue("We should have two handles on the same object", a == b); }
public static ResponseCode forCode(int a){ ResponseCode code = null; for(ResponseCode n : standardResponseCodes){ if(n.value == a){ code = n; } } if(code==null){ synchronized(standardResponseCodes){ code = new ResponseCode(a, "Code " + a); standardResponseCodes.add(code); } } return code; }
ResponseCode { public static ResponseCode forCode(int a){ ResponseCode code = null; for(ResponseCode n : standardResponseCodes){ if(n.value == a){ code = n; } } if(code==null){ synchronized(standardResponseCodes){ code = new ResponseCode(a, "Code " + a); standardResponseCodes.add(code); } } return code; } }
ResponseCode { public static ResponseCode forCode(int a){ ResponseCode code = null; for(ResponseCode n : standardResponseCodes){ if(n.value == a){ code = n; } } if(code==null){ synchronized(standardResponseCodes){ code = new ResponseCode(a, "Code " + a); standardResponseCodes.add(code); } } return code; } private  ResponseCode(int value, String name); }
ResponseCode { public static ResponseCode forCode(int a){ ResponseCode code = null; for(ResponseCode n : standardResponseCodes){ if(n.value == a){ code = n; } } if(code==null){ synchronized(standardResponseCodes){ code = new ResponseCode(a, "Code " + a); standardResponseCodes.add(code); } } return code; } private  ResponseCode(int value, String name); static ResponseCode forCode(int a); int value(); boolean is300Series(); String name(); @Override String toString(); @Override boolean equals(Object other); String show(); boolean eq(ResponseCode that); }
ResponseCode { public static ResponseCode forCode(int a){ ResponseCode code = null; for(ResponseCode n : standardResponseCodes){ if(n.value == a){ code = n; } } if(code==null){ synchronized(standardResponseCodes){ code = new ResponseCode(a, "Code " + a); standardResponseCodes.add(code); } } return code; } private  ResponseCode(int value, String name); static ResponseCode forCode(int a); int value(); boolean is300Series(); String name(); @Override String toString(); @Override boolean equals(Object other); String show(); boolean eq(ResponseCode that); static final ResponseCode CONTINUE; }