blob: 77e4c8151bd67dbbca906c97ef236353b49e17d1 (
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
|
/*
* Collection.oj
*
* Apr 13, 1999 Michiaki Tatsubori
*/
package examples.freeargs;
import examples.freeargs.FreeArgsClass;
import examples.print.*;
/**
* The class <code>Collection</code> represents a collection of objects.
*/
public class Collection instantiates FreeArgsClass
{
private Object[] contents;
public Collection() {
contents = new Object[0];
}
public boolean isEmpty() {
return (contents.length == 0);
}
/** Accepts any number of arguments. */
public generous void set( Object[] args ) {
contents = new Object[args.length];
System.arraycopy( args, 0, contents, 0, args.length );
}
/** Accepts any number of arguments. */
public generous void add( Object[] args ) {
Object[] old = contents;
contents = new Object[old.length + args.length];
System.arraycopy( old, 0, contents, 0, old.length );
System.arraycopy( args, 0, contents, old.length, args.length );
}
public int size() {
return contents.length;
}
/** Obtains a specified object. */
public Object get( int i ) {
return contents[i];
}
}
|