1 7 8 package com.sun.corba.se.impl.ior ; 9 10 import java.util.Collection ; 11 import java.util.List ; 12 import java.util.AbstractList ; 13 import java.util.ListIterator ; 14 import java.util.Iterator ; 15 16 import com.sun.corba.se.spi.ior.MakeImmutable ; 17 18 25 public class FreezableList extends AbstractList { 26 private List delegate = null ; 27 private boolean immutable = false ; 28 29 public boolean equals( Object obj ) 30 { 31 if (obj == null) 32 return false ; 33 34 if (!(obj instanceof FreezableList)) 35 return false ; 36 37 FreezableList other = (FreezableList)obj ; 38 39 return delegate.equals( other.delegate ) && 40 (immutable == other.immutable) ; 41 } 42 43 public int hashCode() 44 { 45 return delegate.hashCode() ; 46 } 47 48 public FreezableList( List delegate, boolean immutable ) 49 { 50 this.delegate = delegate ; 51 this.immutable = immutable ; 52 } 53 54 public FreezableList( List delegate ) 55 { 56 this( delegate, false ) ; 57 } 58 59 public void makeImmutable() 60 { 61 immutable = true ; 62 } 63 64 public boolean isImmutable() 65 { 66 return immutable ; 67 } 68 69 public void makeElementsImmutable() 70 { 71 Iterator iter = iterator() ; 72 while (iter.hasNext()) { 73 Object obj = iter.next() ; 74 if (obj instanceof MakeImmutable) { 75 MakeImmutable element = (MakeImmutable)obj ; 76 element.makeImmutable() ; 77 } 78 } 79 } 80 81 83 public int size() 84 { 85 return delegate.size() ; 86 } 87 88 public Object get(int index) 89 { 90 return delegate.get(index) ; 91 } 92 93 public Object set(int index, Object element) 94 { 95 if (immutable) 96 throw new UnsupportedOperationException () ; 97 98 return delegate.set(index, element) ; 99 } 100 101 public void add(int index, Object element) 102 { 103 if (immutable) 104 throw new UnsupportedOperationException () ; 105 106 delegate.add(index, element) ; 107 } 108 109 public Object remove(int index) 110 { 111 if (immutable) 112 throw new UnsupportedOperationException () ; 113 114 return delegate.remove(index) ; 115 } 116 117 public List subList(int fromIndex, int toIndex) 119 { 120 List list = delegate.subList(fromIndex, toIndex) ; 121 List result = new FreezableList( list, immutable ) ; 122 return result ; 123 } 124 } 125 | Popular Tags |