/** * set element by index * * @param index * @param element * @return */ @Override public T set(int index, T element) { checkPositionIndex(index); ToldElement= array[index]; array[index] = element; return oldElement; }
/** * get element by index * * @param index * @return */ @Override public T get(int index) { checkPositionIndex(index); return array[index]; }
/** * check index * * @param index */ privatevoidcheckPositionIndex(int index) { if (index < 0 || index >= size) { thrownewIndexOutOfBoundsException("Index: " + index + ", Size: " + size); } }
/** * clear list */ @Override publicvoidclear() { for (inti=0; i < size; i++) { array[i] = null; } size = 0; }
/** * contain certain element * * @param element */ @Override publicbooleancontains(T element) { for (inti=0; i < size; i++) { if (element == null) { if (array[i] == null) { returntrue; } } else { if (array[i].equals(element)) { returntrue; } } } returnfalse; }
/** * get list size * * @return */ @Override publicintsize() { return size; } }