1 11 package org.eclipse.ant.internal.ui.dtd.util; 12 13 import java.lang.ref.SoftReference ; 14 15 23 public class Factory { 24 25 29 public FactoryObject getFree() { 30 Head head = getHead(); 31 FactoryObject obj = head.next; 32 if (obj != null) { 33 head.next = obj.next(); 34 obj.next(null); 35 } 36 return obj; 37 } 38 39 42 public void setFree(FactoryObject obj) { 43 Head head = getHead(); 44 obj.next(head.next); 45 head.next = obj; 46 } 47 48 private Head getHead() { 49 Head head = (Head) free.get(); 50 if (head == null) { 51 head = new Head(); 59 free = new SoftReference (head); 60 } 61 return head; 62 } 63 64 private static class Head { 65 public FactoryObject next; 66 } 67 private SoftReference free = new SoftReference (new Head()); 68 } 69 | Popular Tags |