File: A.java

package info (click to toggle)
eclipse-jdt-ui 4.29-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 93,280 kB
  • sloc: java: 831,977; xml: 14,578; jsp: 33; makefile: 5
file content (76 lines) | stat: -rw-r--r-- 1,726 bytes parent folder | download | duplicates (3)
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 implements Bag {
	int size = 0;
	Comparable[] elems = new Comparable[10];
	public java.util.Iterator iterator() {
		return new Iterator(this);
	}
	public Bag add(Comparable e) {
		if (this.size + 1 == this.elems.length) {
			Comparable[] newElems = new Comparable[2 * this.size];
			System.arraycopy(this.elems, 0, newElems, 0, this.size);
			this.elems = newElems;
		}
		this.elems[this.size++] = e;
		return this;
	}
	public Bag addAll(Bag v1) {
		java.util.Iterator i = v1.iterator();
		for (; i.hasNext(); this.add((Comparable) i.next()));
		return this;
	}
	public void sort() { /* insertion sort */
		for (int i = 1; i < this.size; i++) {
			Comparable e1 = this.elems[i];
			int j = i;
			while ((j > 0) && (this.elems[j - 1].compareTo(e1) > 0)) {
				this.elems[j] = this.elems[j - 1];
				j--;
			}
			this.elems[j] = e1;
		}
	}
}
class Iterator implements java.util.Iterator {
	private int count = 0;
	private A v2;
	Iterator(A v3) {
		this.v2 = v3;
	}
	public boolean hasNext() {
		return this.count < this.v2.size;
	}
	public Object next() {
		return this.v2.elems[this.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(Bag v5) {
		v5.add("foo").add("bar");
	}
	static void update(Bag v6) {
		Bag v7 = new A().add("zap").add("baz");
		v6.addAll(v7);
	}
	static void sortList(A v8) {
		v8.sort();
	}
	static void print(Bag v9) {
		for (java.util.Iterator iter = v9.iterator(); iter.hasNext();)
			System.out.println("Object: " + iter.next());
	}
}