File: A.java

package info (click to toggle)
eclipse-jdt-ui 4.15-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 84,736 kB
  • sloc: java: 721,354; xml: 13,098; jsp: 33; makefile: 5
file content (76 lines) | stat: -rw-r--r-- 1,597 bytes parent folder | download | duplicates (4)
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
package p;

class A {
	int size = 0;
	Comparable[] elems = new Comparable[10];
	public java.util.Iterator iterator() {
		return new Iterator(this);
	}
	public A add(Comparable e) {
		if (size + 1 == elems.length) {
			Comparable[] newElems = new Comparable[2 * size];
			System.arraycopy(elems, 0, newElems, 0, size);
			elems = newElems;
		}
		elems[size++] = e;
		return this;
	}
	public A addAll(A v1) {
		java.util.Iterator i = v1.iterator();
		for (; i.hasNext(); add((Comparable) i.next()));
		return this;
	}
	public void sort() { /* insertion sort */
		for (int i = 1; i < size; i++) {
			Comparable e1 = elems[i];
			int j = i;
			while ((j > 0) && (elems[j - 1].compareTo(e1) > 0)) {
				elems[j] = elems[j - 1];
				j--;
			}
			elems[j] = e1;
		}
	}
}
class Iterator implements java.util.Iterator {
	private int count = 0;
	private A v2;
	Iterator(A v3) {
		v2 = v3;
	}
	public boolean hasNext() {
		return count < v2.size;
	}
	public Object next() {
		return v2.elems[count++];
	}
	public void remove() {
		throw new UnsupportedOperationException();
	}
}
class Client {
	public static void main(String[] args) {
		A v4 = createList();
		populate(v4);
		update(v4);
		sortList(v4);
		print(v4);
	}
	static A createList() {
		return new A();
	}
	static void populate(A v5) {
		v5.add("foo").add("bar");
	}
	static void update(A v6) {
		A v7 = new A().add("zap").add("baz");
		v6.addAll(v7);
	}
	static void sortList(A v8) {
		v8.sort();
	}
	static void print(A v9) {
		for (java.util.Iterator iter = v9.iterator(); iter.hasNext();)
			System.out.println("Object: " + iter.next());
	}
}