Package com.serov.lab1
Class Container<T>
java.lang.Object
com.serov.lab1.Container<T>
Container implementation
- Author:
- n.a.serov
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor without parameters, creates a container of a size defined in Container.DEFAULT_SIZEContainer(int size) Constructor with given size, creates a container of given sizeConstructor with all given fields, creates a container with given elements count, given size and copies the array of type T -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the container and sets elements count to 0, container size does not changegetElementAt(int index) Returns the element at given indexintReturns the count of elements in a containerintgetSize()Returns the size of a containervoidinsertElement(T newValue) Inserts a new element to the end of the containerremoveElementAt(int index) Removes the element at given index, rebuilds the container without this elementvoidsetElementAt(int index, T newValue) Sets the count of elements of a containertoString()Returns the container's elements as a string
-
Field Details
-
DEFAULT_SIZE
public static final int DEFAULT_SIZEDefault size- See Also:
-
-
Constructor Details
-
Container
public Container()Default constructor without parameters, creates a container of a size defined in Container.DEFAULT_SIZE -
Container
public Container(int size) Constructor with given size, creates a container of given size- Parameters:
size- the size of a new container
-
Container
Constructor with all given fields, creates a container with given elements count, given size and copies the array of type T- Parameters:
elementsCount- the count of elements of a new containersize- the size of a new containerelements- the array of elements to be copied to a new container
-
-
Method Details
-
clear
public void clear()Clears the container and sets elements count to 0, container size does not change -
getSize
public int getSize()Returns the size of a container- Returns:
- the size of a container
-
getElementsCount
public int getElementsCount()Returns the count of elements in a container- Returns:
- the count of elements in a container
-
getElementAt
Returns the element at given index- Parameters:
index- index of an element to get value from- Returns:
- the element at given index
- Throws:
IndexOutOfBoundsException- If the given index is not in a current container's bounds
-
setElementAt
Sets the count of elements of a container- Parameters:
index- the index of an element to be changednewValue- the new value of an element to be changed- Throws:
NullPointerException- If a new value is null
-
insertElement
Inserts a new element to the end of the container- Parameters:
newValue- the value of an element to be added to the end of the container- Throws:
NullPointerException- If a new value in null
-
removeElementAt
Removes the element at given index, rebuilds the container without this element- Parameters:
index- the index of an element to remove- Returns:
- the value of the removed element
- Throws:
IndexOutOfBoundsException- If the given index is not in a current container's bounds
-
toString
Returns the container's elements as a string
-