aboutsummaryrefslogtreecommitdiffstats
path: root/libraries/spongycastle/core/src/main/jdk1.1/java/util/AbstractList.java
blob: 363b57aecebdce413ef6605bf5f79c18afc4d0bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
package java.util;

/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:
 * @version 1.0
 */

public abstract class AbstractList extends AbstractCollection implements List

{
  protected AbstractList al = this;


  protected AbstractList()
        {
    }

    public boolean add(Object o) throws UnsupportedOperationException, ClassCastException, IllegalArgumentException
        {
            try
                {
                    add(size(),o);
                  return true;
                }
            catch(UnsupportedOperationException ue)
                {
                    throw ue;
                }
        }

    public abstract Object get(int index) throws IndexOutOfBoundsException;

    public Object set(int index,Object element) throws UnsupportedOperationException, ClassCastException, IllegalArgumentException, IndexOutOfBoundsException
        {
            throw new UnsupportedOperationException();
        }

    public void add(int index,Object element)  throws UnsupportedOperationException, ClassCastException, IllegalArgumentException, IndexOutOfBoundsException
        {
            throw new UnsupportedOperationException();
        }

    public Object remove(int index)  throws UnsupportedOperationException, IndexOutOfBoundsException
        {
            Object o = get(index);

            removeRange(index,index+1);
            return o;
        }

    public int indexOf(Object o)
        {
             ListIterator li = listIterator();
      Object e;
          while(li.hasNext())
                {
          int index=li.nextIndex();
                    e=li.next();
          System.out.println(e);
                    if(o==null)
                        {
                            if(e==null)
                                return index;
                        }
                    else
                        {
                            if(o.equals(e))
                                return index;
                        }
                }
            return -1;
        }

    public int lastIndexOf(Object o)
        {
            ListIterator li=listIterator(size());
          while(li.hasPrevious())
                {
                    int index=li.previousIndex();
                    Object e=li.previous();
                    if(o==null)
                        {
                            if(e==null)
                                return index;
                        }
                    else
                        {
                            if(o.equals(e))
                                return index;
                        }
                }
            return -1;
        }

    public void clear() throws UnsupportedOperationException
        {
            try
                {
                    removeRange(0,size());
                }
            catch(UnsupportedOperationException ue)
                {
                    throw ue;
                }
        }

    public boolean addAll(int index,Collection c) throws UnsupportedOperationException, ClassCastException, IllegalArgumentException, IndexOutOfBoundsException
        {
            Iterator it=c.iterator();
            boolean ret=false;
            while(it.hasNext())
                {
                    try
                        {
                            add(index++,it.next());
                            ret=true;
                        }
                    catch(UnsupportedOperationException ue)
                        {
                            throw ue;
                        }
                }
            return ret;
        }

    public Iterator iterator()
        {
            return new AbstractListIterator(this,0);
        }

    public ListIterator listIterator()
        {
            return listIterator(0);
        }

    public ListIterator listIterator(int index) throws IndexOutOfBoundsException
        {
             if(index<0||index>size())    throw new IndexOutOfBoundsException();
            return new AbstractListListIterator(this,index);
        }

    public List subList(int fromIndex,int toIndex) throws IndexOutOfBoundsException,IllegalArgumentException
        {
          if(fromIndex < 0 || toIndex > size())
                throw new IndexOutOfBoundsException();
            if(fromIndex>toIndex)
                throw new IllegalArgumentException();
              return (List) new Sublist(this,fromIndex,toIndex);
        }

    public boolean equals(Object o)
        {
            if(o==this)
                return true;
            if(!(o instanceof List))
                return false;
            Iterator it1=iterator();
            Iterator it2=((List)o).iterator();
            while(it1.hasNext())
                {
                    if(!it2.hasNext())
                        return false;
                    Object e1=it1.next();
                    Object e2=it2.next();
                    if(e1==null)
                        {
                            if(e2!=null)
                                return false;
                        }
                    if(!e1.equals(e2))
                        return false;
                }
            return true;
        }

    public int hashCode()
        {
          int hashCode = 1;
            Iterator it = iterator();
            while (it.hasNext())
                {
                    Object o = it.next();
                    hashCode = 31*hashCode + (o==null ? 0 : o.hashCode());
                }
            return hashCode;
    }

    protected void removeRange(int fromIndex,int toIndex)
        {
    System.out.println("breakpoint 1");
            if(fromIndex==toIndex) return;
          System.out.println("breakpoint 2");
             ListIterator li=listIterator(fromIndex);
          System.out.println("breakpoint 3");
            int i=fromIndex;
            do
              {
                    li.next();
                    li.remove();
                    i++;
                }while(li.hasNext()&&i<toIndex);
        }

////////////////////////////////////////////////////////////
/////////////innere Klasse AbstractIterator/////////////////
////////////////////////////////////////////////////////////

private class AbstractListIterator implements Iterator
    {
        AbstractList m_al=null;
        int m_nextIndex=0;
        public AbstractListIterator(AbstractList al,int index)
            {
                m_al=al;
                m_nextIndex=index;
            }

        public boolean hasNext()
            {
                return m_nextIndex < m_al.size();
            }

    public Object next()
            {
        return m_al.get(m_nextIndex++);
            }

        public void remove()
          {
              m_al.remove(m_nextIndex - 1);
            }
    }

///////////////////////////////////////////////////////////////////////////////
//////////// innere Klasse AbstraktListListIterator
///////////////////////////////////////////////////////////////////////////////


private class AbstractListListIterator extends AbstractListIterator implements ListIterator
    {
        public AbstractListListIterator(AbstractList al,int index)
            {
                super(al,index);
            }

        public boolean hasPrevious()
            {
                return m_nextIndex>0;
            }

        public Object previous()// throws NoSuchElementException;
          {
                return m_al.get(--m_nextIndex);
            }

        public int nextIndex()
            {
                return m_nextIndex;
            }

        public int previousIndex()
            {
                return m_nextIndex-1;
            }

        public void set(Object o) //throws UnsupportedOperationException, ClassCastException, IllegalArgumentException,IllegalStateException;
          {
                m_al.set(m_nextIndex-1,o);
            }

        public void add(Object o)// throws UnsupportedOperationException, ClassCastException, IllegalArgumentException;
          {
                m_al.add(m_nextIndex-1,o);
            }
    }


}