1 19 package org.openide.text; 20 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 import java.util.ListIterator ; 26 27 29 final class LazyLines extends Object implements List <Line> { 30 private List <Line> delegate; 31 private DocumentLine.Set set; 32 33 public LazyLines(DocumentLine.Set set) { 34 this.set = set; 35 } 36 37 39 private List <Line> createDelegate() { 40 int cnt = set.listener.getOriginalLineCount(); 41 List <Line> l = new ArrayList <Line>(cnt); 42 43 for (int i = 0; i < cnt; i++) { 44 l.add(set.getOriginal(i)); 45 } 46 47 return l; 48 } 49 50 private synchronized List <Line> getDelegate() { 51 if (delegate == null) { 52 delegate = createDelegate(); 53 } 54 55 return delegate; 56 } 57 58 public int indexOf(Object o) { 59 if (o instanceof DocumentLine) { 60 Line find = set.findLine((DocumentLine) o); 61 62 if (find != null) { 63 int indx = set.listener.getOld(find.getLineNumber()); 64 65 if (set.getOriginal(indx).equals(o)) { 66 return indx; 68 } 69 } 70 } 71 72 return -1; 73 } 74 75 public int lastIndexOf(Object o) { 76 return indexOf(o); 77 } 78 79 public int hashCode() { 83 return getDelegate().hashCode(); 84 } 85 86 public boolean addAll(java.util.Collection c) { 87 throw new UnsupportedOperationException (); 88 } 89 90 public boolean removeAll(java.util.Collection c) { 91 throw new UnsupportedOperationException (); 92 } 93 94 public ListIterator <Line> listIterator() { 95 return getDelegate().listIterator(); 96 } 97 98 public Object [] toArray() { 99 return getDelegate().toArray(); 100 } 101 102 public <T> T[] toArray(T[] a) { 103 return getDelegate().toArray(a); 104 } 105 106 public ListIterator <Line> listIterator(int index) { 107 return getDelegate().listIterator(index); 108 } 109 110 public boolean remove(Object o) { 111 throw new UnsupportedOperationException (); 112 } 113 114 public boolean equals(Object obj) { 115 return getDelegate().equals(obj); 116 } 117 118 public boolean contains(Object o) { 119 return getDelegate().contains(o); 120 } 121 122 public void add(int index, Line element) { 123 throw new UnsupportedOperationException (); 124 } 125 126 public void clear() { 127 getDelegate().clear(); 128 } 129 130 public Line set(int index, Line element) { 131 throw new UnsupportedOperationException (); 132 } 133 134 public int size() { 135 return getDelegate().size(); 136 } 137 138 public Line get(int index) { 139 return getDelegate().get(index); 140 } 141 142 public boolean containsAll(Collection <?> c) { 143 return getDelegate().containsAll(c); 144 } 145 146 public boolean add(Line o) { 147 throw new UnsupportedOperationException (); 148 } 149 150 public boolean isEmpty() { 151 return getDelegate().isEmpty(); 152 } 153 154 public boolean retainAll(Collection <?> c) { 155 throw new UnsupportedOperationException (); 156 } 157 158 public List <Line> subList(int fromIndex, int toIndex) { 159 return getDelegate().subList(fromIndex, toIndex); 160 } 161 162 public Line remove(int index) { 163 return getDelegate().remove(index); 164 } 165 166 public Iterator <Line> iterator() { 167 return getDelegate().iterator(); 168 } 169 170 public boolean addAll(int index, java.util.Collection c) { 171 throw new UnsupportedOperationException (); 172 } 173 } 174 | Popular Tags |