ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/ListBash.java
(Generate patch)

Comparing jsr166/src/test/loops/ListBash.java (file contents):
Revision 1.2 by dl, Mon May 9 19:33:30 2005 UTC vs.
Revision 1.3 by dl, Tue May 31 15:08:32 2005 UTC

# Line 22 | Line 22 | public class ListBash {
22  
23          boolean synch = (args.length>3);
24  
25 +        boolean canRemove = true;
26          for (int i=0; i<numItr; i++) {
27              List s1 = newList(cl, synch);
28              AddRandoms(s1, listSize);
# Line 63 | Line 64 | public class ListBash {
64                  Object o = e.next();
65                  if (!union.contains(o))
66                      fail("List doesn't contain one of its elements.");
67 <                e.remove();
67 >                if (canRemove) {
68 >                    try { e.remove();
69 >                    } catch (UnsupportedOperationException uoe) {
70 >                        canRemove = false;
71 >                    }
72 >                }
73              }
74 <            if (!union.isEmpty())
74 >            if (canRemove && !union.isEmpty())
75                  fail("List nonempty after deleting all elements.");
76  
77              s1.clear();
# Line 91 | Line 97 | public class ListBash {
97          if (s.size() != listSize)
98              fail("Size of [0..n-1] != n");
99  
100 <        List even = clone(s, cl, synch);
101 <        Iterator it = even.iterator();
102 <        while(it.hasNext())
103 <            if(((Integer)it.next()).intValue() % 2 == 1)
104 <                it.remove();
105 <        it = even.iterator();
106 <        while(it.hasNext())
107 <            if(((Integer)it.next()).intValue() % 2 == 1)
108 <                fail("Failed to remove all odd nubmers.");
109 <
110 <        List odd = clone(s, cl, synch);
111 <        for (int i=0; i<(listSize/2); i++)
112 <            odd.remove(i);
113 <        for (int i=0; i<(listSize/2); i++) {
114 <            int ii = ((Integer)odd.get(i)).intValue();
115 <            if(ii % 2 != 1)
116 <                fail("Failed to remove all even nubmers. " + ii);
117 <        }
100 >        List even = clone(s, cl, synch);
101 >        List odd = clone(s, cl, synch);
102 >        List all;
103 >        Iterator it;
104 >
105 >        if (!canRemove)
106 >            all = clone(s, cl, synch);
107 >        else {
108 >            it = even.iterator();
109 >            while(it.hasNext())
110 >                if(((Integer)it.next()).intValue() % 2 == 1)
111 >                    it.remove();
112 >            it = even.iterator();
113 >            while(it.hasNext())
114 >                if(((Integer)it.next()).intValue() % 2 == 1)
115 >                    fail("Failed to remove all odd nubmers.");
116 >            
117 >            for (int i=0; i<(listSize/2); i++)
118 >                odd.remove(i);
119 >            for (int i=0; i<(listSize/2); i++) {
120 >                int ii = ((Integer)odd.get(i)).intValue();
121 >                if(ii % 2 != 1)
122 >                    fail("Failed to remove all even nubmers. " + ii);
123 >            }
124  
125 <        List all = clone(odd, cl, synch);
126 <        for (int i=0; i<(listSize/2); i++)
127 <            all.add(2*i, even.get(i));
128 <        if (!all.equals(s))
129 <            fail("Failed to reconstruct ints from odds and evens.");
130 <
131 <        all = clone(odd,  cl, synch);
132 <        ListIterator itAll = all.listIterator(all.size());
133 <        ListIterator itEven = even.listIterator(even.size());
134 <        while (itEven.hasPrevious()) {
135 <            itAll.previous();
136 <            itAll.add(itEven.previous());
137 <            itAll.previous(); // ???
138 <        }
139 <        itAll = all.listIterator();
140 <        while (itAll.hasNext()) {
141 <            Integer i = (Integer)itAll.next();
142 <            itAll.set(new Integer(i.intValue()));
143 <        }
144 <        itAll = all.listIterator();
145 <        it = s.iterator();
146 <        while(it.hasNext())
147 <            if(it.next()==itAll.next())
148 <                fail("Iterator.set failed to change value.");
149 <
150 <        if (!all.equals(s))
151 <            fail("Failed to reconstruct ints with ListIterator.");
152 <
153 <        it = all.listIterator();
154 <        int i=0;
155 <        while (it.hasNext()) {
156 <            Object o = it.next();
157 <            if (all.indexOf(o) != all.lastIndexOf(o))
158 <                fail("Apparent duplicate detected.");
159 <            if (all.subList(i,   all.size()).indexOf(o) != 0) {
125 >            all = clone(odd, cl, synch);
126 >            for (int i=0; i<(listSize/2); i++)
127 >                all.add(2*i, even.get(i));
128 >            if (!all.equals(s))
129 >                fail("Failed to reconstruct ints from odds and evens.");
130 >            
131 >            all = clone(odd,  cl, synch);
132 >            ListIterator itAll = all.listIterator(all.size());
133 >            ListIterator itEven = even.listIterator(even.size());
134 >            while (itEven.hasPrevious()) {
135 >                itAll.previous();
136 >                itAll.add(itEven.previous());
137 >                itAll.previous(); // ???
138 >            }
139 >            itAll = all.listIterator();
140 >            while (itAll.hasNext()) {
141 >                Integer i = (Integer)itAll.next();
142 >                itAll.set(new Integer(i.intValue()));
143 >            }
144 >            itAll = all.listIterator();
145 >            it = s.iterator();
146 >            while(it.hasNext())
147 >                if(it.next()==itAll.next())
148 >                    fail("Iterator.set failed to change value.");
149 >        }
150 >        if (!all.equals(s))
151 >            fail("Failed to reconstruct ints with ListIterator.");
152 >        
153 >        it = all.listIterator();
154 >        int i=0;
155 >        while (it.hasNext()) {
156 >            Object o = it.next();
157 >            if (all.indexOf(o) != all.lastIndexOf(o))
158 >                fail("Apparent duplicate detected.");
159 >            if (all.subList(i,   all.size()).indexOf(o) != 0) {
160                  System.out.println("s0: " + all.subList(i,   all.size()).indexOf(o));
161                  fail("subList/indexOf is screwy.");
162              }
163              if (all.subList(i+1, all.size()).indexOf(o) != -1) {
164                  System.out.println("s-1: " + all.subList(i+1, all.size()).indexOf(o));
165 <                fail("subList/indexOf is screwy.");
165 >                fail("subList/indexOf is screwy.");
166              }
167              if (all.subList(0,i+1).lastIndexOf(o) != i) {
168                  System.out.println("si" + all.subList(0,i+1).lastIndexOf(o));
169 <                fail("subList/lastIndexOf is screwy.");
169 >                fail("subList/lastIndexOf is screwy.");
170              }
171 <            i++;
172 <        }
171 >            i++;
172 >        }
173  
174          List l = newList(cl, synch);
175          AddRandoms(l, listSize);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines