forked from bobocode-projects/java-persistence-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request bobocode-projects#26 from bobocode-projects/GP-33_…
…A_new_Array_Wrapper_exercise_into_main GP-33 Add ArrayList exercise into main
- Loading branch information
Showing
4 changed files
with
528 additions
and
0 deletions.
There are no files selected for viewing
154 changes: 154 additions & 0 deletions
154
2-0-data-structures-and-algorithms/src/main/java/com/bobocode/array_list/ArrayList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
package com.bobocode.array_list; | ||
|
||
import com.bobocode.linked_list.List; | ||
import com.bobocode.util.ExerciseNotCompletedException; | ||
|
||
/** | ||
* {@link ArrayList} is an implementation of {@link List} interface. This resizable data structure | ||
* based on an array and is simplified version of {@link java.util.ArrayList}. | ||
*/ | ||
public class ArrayList<T> implements List<T> { | ||
|
||
/** | ||
* This constructor creates an instance of {@link ArrayList} with a specific capacity of an array inside. | ||
* | ||
* @param initCapacity - the initial capacity of the list | ||
* @throws IllegalArgumentException – if the specified initial capacity is negative or 0. | ||
*/ | ||
public ArrayList(int initCapacity) { | ||
throw new ExerciseNotCompletedException(); // todo: implement this method | ||
} | ||
|
||
/** | ||
* This constructor creates an instance of {@link ArrayList} with a default capacity of an array inside. | ||
* A default size of inner array is 5; | ||
*/ | ||
public ArrayList() { | ||
throw new ExerciseNotCompletedException(); // todo: implement this method | ||
} | ||
|
||
/** | ||
* Creates and returns an instance of {@link ArrayList} with provided elements | ||
* | ||
* @param elements to add | ||
* @return new instance | ||
*/ | ||
public static <T> List<T> of(T... elements) { | ||
throw new ExerciseNotCompletedException(); // todo: implement this method | ||
} | ||
|
||
/** | ||
* Adds an element to the array and returns index of position. | ||
* | ||
* @param element element to add | ||
*/ | ||
@Override | ||
public void add(T element) { | ||
throw new ExerciseNotCompletedException(); // todo: implement this method | ||
} | ||
|
||
/** | ||
* Adds an element to the specific position in the array where | ||
* | ||
* @param index index of position | ||
* @param element element to add | ||
*/ | ||
@Override | ||
public void add(int index, T element) { | ||
throw new ExerciseNotCompletedException(); // todo: implement this method | ||
} | ||
|
||
/** | ||
* Retrieves an element by its position index. In case provided index in out of the list bounds it | ||
* throws {@link IndexOutOfBoundsException} | ||
* | ||
* @param index index of element | ||
* @return en element | ||
*/ | ||
@Override | ||
public T get(int index) { | ||
throw new ExerciseNotCompletedException(); // todo: implement this method | ||
} | ||
|
||
/** | ||
* Returns the first element of the list. Operation is performed in constant time O(1) | ||
* | ||
* @return the first element of the list | ||
* @throws java.util.NoSuchElementException if list is empty | ||
*/ | ||
@Override | ||
public T getFirst() { | ||
throw new ExerciseNotCompletedException(); // todo: implement this method | ||
} | ||
|
||
/** | ||
* Returns the last element of the list. Operation is performed in constant time O(1) | ||
* | ||
* @return the last element of the list | ||
* @throws java.util.NoSuchElementException if list is empty | ||
*/ | ||
@Override | ||
public T getLast() { | ||
throw new ExerciseNotCompletedException(); // todo: implement this method | ||
} | ||
|
||
/** | ||
* Changes the value of array at specific position. In case provided index in out of the list bounds it | ||
* throws {@link IndexOutOfBoundsException} | ||
* | ||
* @param index position of value | ||
* @param element a new value | ||
*/ | ||
@Override | ||
public void set(int index, T element) { | ||
throw new ExerciseNotCompletedException(); // todo: implement this method | ||
} | ||
|
||
/** | ||
* Removes an elements by its position index. In case provided index in out of the list bounds it | ||
* throws {@link IndexOutOfBoundsException} | ||
* | ||
* @param index element index | ||
*/ | ||
@Override | ||
public void remove(int index) { | ||
throw new ExerciseNotCompletedException(); // todo: implement this method | ||
} | ||
|
||
/** | ||
* Checks for existing of a specific element in the list. | ||
* | ||
* @param element is element | ||
* @return If element exists method returns true, otherwise it returns false | ||
*/ | ||
@Override | ||
public boolean contains(T element) { | ||
throw new ExerciseNotCompletedException(); // todo: implement this method | ||
} | ||
|
||
/** | ||
* Checks if a list is empty | ||
* | ||
* @return {@code true} if list is empty, {@code false} otherwise | ||
*/ | ||
@Override | ||
public boolean isEmpty() { | ||
throw new ExerciseNotCompletedException(); // todo: implement this method | ||
} | ||
|
||
/** | ||
* @return amount of saved elements | ||
*/ | ||
@Override | ||
public int size() { | ||
throw new ExerciseNotCompletedException(); // todo: implement this method | ||
} | ||
|
||
/** | ||
* Removes all list elements | ||
*/ | ||
@Override | ||
public void clear() { | ||
throw new ExerciseNotCompletedException(); // todo: implement this method | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
2-0-data-structures-and-algorithms/src/main/java/com/bobocode/array_list/README.MD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# <img src="https://raw.githubusercontent.com/bobocode-projects/resources/master/image/logo_transparent_background.png" height=50/>Array Wrapper exercise :muscle: | ||
Improve your basic knowledge about data structures and Java Core. | ||
This wrapper is a simple version of the `ArrayList` data structure. | ||
### Task | ||
`ListOfLongs` interface provides an API with a couple of methods for a wrapper of a default array in Java. Your job is to implement the *todo* section of `ArrayListOfLongs` class. | ||
To verify your implementation, run `ListOfLongsTest.java`. | ||
|
||
### Pre-conditions :heavy_exclamation_mark: | ||
You're supposed to be familiar with arrays, cycles, conditions, exceptions and variables. | ||
|
||
### How to start :question: | ||
* Just clone the repository and start implementing the **todo** section, verify your changes by running tests | ||
* If you don't have enough knowledge about this domain, check out the [links below](#related-materials-information_source) | ||
* Don't worry if you got stuck, checkout the **exercise/completed** branch and see the final implementation | ||
|
||
### Related materials :information_source: | ||
###to do |
Oops, something went wrong.