X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Futil%2FVec.java;h=cffe9f5df2ed32959e75fa1a5d548b83fd737a07;hb=HEAD;hp=6d1fbd5b85a86577bf9bf56ffe3083367ef7e56f;hpb=e1076a62356975f3b8c308146185fefd0e23fa2d;p=org.ibex.util.git diff --git a/src/org/ibex/util/Vec.java b/src/org/ibex/util/Vec.java index 6d1fbd5..cffe9f5 100644 --- a/src/org/ibex/util/Vec.java +++ b/src/org/ibex/util/Vec.java @@ -1,9 +1,6 @@ -// Copyright (C) 2003 Adam Megacz all rights reserved. -// -// You may modify, copy, and redistribute this code under the terms of -// the GNU Library Public License version 2.1, with the exception of -// the portion of clause 6a after the semicolon (aka the "obnoxious -// relink clause") +// Copyright 2000-2005 the Contributors, as shown in the revision logs. +// Licensed under the Apache Public Source License 2.0 ("the License"). +// You may not use this file except in compliance with the License. package org.ibex.util; import java.io.*; @@ -17,7 +14,7 @@ import java.io.*; * * @see java.util.Vector */ -public final class Vec implements Serializable { +public final class Vec implements Serializable, Cloneable { private Object[] store; private int size = 0; @@ -25,7 +22,13 @@ public final class Vec implements Serializable { public Vec() { this(10); } public Vec(int i) { store = new Object[i]; } public Vec(int i, Object[] store) { size = i; this.store = store; } - + public Vec(Vec old) { + store = new Object[old.store.length]; + System.arraycopy(old.store, 0, store, 0, old.store.length); + this.size = old.size; + } + + public Object clone() { return new Vec(this); } private void grow() { grow(store.length * 2); } private void grow(int newsize) { Object[] newstore = new Object[newsize]; @@ -50,6 +53,7 @@ public final class Vec implements Serializable { return -1; } + public void add(Object o) { addElement(o); } public void addElement(Object o) { if (size >= store.length - 1) grow(); store[size++] = o; @@ -59,6 +63,7 @@ public final class Vec implements Serializable { return lastElement(); } + public Object get(int i) { return elementAt(i); } public Object elementAt(int i) { return store[i]; } @@ -98,6 +103,7 @@ public final class Vec implements Serializable { store[i] = in[i]; } + public void remove(int i) { removeElementAt(i); } public void removeElementAt(int i) { if (i >= size || i < 0) throw new RuntimeException("tried to remove an element outside the vector's limits"); for(int j=i; j