diff --git a/2-0-data-structures-and-algorithms/pom.xml b/2-0-data-structures-and-algorithms/pom.xml index f1340f395..0d5e1efe9 100644 --- a/2-0-data-structures-and-algorithms/pom.xml +++ b/2-0-data-structures-and-algorithms/pom.xml @@ -3,6 +3,14 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + + + com.bobocode + java-fundamentals-util + 1.0-SNAPSHOT + compile + + com.bobocode diff --git a/2-0-data-structures-and-algorithms/src/main/java/com/bobocode/linked_list/LinkedList.java b/2-0-data-structures-and-algorithms/src/main/java/com/bobocode/linked_list/LinkedList.java index 4c1cf3d4a..7d478acdf 100644 --- a/2-0-data-structures-and-algorithms/src/main/java/com/bobocode/linked_list/LinkedList.java +++ b/2-0-data-structures-and-algorithms/src/main/java/com/bobocode/linked_list/LinkedList.java @@ -1,5 +1,9 @@ package com.bobocode.linked_list; + + +import com.bobocode.util.ExerciseNotCompletedException; + import java.util.NoSuchElementException; /** @@ -18,7 +22,7 @@ public class LinkedList implements List { * @return a new list of elements the were passed as method parameters */ public static List of(T... elements) { - throw new UnsupportedOperationException("This method is not implemented yet"); // todo: implement this method + throw new ExerciseNotCompletedException(); // todo: implement this method } /** @@ -28,7 +32,7 @@ public static List of(T... elements) { */ @Override public void add(T element) { - throw new UnsupportedOperationException("This method is not implemented yet"); // todo: implement this method + throw new ExerciseNotCompletedException(); // todo: implement this method } /** @@ -40,7 +44,7 @@ public void add(T element) { */ @Override public void add(int index, T element) { - throw new UnsupportedOperationException("This method is not implemented yet"); // todo: implement this method + throw new ExerciseNotCompletedException(); // todo: implement this method } /** @@ -52,7 +56,7 @@ public void add(int index, T element) { */ @Override public void set(int index, T element) { - throw new UnsupportedOperationException("This method is not implemented yet"); // todo: implement this method + throw new ExerciseNotCompletedException(); // todo: implement this method } /** @@ -64,18 +68,18 @@ public void set(int index, T element) { */ @Override public T get(int index) { - throw new UnsupportedOperationException("This method is not implemented yet"); // todo: implement this method + 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 + * @throws NoSuchElementException if list is empty */ @Override public T getFirst() { - throw new UnsupportedOperationException("This method is not implemented yet"); // todo: implement this method + throw new ExerciseNotCompletedException(); // todo: implement this method } /** @@ -86,7 +90,7 @@ public T getFirst() { */ @Override public T getLast() { - throw new UnsupportedOperationException("This method is not implemented yet"); // todo: implement this method + throw new ExerciseNotCompletedException(); // todo: implement this method } /** @@ -97,7 +101,7 @@ public T getLast() { */ @Override public void remove(int index) { - throw new UnsupportedOperationException("This method is not implemented yet"); // todo: implement this method + throw new ExerciseNotCompletedException(); // todo: implement this method } @@ -108,7 +112,7 @@ public void remove(int index) { */ @Override public boolean contains(T element) { - throw new UnsupportedOperationException("This method is not implemented yet"); // todo: implement this method + throw new ExerciseNotCompletedException(); // todo: implement this method } /** @@ -118,7 +122,7 @@ public boolean contains(T element) { */ @Override public boolean isEmpty() { - throw new UnsupportedOperationException("This method is not implemented yet"); // todo: implement this method + throw new ExerciseNotCompletedException(); // todo: implement this method } /** @@ -128,7 +132,7 @@ public boolean isEmpty() { */ @Override public int size() { - throw new UnsupportedOperationException("This method is not implemented yet"); // todo: implement this method + throw new ExerciseNotCompletedException(); // todo: implement this method } /** @@ -136,6 +140,6 @@ public int size() { */ @Override public void clear() { - throw new UnsupportedOperationException("This method is not implemented yet"); // todo: implement this method + throw new ExerciseNotCompletedException(); // todo: implement this method } } diff --git a/3-0-java-core/pom.xml b/3-0-java-core/pom.xml index c64260c12..e291a887e 100644 --- a/3-0-java-core/pom.xml +++ b/3-0-java-core/pom.xml @@ -3,6 +3,14 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + + + com.bobocode + java-fundamentals-util + 1.0-SNAPSHOT + compile + + com.bobocode diff --git a/3-0-java-core/src/main/java/com/bobocode/file_reader/FileReaders.java b/3-0-java-core/src/main/java/com/bobocode/file_reader/FileReaders.java new file mode 100644 index 000000000..685d2d473 --- /dev/null +++ b/3-0-java-core/src/main/java/com/bobocode/file_reader/FileReaders.java @@ -0,0 +1,19 @@ +package com.bobocode.file_reader; + +import com.bobocode.util.ExerciseNotCompletedException; + +/** + * {@link FileReaders} provides an API that allow to read whole file into a {@link String} by file name. + */ +public class FileReaders { + + /** + * Returns a {@link String} that contains whole text from the file specified by name. + * + * @param fileName a name of a text file + * @return string that holds whole file content + */ + public static String readWholeFile(String fileName) { + throw new ExerciseNotCompletedException(); //todo + } +} diff --git a/3-0-java-core/src/test/java/com/bobocode/file_reader/FileReadersTest.java b/3-0-java-core/src/test/java/com/bobocode/file_reader/FileReadersTest.java new file mode 100644 index 000000000..a7e4311fe --- /dev/null +++ b/3-0-java-core/src/test/java/com/bobocode/file_reader/FileReadersTest.java @@ -0,0 +1,36 @@ +package com.bobocode.file_reader; + +import com.bobocode.file_reader.FileReaders; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + + +public class FileReadersTest { + + @Test + void testReadWholeFileOnEmptyFile() { + String fileContent = FileReaders.readWholeFile("empty.txt"); + + assertEquals("", fileContent); + + } + + @Test + void testReadWholeFileOnFileWithEmptyLines() { + String fileContent = FileReaders.readWholeFile("lines.txt"); + + assertEquals("Hey!\n" + + "\n" + + "What's up?\n" + + "\n" + + "Hi!", fileContent); + } + + @Test + void testReadWholeFile() { + String fileContent = FileReaders.readWholeFile("simple.txt"); + + assertEquals("Hello!\n" + "It's a test file.", fileContent); + } +} diff --git a/3-0-java-core/src/test/resources/empty.txt b/3-0-java-core/src/test/resources/empty.txt new file mode 100644 index 000000000..e69de29bb diff --git a/3-0-java-core/src/test/resources/lines.txt b/3-0-java-core/src/test/resources/lines.txt new file mode 100644 index 000000000..7c294a97f --- /dev/null +++ b/3-0-java-core/src/test/resources/lines.txt @@ -0,0 +1,5 @@ +Hey! + +What's up? + +Hi! \ No newline at end of file diff --git a/3-0-java-core/src/test/resources/simple.txt b/3-0-java-core/src/test/resources/simple.txt new file mode 100644 index 000000000..ac906f0b9 --- /dev/null +++ b/3-0-java-core/src/test/resources/simple.txt @@ -0,0 +1,2 @@ +Hello! +It's a test file. \ No newline at end of file