summaryrefslogtreecommitdiff
path: root/tutorial/examples/freeargs/Collection.oj
diff options
context:
space:
mode:
Diffstat (limited to 'tutorial/examples/freeargs/Collection.oj')
-rw-r--r--tutorial/examples/freeargs/Collection.oj52
1 files changed, 52 insertions, 0 deletions
diff --git a/tutorial/examples/freeargs/Collection.oj b/tutorial/examples/freeargs/Collection.oj
new file mode 100644
index 0000000..77e4c81
--- /dev/null
+++ b/tutorial/examples/freeargs/Collection.oj
@@ -0,0 +1,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];
+ }
+
+}