├── .gitignore ├── README.md ├── basic-arrays ├── basic-arrays.iml └── src │ └── mini │ └── java │ └── basic │ └── arrays │ ├── Main.java │ ├── MathVector.java │ ├── MathVectorLombok.java │ ├── MathVectorTest.java │ ├── RandomMathVector.java │ ├── test │ ├── README.md │ └── TimeSeriesTest.java │ └── testsolution │ ├── AnonymousTimeSeries.java │ ├── TimeSeries.java │ └── TimeSeriesTest.java ├── basic-collections ├── basic-collections.iml ├── dataset.csv ├── dataset_empty_product.csv ├── dataset_malformed_product.csv ├── dataset_malformed_warehouse.csv └── src │ └── mini │ └── java │ └── basic │ └── collections │ ├── CollectionsTest.java │ └── test │ ├── CachingAndPagingDataRepository.java │ ├── DataLoader.java │ ├── DataMappers.java │ ├── DataRepositoryTest.java │ ├── NoDataException.java │ ├── ProductDataMalformedException.java │ ├── SimpleDataRepository.java │ ├── WarehouseDataMalformedException.java │ └── solution │ ├── CachingAndPagingDataRepository.java │ ├── DataLoader.java │ ├── DataMappers.java │ ├── DataRepositoryTest.java │ ├── NoDataException.java │ ├── ProductDataMalformedException.java │ ├── SimpleDataRepository.java │ └── WarehouseDataMalformedException.java ├── basic-generics ├── basic-generics.iml └── src │ └── mini │ └── java │ └── basic │ └── generics │ ├── Dataset.java │ ├── GenericsTest.java │ ├── SeriesSummer.java │ └── TimeSeries.java ├── basic-interfaces ├── basic-interfaces.iml └── src │ └── mini │ └── java │ └── basic │ └── interfaces │ ├── AbstractTimeSeries.java │ ├── IntegerTimeSeries.java │ ├── Printable.java │ ├── SeriesTest.java │ ├── StringTimeSeries.java │ ├── Summable.java │ └── test │ ├── AbstractRandomizer.java │ ├── IntegerList.java │ ├── IntegerRandomizer.java │ ├── RandomizerTests.java │ ├── StringRandomizer.java │ └── TypeAware.java ├── basic-iostreams ├── basic-iostreams.iml └── src │ └── mini │ └── java │ └── basic │ └── iostreams │ ├── SerializableObject.java │ ├── SerializableObjectWithTransients.java │ ├── SerializationTests.java │ ├── TextFileStreamsTests.java │ └── test │ ├── CSVDataset.java │ ├── CSVSerializerDeserializerTest.java │ └── test.csv ├── basic-objects ├── basic-objects.iml └── src │ └── mini │ └── java │ └── basic │ └── objects │ └── Main.java ├── basic-swing ├── basic-swing.iml └── src │ ├── BasicForm.form │ └── BasicForm.java ├── basic-threading ├── basic-threading.iml └── src │ └── mini │ └── java │ └── basic │ └── threading │ └── ThreadingTest.java ├── docs └── images │ ├── add-test-file.gif │ ├── create-project.gif │ ├── debug-all-tests.png │ └── generate-class.gif ├── lab-objective-basics.iml └── test.csv /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | \.idea/ 3 | out/ 4 | *.jar 5 | 6 | gson_serialized\.json 7 | 8 | java_serialized\.bin 9 | 10 | test\.txt 11 | 12 | \.DS_Store 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Programowanie Obiektowe - Java 2 | ## MiNI PW, Wiosna 2019/2020 3 | 4 | ### Laboratorium 1 - Środowisko i Hello World 5 | 6 | ```java 7 | package mini.java.basic.objects; 8 | 9 | public class Main { 10 | public static void main(String[] args) { 11 | System.out.println("Hello World!"); 12 | } 13 | } 14 | ``` 15 | 16 | #### Przydatne do poruszania się po środowisku IntelliJ IDEA 17 | - Sktóry klawiaturowe - https://resources.jetbrains.com/storage/products/intellij-idea/docs/IntelliJIDEA_ReferenceCard.pdf 18 | - Szybki start dla IDEA - https://www.jetbrains.com/help/idea/getting-started.html 19 | - Hello World w Java + IDEA - https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-application.html 20 | 21 | ### Laboratorium 2 i 3 - Obiekty, klasy i tablice 22 | 23 | ```java 24 | package mini.java.basic.objects; 25 | 26 | public class Vehicle { 27 | protected String name; 28 | protected String[] manufacturerNames; 29 | protected int price; 30 | } 31 | 32 | public class Plane extends Vehicle { 33 | private int flightSpeed; 34 | private int altitude; 35 | } 36 | 37 | public class Car extends Vehicle { 38 | private int speed; 39 | } 40 | 41 | public class Bicycle extends Vehicle { 42 | private boolean twoPerson; 43 | } 44 | ``` 45 | 46 | #### Przydatne linki 47 | - Dziedziczenie - opis na Wikipedia (teoria) - https://pl.wikipedia.org/wiki/Dziedziczenie_%28programowanie%29 48 | - Dziedziczenie - tutorial od Oracle - https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html 49 | 50 | #### Poprzednie zadania punktowane 51 | - [Rok 2018/2019](basic-arrays/src/mini/java/basic/arrays/test/README.md) 52 | 53 | 54 | ## Jak skutecznie zabrać się za rozwiązanie zadania punktowanego 55 | [Instrukcja ze zrzutami ekranu](https://github.com/Rughalt/mini-objective-java/wiki/Zadania-Punktowane) 56 | 57 | 58 | ## Oprogramowanie 59 | - Licencje Jetbrains dla studentów - https://www.jetbrains.com/student/ 60 | - Java 11/8 - Amazon Corretto - https://docs.aws.amazon.com/corretto/index.html 61 | 62 | -------------------------------------------------------------------------------- /basic-arrays/basic-arrays.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /basic-arrays/src/mini/java/basic/arrays/Main.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.arrays; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | // write your code here 6 | 7 | } 8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /basic-arrays/src/mini/java/basic/arrays/MathVector.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.arrays; 2 | 3 | import java.util.Arrays; 4 | 5 | public class MathVector { 6 | /** 7 | * Tablica licz reprezentująca wektor 8 | */ 9 | protected int[] i; 10 | 11 | /** 12 | * Zmienna reprezentująca informację czy wektor jest zrandomizowany 13 | */ 14 | protected boolean randomized = false; 15 | 16 | /** 17 | * Tworzy instancję obiektu MathVector z tablicy liczb. 18 | * @implNote int... (zmienna liczba argumentów) jest innym sposobem zapisu int[] przy przekazywaniu jako parametr funkcji 19 | * @param i Tablica liczb do utowrzenia obiektu 20 | */ 21 | public MathVector(int... i) { 22 | this.i = i; 23 | } 24 | 25 | 26 | /** 27 | * Prosty getter, zwraca tablicę i 28 | * @return tablica liczb i 29 | */ 30 | public int[] getI() { 31 | return i; 32 | } 33 | 34 | /** 35 | * Prosty setter, ustawia wartość tablicy i (przypisuje zmiennej i przekazaną tablicę) 36 | * @param i 37 | */ 38 | public void setI(int[] i) { 39 | this.i = i; 40 | } 41 | 42 | /** 43 | * 44 | * @param o 45 | * @return true jeżeli obiekty są identyczne, false jeżeli nie 46 | */ 47 | @Override 48 | public boolean equals(Object o) { 49 | if (this == o) return true; 50 | if (o == null || !o.getClass().equals(this.getClass())) return false; 51 | MathVector that = (MathVector) o; 52 | return Arrays.equals(getI(), that.getI()); 53 | } 54 | 55 | 56 | /** 57 | * Wylicza hashcode dla obiektu 58 | * @return hashcode 59 | */ 60 | @Override 61 | public int hashCode() { 62 | return Arrays.hashCode(getI()); 63 | } 64 | 65 | /** 66 | * Zwraca tekst będący reprezentacją obiektu 67 | * @return tekst reprezentujący obiekt 68 | */ 69 | @Override 70 | public String toString() { 71 | return "MathVector{" + 72 | "i=" + Arrays.toString(i) + 73 | '}'; 74 | } 75 | 76 | /** 77 | * Zwraca nowy wektor będący iloczynem skalarnym tego wektora oraz liczby s 78 | * @param s 79 | * @return wektor 80 | */ 81 | public MathVector multiplyByScalar(int s) { 82 | int[] j = new int[this.i.length]; 83 | for( int idx = 0; idx < this.i.length; idx++) { 84 | j[idx] = this.i[idx] * s; 85 | } 86 | return new MathVector(j); 87 | } 88 | 89 | /** 90 | * Zwraca długość tablicy i 91 | * @return długość tablicy i 92 | */ 93 | public int getLength() { 94 | return i.length; 95 | } 96 | 97 | /** 98 | * Getter dla zmiennej randomized (mówiącej czy wektor jest losowy) 99 | * @return 100 | */ 101 | public boolean isRandomized() { 102 | return randomized; 103 | } 104 | 105 | /** 106 | * Setter dla zmiennej randomized (mówiącej czy wektor jest losowy) 107 | */ 108 | public void setRandomized(boolean randomized) { 109 | this.randomized = randomized; 110 | } 111 | 112 | /** 113 | * Metoda zwracającz informację czy wektor jest zrandomizowany 114 | * @return 115 | */ 116 | public boolean isRandomizedMethod() { 117 | return false; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /basic-arrays/src/mini/java/basic/arrays/MathVectorLombok.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.arrays; 2 | 3 | import lombok.*; 4 | 5 | import java.util.Arrays; 6 | 7 | @Data 8 | public class MathVectorLombok { 9 | protected int[] data; 10 | protected boolean randomized = false; 11 | } 12 | 13 | 14 | -------------------------------------------------------------------------------- /basic-arrays/src/mini/java/basic/arrays/MathVectorTest.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.arrays; 2 | 3 | import org.junit.Assert; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | public class MathVectorTest { 8 | 9 | /** 10 | * Test sprawdzający sposób działania prymitywnego przyrównania (==) dla porównywania obiektów 11 | */ 12 | @org.junit.Test 13 | public void primitiveEquals() { 14 | MathVector vector1 = new MathVector(1,2,3,4); 15 | int[] j = {1,2,3,4}; 16 | MathVector vector2 = new MathVector(j); 17 | assertFalse(vector1 == vector2); 18 | } 19 | 20 | /** 21 | * Test sprawdzający sposób działania zaimplementowanej metody equals dla porównywania obiektów (obiekty w założeniu różne) 22 | */ 23 | @org.junit.Test 24 | public void equalsFalse() { 25 | MathVector vector1 = new MathVector(1,2,3,4); 26 | MathVector vector2 = new MathVector(1,2,3); 27 | assertNotEquals(vector1, vector2); 28 | } 29 | 30 | /** 31 | * Test sprawdzający sposób działania zaimplementowanej metody equals dla porównywania obiektów (obiekty w założeniu identyczne) 32 | */ 33 | @org.junit.Test 34 | public void equalsTrue() { 35 | MathVector vector1 = new MathVector(1,2,3,4); 36 | int[] j = {1,2,3,4}; 37 | MathVector vector2 = new MathVector(j); 38 | assertEquals(vector1, vector2); 39 | } 40 | 41 | /** 42 | * Test sprawdzający sposób działania zaimplementowanej metody hashcode dla porównywania obiektów (obiekty w założeniu identyczne) 43 | */ 44 | @org.junit.Test 45 | public void hashcodeEquals() { 46 | MathVector vector1 = new MathVector(1,2,3,4); 47 | MathVector vector2 = new MathVector(1,2,3,4); 48 | assertEquals(vector1.hashCode(), vector2.hashCode()); 49 | } 50 | 51 | 52 | /** 53 | * Test sprawdzający sposób działanie metody multiplyByScalar 54 | */ 55 | @org.junit.Test 56 | public void multiplicationTest() { 57 | MathVector vector1 = new MathVector(1,2,3,4); 58 | MathVector vector2 = vector1.multiplyByScalar(3); 59 | assertEquals(vector1, new MathVector(1,2,3,4)); 60 | assertEquals(vector2, new MathVector(3,6,9,12)); 61 | } 62 | 63 | 64 | /** 65 | * Test sprawdzający wynik porównania po rzutowaniu 66 | */ 67 | @org.junit.Test 68 | public void castEqualityTest() { 69 | RandomMathVector vector1 = new RandomMathVector(5); 70 | MathVector castedVector = (MathVector) vector1; 71 | RandomMathVector castedVector2 = (RandomMathVector) castedVector; 72 | assertEquals(castedVector2,vector1); 73 | } 74 | 75 | /** 76 | * Test sprawdzający wynik porównania bez rzutowania dla klasy dziedziczącej i głównej 77 | */ 78 | @org.junit.Test 79 | public void classEqualityTest() { 80 | RandomMathVector vector1 = new RandomMathVector(5); 81 | MathVector vector2 = new MathVector(1,2,3,4); 82 | assertNotEquals(vector1.getClass(),vector2.getClass()); 83 | } 84 | 85 | /** 86 | * Test sprawdzający zachowanie metody instanceof dla klasy dziedziczącej 87 | */ 88 | @org.junit.Test 89 | public void classEqualityInstanceOfTest() { 90 | RandomMathVector vector1 = new RandomMathVector(5); 91 | assertTrue(vector1 instanceof MathVector); 92 | } 93 | 94 | /** 95 | * Test sprawdzający długość nowego wektora typu RandomMathVector 96 | */ 97 | @org.junit.Test 98 | public void randomVectorLengthTest() { 99 | MathVector vector1 = new RandomMathVector(5); 100 | assertEquals(vector1.getLength(),5); 101 | } 102 | 103 | /** 104 | * Testy sprawdzające zachowanie metod isRandomized i isRandomizedMethod dla obiektów klas MathVector i RandomMathVector 105 | */ 106 | @org.junit.Test 107 | public void isRandomizedTestRandomMathVector() { 108 | MathVector vector1 = new RandomMathVector(5); 109 | assertTrue(vector1.isRandomized()); 110 | } 111 | 112 | 113 | @org.junit.Test 114 | public void isRandomizedTestMathVector() { 115 | MathVector vector1 = new MathVector(5); 116 | assertFalse(vector1.isRandomized()); 117 | } 118 | 119 | @org.junit.Test 120 | public void isRandomizedTestRandomMathVectorMethod() { 121 | MathVector vector1 = new RandomMathVector(5); 122 | assertTrue(vector1.isRandomizedMethod()); 123 | } 124 | 125 | 126 | @org.junit.Test 127 | public void isRandomizedTestMathVectorMethod() { 128 | MathVector vector1 = new MathVector(5); 129 | assertFalse(vector1.isRandomizedMethod()); 130 | } 131 | 132 | 133 | @org.junit.Test 134 | public void lombokTest() { 135 | MathVectorLombok mlLombok = new MathVectorLombok(); 136 | ml. 137 | } 138 | } -------------------------------------------------------------------------------- /basic-arrays/src/mini/java/basic/arrays/RandomMathVector.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.arrays; 2 | 3 | public class RandomMathVector extends MathVector { 4 | 5 | public RandomMathVector(int length) { 6 | this.i = new int[length]; 7 | for (int idx = 0; idx < length; idx++) 8 | this.i[idx] = (int) (Math.random()*10.0); 9 | this.randomized = true; 10 | } 11 | 12 | @Override 13 | public boolean isRandomizedMethod() { 14 | return true; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /basic-arrays/src/mini/java/basic/arrays/test/README.md: -------------------------------------------------------------------------------- 1 | # 2018/2019 - Zadanie 1 - Tablice i dziedziczenie 2 | 3 | Twoim zadaniem jest napisanie dwóch klas implementujących metody tak, 4 | aby napisane testy jednostkowe wykonały się poprawnie. Sygnatury klas to: 5 | 6 | ```java 7 | /*** 8 | * Klasa ta reprezentuje serie czasową z danymi 9 | */ 10 | class TimeSeries { 11 | private int[] data; // Dane w serii 12 | private String name; // Nazwa serii czasowej 13 | 14 | public getMaximum() {}; // Zwraca największą wartość z serii 15 | public average() {}; // Zwraca średnią 16 | } 17 | ``` 18 | 19 | ```java 20 | /*** 21 | * Klasa ta reprezentuje serie czasową z danymi, nie posiadającą nazwy. 22 | */ 23 | class AnonymousTimeSeries { 24 | private int[] data; // Dane w serii 25 | 26 | public getMaximum() {}; // Zwraca największą wartość z serii 27 | public average() {}; // Zwraca średnią 28 | } 29 | ``` 30 | 31 | ## Wskazówki 32 | - Korzystaj z możliwości generowania kodu przez IntelliJ - ułatwia 33 | to w sposób znaczący pracę. Pamiętaj, że kod nie skompiluje się jeżeli metod nie będzie - 34 | natomiast jeżeli nie będą nic robić, jedyne co może się stać to zły wynik testu 35 | (albo zawieszenie się maszyny - z tym zawsze trzeba się liczyć 😉) 36 | - Uruchamiaj testy zawsze korzystając z opcji debug 🐛. 37 | Dzieki temu ławiej jest znaleźć i zrozumieć dlaczego program nie działa tak jak trzeba. 38 | Pamiętaj o możliwości stawiania breakpointów 🛑. 39 | - Pamiętaj o umiejscowieniu kodu w odpowiednim pakiecie. 40 | Najprościej, jeśli utowrzysz nowy projekt, dodasz plik z testem i pozwolisz `Alt+Enter` 41 | na nazwie pakietu wykonać swoją magię 42 | 43 | ## Jak skutecznie zabrać się za rozwiązanie zadania 44 | [Instrukcja ze zrzutami ekranu](https://github.com/Rughalt/mini-objective-java/wiki/Zadania-Punktowane) 45 | 46 | ## Powodzenia! 47 | -------------------------------------------------------------------------------- /basic-arrays/src/mini/java/basic/arrays/test/TimeSeriesTest.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.arrays.test; 2 | 3 | import static org.junit.Assert.*; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | public class TimeSeriesTest { 7 | 8 | 9 | /*** 10 | * Prosty equals() - sprawdzenie dla identycznych 11 | * @difficulty 1 12 | */ 13 | @org.junit.Test 14 | public void primitiveEquals() { 15 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3,4); 16 | int[] j = {1,2,3,4}; 17 | TimeSeries timeSeries2 = new TimeSeries("TS1",j); 18 | assertFalse(timeSeries1 == timeSeries2); 19 | } 20 | 21 | /*** 22 | * Prosty equals() - sprawdzenie dla różnych 23 | * @difficulty 1 24 | */ 25 | @org.junit.Test 26 | public void equalsFalse() { 27 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3,4); 28 | int[] j = {1,2,3,4}; 29 | TimeSeries timeSeries2 = new TimeSeries("TS2",j); 30 | assertNotEquals(timeSeries1, timeSeries2); 31 | } 32 | 33 | /*** 34 | * Prosty equals() - sprawdzenie dla różnych 35 | * @difficulty 1 36 | */ 37 | @org.junit.Test 38 | public void equalsFalseArray() { 39 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3,4); 40 | int[] j = {1,2,3}; 41 | TimeSeries timeSeries2 = new TimeSeries("TS1",j); 42 | assertNotEquals(timeSeries1, timeSeries2); 43 | } 44 | /*** 45 | * Prosty equals 46 | * @difficulty 1 47 | */ 48 | @org.junit.Test 49 | public void equalsTrue() { 50 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3,4); 51 | int[] j = {1,2,3,4}; 52 | TimeSeries timeSeries2 = new TimeSeries("TS1",j); 53 | assertEquals(timeSeries1, timeSeries2); 54 | } 55 | 56 | /*** 57 | * Prosty equals - sprawdzenie dla nazwy *null* 58 | * @difficulty 1 59 | */ 60 | @org.junit.Test 61 | public void equalsTrueNullName() { 62 | TimeSeries timeSeries1 = new TimeSeries(null,1,2,3,4); 63 | int[] j = {1,2,3,4}; 64 | TimeSeries timeSeries2 = new TimeSeries(null,j); 65 | assertEquals(timeSeries1, timeSeries2); 66 | } 67 | 68 | /*** 69 | * Prosty hashcode() - sprawdzenie czy generowane są identyczne 70 | * @difficulty 1 71 | */ 72 | @org.junit.Test 73 | public void hashcodeEquals() { 74 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3,4); 75 | int[] j = {1,2,3,4}; 76 | TimeSeries timeSeries2 = new TimeSeries("TS1",j); 77 | assertEquals(timeSeries1.hashCode(), timeSeries2.hashCode()); 78 | } 79 | 80 | /*** 81 | * Prosty hashcode() - sprawdzenie czy zmiana nazwy wpływa na hashcode() 82 | * @difficulty 1 83 | */ 84 | @org.junit.Test 85 | public void hashcodeNotEqualsName() { 86 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3,4); 87 | int[] j = {1,2,3,4}; 88 | TimeSeries timeSeries2 = new TimeSeries("TS2",j); 89 | assertNotEquals(timeSeries1.hashCode(), timeSeries2.hashCode()); 90 | } 91 | 92 | /*** 93 | * Prosty hashcode() - sprawdzenie czy zmiana danych serii wpływa na hashcode() 94 | * @difficulty 1 95 | */ 96 | @org.junit.Test 97 | public void hashcodeNotEqualsValue() { 98 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3,4); 99 | int[] j = {1,2,3}; 100 | TimeSeries timeSeries2 = new TimeSeries("TS1",j); 101 | assertNotEquals(timeSeries1.hashCode(), timeSeries2.hashCode()); 102 | } 103 | 104 | /*** 105 | * Sprawdzenie działania metody zmiennej _name_ 106 | * @difficulty 1 107 | */ 108 | @org.junit.Test 109 | public void averageTest() { 110 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3); 111 | TimeSeries timeSeries2 = new TimeSeries("TS1",4,2,3); 112 | assertEquals(2.0, timeSeries1.average(),0); 113 | assertEquals(3.0, timeSeries2.average(),0); 114 | } 115 | 116 | /*** 117 | * Sprawdzenie gettera zmiennej _name_ 118 | * @difficulty 1 119 | */ 120 | @org.junit.Test 121 | public void getNameTest() { 122 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3); 123 | assertEquals(timeSeries1.getName(),"TS1"); 124 | } 125 | 126 | /*** 127 | * Sprawdzenie gettera zmiennej @name 128 | * @difficulty 1 129 | */ 130 | @org.junit.Test 131 | public void getNameTestNull() { 132 | TimeSeries timeSeries1 = new TimeSeries(null,1,2,3); 133 | assertEquals(timeSeries1.getName(),null); 134 | } 135 | 136 | /*** 137 | * Sprawdzenie metody getMaximum dla liczb ujemych 138 | * @difficulty 1 139 | */ 140 | @org.junit.Test 141 | public void getMaximumTest() { 142 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3,5,6,1); 143 | assertEquals(timeSeries1.getMaximum(),6); 144 | } 145 | 146 | /*** 147 | * Sprawdzenie metody getMaximum dla liczb ujemych 148 | * @difficulty 1 149 | */ 150 | @org.junit.Test 151 | public void getMaximumTestNegative() { 152 | TimeSeries timeSeries1 = new TimeSeries("TS1",-1,-2,-3,-5,-6,-1,-11); 153 | assertEquals(timeSeries1.getMaximum(),-1); 154 | } 155 | 156 | 157 | 158 | /*** 159 | * Sprawdzenie metody average klasy AnonymousTimeSeries 160 | * @difficulty 1 161 | */ 162 | @org.junit.Test 163 | public void anonymousTimeSeriesAverageTst() { 164 | TimeSeries timeSeries1 = new AnonymousTimeSeries(1,2,3); 165 | assertEquals(2.0, timeSeries1.average(),0); 166 | } 167 | /*** 168 | * Sprawdzenie getter pola name klasy AnonymousTimeSeries 169 | * @difficulty 1 170 | */ 171 | @org.junit.Test 172 | public void anonymousTimeSeriesNameTest() { 173 | TimeSeries timeSeries1 = new AnonymousTimeSeries(5,6); 174 | assertNull(timeSeries1.getName()); 175 | } 176 | 177 | /*** 178 | * Sprawdzenie metody equals klasy AnonymousTimeSeries 179 | * @difficulty 1 180 | */ 181 | @org.junit.Test 182 | public void anonymousTimeSeriesEqualityTest() { 183 | TimeSeries timeSeries1 = new AnonymousTimeSeries(5,4,3); 184 | TimeSeries timeSeries2 = new AnonymousTimeSeries(5,4,3); 185 | assertEquals(timeSeries1, timeSeries2); 186 | assertEquals(timeSeries2, timeSeries1); 187 | } 188 | 189 | /*** 190 | * Sprawdzenie metody equals klasy AnonymousTimeSeries wględem klasy bazowej TimeSeries 191 | * @difficulty 1 192 | */ 193 | @org.junit.Test 194 | public void anonymousTimeSeriesEqualityTestAgainstBase() { 195 | TimeSeries timeSeries1 = new AnonymousTimeSeries(5,4,3); 196 | TimeSeries timeSeries2 = new TimeSeries("anonymous", 5,4,3); 197 | assertNotEquals(timeSeries1, timeSeries2); 198 | assertNotEquals(timeSeries2, timeSeries1); 199 | } 200 | 201 | /*** 202 | * Sprawdzenie metody average klasy AnonymousTimeSeries wględem klasy bazowej gdzie nazwa jest Null 203 | * @difficulty 1 204 | */ 205 | @org.junit.Test 206 | public void anonymousTimeSeriesEqualityTestAgainstBaseWithNull() { 207 | TimeSeries timeSeries1 = new AnonymousTimeSeries(5,4,3); 208 | TimeSeries timeSeries2 = new TimeSeries(null, 5,4,3); 209 | assertNotEquals(timeSeries1, timeSeries2); 210 | assertNotEquals(timeSeries2, timeSeries1); 211 | } 212 | 213 | /*** 214 | * Sprawdzenie metody toString klasy AnonymousTimeSeries - nie powinna zawierać pola name, ale powinna zawierać wartości 215 | * @difficulty 1 216 | */ 217 | @org.junit.Test 218 | public void anonymousTimeSeriesToStringNoName() { 219 | TimeSeries timeSeries2 = new AnonymousTimeSeries(5,4,3); 220 | assertTrue(!timeSeries2.toString().toLowerCase().contains("name=") 221 | && timeSeries2.toString().toLowerCase().contains("5") 222 | && timeSeries2.toString().toLowerCase().contains("4") 223 | && timeSeries2.toString().toLowerCase().contains("3")); 224 | } 225 | 226 | /*** 227 | * Sprawdzenie metody toString klasy TimeSeries - powinna zawierać pole name i zawierać wartości 228 | * @difficulty 1 229 | */ 230 | @org.junit.Test 231 | public void timeSeriesToStringName() { 232 | TimeSeries timeSeries2 = new TimeSeries("anonymous", 5,4,3); 233 | assertTrue(timeSeries2.toString().toLowerCase().contains("name=") 234 | && timeSeries2.toString().toLowerCase().contains("5") 235 | && timeSeries2.toString().toLowerCase().contains("4") 236 | && timeSeries2.toString().toLowerCase().contains("3")); 237 | } 238 | 239 | /*** 240 | * Sprawdzenie metody isAnonymous() na klasie bazowej TimeSeries 241 | * @difficulty 1 242 | */ 243 | @org.junit.Test 244 | public void isAnonymousBaseClass() { 245 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3); 246 | assertFalse(timeSeries1.isAnonymous()); 247 | } 248 | 249 | /*** 250 | * Sprawdzenie metody isAnonymous() na klasie AnonymousTimeSeries rzutowanej na TimeSeries 251 | * @difficulty 1 252 | */ 253 | @org.junit.Test 254 | public void isAnonymousInheritedClass() { 255 | TimeSeries timeSeries1 = new AnonymousTimeSeries(5); 256 | assertTrue(timeSeries1.isAnonymous()); 257 | } 258 | 259 | } 260 | -------------------------------------------------------------------------------- /basic-arrays/src/mini/java/basic/arrays/testsolution/AnonymousTimeSeries.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.arrays.testsolution; 2 | 3 | import java.util.Arrays; 4 | 5 | public class AnonymousTimeSeries extends TimeSeries { 6 | public AnonymousTimeSeries(int... data) { 7 | super(null, data); 8 | } 9 | 10 | @Override 11 | public String toString() { 12 | return "AnonymousTimeSeries{" + 13 | "data=" + Arrays.toString(data) + 14 | '}'; 15 | } 16 | 17 | @Override 18 | public boolean isAnonymous() { 19 | return true; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic-arrays/src/mini/java/basic/arrays/testsolution/TimeSeries.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.arrays.testsolution; 2 | 3 | import java.util.Arrays; 4 | import java.util.Objects; 5 | 6 | public class TimeSeries { 7 | private final String name; 8 | protected final int[] data; 9 | 10 | public TimeSeries(String name, int... data) { 11 | this.name = name; 12 | this.data = data; 13 | } 14 | 15 | public double average() { 16 | double sum = 0.0; 17 | for (int i = 0; i < data.length; i++) { 18 | sum+=data[i]; 19 | } 20 | return sum/data.length; 21 | } 22 | 23 | public int getMaximum() { 24 | int maxValue = Integer.MIN_VALUE; 25 | for (int i = 0; i < data.length; i++) { 26 | if (data[i] > maxValue) maxValue = data[i]; 27 | } 28 | return maxValue; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public int[] getData() { 36 | return data; 37 | } 38 | 39 | public boolean isAnonymous() { 40 | return false ; 41 | } 42 | 43 | @Override 44 | public boolean equals(Object o) { 45 | if (this == o) return true; 46 | if (o == null || getClass() != o.getClass()) return false; 47 | TimeSeries that = (TimeSeries) o; 48 | return Objects.equals(name, that.name) && 49 | Arrays.equals(data, that.data); 50 | } 51 | 52 | @Override 53 | public int hashCode() { 54 | int result = Objects.hash(name); 55 | result = 31 * result + Arrays.hashCode(data); 56 | return result; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return "TimeSeries{" + 62 | "name='" + name + '\'' + 63 | ", data=" + Arrays.toString(data) + 64 | '}'; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /basic-arrays/src/mini/java/basic/arrays/testsolution/TimeSeriesTest.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.arrays.testsolution; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | public class TimeSeriesTest { 6 | 7 | 8 | /*** 9 | * Prosty equals() - sprawdzenie dla identycznych 10 | * @difficulty 1 11 | */ 12 | @org.junit.Test 13 | public void primitiveEquals() { 14 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3,4); 15 | int[] j = {1,2,3,4}; 16 | TimeSeries timeSeries2 = new TimeSeries("TS1",j); 17 | assertFalse(timeSeries1 == timeSeries2); 18 | } 19 | 20 | /*** 21 | * Prosty equals() - sprawdzenie dla różnych 22 | * @difficulty 1 23 | */ 24 | @org.junit.Test 25 | public void equalsFalse() { 26 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3,4); 27 | int[] j = {1,2,3,4}; 28 | TimeSeries timeSeries2 = new TimeSeries("TS2",j); 29 | assertNotEquals(timeSeries1, timeSeries2); 30 | } 31 | 32 | /*** 33 | * Prosty equals() - sprawdzenie dla różnych 34 | * @difficulty 1 35 | */ 36 | @org.junit.Test 37 | public void equalsFalseArray() { 38 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3,4); 39 | int[] j = {1,2,3}; 40 | TimeSeries timeSeries2 = new TimeSeries("TS1",j); 41 | assertNotEquals(timeSeries1, timeSeries2); 42 | } 43 | /*** 44 | * Prosty equals 45 | * @difficulty 1 46 | */ 47 | @org.junit.Test 48 | public void equalsTrue() { 49 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3,4); 50 | int[] j = {1,2,3,4}; 51 | TimeSeries timeSeries2 = new TimeSeries("TS1",j); 52 | assertEquals(timeSeries1, timeSeries2); 53 | } 54 | 55 | /*** 56 | * Prosty equals - sprawdzenie dla nazwy *null* 57 | * @difficulty 1 58 | */ 59 | @org.junit.Test 60 | public void equalsTrueNullName() { 61 | TimeSeries timeSeries1 = new TimeSeries(null,1,2,3,4); 62 | int[] j = {1,2,3,4}; 63 | TimeSeries timeSeries2 = new TimeSeries(null,j); 64 | assertEquals(timeSeries1, timeSeries2); 65 | } 66 | 67 | /*** 68 | * Prosty hashcode() - sprawdzenie czy generowane są identyczne 69 | * @difficulty 1 70 | */ 71 | @org.junit.Test 72 | public void hashcodeEquals() { 73 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3,4); 74 | int[] j = {1,2,3,4}; 75 | TimeSeries timeSeries2 = new TimeSeries("TS1",j); 76 | assertEquals(timeSeries1.hashCode(), timeSeries2.hashCode()); 77 | } 78 | 79 | /*** 80 | * Prosty hashcode() - sprawdzenie czy zmiana nazwy wpływa na hashcode() 81 | * @difficulty 1 82 | */ 83 | @org.junit.Test 84 | public void hashcodeNotEqualsName() { 85 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3,4); 86 | int[] j = {1,2,3,4}; 87 | TimeSeries timeSeries2 = new TimeSeries("TS2",j); 88 | assertNotEquals(timeSeries1.hashCode(), timeSeries2.hashCode()); 89 | } 90 | 91 | /*** 92 | * Prosty hashcode() - sprawdzenie czy zmiana danych serii wpływa na hashcode() 93 | * @difficulty 1 94 | */ 95 | @org.junit.Test 96 | public void hashcodeNotEqualsValue() { 97 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3,4); 98 | int[] j = {1,2,3}; 99 | TimeSeries timeSeries2 = new TimeSeries("TS1",j); 100 | assertNotEquals(timeSeries1.hashCode(), timeSeries2.hashCode()); 101 | } 102 | 103 | /*** 104 | * Sprawdzenie działania metody zmiennej _name_ 105 | * @difficulty 1 106 | */ 107 | @org.junit.Test 108 | public void averageTest() { 109 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3); 110 | TimeSeries timeSeries2 = new TimeSeries("TS1",4,2,3); 111 | assertEquals(2.0, timeSeries1.average(),0); 112 | assertEquals(3.0, timeSeries2.average(),0); 113 | } 114 | 115 | /*** 116 | * Sprawdzenie gettera zmiennej _name_ 117 | * @difficulty 1 118 | */ 119 | @org.junit.Test 120 | public void getNameTest() { 121 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3); 122 | assertEquals(timeSeries1.getName(),"TS1"); 123 | } 124 | 125 | /*** 126 | * Sprawdzenie gettera zmiennej @name 127 | * @difficulty 1 128 | */ 129 | @org.junit.Test 130 | public void getNameTestNull() { 131 | TimeSeries timeSeries1 = new TimeSeries(null,1,2,3); 132 | assertEquals(timeSeries1.getName(),null); 133 | } 134 | 135 | /*** 136 | * Sprawdzenie metody getMaximum dla liczb ujemych 137 | * @difficulty 1 138 | */ 139 | @org.junit.Test 140 | public void getMaximumTest() { 141 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3,5,6,1); 142 | assertEquals(timeSeries1.getMaximum(),6); 143 | } 144 | 145 | /*** 146 | * Sprawdzenie metody getMaximum dla liczb ujemych 147 | * @difficulty 1 148 | */ 149 | @org.junit.Test 150 | public void getMaximumTestNegative() { 151 | TimeSeries timeSeries1 = new TimeSeries("TS1",-1,-2,-3,-5,-6,-1,-11); 152 | assertEquals(timeSeries1.getMaximum(),-1); 153 | } 154 | 155 | 156 | 157 | /*** 158 | * Sprawdzenie metody average klasy AnonymousTimeSeries 159 | * @difficulty 1 160 | */ 161 | @org.junit.Test 162 | public void anonymousTimeSeriesAverageTst() { 163 | TimeSeries timeSeries1 = new AnonymousTimeSeries(1,2,3); 164 | assertEquals(2.0, timeSeries1.average(),0); 165 | } 166 | /*** 167 | * Sprawdzenie getter pola name klasy AnonymousTimeSeries 168 | * @difficulty 1 169 | */ 170 | @org.junit.Test 171 | public void anonymousTimeSeriesNameTest() { 172 | TimeSeries timeSeries1 = new AnonymousTimeSeries(5,6); 173 | assertNull(timeSeries1.getName()); 174 | } 175 | 176 | /*** 177 | * Sprawdzenie metody equals klasy AnonymousTimeSeries 178 | * @difficulty 1 179 | */ 180 | @org.junit.Test 181 | public void anonymousTimeSeriesEqualityTest() { 182 | TimeSeries timeSeries1 = new AnonymousTimeSeries(5,4,3); 183 | TimeSeries timeSeries2 = new AnonymousTimeSeries(5,4,3); 184 | assertEquals(timeSeries1, timeSeries2); 185 | assertEquals(timeSeries2, timeSeries1); 186 | } 187 | 188 | /*** 189 | * Sprawdzenie metody equals klasy AnonymousTimeSeries wględem klasy bazowej TimeSeries 190 | * @difficulty 1 191 | */ 192 | @org.junit.Test 193 | public void anonymousTimeSeriesEqualityTestAgainstBase() { 194 | TimeSeries timeSeries1 = new AnonymousTimeSeries(5,4,3); 195 | TimeSeries timeSeries2 = new TimeSeries("anonymous", 5,4,3); 196 | assertNotEquals(timeSeries1, timeSeries2); 197 | assertNotEquals(timeSeries2, timeSeries1); 198 | } 199 | 200 | /*** 201 | * Sprawdzenie metody average klasy AnonymousTimeSeries wględem klasy bazowej gdzie nazwa jest Null 202 | * @difficulty 1 203 | */ 204 | @org.junit.Test 205 | public void anonymousTimeSeriesEqualityTestAgainstBaseWithNull() { 206 | TimeSeries timeSeries1 = new AnonymousTimeSeries(5,4,3); 207 | TimeSeries timeSeries2 = new TimeSeries(null, 5,4,3); 208 | assertNotEquals(timeSeries1, timeSeries2); 209 | assertNotEquals(timeSeries2, timeSeries1); 210 | } 211 | 212 | /*** 213 | * Sprawdzenie metody toString klasy AnonymousTimeSeries - nie powinna zawierać pola name, ale powinna zawierać wartości 214 | * @difficulty 1 215 | */ 216 | @org.junit.Test 217 | public void anonymousTimeSeriesToStringNoName() { 218 | TimeSeries timeSeries2 = new AnonymousTimeSeries(5,4,3); 219 | assertTrue(!timeSeries2.toString().toLowerCase().contains("name=") 220 | && timeSeries2.toString().toLowerCase().contains("5") 221 | && timeSeries2.toString().toLowerCase().contains("4") 222 | && timeSeries2.toString().toLowerCase().contains("3")); 223 | } 224 | 225 | /*** 226 | * Sprawdzenie metody toString klasy TimeSeries - powinna zawierać pole name i zawierać wartości 227 | * @difficulty 1 228 | */ 229 | @org.junit.Test 230 | public void timeSeriesToStringName() { 231 | TimeSeries timeSeries2 = new TimeSeries("anonymous", 5,4,3); 232 | assertTrue(timeSeries2.toString().toLowerCase().contains("name=") 233 | && timeSeries2.toString().toLowerCase().contains("5") 234 | && timeSeries2.toString().toLowerCase().contains("4") 235 | && timeSeries2.toString().toLowerCase().contains("3")); 236 | } 237 | 238 | /*** 239 | * Sprawdzenie metody isAnonymous() na klasie bazowej TimeSeries 240 | * @difficulty 1 241 | */ 242 | @org.junit.Test 243 | public void isAnonymousBaseClass() { 244 | TimeSeries timeSeries1 = new TimeSeries("TS1",1,2,3); 245 | assertFalse(timeSeries1.isAnonymous()); 246 | } 247 | 248 | /*** 249 | * Sprawdzenie metody isAnonymous() na klasie AnonymousTimeSeries rzutowanej na TimeSeries 250 | * @difficulty 1 251 | */ 252 | @org.junit.Test 253 | public void isAnonymousInheritedClass() { 254 | TimeSeries timeSeries1 = new AnonymousTimeSeries(5); 255 | assertTrue(timeSeries1.isAnonymous()); 256 | } 257 | 258 | } 259 | -------------------------------------------------------------------------------- /basic-collections/basic-collections.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /basic-collections/dataset.csv: -------------------------------------------------------------------------------- 1 | products;1;Eggs;0.29;true 2 | products;2;Sugar;1.99;true 3 | products;3;Milk;1.09;true 4 | products;4;Honey;2.99;false 5 | products;5;Mascarpone;1.99;true 6 | products;6;Tomato;3.99;true 7 | products;7;Printer Paper;2.99;false 8 | products;8;Printer Toner;12.99;false 9 | products;9;Thermal Paste;1.99;true) 10 | warehouses;1;TX;false;7,8,9; 11 | warehouses;2;AU;true;1,2,3,4,5,6; 12 | warehouses;3;CA;true;; -------------------------------------------------------------------------------- /basic-collections/dataset_empty_product.csv: -------------------------------------------------------------------------------- 1 | warehouses;2;AU;true;1,2,3,4,5,6; 2 | warehouses;3;CA;true;; -------------------------------------------------------------------------------- /basic-collections/dataset_malformed_product.csv: -------------------------------------------------------------------------------- 1 | products;1;Eggs;0.29;true 2 | products;2;Sugar;1.99;true 3 | products;3;Milk;1.09;true 4 | products;4;Honey;2.99;false 5 | products;5;Mascarpone;1.99;true 6 | products;6;Tomato;3.99;true 7 | products;7;Printer Paper;2.99;false 8 | products;8;Printer Toner;12.99;false 9 | products;9;Thermal Paste;hwaiaw4uyci4y 10 | warehouses;2;AU;true;1,2,3,4,5,6; 11 | warehouses;3;CA;true;; -------------------------------------------------------------------------------- /basic-collections/dataset_malformed_warehouse.csv: -------------------------------------------------------------------------------- 1 | products;1;Eggs;0.29;true 2 | products;2;Sugar;1.99;true 3 | products;3;Milk;1.09;true 4 | products;4;Honey;2.99;false 5 | products;5;Mascarpone;1.99;true 6 | products;6;Tomato;3.99;true 7 | products;7;Printer Paper;2.99;false 8 | products;8;Printer Toner;12.99;false 9 | warehouses;1;TX;false;wololol; 10 | warehouses;2;AU;true;1,2,3,4,5,6; 11 | warehouses;3;CA;true;; -------------------------------------------------------------------------------- /basic-collections/src/mini/java/basic/collections/CollectionsTest.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.collections; 2 | 3 | import java.util.*; 4 | import java.util.stream.Collectors; 5 | 6 | import static org.junit.Assert.*; 7 | import static org.junit.Assert.assertEquals; 8 | 9 | public class CollectionsTest { 10 | 11 | 12 | @org.junit.Test 13 | public void listAdd() { 14 | List l = new ArrayList<>(); 15 | l.add("a"); 16 | l.addAll(List.of("b","c")); 17 | assertEquals(l, List.of("a","b","c")); 18 | } 19 | 20 | @org.junit.Test 21 | public void listRemove() { 22 | List list = new ArrayList<>(List.of("a", "b", "b")); 23 | boolean removed = list.remove("c"); 24 | assertEquals(list, List.of("a","b","b")); 25 | assertFalse(removed); 26 | } 27 | 28 | @org.junit.Test 29 | public void listRemoveDuplicated() { 30 | List list = new ArrayList<>(List.of("a", "b", "b")); 31 | boolean removed = list.remove("b"); 32 | assertEquals(list, List.of("a","b")); 33 | assertTrue(removed); 34 | } 35 | 36 | @org.junit.Test 37 | public void listRemoveAll() { 38 | List list = new ArrayList<>(List.of("a", "b", "b")); 39 | while (list.remove("b")) { } 40 | assertEquals(list, List.of("a")); 41 | } 42 | 43 | @org.junit.Test 44 | public void listRemoveAllStream() { 45 | List list = new ArrayList<>(List.of("a", "b", "b")); 46 | List l = list.stream() 47 | .filter(element -> !element.equals("b")) 48 | .collect(Collectors.toList()); 49 | List l2 = new ArrayList<>(); 50 | 51 | assertEquals(l, List.of("a")); 52 | } 53 | 54 | @org.junit.Test 55 | public void listSort() { 56 | List l = new ArrayList<>(); 57 | l.add("c"); 58 | l.addAll(List.of("b","a")); 59 | l.sort(Comparator.naturalOrder()); 60 | assertEquals(l, List.of("a","b","c")); 61 | } 62 | 63 | @org.junit.Test 64 | public void setAdd() { 65 | Set linkedHashSet = new LinkedHashSet<>(List.of("a", "b", "d")); 66 | Set hashSet = new HashSet<>(List.of("a", "b", "d")); 67 | System.out.print("Hashset: "); 68 | hashSet.forEach(s -> System.out.printf("%s,", s)); 69 | System.out.println(); 70 | System.out.print("LinkedHashSet: "); 71 | for (String s1 : linkedHashSet) { 72 | System.out.printf("%s,", s1); 73 | } 74 | System.out.println(); 75 | hashSet.add("c"); 76 | linkedHashSet.add("c"); 77 | hashSet.add("d"); 78 | linkedHashSet.add("d"); 79 | System.out.print("Hashset: "); 80 | hashSet.forEach(s1 -> System.out.printf("%s,", s1)); 81 | System.out.println(); 82 | System.out.print("LinkedHashSet: "); 83 | linkedHashSet.forEach(s -> System.out.printf("%s,", s)); 84 | } 85 | 86 | 87 | 88 | @org.junit.Test 89 | public void mapPut() { 90 | Map hashMap = new HashMap<>(); 91 | hashMap.put("a","string a"); 92 | hashMap.put("a","string b"); 93 | assertEquals(hashMap.get("a"),"string b"); 94 | 95 | hashMap.putIfAbsent("a","string c"); 96 | assertEquals(hashMap.get("a"),"string b"); 97 | } 98 | 99 | @org.junit.Test 100 | public void mapGet() { 101 | Map hashMap = new HashMap<>(); 102 | hashMap.put("a","string a"); 103 | hashMap.put("b","string b"); 104 | 105 | assertEquals(hashMap.get("a"),"string a"); 106 | assertFalse(hashMap.containsKey("c")); 107 | assertEquals(hashMap.getOrDefault("c","trelemorele"),"trelemorele"); 108 | } 109 | 110 | @org.junit.Test 111 | public void mapComplexType() { 112 | Map hashMap = new HashMap<>(); 113 | hashMap.put(String.class, new StringPrinter()); 114 | hashMap.put(Integer.class, new IntegerPrinter()); 115 | hashMap.put(Number.class, new NumberPrinter()); 116 | 117 | 118 | Integer a = 3; 119 | hashMap.getOrDefault(a.getClass(), new DefaultLogger()).print(a); 120 | Object b = new String("3"); 121 | hashMap.getOrDefault(b.getClass(), new DefaultLogger()).print(b); 122 | Object c = new ArrayList<>(); 123 | hashMap.getOrDefault(c.getClass(), new DefaultLogger()).print(c); 124 | 125 | Double d = 3.0; 126 | Printer printer = hashMap.get(d.getClass()); 127 | if (printer != null) { 128 | printer.print(d); 129 | } 130 | } 131 | 132 | private interface Printer { 133 | void print(T object); 134 | } 135 | 136 | private class StringPrinter implements Printer { 137 | @Override 138 | public void print(String v) { 139 | System.out.println("String: "+ v); 140 | } 141 | } 142 | 143 | private class IntegerPrinter implements Printer { 144 | @Override 145 | public void print(Integer v) { 146 | System.out.println("Integer: "+ v); 147 | } 148 | } 149 | 150 | private class NumberPrinter implements Printer { 151 | @Override 152 | public void print(Number v) { 153 | System.out.println("Number: "+ v); 154 | } 155 | } 156 | 157 | 158 | private class DefaultLogger implements Printer { 159 | @Override 160 | public void print(Object object) { 161 | System.out.println("Default: " + object.toString()); 162 | } 163 | } 164 | 165 | @org.junit.Test 166 | public void exceptionTest() { 167 | Map hashMap = new HashMap<>(); 168 | hashMap.put(String.class, new StringPrinter()); 169 | 170 | Double d = 3.0; 171 | try { 172 | printForObject(hashMap, d); 173 | } catch (StupidException e) { 174 | System.out.println("Catched!"); 175 | } 176 | 177 | 178 | } 179 | 180 | 181 | private void printForObject(Map hashMap, Object d) throws StupidException { 182 | try { 183 | hashMap.get(d.getClass()).print(d); 184 | } catch (NullPointerException e) { 185 | 186 | new DefaultLogger().print(String.format("Exception ifnored for %s", d.getClass().toGenericString())); 187 | // Throws RuntimeException does not need to be handled 188 | // throw new RuntimeException(); 189 | // Throw normal Exception, needs to be either try{}/catched{} or added to method definition (throws) 190 | // throw new StupidException(List.of("stupid")); 191 | } catch (Throwable e) { 192 | e.printStackTrace(); 193 | } finally { 194 | System.out.println("Finally"); 195 | } 196 | } 197 | 198 | private class StupidException extends Exception { 199 | private List a; 200 | public StupidException(List a) { 201 | this.a = a; 202 | } 203 | } 204 | 205 | 206 | } 207 | -------------------------------------------------------------------------------- /basic-collections/src/mini/java/basic/collections/test/CachingAndPagingDataRepository.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.collections.test; 2 | 3 | import java.io.IOException; 4 | import java.util.Collection; 5 | 6 | /** 7 | * Caching and paging data repository 8 | * 9 | * Cache can be implemented in any *sensible* way (this means using maps). Cache should have 10 | * ability to retrieve both full datasets (for both entities Product and Warehouse) 11 | * and single elements by id (this is enforced by tests). 12 | * 13 | * You also have to provide correct implementation for @see mini.java.basic.collections.test.DataLoader 14 | * and @see mini.java.basic.collections.test.DataMapper 15 | * 16 | * Hints: 17 | * - Basic map functionality was showcased in labs before 18 | * - You don't have to have only one map for caching 19 | * - Some methods are simpler to implement, some harder - as 20 | * each is worth the same number of points, if you get stuck, 21 | * see if you can implement next one. 22 | * - Think about what functions will need to clear caches and how. 23 | * 24 | * Scoring: 25 | * - Each passed test (with correct implementation) 26 | * is worth 10% of possible score (2,5 points) 27 | * @see DataRepositoryTest 28 | * 29 | * Entities: 30 | * @see SimpleDataRepository.Product 31 | * @see SimpleDataRepository.Warehouse 32 | */ 33 | public class CachingAndPagingDataRepository { 34 | private SimpleDataRepository dataRepository; 35 | 36 | public CachingAndPagingDataRepository() throws ProductDataMalformedException, NoDataException, WarehouseDataMalformedException, IOException { 37 | dataRepository = new SimpleDataRepository("dataset.csv"); 38 | } 39 | 40 | /** 41 | * This function should not be changed!!! 42 | * @return Returns number of calls registered by fake database engine 43 | */ 44 | public int getRepositoryCalls() { 45 | return dataRepository.getCalls(); 46 | } 47 | 48 | /*** 49 | * Returns all products from database. Can be used to pre-populate single element 50 | * cache (for use in getProductById(id)). Can also be used as a helper function in 51 | * other methods. 52 | * @see CachingAndPagingDataRepository#getProductsById(int) 53 | * @return List of all products 54 | */ 55 | public Collection getAllProducts() { 56 | return dataRepository.getProducts(); 57 | } 58 | 59 | /*** 60 | * Retrieves product from database. In best case scenario should be aware of getAllProducts() method. 61 | * @see CachingAndPagingDataRepository#getAllProducts() 62 | * @param i id of product to retrieve 63 | * @return Retrieved product 64 | */ 65 | public SimpleDataRepository.Product getProductsById(int i) { 66 | return dataRepository.getProductById(i); 67 | } 68 | 69 | /*** 70 | * Returns all products from database, sorted by name. 71 | * @return List of products 72 | */ 73 | public Collection getAllProductsSortedByName() { 74 | return dataRepository.getProducts(); 75 | } 76 | 77 | /*** 78 | * Returns all products from database, filtered by expires true sorted by name. 79 | * @return List of products 80 | */ 81 | public Collection getAllProductsFilteredByExpiresTrueAndSortedByName() { 82 | return dataRepository.getProducts(); 83 | } 84 | 85 | /*** 86 | * Returns page of products from database. Should behave gracefully - return empty 87 | * list - if page is out of bounds. 88 | * @param page Page number 89 | * @param pagesize Size of page 90 | * @return List of products 91 | */ 92 | public Collection getProductsPage(int page, int pagesize) { 93 | return dataRepository.getProducts(); 94 | } 95 | 96 | /*** 97 | * Returns all warehouses from database. Should fill products field in each retrieved warehouse element 98 | * @see CachingAndPagingDataRepository#getProductsById(int) 99 | * @see SimpleDataRepository.Warehouse#products 100 | * @return List of all warehouses 101 | */ 102 | public Collection getAllWarehouses() { 103 | return dataRepository.getWarehouses(); 104 | } 105 | 106 | 107 | /** 108 | * Updates product in database 109 | * @param i Id of product to update 110 | * @param product Product data to save to database 111 | */ 112 | public void updateProduct(int i, SimpleDataRepository.Product product) { 113 | dataRepository.updateProduct(i, product); 114 | } 115 | 116 | /** 117 | * Upserts product in database - inserts if id is missing, updates if id exists in database 118 | * @param product Product data to save to database 119 | */ 120 | public void upsertProduct(SimpleDataRepository.Product product) { 121 | dataRepository.upsertProduct(product); 122 | } 123 | 124 | 125 | 126 | 127 | } 128 | -------------------------------------------------------------------------------- /basic-collections/src/mini/java/basic/collections/test/DataLoader.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.collections.test; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.FileReader; 5 | import java.io.IOException; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | public class DataLoader { 10 | /** 11 | * DataLoader loads data from file. Data is saved in csv files in format 12 | * table;field1;field2;field3... Data is filtered using @dataFileName, and if no 13 | * line is found, function should rise NoDataException. Loaded data is converted to Object[] 14 | * by splitting against the ";" 15 | * @param dataFileName data file name/path 16 | * @param dataset name of dataset to load from file 17 | * @return loaded data, in form of List of Object[] 18 | * @throws IOException Bubbled IOException 19 | * @throws NoDataException No data in file for dataset 20 | */ 21 | public List getData(String dataFileName, String dataset) throws IOException, NoDataException { 22 | List dataSetObjects = new ArrayList<>(); 23 | return dataSetObjects; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /basic-collections/src/mini/java/basic/collections/test/DataMappers.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.collections.test; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | public class DataMappers { 8 | /** 9 | * Maps line of data to @SimpleDataRepository.Product 10 | * @param objects Data loaded from DataLoader 11 | * @return Object[] parsed into @SimpleDataRepository.Product 12 | * @throws ProductDataMalformedException thrown if data is malformed/cannot be parsed 13 | */ 14 | public static SimpleDataRepository.Product mapToProduct(Object[] objects) throws ProductDataMalformedException { 15 | return null; 16 | } 17 | 18 | 19 | /** 20 | * Maps line of data to @SimpleDataRepository.Warehouse 21 | * @param objects Data loaded from DataLoader 22 | * @return Object[] parsed into @SimpleDataRepository.Warehouse 23 | * @throws WarehouseDataMalformedException thrown if data is malformed/cannot be parsed 24 | */ 25 | public static SimpleDataRepository.Warehouse mapToWarehouse(Object[] objects) throws WarehouseDataMalformedException { 26 | return null; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /basic-collections/src/mini/java/basic/collections/test/DataRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.collections.test; 2 | 3 | import org.junit.Assert; 4 | 5 | import java.io.IOException; 6 | import java.util.Collection; 7 | 8 | public class DataRepositoryTest { 9 | 10 | /*** 11 | * Checks if cache is implemented correctly for simple element type 12 | * @difficulty 1 13 | */ 14 | @org.junit.Test(timeout = 1800) 15 | public void getAllProducts() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 16 | CachingAndPagingDataRepository dataRepository = new CachingAndPagingDataRepository(); 17 | 18 | // Inital get data 19 | Collection data = dataRepository.getAllProducts(); 20 | 21 | // Get data again 22 | data = dataRepository.getAllProducts(); 23 | 24 | // Checks 25 | Assert.assertEquals(dataRepository.getRepositoryCalls(), 1); 26 | Assert.assertEquals(data.size(), 9); 27 | } 28 | 29 | /*** 30 | * Checks if DataLoader and Mapper throw good Exception 31 | * @difficulty 1 32 | */ 33 | @org.junit.Test(timeout = 1800, expected = ProductDataMalformedException.class) 34 | public void tryGetMalformedProducts() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 35 | SimpleDataRepository simpleDataRepository = new SimpleDataRepository("dataset_malformed_product.csv"); 36 | } 37 | 38 | /*** 39 | * Checks if DataLoader and Mapper throw good Exception 40 | * @difficulty 1 41 | */ 42 | @org.junit.Test(timeout = 1800, expected = WarehouseDataMalformedException.class) 43 | public void tryGetMalformedWarehouse() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 44 | SimpleDataRepository simpleDataRepository = new SimpleDataRepository("dataset_malformed_warehouse.csv"); 45 | } 46 | 47 | /*** 48 | * Checks if DataLoader and Mapper throw good Exception 49 | * @difficulty 1 50 | */ 51 | @org.junit.Test(timeout = 1800, expected = NoDataException.class) 52 | public void tryGetEmptyProduct() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 53 | SimpleDataRepository simpleDataRepository = new SimpleDataRepository("dataset_empty_product.csv"); 54 | } 55 | 56 | /*** 57 | * Checks if DataLoader bubbles IOException 58 | * @difficulty 1 59 | */ 60 | @org.junit.Test(timeout = 1800, expected = IOException.class) 61 | public void tryGetNonextistingFile() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 62 | SimpleDataRepository simpleDataRepository = new SimpleDataRepository("dataset_thereisnothing.csv"); 63 | } 64 | 65 | 66 | /*** 67 | * Checks if cache is implemented correctly for single elements 68 | * @difficulty 1 69 | */ 70 | @org.junit.Test(timeout = 2800) 71 | public void getProductsById() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 72 | CachingAndPagingDataRepository dataRepository = new CachingAndPagingDataRepository(); 73 | int randomProductId = (int)Math.floor(Math.random() * 6) + 2; 74 | // Inital get data 75 | SimpleDataRepository.Product product1 = dataRepository.getProductsById(1); 76 | SimpleDataRepository.Product product2 = dataRepository.getProductsById(randomProductId); 77 | 78 | // Get data again 79 | product1 = dataRepository.getProductsById(1); 80 | product2 = dataRepository.getProductsById(randomProductId); 81 | 82 | // Checks 83 | Assert.assertEquals(dataRepository.getRepositoryCalls(), 2); 84 | Assert.assertNotNull(product1); 85 | Assert.assertNotNull(product2); 86 | Assert.assertEquals(1, product1.getId()); 87 | Assert.assertEquals(randomProductId, product2.getId()); 88 | } 89 | 90 | /*** 91 | * Checks if cache is optimized for retrieving single elements when all 92 | * elements were requested before. 93 | * @difficulty 2 94 | */ 95 | @org.junit.Test(timeout = 1800) 96 | public void getAllProductsAndProductsByIdOptimization() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 97 | CachingAndPagingDataRepository dataRepository = new CachingAndPagingDataRepository(); 98 | int randomProductId = (int)Math.floor(Math.random() * 6) + 2; 99 | // Inital get data 100 | Collection data = dataRepository.getAllProducts(); 101 | SimpleDataRepository.Product product2 = dataRepository.getProductsById(randomProductId); 102 | 103 | // Get data again 104 | data = dataRepository.getAllProducts(); 105 | product2 = dataRepository.getProductsById(randomProductId); 106 | 107 | // Checks 108 | Assert.assertEquals(dataRepository.getRepositoryCalls(), 1); 109 | Assert.assertNotNull(product2); 110 | Assert.assertEquals(9, data.size()); 111 | Assert.assertEquals(randomProductId, product2.getId()); 112 | } 113 | 114 | /*** 115 | * Checks if cache extensions (sorting data from repository) is implemented correctly 116 | * @difficulty 2 117 | */ 118 | @org.junit.Test(timeout = 1800) 119 | public void getAllProductsSortedName() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 120 | CachingAndPagingDataRepository dataRepository = new CachingAndPagingDataRepository(); 121 | 122 | // Inital get data 123 | Collection data = dataRepository.getAllProductsSortedByName(); 124 | 125 | // Get data again 126 | data = dataRepository.getAllProductsSortedByName(); 127 | 128 | // Checks 129 | Assert.assertEquals(dataRepository.getRepositoryCalls(), 1); 130 | Assert.assertArrayEquals(new int[]{1,4,5,3,7,8,2,9,6}, data.stream().mapToInt(SimpleDataRepository.Product::getId).toArray()); 131 | } 132 | 133 | /*** 134 | * Checks if complex function with filtering and sorting 135 | * @difficulty 2 136 | */ 137 | @org.junit.Test(timeout = 1800) 138 | public void getAllProductsFilteredByExpiresTrueAndSortedName() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 139 | CachingAndPagingDataRepository dataRepository = new CachingAndPagingDataRepository(); 140 | 141 | // Inital get data 142 | Collection data = dataRepository.getAllProductsFilteredByExpiresTrueAndSortedByName(); 143 | 144 | // Get data again 145 | data = dataRepository.getAllProductsFilteredByExpiresTrueAndSortedByName(); 146 | 147 | // Checks 148 | Assert.assertEquals(dataRepository.getRepositoryCalls(), 1); 149 | Assert.assertArrayEquals(new int[]{1,5,3,2,9,6}, data.stream().mapToInt(SimpleDataRepository.Product::getId).toArray()); 150 | } 151 | 152 | /*** 153 | * Checks if cache extensions (paging data from repository) is implemented correctly 154 | * @difficulty 2 155 | */ 156 | @org.junit.Test(timeout = 1800) 157 | public void getProductsPage() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 158 | CachingAndPagingDataRepository dataRepository = new CachingAndPagingDataRepository(); 159 | 160 | // Inital get data 161 | Collection page1 = dataRepository.getProductsPage(0,3); 162 | Collection page2 = dataRepository.getProductsPage(5,3); 163 | Collection page5 = dataRepository.getProductsPage(5,3); 164 | 165 | // Get data again 166 | page1 = dataRepository.getProductsPage(0,3); 167 | page2 = dataRepository.getProductsPage(1,3); 168 | page5 = dataRepository.getProductsPage(5,3); 169 | 170 | // Checks 171 | Assert.assertEquals(dataRepository.getRepositoryCalls(), 1); 172 | Assert.assertArrayEquals(new int[]{1,2,3}, page1.stream().mapToInt(SimpleDataRepository.Product::getId).toArray()); 173 | Assert.assertArrayEquals(new int[]{4,5,6}, page2.stream().mapToInt(SimpleDataRepository.Product::getId).toArray()); 174 | Assert.assertArrayEquals(new int[]{}, page5.stream().mapToInt(SimpleDataRepository.Product::getId).toArray()); 175 | } 176 | 177 | /*** 178 | * Checks if cache is implemented correctly for updating product 179 | * @difficulty 2 180 | */ 181 | @org.junit.Test(timeout = 5800) 182 | public void updateProductInRepository() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 183 | CachingAndPagingDataRepository dataRepository = new CachingAndPagingDataRepository(); 184 | int randomProductId = (int)Math.floor(Math.random() * 6) + 2; 185 | // Inital get data 186 | SimpleDataRepository.Product product1 = dataRepository.getProductsById(1); 187 | Collection productData = dataRepository.getAllProducts(); 188 | 189 | // Get data again 190 | product1 = dataRepository.getProductsById(1); 191 | productData = dataRepository.getAllProducts(); 192 | 193 | // Update product 194 | dataRepository.updateProduct(1, new SimpleDataRepository.Product("Updated!",99.99, false)); 195 | 196 | 197 | // Get data, again... we should request new ones since they were changed... 198 | product1 = dataRepository.getProductsById(1); 199 | productData = dataRepository.getAllProducts(); 200 | 201 | // Checks 202 | Assert.assertEquals(dataRepository.getRepositoryCalls(), 5); 203 | Assert.assertNotNull(product1); 204 | Assert.assertEquals(1, product1.getId()); 205 | Assert.assertEquals("Updated!", product1.getName()); 206 | Assert.assertEquals(productData.size(), 9); 207 | } 208 | 209 | /*** 210 | * Checks if cache is implemented correctly for different element types 211 | * @difficulty 3 212 | */ 213 | @org.junit.Test(timeout = 2800) 214 | public void getAllProductsAndWarehouses() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 215 | CachingAndPagingDataRepository dataRepository = new CachingAndPagingDataRepository(); 216 | // Inital get data 217 | Collection productData = dataRepository.getAllProducts(); 218 | Collection warehouseData = dataRepository.getAllWarehouses(); 219 | 220 | // Get data again 221 | productData = dataRepository.getAllProducts(); 222 | warehouseData = dataRepository.getAllWarehouses(); 223 | 224 | // Checks 225 | Assert.assertEquals(dataRepository.getRepositoryCalls(), 2); 226 | Assert.assertEquals(productData.size(), 9); 227 | Assert.assertEquals(warehouseData.size(), 3); 228 | Assert.assertArrayEquals(new int[]{7,8,9}, warehouseData.stream().findFirst().get().getProducts().stream().mapToInt(SimpleDataRepository.Product::getId).toArray()); 229 | } 230 | 231 | 232 | /*** 233 | * Checks if cache is implemented correctly for upsert (update or insert) product - insert 234 | * @difficulty 3 235 | */ 236 | @org.junit.Test(timeout = 6800) 237 | public void upsertInsertProductInRepository() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 238 | CachingAndPagingDataRepository dataRepository = new CachingAndPagingDataRepository(); 239 | int randomProductId = (int)Math.floor(Math.random() * 6) + 2; 240 | // Inital get data 241 | SimpleDataRepository.Product product1 = dataRepository.getProductsById(1); 242 | Collection productData = dataRepository.getAllProducts(); 243 | Collection warehouseData = dataRepository.getAllWarehouses(); 244 | 245 | // Get data again 246 | product1 = dataRepository.getProductsById(1); 247 | productData = dataRepository.getAllProducts(); 248 | 249 | // Insert product 250 | dataRepository.upsertProduct(new SimpleDataRepository.Product("Updated!",99.99, false)); 251 | 252 | 253 | // Get data, again... 254 | product1 = dataRepository.getProductsById(1); // This should not be requested again 255 | SimpleDataRepository.Product product10 = dataRepository.getProductsById(10); // This should be requested 256 | productData = dataRepository.getAllProducts(); // This should be requested 257 | warehouseData = dataRepository.getAllWarehouses(); // This should not be requested 258 | 259 | // Checks 260 | Assert.assertEquals(dataRepository.getRepositoryCalls(), 6); 261 | Assert.assertNotNull(product1); 262 | Assert.assertEquals(1, product1.getId()); 263 | Assert.assertEquals("Updated!", product10.getName()); 264 | Assert.assertEquals(productData.size(), 10); 265 | } 266 | 267 | /*** 268 | * Checks if cache is implemented correctly for upsert (update or insert) product - update 269 | * @difficulty 3 270 | */ 271 | @org.junit.Test(timeout = 7800) 272 | public void upsertUpdateProductInRepository() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 273 | CachingAndPagingDataRepository dataRepository = new CachingAndPagingDataRepository(); 274 | int randomProductId = (int)Math.floor(Math.random() * 6) + 2; 275 | // Inital get data 276 | SimpleDataRepository.Product product1 = dataRepository.getProductsById(1); 277 | Collection productData = dataRepository.getAllProducts(); 278 | Collection warehouseData = dataRepository.getAllWarehouses(); 279 | 280 | // Get data again 281 | product1 = dataRepository.getProductsById(1); 282 | productData = dataRepository.getAllProducts(); 283 | 284 | // Update product 285 | product1.setName("Updated!"); 286 | dataRepository.upsertProduct(product1); 287 | 288 | 289 | // Get data, again... 290 | product1 = dataRepository.getProductsById(1); // This should be requested 291 | productData = dataRepository.getAllProducts(); // This should be requested 292 | warehouseData = dataRepository.getAllWarehouses(); // This should be requested 293 | 294 | // Checks 295 | Assert.assertEquals(dataRepository.getRepositoryCalls(), 7); 296 | Assert.assertNotNull(product1); 297 | Assert.assertEquals(1, product1.getId()); 298 | Assert.assertEquals("Updated!", product1.getName()); 299 | Assert.assertEquals(productData.size(), 9); 300 | } 301 | } 302 | -------------------------------------------------------------------------------- /basic-collections/src/mini/java/basic/collections/test/NoDataException.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.collections.test; 2 | 3 | /** 4 | * Simple exception 5 | */ 6 | public class NoDataException extends Exception { 7 | } 8 | -------------------------------------------------------------------------------- /basic-collections/src/mini/java/basic/collections/test/ProductDataMalformedException.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.collections.test; 2 | 3 | public class ProductDataMalformedException extends Exception { 4 | } 5 | -------------------------------------------------------------------------------- /basic-collections/src/mini/java/basic/collections/test/SimpleDataRepository.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.collections.test; 2 | 3 | import java.io.IOException; 4 | import java.util.*; 5 | 6 | 7 | /** 8 | * This class represents simple data repository (database data access interface) 9 | * You should not change this class 10 | */ 11 | public class SimpleDataRepository { 12 | private Map products; 13 | private Map warehouses; 14 | private DataLoader dataLoader = new DataLoader(); 15 | 16 | private int calls = 0; 17 | private int productLastIndex = 9; 18 | private int warehouseLastIndex = 3; 19 | 20 | /** 21 | * Repository initializaion using external datasource 22 | */ 23 | public SimpleDataRepository(String dataFileName) throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 24 | products = new HashMap<>(); 25 | warehouses = new HashMap<>(); 26 | for (Object[] objects1 : dataLoader.getData(dataFileName, "products")) { 27 | Product p = DataMappers.mapToProduct(objects1); 28 | products.put(p.id, p); 29 | } 30 | for (Object[] objects : dataLoader.getData(dataFileName, "warehouses")) { 31 | Warehouse w = DataMappers.mapToWarehouse(objects); 32 | warehouses.put(w.id, w); 33 | } 34 | } 35 | 36 | /** 37 | * Return all products 38 | * @return List with all products in database 39 | */ 40 | public Collection getProducts() { 41 | fakeProcess(); 42 | return products.values(); 43 | } 44 | 45 | /** 46 | * Returns product by id. 47 | * @param id Product id 48 | * @return Product data 49 | */ 50 | public Product getProductById(int id) { 51 | fakeProcess(); 52 | return products.get(id); 53 | } 54 | 55 | /** 56 | * Return all warehouses 57 | * @return List with all warehouses in database 58 | */ 59 | public Collection getWarehouses() { 60 | fakeProcess(); 61 | return warehouses.values(); 62 | } 63 | 64 | /** 65 | * Returns warehouse by id. Not used, but for the sake of completeness 66 | * @param id Warehouse id 67 | * @return Warehouse data 68 | */ 69 | public Warehouse getWarehouseById(int id) { 70 | fakeProcess(); 71 | return warehouses.get(id); 72 | } 73 | 74 | /** 75 | * Upserts product. 76 | * @param product Product data 77 | */ 78 | public boolean upsertProduct(Product product) { 79 | fakeProcess(); 80 | boolean updated = true; 81 | if (!products.containsKey(product.id)) { 82 | product.id = ++productLastIndex; 83 | updated = false; 84 | } 85 | products.put(product.id, product); 86 | return updated; 87 | } 88 | 89 | /** 90 | * Updates product. 91 | * @param id Id of product to update 92 | * @param product Product data 93 | */ 94 | public void updateProduct(Integer id, Product product) { 95 | fakeProcess(); 96 | if (!products.containsKey(id)) throw new RepositoryElementNotFoundException("Element not found in database, contents not changed"); 97 | product.id = id; 98 | products.put(id, product); 99 | } 100 | 101 | /** 102 | * Upserts warehouse. Not used, but for the sake of completeness 103 | * @param warehouse Warehouse data 104 | */ 105 | public boolean upsertWarehouse(Warehouse warehouse) { 106 | fakeProcess(); 107 | boolean updated = true; 108 | if (!warehouses.containsKey(warehouse.id)) { 109 | warehouse.id = ++warehouseLastIndex; 110 | updated = false; 111 | } 112 | warehouses.put(warehouse.id, warehouse); 113 | return updated; 114 | } 115 | 116 | /** 117 | * Updates warehouse. Not used, but for the sake of completeness 118 | * @param id Id of warehouse to update 119 | * @param warehouse Warehouse data 120 | */ 121 | public void updateWarehouse(Integer id, Warehouse warehouse) { 122 | fakeProcess(); 123 | if (!warehouses.containsKey(id)) throw new RepositoryElementNotFoundException("Element not found in database, contents not changed"); 124 | warehouse.id = id; 125 | warehouses.put(id, warehouse); 126 | } 127 | 128 | /** 129 | * Fake processing timeout, for testing 130 | */ 131 | private void fakeProcess() { 132 | try { 133 | calls++; 134 | Thread.currentThread().sleep(1000); 135 | } catch (InterruptedException e) { 136 | // Sleep interrupted 137 | } 138 | } 139 | 140 | public int getCalls() { 141 | return calls; 142 | } 143 | 144 | /*** 145 | * Product entity 146 | */ 147 | public static class Product { 148 | private int id; 149 | private String name; 150 | private double price; 151 | private boolean expires; 152 | 153 | public Product(int id, String name, double price, boolean expires) { 154 | this.id = id; 155 | this.name = name; 156 | this.price = price; 157 | this.expires = expires; 158 | } 159 | 160 | public Product(String name, double price, boolean expires) { 161 | this.id = -1; 162 | this.name = name; 163 | this.price = price; 164 | this.expires = expires; 165 | } 166 | 167 | public int getId() { 168 | return id; 169 | } 170 | 171 | public String getName() { 172 | return name; 173 | } 174 | 175 | public double getPrice() { 176 | return price; 177 | } 178 | 179 | public boolean isExpires() { 180 | return expires; 181 | } 182 | 183 | public void setName(String name) { 184 | this.name = name; 185 | } 186 | 187 | public void setPrice(double price) { 188 | this.price = price; 189 | } 190 | 191 | public void setExpires(boolean expires) { 192 | this.expires = expires; 193 | } 194 | 195 | @Override 196 | public boolean equals(Object o) { 197 | if (this == o) return true; 198 | if (o == null || getClass() != o.getClass()) return false; 199 | Product product = (Product) o; 200 | return id == product.id && 201 | Double.compare(product.price, price) == 0 && 202 | expires == product.expires && 203 | Objects.equals(name, product.name); 204 | } 205 | 206 | @Override 207 | public int hashCode() { 208 | 209 | return Objects.hash(id, name, price, expires); 210 | } 211 | 212 | @Override 213 | public String toString() { 214 | return "Product{" + 215 | "id=" + id + 216 | ", name='" + name + '\'' + 217 | ", price=" + price + 218 | ", expires=" + expires + 219 | '}'; 220 | } 221 | } 222 | 223 | /** 224 | * Warehouse entity 225 | */ 226 | public static class Warehouse { 227 | private int id; 228 | private final String location; 229 | private final boolean open; 230 | private final List productIds; 231 | 232 | /** 233 | * Products must be initialized after loading from database using data 234 | * from productIds field, they are never stored in database 235 | */ 236 | transient private List products; 237 | 238 | public Warehouse(int id, String location, boolean open, List products) { 239 | 240 | this.id = id; 241 | this.location = location; 242 | this.open = open; 243 | this.productIds = products; 244 | } 245 | 246 | public int getId() { 247 | return id; 248 | } 249 | 250 | public String getLocation() { 251 | return location; 252 | } 253 | 254 | public boolean isOpen() { 255 | return open; 256 | } 257 | 258 | public List getProductIds() { 259 | return productIds; 260 | } 261 | 262 | 263 | public List getProducts() { 264 | return products; 265 | } 266 | 267 | public void setProducts(List products) { 268 | this.products = products; 269 | } 270 | 271 | @Override 272 | public boolean equals(Object o) { 273 | if (this == o) return true; 274 | if (o == null || getClass() != o.getClass()) return false; 275 | Warehouse warehouse = (Warehouse) o; 276 | return id == warehouse.id && 277 | open == warehouse.open && 278 | Objects.equals(location, warehouse.location) && 279 | Objects.equals(productIds, warehouse.productIds); 280 | } 281 | 282 | @Override 283 | public int hashCode() { 284 | return Objects.hash(id, location, open, productIds); 285 | } 286 | 287 | @Override 288 | public String toString() { 289 | return "Warehouse{" + 290 | "id=" + id + 291 | ", location='" + location + '\'' + 292 | ", open=" + open + 293 | ", products=" + productIds + 294 | '}'; 295 | } 296 | 297 | } 298 | 299 | private class RepositoryElementNotFoundException extends RuntimeException { 300 | private String message; 301 | 302 | public RepositoryElementNotFoundException(String s) { 303 | message = s; 304 | } 305 | } 306 | } 307 | -------------------------------------------------------------------------------- /basic-collections/src/mini/java/basic/collections/test/WarehouseDataMalformedException.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.collections.test; 2 | 3 | /** 4 | * Simple excaption for malformed @Warehouse data 5 | */ 6 | public class WarehouseDataMalformedException extends Exception { 7 | } 8 | -------------------------------------------------------------------------------- /basic-collections/src/mini/java/basic/collections/test/solution/CachingAndPagingDataRepository.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.collections.test.solution; 2 | 3 | import java.io.IOException; 4 | import java.util.*; 5 | 6 | /** 7 | * Caching and paging data repository 8 | * 9 | * Cache can be implemented in any *sensible* way (this means using maps). Cache should have 10 | * ability to retrieve both full datasets (for both entities Product and Warehouse) 11 | * and single elements by id (this is enforced by tests). 12 | * 13 | * You also have to provide correct implementation for @see mini.java.basic.collections.test.DataLoader 14 | * and @see mini.java.basic.collections.test.DataMapper 15 | * 16 | * Hints: 17 | * - Basic map functionality was showcased in labs before 18 | * - You don't have to have only one map for caching 19 | * - Some methods are simpler to implement, some harder - as 20 | * each is worth the same number of points, if you get stuck, 21 | * see if you can implement next one. 22 | * - Think about what functions will need to clear caches and how. 23 | * 24 | * Scoring: 25 | * - Each passed test (with correct implementation) 26 | * is worth 10% of possible score (2,5 points) 27 | * @see DataRepositoryTest 28 | * 29 | * Entities: 30 | * @see SimpleDataRepository.Product 31 | * @see SimpleDataRepository.Warehouse 32 | */ 33 | public class CachingAndPagingDataRepository { 34 | private SimpleDataRepository dataRepository; 35 | 36 | public CachingAndPagingDataRepository() throws ProductDataMalformedException, NoDataException, WarehouseDataMalformedException, IOException { 37 | dataRepository = new SimpleDataRepository("dataset.csv"); 38 | } 39 | 40 | /** 41 | * This function should not be changed!!! 42 | * @return Returns number of calls registered by fake database engine 43 | */ 44 | public int getRepositoryCalls() { 45 | return dataRepository.getCalls(); 46 | } 47 | 48 | /*** 49 | * Returns all products from database. Can be used to pre-populate single element 50 | * cache (for use in getProductById(id)). Can also be used as a helper function in 51 | * other methods. 52 | * @see CachingAndPagingDataRepository#getProductsById(int) 53 | * @return List of all products 54 | */ 55 | public Collection getAllProducts() { 56 | return dataRepository.getProducts(); 57 | } 58 | 59 | /*** 60 | * Retrieves product from database. In best case scenario should be aware of getAllProducts() method. 61 | * @see CachingAndPagingDataRepository#getAllProducts() 62 | * @param i id of product to retrieve 63 | * @return Retrieved product 64 | */ 65 | public SimpleDataRepository.Product getProductsById(int i) { 66 | return dataRepository.getProductById(i); 67 | } 68 | 69 | /*** 70 | * Returns all products from database, sorted by name. 71 | * @return List of products 72 | */ 73 | public Collection getAllProductsSortedByName() { 74 | return dataRepository.getProducts(); 75 | } 76 | 77 | /*** 78 | * Returns all products from database, filtered by expires true sorted by name. 79 | * @return List of products 80 | */ 81 | public Collection getAllProductsFilteredByExpiresTrueAndSortedByName() { 82 | return dataRepository.getProducts(); 83 | } 84 | 85 | /*** 86 | * Returns page of products from database. Should behave gracefully - return empty 87 | * list - if page is out of bounds. 88 | * @param page Page number 89 | * @param pagesize Size of page 90 | * @return List of products 91 | */ 92 | public Collection getProductsPage(int page, int pagesize) { 93 | return dataRepository.getProducts(); 94 | } 95 | 96 | /*** 97 | * Returns all warehouses from database. Should fill products field in each retrieved warehouse element 98 | * @see CachingAndPagingDataRepository#getProductsById(int) 99 | * @see SimpleDataRepository.Warehouse#products 100 | * @return List of all warehouses 101 | */ 102 | public Collection getAllWarehouses() { 103 | return dataRepository.getWarehouses(); 104 | } 105 | 106 | 107 | /** 108 | * Updates product in database 109 | * @param i Id of product to update 110 | * @param product Product data to save to database 111 | */ 112 | public void updateProduct(int i, SimpleDataRepository.Product product) { 113 | dataRepository.updateProduct(i, product); 114 | } 115 | 116 | /** 117 | * Upserts product in database - inserts if id is missing, updates if id exists in database 118 | * @param product Product data to save to database 119 | */ 120 | public void upsertProduct(SimpleDataRepository.Product product) { 121 | dataRepository.upsertProduct(product); 122 | } 123 | 124 | 125 | 126 | 127 | } 128 | -------------------------------------------------------------------------------- /basic-collections/src/mini/java/basic/collections/test/solution/DataLoader.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.collections.test.solution; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.FileReader; 5 | import java.io.IOException; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | public class DataLoader { 10 | /** 11 | * DataLoader loads data from file. Data is saved in csv files in format 12 | * table;field1;field2;field3... Data is filtered using @dataFileName, and if no 13 | * line is found, function should rise NoDataException. Loaded data is converted to Object[] 14 | * by splitting against the ";" 15 | * @param dataFileName data file name/path 16 | * @param dataset name of dataset to load from file 17 | * @return loaded data, in form of List of Object[] 18 | * @throws IOException Bubbled IOException 19 | * @throws NoDataException No data in file for dataset 20 | */ 21 | public List getData(String dataFileName, String dataset) throws IOException, NoDataException { 22 | List dataSetObjects = new ArrayList<>(); 23 | BufferedReader reader; 24 | reader = new BufferedReader(new FileReader(dataFileName)); 25 | String line = reader.readLine(); 26 | while (line != null) { 27 | if (line.startsWith(dataset)) 28 | dataSetObjects.add(line.split(";")); 29 | line = reader.readLine(); 30 | } 31 | if (dataSetObjects.size() == 0) 32 | throw new NoDataException(); 33 | reader.close(); 34 | return dataSetObjects; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /basic-collections/src/mini/java/basic/collections/test/solution/DataMappers.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.collections.test.solution; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | public class DataMappers { 8 | /** 9 | * Maps line of data to @SimpleDataRepository.Product 10 | * @param objects Data loaded from DataLoader 11 | * @return Object[] parsed into @SimpleDataRepository.Product 12 | * @throws ProductDataMalformedException thrown if data is malformed/cannot be parsed 13 | */ 14 | public static SimpleDataRepository.Product mapToProduct(Object[] objects) throws ProductDataMalformedException { 15 | if (objects.length != 5) throw new ProductDataMalformedException(); 16 | try { 17 | return new SimpleDataRepository.Product(Integer.parseInt(objects[1].toString()), objects[2].toString(), Double.parseDouble(objects[3].toString()), Boolean.getBoolean(objects[4].toString())); 18 | } catch (Exception e) { 19 | throw new ProductDataMalformedException(); 20 | } 21 | } 22 | 23 | 24 | /** 25 | * Maps line of data to @SimpleDataRepository.Warehouse 26 | * @param objects Data loaded from DataLoader 27 | * @return Object[] parsed into @SimpleDataRepository.Warehouse 28 | * @throws WarehouseDataMalformedException thrown if data is malformed/cannot be parsed 29 | */ 30 | public static SimpleDataRepository.Warehouse mapToWarehouse(Object[] objects) throws WarehouseDataMalformedException { 31 | if (objects.length < 4) throw new WarehouseDataMalformedException(); 32 | try { 33 | return new SimpleDataRepository.Warehouse(Integer.parseInt(objects[1].toString()), objects[2].toString(), Boolean.parseBoolean(objects[3].toString()), objects.length == 4 ? List.of() : Arrays.stream(objects[4].toString().split(",")).map(Integer::parseInt).collect(Collectors.toList())); 34 | 35 | } catch (Exception e) { 36 | throw new WarehouseDataMalformedException(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /basic-collections/src/mini/java/basic/collections/test/solution/DataRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.collections.test.solution; 2 | 3 | import org.junit.Assert; 4 | 5 | import java.io.IOException; 6 | import java.util.Collection; 7 | 8 | public class DataRepositoryTest { 9 | 10 | /*** 11 | * Checks if cache is implemented correctly for simple element type 12 | * @difficulty 1 13 | */ 14 | @org.junit.Test(timeout = 1800) 15 | public void getAllProducts() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 16 | CachingAndPagingDataRepository dataRepository = new CachingAndPagingDataRepository(); 17 | 18 | // Inital get data 19 | Collection data = dataRepository.getAllProducts(); 20 | 21 | // Get data again 22 | data = dataRepository.getAllProducts(); 23 | 24 | // Checks 25 | Assert.assertEquals(dataRepository.getRepositoryCalls(), 1); 26 | Assert.assertEquals(data.size(), 9); 27 | } 28 | 29 | /*** 30 | * Checks if DataLoader and Mapper throw good Exception 31 | * @difficulty 1 32 | */ 33 | @org.junit.Test(timeout = 1800, expected = ProductDataMalformedException.class) 34 | public void tryGetMalformedProducts() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 35 | SimpleDataRepository simpleDataRepository = new SimpleDataRepository("dataset_malformed_product.csv"); 36 | } 37 | 38 | /*** 39 | * Checks if DataLoader and Mapper throw good Exception 40 | * @difficulty 1 41 | */ 42 | @org.junit.Test(timeout = 1800, expected = WarehouseDataMalformedException.class) 43 | public void tryGetMalformedWarehouse() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 44 | SimpleDataRepository simpleDataRepository = new SimpleDataRepository("dataset_malformed_warehouse.csv"); 45 | } 46 | 47 | /*** 48 | * Checks if DataLoader and Mapper throw good Exception 49 | * @difficulty 1 50 | */ 51 | @org.junit.Test(timeout = 1800, expected = NoDataException.class) 52 | public void tryGetEmptyProduct() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 53 | SimpleDataRepository simpleDataRepository = new SimpleDataRepository("dataset_empty_product.csv"); 54 | } 55 | 56 | /*** 57 | * Checks if DataLoader bubbles IOException 58 | * @difficulty 1 59 | */ 60 | @org.junit.Test(timeout = 1800, expected = IOException.class) 61 | public void tryGetNonextistingFile() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 62 | SimpleDataRepository simpleDataRepository = new SimpleDataRepository("dataset_thereisnothing.csv"); 63 | } 64 | 65 | 66 | /*** 67 | * Checks if cache is implemented correctly for single elements 68 | * @difficulty 1 69 | */ 70 | @org.junit.Test(timeout = 2800) 71 | public void getProductsById() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 72 | CachingAndPagingDataRepository dataRepository = new CachingAndPagingDataRepository(); 73 | int randomProductId = (int)Math.floor(Math.random() * 6) + 2; 74 | // Inital get data 75 | SimpleDataRepository.Product product1 = dataRepository.getProductsById(1); 76 | SimpleDataRepository.Product product2 = dataRepository.getProductsById(randomProductId); 77 | 78 | // Get data again 79 | product1 = dataRepository.getProductsById(1); 80 | product2 = dataRepository.getProductsById(randomProductId); 81 | 82 | // Checks 83 | Assert.assertEquals(dataRepository.getRepositoryCalls(), 2); 84 | Assert.assertNotNull(product1); 85 | Assert.assertNotNull(product2); 86 | Assert.assertEquals(1, product1.getId()); 87 | Assert.assertEquals(randomProductId, product2.getId()); 88 | } 89 | 90 | /*** 91 | * Checks if cache is optimized for retrieving single elements when all 92 | * elements were requested before. 93 | * @difficulty 2 94 | */ 95 | @org.junit.Test(timeout = 1800) 96 | public void getAllProductsAndProductsByIdOptimization() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 97 | CachingAndPagingDataRepository dataRepository = new CachingAndPagingDataRepository(); 98 | int randomProductId = (int)Math.floor(Math.random() * 6) + 2; 99 | // Inital get data 100 | Collection data = dataRepository.getAllProducts(); 101 | SimpleDataRepository.Product product2 = dataRepository.getProductsById(randomProductId); 102 | 103 | // Get data again 104 | data = dataRepository.getAllProducts(); 105 | product2 = dataRepository.getProductsById(randomProductId); 106 | 107 | // Checks 108 | Assert.assertEquals(dataRepository.getRepositoryCalls(), 1); 109 | Assert.assertNotNull(product2); 110 | Assert.assertEquals(9, data.size()); 111 | Assert.assertEquals(randomProductId, product2.getId()); 112 | } 113 | 114 | /*** 115 | * Checks if cache extensions (sorting data from repository) is implemented correctly 116 | * @difficulty 2 117 | */ 118 | @org.junit.Test(timeout = 1800) 119 | public void getAllProductsSortedName() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 120 | CachingAndPagingDataRepository dataRepository = new CachingAndPagingDataRepository(); 121 | 122 | // Inital get data 123 | Collection data = dataRepository.getAllProductsSortedByName(); 124 | 125 | // Get data again 126 | data = dataRepository.getAllProductsSortedByName(); 127 | 128 | // Checks 129 | Assert.assertEquals(dataRepository.getRepositoryCalls(), 1); 130 | Assert.assertArrayEquals(new int[]{1,4,5,3,7,8,2,9,6}, data.stream().mapToInt(SimpleDataRepository.Product::getId).toArray()); 131 | } 132 | 133 | /*** 134 | * Checks if complex function with filtering and sorting 135 | * @difficulty 2 136 | */ 137 | @org.junit.Test(timeout = 1800) 138 | public void getAllProductsFilteredByExpiresTrueAndSortedName() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 139 | CachingAndPagingDataRepository dataRepository = new CachingAndPagingDataRepository(); 140 | 141 | // Inital get data 142 | Collection data = dataRepository.getAllProductsFilteredByExpiresTrueAndSortedByName(); 143 | 144 | // Get data again 145 | data = dataRepository.getAllProductsFilteredByExpiresTrueAndSortedByName(); 146 | 147 | // Checks 148 | Assert.assertEquals(dataRepository.getRepositoryCalls(), 1); 149 | Assert.assertArrayEquals(new int[]{1,5,3,2,9,6}, data.stream().mapToInt(SimpleDataRepository.Product::getId).toArray()); 150 | } 151 | 152 | /*** 153 | * Checks if cache extensions (paging data from repository) is implemented correctly 154 | * @difficulty 2 155 | */ 156 | @org.junit.Test(timeout = 1800) 157 | public void getProductsPage() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 158 | CachingAndPagingDataRepository dataRepository = new CachingAndPagingDataRepository(); 159 | 160 | // Inital get data 161 | Collection page1 = dataRepository.getProductsPage(0,3); 162 | Collection page2 = dataRepository.getProductsPage(5,3); 163 | Collection page5 = dataRepository.getProductsPage(5,3); 164 | 165 | // Get data again 166 | page1 = dataRepository.getProductsPage(0,3); 167 | page2 = dataRepository.getProductsPage(1,3); 168 | page5 = dataRepository.getProductsPage(5,3); 169 | 170 | // Checks 171 | Assert.assertEquals(dataRepository.getRepositoryCalls(), 1); 172 | Assert.assertArrayEquals(new int[]{1,2,3}, page1.stream().mapToInt(SimpleDataRepository.Product::getId).toArray()); 173 | Assert.assertArrayEquals(new int[]{4,5,6}, page2.stream().mapToInt(SimpleDataRepository.Product::getId).toArray()); 174 | Assert.assertArrayEquals(new int[]{}, page5.stream().mapToInt(SimpleDataRepository.Product::getId).toArray()); 175 | } 176 | 177 | /*** 178 | * Checks if cache is implemented correctly for updating product 179 | * @difficulty 2 180 | */ 181 | @org.junit.Test(timeout = 5800) 182 | public void updateProductInRepository() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 183 | CachingAndPagingDataRepository dataRepository = new CachingAndPagingDataRepository(); 184 | int randomProductId = (int)Math.floor(Math.random() * 6) + 2; 185 | // Inital get data 186 | SimpleDataRepository.Product product1 = dataRepository.getProductsById(1); 187 | Collection productData = dataRepository.getAllProducts(); 188 | 189 | // Get data again 190 | product1 = dataRepository.getProductsById(1); 191 | productData = dataRepository.getAllProducts(); 192 | 193 | // Update product 194 | dataRepository.updateProduct(1, new SimpleDataRepository.Product("Updated!",99.99, false)); 195 | 196 | 197 | // Get data, again... we should request new ones since they were changed... 198 | product1 = dataRepository.getProductsById(1); 199 | productData = dataRepository.getAllProducts(); 200 | 201 | // Checks 202 | Assert.assertEquals(dataRepository.getRepositoryCalls(), 5); 203 | Assert.assertNotNull(product1); 204 | Assert.assertEquals(1, product1.getId()); 205 | Assert.assertEquals("Updated!", product1.getName()); 206 | Assert.assertEquals(productData.size(), 9); 207 | } 208 | 209 | /*** 210 | * Checks if cache is implemented correctly for different element types 211 | * @difficulty 3 212 | */ 213 | @org.junit.Test(timeout = 2800) 214 | public void getAllProductsAndWarehouses() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 215 | CachingAndPagingDataRepository dataRepository = new CachingAndPagingDataRepository(); 216 | // Inital get data 217 | Collection productData = dataRepository.getAllProducts(); 218 | Collection warehouseData = dataRepository.getAllWarehouses(); 219 | 220 | // Get data again 221 | productData = dataRepository.getAllProducts(); 222 | warehouseData = dataRepository.getAllWarehouses(); 223 | 224 | // Checks 225 | Assert.assertEquals(dataRepository.getRepositoryCalls(), 2); 226 | Assert.assertEquals(productData.size(), 9); 227 | Assert.assertEquals(warehouseData.size(), 3); 228 | Assert.assertArrayEquals(new int[]{7,8,9}, warehouseData.stream().findFirst().get().getProducts().stream().mapToInt(SimpleDataRepository.Product::getId).toArray()); 229 | } 230 | 231 | 232 | /*** 233 | * Checks if cache is implemented correctly for upsert (update or insert) product - insert 234 | * @difficulty 3 235 | */ 236 | @org.junit.Test(timeout = 6800) 237 | public void upsertInsertProductInRepository() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 238 | CachingAndPagingDataRepository dataRepository = new CachingAndPagingDataRepository(); 239 | int randomProductId = (int)Math.floor(Math.random() * 6) + 2; 240 | // Inital get data 241 | SimpleDataRepository.Product product1 = dataRepository.getProductsById(1); 242 | Collection productData = dataRepository.getAllProducts(); 243 | Collection warehouseData = dataRepository.getAllWarehouses(); 244 | 245 | // Get data again 246 | product1 = dataRepository.getProductsById(1); 247 | productData = dataRepository.getAllProducts(); 248 | 249 | // Insert product 250 | dataRepository.upsertProduct(new SimpleDataRepository.Product("Updated!",99.99, false)); 251 | 252 | 253 | // Get data, again... 254 | product1 = dataRepository.getProductsById(1); // This should not be requested again 255 | SimpleDataRepository.Product product10 = dataRepository.getProductsById(10); // This should be requested 256 | productData = dataRepository.getAllProducts(); // This should be requested 257 | warehouseData = dataRepository.getAllWarehouses(); // This should not be requested 258 | 259 | // Checks 260 | Assert.assertEquals(dataRepository.getRepositoryCalls(), 6); 261 | Assert.assertNotNull(product1); 262 | Assert.assertEquals(1, product1.getId()); 263 | Assert.assertEquals("Updated!", product10.getName()); 264 | Assert.assertEquals(productData.size(), 10); 265 | } 266 | 267 | /*** 268 | * Checks if cache is implemented correctly for upsert (update or insert) product - update 269 | * @difficulty 3 270 | */ 271 | @org.junit.Test(timeout = 7800) 272 | public void upsertUpdateProductInRepository() throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 273 | CachingAndPagingDataRepository dataRepository = new CachingAndPagingDataRepository(); 274 | int randomProductId = (int)Math.floor(Math.random() * 6) + 2; 275 | // Inital get data 276 | SimpleDataRepository.Product product1 = dataRepository.getProductsById(1); 277 | Collection productData = dataRepository.getAllProducts(); 278 | Collection warehouseData = dataRepository.getAllWarehouses(); 279 | 280 | // Get data again 281 | product1 = dataRepository.getProductsById(1); 282 | productData = dataRepository.getAllProducts(); 283 | 284 | // Update product 285 | product1.setName("Updated!"); 286 | dataRepository.upsertProduct(product1); 287 | 288 | 289 | // Get data, again... 290 | product1 = dataRepository.getProductsById(1); // This should be requested 291 | productData = dataRepository.getAllProducts(); // This should be requested 292 | warehouseData = dataRepository.getAllWarehouses(); // This should be requested 293 | 294 | // Checks 295 | Assert.assertEquals(dataRepository.getRepositoryCalls(), 7); 296 | Assert.assertNotNull(product1); 297 | Assert.assertEquals(1, product1.getId()); 298 | Assert.assertEquals("Updated!", product1.getName()); 299 | Assert.assertEquals(productData.size(), 9); 300 | } 301 | } 302 | -------------------------------------------------------------------------------- /basic-collections/src/mini/java/basic/collections/test/solution/NoDataException.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.collections.test.solution; 2 | 3 | /** 4 | * Simple exception 5 | */ 6 | public class NoDataException extends Exception { 7 | } 8 | -------------------------------------------------------------------------------- /basic-collections/src/mini/java/basic/collections/test/solution/ProductDataMalformedException.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.collections.test.solution; 2 | 3 | public class ProductDataMalformedException extends Exception { 4 | } 5 | -------------------------------------------------------------------------------- /basic-collections/src/mini/java/basic/collections/test/solution/SimpleDataRepository.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.collections.test.solution; 2 | 3 | import java.io.IOException; 4 | import java.util.*; 5 | 6 | public class SimpleDataRepository { 7 | private Map products; 8 | private Map warehouses; 9 | private DataLoader dataLoader = new DataLoader(); 10 | 11 | private int calls = 0; 12 | private int productLastIndex = 9; 13 | private int warehouseLastIndex = 3; 14 | 15 | /** 16 | * Repository initializaion using external datasource 17 | */ 18 | public SimpleDataRepository(String dataFileName) throws IOException, NoDataException, WarehouseDataMalformedException, ProductDataMalformedException { 19 | products = new HashMap<>(); 20 | warehouses = new HashMap<>(); 21 | for (Object[] objects1 : dataLoader.getData(dataFileName, "products")) { 22 | Product p = DataMappers.mapToProduct(objects1); 23 | products.put(p.id, p); 24 | } 25 | for (Object[] objects : dataLoader.getData(dataFileName, "warehouses")) { 26 | Warehouse w = DataMappers.mapToWarehouse(objects); 27 | warehouses.put(w.id, w); 28 | } 29 | } 30 | 31 | /** 32 | * Return all products 33 | * @return List with all products in database 34 | */ 35 | public Collection getProducts() { 36 | fakeProcess(); 37 | return products.values(); 38 | } 39 | 40 | /** 41 | * Returns product by id. 42 | * @param id Product id 43 | * @return Product data 44 | */ 45 | public Product getProductById(int id) { 46 | fakeProcess(); 47 | return products.get(id); 48 | } 49 | 50 | /** 51 | * Return all warehouses 52 | * @return List with all warehouses in database 53 | */ 54 | public Collection getWarehouses() { 55 | fakeProcess(); 56 | return warehouses.values(); 57 | } 58 | 59 | /** 60 | * Returns warehouse by id. Not used, but for the sake of completeness 61 | * @param id Warehouse id 62 | * @return Warehouse data 63 | */ 64 | public Warehouse getWarehouseById(int id) { 65 | fakeProcess(); 66 | return warehouses.get(id); 67 | } 68 | 69 | /** 70 | * Upserts product. 71 | * @param product Product data 72 | */ 73 | public boolean upsertProduct(Product product) { 74 | fakeProcess(); 75 | boolean updated = true; 76 | if (!products.containsKey(product.id)) { 77 | product.id = ++productLastIndex; 78 | updated = false; 79 | } 80 | products.put(product.id, product); 81 | return updated; 82 | } 83 | 84 | /** 85 | * Updates product. 86 | * @param id Id of product to update 87 | * @param product Product data 88 | */ 89 | public void updateProduct(Integer id, Product product) { 90 | fakeProcess(); 91 | if (!products.containsKey(id)) throw new RepositoryElementNotFoundException("Element not found in database, contents not changed"); 92 | product.id = id; 93 | products.put(id, product); 94 | } 95 | 96 | /** 97 | * Upserts warehouse. Not used, but for the sake of completeness 98 | * @param warehouse Warehouse data 99 | */ 100 | public boolean upsertWarehouse(Warehouse warehouse) { 101 | fakeProcess(); 102 | boolean updated = true; 103 | if (!warehouses.containsKey(warehouse.id)) { 104 | warehouse.id = ++warehouseLastIndex; 105 | updated = false; 106 | } 107 | warehouses.put(warehouse.id, warehouse); 108 | return updated; 109 | } 110 | 111 | /** 112 | * Updates warehouse. Not used, but for the sake of completeness 113 | * @param id Id of warehouse to update 114 | * @param warehouse Warehouse data 115 | */ 116 | public void updateWarehouse(Integer id, Warehouse warehouse) { 117 | fakeProcess(); 118 | if (!warehouses.containsKey(id)) throw new RepositoryElementNotFoundException("Element not found in database, contents not changed"); 119 | warehouse.id = id; 120 | warehouses.put(id, warehouse); 121 | } 122 | 123 | /** 124 | * Fake processing timeout, for testing 125 | */ 126 | private void fakeProcess() { 127 | try { 128 | calls++; 129 | Thread.currentThread().sleep(0); 130 | } catch (InterruptedException e) { 131 | // Sleep interrupted 132 | } 133 | } 134 | 135 | public int getCalls() { 136 | return calls; 137 | } 138 | 139 | /*** 140 | * Product entity 141 | */ 142 | public static class Product { 143 | private int id; 144 | private String name; 145 | private double price; 146 | private boolean expires; 147 | 148 | public Product(int id, String name, double price, boolean expires) { 149 | this.id = id; 150 | this.name = name; 151 | this.price = price; 152 | this.expires = expires; 153 | } 154 | 155 | public Product(String name, double price, boolean expires) { 156 | this.id = -1; 157 | this.name = name; 158 | this.price = price; 159 | this.expires = expires; 160 | } 161 | 162 | public int getId() { 163 | return id; 164 | } 165 | 166 | public String getName() { 167 | return name; 168 | } 169 | 170 | public double getPrice() { 171 | return price; 172 | } 173 | 174 | public boolean isExpires() { 175 | return expires; 176 | } 177 | 178 | public void setName(String name) { 179 | this.name = name; 180 | } 181 | 182 | public void setPrice(double price) { 183 | this.price = price; 184 | } 185 | 186 | public void setExpires(boolean expires) { 187 | this.expires = expires; 188 | } 189 | 190 | @Override 191 | public boolean equals(Object o) { 192 | if (this == o) return true; 193 | if (o == null || getClass() != o.getClass()) return false; 194 | Product product = (Product) o; 195 | return id == product.id && 196 | Double.compare(product.price, price) == 0 && 197 | expires == product.expires && 198 | Objects.equals(name, product.name); 199 | } 200 | 201 | @Override 202 | public int hashCode() { 203 | 204 | return Objects.hash(id, name, price, expires); 205 | } 206 | 207 | @Override 208 | public String toString() { 209 | return "Product{" + 210 | "id=" + id + 211 | ", name='" + name + '\'' + 212 | ", price=" + price + 213 | ", expires=" + expires + 214 | '}'; 215 | } 216 | } 217 | 218 | /** 219 | * Warehouse entity 220 | */ 221 | public static class Warehouse { 222 | private int id; 223 | private final String location; 224 | private final boolean open; 225 | private final List productIds; 226 | 227 | /** 228 | * Products must be initialized after loading from database using data 229 | * from productIds field, they are never stored in database 230 | */ 231 | transient private List products; 232 | 233 | public Warehouse(int id, String location, boolean open, List products) { 234 | 235 | this.id = id; 236 | this.location = location; 237 | this.open = open; 238 | this.productIds = products; 239 | } 240 | 241 | public int getId() { 242 | return id; 243 | } 244 | 245 | public String getLocation() { 246 | return location; 247 | } 248 | 249 | public boolean isOpen() { 250 | return open; 251 | } 252 | 253 | public List getProductIds() { 254 | return productIds; 255 | } 256 | 257 | 258 | public List getProducts() { 259 | return products; 260 | } 261 | 262 | public void setProducts(List products) { 263 | this.products = products; 264 | } 265 | 266 | @Override 267 | public boolean equals(Object o) { 268 | if (this == o) return true; 269 | if (o == null || getClass() != o.getClass()) return false; 270 | Warehouse warehouse = (Warehouse) o; 271 | return id == warehouse.id && 272 | open == warehouse.open && 273 | Objects.equals(location, warehouse.location) && 274 | Objects.equals(productIds, warehouse.productIds); 275 | } 276 | 277 | @Override 278 | public int hashCode() { 279 | return Objects.hash(id, location, open, productIds); 280 | } 281 | 282 | @Override 283 | public String toString() { 284 | return "Warehouse{" + 285 | "id=" + id + 286 | ", location='" + location + '\'' + 287 | ", open=" + open + 288 | ", products=" + productIds + 289 | '}'; 290 | } 291 | 292 | } 293 | 294 | private class RepositoryElementNotFoundException extends RuntimeException { 295 | private String message; 296 | 297 | public RepositoryElementNotFoundException(String s) { 298 | message = s; 299 | } 300 | } 301 | } 302 | -------------------------------------------------------------------------------- /basic-collections/src/mini/java/basic/collections/test/solution/WarehouseDataMalformedException.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.collections.test.solution; 2 | 3 | /** 4 | * Simple excaption for malformed @Warehouse data 5 | */ 6 | public class WarehouseDataMalformedException extends Exception { 7 | } 8 | -------------------------------------------------------------------------------- /basic-generics/basic-generics.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /basic-generics/src/mini/java/basic/generics/Dataset.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.generics; 2 | 3 | import java.util.List; 4 | 5 | public class Dataset> { 6 | private List timeSeries; 7 | 8 | public Dataset(List timeSeries) { 9 | this.timeSeries = timeSeries; 10 | } 11 | 12 | public E[] getFirstData() { 13 | return timeSeries.get(0).getData(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /basic-generics/src/mini/java/basic/generics/GenericsTest.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.generics; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import static org.junit.Assert.*; 7 | import static org.junit.Assert.assertTrue; 8 | 9 | public class GenericsTest { 10 | @org.junit.Test 11 | public void timeSeriesIntegerConstructor() { 12 | TimeSeries timeSeriesInteger = new TimeSeries("TS1",1,2,3,4); 13 | assertEquals(timeSeriesInteger.first(), Integer.valueOf(1)); 14 | assertEquals(timeSeriesInteger.last(), Integer.valueOf(4)); 15 | } 16 | 17 | @org.junit.Test 18 | public void timeSeriesStringConstructor() { 19 | TimeSeries timeSeriesFloat = new TimeSeries("TS1",1.0,2.0,3.0); 20 | assertEquals(timeSeriesFloat.first(), Double.valueOf(1.0)); 21 | assertEquals(timeSeriesFloat.last(), Double.valueOf(3.0)); 22 | } 23 | 24 | 25 | 26 | @org.junit.Test 27 | public void timeSeriesIntegerFromMethod() { 28 | TimeSeries timeSeriesInteger = TimeSeries.empty("empty",1,Integer.class); 29 | assertNull(timeSeriesInteger.first()); 30 | assertNull(timeSeriesInteger.last()); 31 | } 32 | 33 | @org.junit.Test 34 | public void timeSeriesNameEquality() { 35 | TimeSeries timeSeriesInteger = TimeSeries.empty("empty",1,Integer.class); 36 | TimeSeries timeSeriesFloat = TimeSeries.empty("empty",1,Float.class); 37 | assertTrue(timeSeriesInteger.nameEquals(timeSeriesFloat)); 38 | assertTrue(timeSeriesFloat.nameEquals(timeSeriesInteger)); 39 | } 40 | 41 | 42 | @org.junit.Test 43 | public void testDataset() { 44 | List> l = new ArrayList<>(); 45 | l.add(new TimeSeries<>("TS1", 1, 2, 3, 4)); 46 | Dataset> d = new Dataset<>(l); 47 | } 48 | 49 | 50 | @org.junit.Test(expected = ClassCastException.class) 51 | public void testDatasetNoType() { 52 | List> l = new ArrayList<>(); 53 | l.add(new TimeSeries("TS1",1.0,2.0,3.0,4.0)); 54 | Dataset d = new Dataset(l); 55 | Integer[] data = d.getFirstData(); 56 | } 57 | 58 | @org.junit.Test 59 | public void summerTest() { 60 | List> l = new ArrayList<>(); 61 | l.add(new TimeSeries<>("TS1", 1, 2, 3, 4)); 62 | l.add(new TimeSeries<>("TS1", 1, 2, 3, 4)); 63 | SeriesSummer> d = new SeriesSummer<>(l); 64 | assertEquals(d.sum(),Integer.valueOf(20)); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /basic-generics/src/mini/java/basic/generics/SeriesSummer.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.generics; 2 | 3 | // Lista TimeSeries od Number 4 | // E sum() 5 | 6 | import java.util.List; 7 | 8 | public class SeriesSummer> { 9 | private List l; 10 | 11 | public SeriesSummer(List l) { 12 | this.l = l; 13 | } 14 | 15 | public E sum() { 16 | //code 17 | E sum = null; 18 | for (R ts : 19 | l) { 20 | for (E d : 21 | ts.getData()) { 22 | if (sum == null) 23 | sum = d; 24 | else 25 | sum = (E) addNumbers(sum,d); 26 | } 27 | } 28 | return sum; 29 | } 30 | 31 | public static Number addNumbers(Number a, Number b) { 32 | if(a instanceof Double || b instanceof Double) { 33 | return a.doubleValue() + b.doubleValue(); 34 | } else if(a instanceof Float || b instanceof Float) { 35 | return a.floatValue() + b.floatValue(); 36 | } else if(a instanceof Long || b instanceof Long) { 37 | return a.longValue() + b.longValue(); 38 | } else { 39 | return a.intValue() + b.intValue(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /basic-generics/src/mini/java/basic/generics/TimeSeries.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.generics; 2 | 3 | import java.lang.reflect.Array; 4 | 5 | public class TimeSeries { 6 | private final String name; 7 | private final T[] data; 8 | 9 | public TimeSeries(String name, T... data) { 10 | this.name = name; 11 | this.data = data; 12 | } 13 | 14 | public static TimeSeries empty(String name, Integer length, Class clazz) { 15 | @SuppressWarnings("unchecked") 16 | TimeSeries timeSeries = new TimeSeries<>(name, (U[]) Array.newInstance(clazz, length)); 17 | 18 | return timeSeries; 19 | } 20 | 21 | 22 | public String getName() { 23 | return name; 24 | } 25 | 26 | public T first() { 27 | if (data == null) 28 | throw new IndexOutOfBoundsException(); 29 | return data[0]; 30 | } 31 | 32 | public T last() { 33 | if (data == null) 34 | throw new IndexOutOfBoundsException(); 35 | return data[data.length - 1]; 36 | } 37 | 38 | public float firstFloat() { 39 | if (data == null) 40 | throw new IndexOutOfBoundsException(); 41 | return data[data.length - 1].floatValue(); 42 | } 43 | 44 | public boolean nameEquals(TimeSeries that) { 45 | return this.getName().equals(that.getName()); 46 | } 47 | 48 | 49 | public static boolean staticNameEquals(TimeSeries l,TimeSeries r) { 50 | return l.getName().equals(r.getName()); 51 | } 52 | 53 | public T[] getData() { 54 | return data; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /basic-interfaces/basic-interfaces.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /basic-interfaces/src/mini/java/basic/interfaces/AbstractTimeSeries.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.interfaces; 2 | 3 | import java.util.List; 4 | 5 | public abstract class AbstractTimeSeries { 6 | List data; 7 | 8 | 9 | String name; 10 | 11 | public AbstractTimeSeries(String name, List data) { 12 | this.name = name; 13 | this.data = data; 14 | } 15 | 16 | 17 | /** 18 | * Dodaje obiekt do listy 19 | * @param o Obiekt do dodania 20 | */ 21 | public void add(T o) { 22 | data.add(o); 23 | } 24 | 25 | 26 | /** 27 | * Usuwa obiekt z listy 28 | * @param i ondeks obiektu to usunięcia 29 | */ 30 | public void remove(int i) { 31 | data.remove(i); 32 | } 33 | 34 | 35 | /** 36 | * Zwraca obiekt z listy 37 | * @param i Indeks obiektu do zwrócenia 38 | * @return Obiekt na konkretnym miejscu 39 | */ 40 | public T get(int i) { 41 | return data.get(i); 42 | } 43 | 44 | 45 | public String getName() { 46 | return name; 47 | } 48 | 49 | public void setName(String name) { 50 | this.name = name; 51 | } 52 | 53 | 54 | /** 55 | * Tworzy nowy obiekt klasy T. Pozwala to na proste obejście problemu z inicjalizacją klasy generycznej jeżeli 56 | * klasy rozszerzające AbstractTimeSeries poprawnie zaimplementują tę metodę. 57 | * @return Nowy obiekt klasy T. 58 | */ 59 | public abstract T createElementInstance(); 60 | } 61 | -------------------------------------------------------------------------------- /basic-interfaces/src/mini/java/basic/interfaces/IntegerTimeSeries.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.interfaces; 2 | 3 | import java.util.List; 4 | 5 | public class IntegerTimeSeries extends AbstractTimeSeries implements Summable{ 6 | 7 | 8 | public IntegerTimeSeries(String name, List data) { 9 | super(name, data); 10 | } 11 | 12 | @Override 13 | public Integer createElementInstance() { 14 | return 0; 15 | } 16 | 17 | @Override 18 | public Integer sum() { 19 | return data.stream().mapToInt(Integer::intValue).sum(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic-interfaces/src/mini/java/basic/interfaces/Printable.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.interfaces; 2 | 3 | /** 4 | * Klasa implementująca ten interfejs potrafi wydrukować swoją zawartość na wyjście standardowe. 5 | */ 6 | public interface Printable { 7 | void printToSystemOut(); 8 | } 9 | -------------------------------------------------------------------------------- /basic-interfaces/src/mini/java/basic/interfaces/SeriesTest.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.interfaces; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import static org.junit.Assert.*; 7 | import static org.junit.Assert.assertTrue; 8 | 9 | public class SeriesTest { 10 | 11 | @org.junit.Test 12 | public void integerSeriesTest() { 13 | List data = new ArrayList<>(); 14 | data.add(1); 15 | data.add(3); 16 | IntegerTimeSeries i = new IntegerTimeSeries("Name",data); 17 | assertEquals(i.get(1),Integer.valueOf(3)); 18 | assertEquals(i.sum(), Integer.valueOf(4)); 19 | } 20 | 21 | @org.junit.Test 22 | public void stringSeriesTest() { 23 | List data = new ArrayList<>(); 24 | data.add("Ala"); 25 | data.add("Makota"); 26 | StringTimeSeries i = new StringTimeSeries("Name",data); 27 | assertEquals(i.get(1),"Makota"); 28 | assertEquals(i.sum(), "AlaMakota"); 29 | } 30 | 31 | @org.junit.Test 32 | public void stringSeriesConsoleInterfacetTest() { 33 | List data = new ArrayList<>(); 34 | data.add("Ala"); 35 | data.add("Makota"); 36 | StringTimeSeries i = new StringTimeSeries("Name",data); 37 | ((Printable)i).printToSystemOut(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /basic-interfaces/src/mini/java/basic/interfaces/StringTimeSeries.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.interfaces; 2 | 3 | import org.jetbrains.annotations.Nullable; 4 | 5 | import java.util.List; 6 | 7 | public class StringTimeSeries extends AbstractTimeSeries implements Printable, Summable { 8 | public StringTimeSeries(@Nullable String name, List data) { 9 | super(name, data); 10 | } 11 | 12 | @Override 13 | public String createElementInstance() { 14 | return ""; 15 | } 16 | 17 | @Override 18 | public String sum() { 19 | StringBuilder sb = new StringBuilder(); 20 | for (String el : data) 21 | sb.append(el); 22 | return sb.toString(); 23 | } 24 | 25 | @Override 26 | public void printToSystemOut() { 27 | data.forEach(d -> System.out.println(d)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /basic-interfaces/src/mini/java/basic/interfaces/Summable.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.interfaces; 2 | 3 | /** 4 | * Klasa implementująca ten interfejs potrafi się zsumować 5 | * @param Sumowany typ 6 | */ 7 | public interface Summable { 8 | T sum(); 9 | } 10 | -------------------------------------------------------------------------------- /basic-interfaces/src/mini/java/basic/interfaces/test/AbstractRandomizer.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.interfaces.test; 2 | 3 | import java.lang.reflect.Array; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.Random; 7 | 8 | /** 9 | * Generates random object for generic type. 10 | * To implement calss you need to provide next() method to generate new rendom object ot given type. 11 | * 12 | * @see AbstractRandomizer#next(int) 13 | * @param Type 14 | */ 15 | public abstract class AbstractRandomizer implements TypeAware { 16 | protected Random random; 17 | long seed = 0; 18 | 19 | /** 20 | * Returns new random object of type T 21 | * This is only method you need to implement 22 | * 23 | * @param limit Length of the object 24 | * @return New random object 25 | * 26 | */ 27 | 28 | @Deprecated 29 | public abstract T next(int limit); 30 | 31 | public List nextList(int length, int limit) { 32 | List al = new ArrayList<>(); 33 | for (int i = 0; i < length; i++) { 34 | al.add(next(limit)); 35 | } 36 | return al; 37 | } 38 | 39 | 40 | public void reseed() { 41 | random = new Random(); 42 | } 43 | 44 | public long getSeed() { 45 | return seed; 46 | } 47 | 48 | public void setSeed(long seed) { 49 | random = new Random(seed); 50 | this.seed = seed; 51 | } 52 | 53 | 54 | public T[] nextArray(int length, int limit) { 55 | return nextList(length,limit).toArray((T[]) Array.newInstance(getElementClass(), length)); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /basic-interfaces/src/mini/java/basic/interfaces/test/IntegerList.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.interfaces.test; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class IntegerList extends ArrayList implements TypeAware { 7 | public Integer getEmpty() { 8 | return 0; 9 | } 10 | 11 | public Class getElementClass() { 12 | return Integer.class; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /basic-interfaces/src/mini/java/basic/interfaces/test/IntegerRandomizer.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.interfaces.test; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Random; 6 | 7 | /** 8 | * Klasa IntegerRandomizer generuje nowe, losowe liczby całkowite w podanym przedziale 9 | */ 10 | public class IntegerRandomizer extends AbstractRandomizer implements TypeAware { 11 | private Random random; 12 | long seed = 0; 13 | 14 | public IntegerRandomizer() { 15 | random = new Random(); 16 | } 17 | 18 | public IntegerRandomizer(long seed) { 19 | this.seed = seed; 20 | random = new Random(seed); 21 | } 22 | 23 | public Integer next(int limit) { 24 | return random.nextInt(limit); 25 | } 26 | 27 | 28 | 29 | @Override 30 | public Integer getEmpty() { 31 | return 0; 32 | } 33 | 34 | @Override 35 | public Class getElementClass() { 36 | return Integer.class; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /basic-interfaces/src/mini/java/basic/interfaces/test/RandomizerTests.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.interfaces.test; 2 | 3 | import org.junit.Test; 4 | 5 | import java.lang.reflect.Type; 6 | import java.util.List; 7 | 8 | import static org.junit.Assert.*; 9 | 10 | /* 11 | Testy dla klas IntegerRandomizer, StringRandomizer 12 | Zadanie: 13 | 1. Zaproponuj i wydziel z klas interfejs/klasy abstrakcyjną 14 | 2. Przekonwertuj testy tak aby tam gdzie to możliwe korzystały z nowych obiektów 15 | */ 16 | public class RandomizerTests { 17 | 18 | @Test 19 | public void next() { 20 | AbstractRandomizer integerRandomizer = new IntegerRandomizer(); 21 | AbstractRandomizer stringRandomizer = new StringRandomizer(); 22 | //TODO: asdasdasdsa 23 | for (int i = 0; i < 1000; i++) { 24 | Integer testedInteger = integerRandomizer.next(10); 25 | assertTrue(testedInteger >= 0 && testedInteger < 10); 26 | String testedString = stringRandomizer.next(10); 27 | assertEquals(10, testedString.length()); 28 | } 29 | 30 | } 31 | 32 | public void nextList() { 33 | AbstractRandomizer integerRandomizer = new IntegerRandomizer(); 34 | AbstractRandomizer stringRandomizer = new StringRandomizer(); 35 | 36 | assertTrue(integerRandomizer.nextList(1000,5).stream().allMatch(i -> i >= 0 && i < 5)); 37 | assertTrue(stringRandomizer.nextList(1000,5).stream().allMatch(s -> s.length() == 5)); 38 | } 39 | 40 | @Test 41 | public void nextArray() { 42 | AbstractRandomizer integerRandomizer = new IntegerRandomizer(); 43 | AbstractRandomizer stringRandomizer = new StringRandomizer(); 44 | 45 | List l = List.of(integerRandomizer,stringRandomizer); 46 | 47 | assertEquals(10,integerRandomizer.nextArray(10,5).length); 48 | assertEquals(7,stringRandomizer.nextArray(7,7).length); 49 | } 50 | 51 | @Test 52 | public void emptyObjectTest() { 53 | TypeAware integerRandomizer = new IntegerRandomizer(); 54 | TypeAware stringRandomizer = new StringRandomizer(); 55 | TypeAware integerList = new IntegerList(); 56 | 57 | assertEquals(0, integerList.getEmpty()); 58 | assertEquals(0, integerRandomizer.getEmpty()); 59 | assertEquals("", stringRandomizer.getEmpty()); 60 | } 61 | 62 | @Test 63 | public void elementClassTest() { 64 | TypeAware integerRandomizer = new IntegerRandomizer(); 65 | TypeAware stringRandomizer = new StringRandomizer(); 66 | TypeAware integerList = new IntegerList(); 67 | 68 | assertEquals(Integer.class, integerList.getElementClass()); 69 | assertEquals(Integer.class, integerRandomizer.getElementClass()); 70 | assertEquals(String.class, stringRandomizer.getElementClass()); 71 | } 72 | } -------------------------------------------------------------------------------- /basic-interfaces/src/mini/java/basic/interfaces/test/StringRandomizer.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.interfaces.test; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Random; 6 | 7 | /** 8 | * Klasa StringRandomizer generuje nowe, losowe napisy całkowite o konkretnej długości 9 | */ 10 | public class StringRandomizer extends AbstractRandomizer implements TypeAware { 11 | 12 | public StringRandomizer() { 13 | random = new Random(); 14 | } 15 | 16 | public StringRandomizer(long seed) { 17 | this.seed = seed; 18 | random = new Random(seed); 19 | } 20 | 21 | @Override 22 | public String next(int limit) { 23 | StringBuilder sb = new StringBuilder(); 24 | for (int i = 0; i < limit; i++) { 25 | char c = (char) (random.nextInt(26) + 'a'); 26 | sb.append(c); 27 | } 28 | return sb.toString(); 29 | } 30 | 31 | 32 | public String getEmpty() { 33 | return new String(); 34 | } 35 | 36 | public Class getElementClass() { 37 | return String.class; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /basic-interfaces/src/mini/java/basic/interfaces/test/TypeAware.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.interfaces.test; 2 | 3 | public interface TypeAware { 4 | T getEmpty(); 5 | 6 | Class getElementClass(); 7 | } 8 | -------------------------------------------------------------------------------- /basic-iostreams/basic-iostreams.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /basic-iostreams/src/mini/java/basic/iostreams/SerializableObject.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.iostreams; 2 | 3 | import mini.java.basic.interfaces.test.IntegerRandomizer; 4 | import mini.java.basic.interfaces.test.StringRandomizer; 5 | 6 | import java.io.Serializable; 7 | import java.util.List; 8 | import java.util.Objects; 9 | 10 | public class SerializableObject implements Serializable { 11 | private String stringField; 12 | private Integer integerField; 13 | private List stringList; 14 | 15 | public String getStringField() { 16 | return stringField; 17 | } 18 | 19 | public void setStringField(String stringField) { 20 | this.stringField = stringField; 21 | } 22 | 23 | public Integer getIntegerField() { 24 | return integerField; 25 | } 26 | 27 | public void setIntegerField(Integer integerField) { 28 | this.integerField = integerField; 29 | } 30 | 31 | public List getStringList() { 32 | return stringList; 33 | } 34 | 35 | public void setStringList(List stringList) { 36 | this.stringList = stringList; 37 | } 38 | 39 | public SerializableObject() { 40 | stringField = (new StringRandomizer()).next(10); 41 | stringList = (new StringRandomizer()).nextList(10,20); 42 | integerField = (new IntegerRandomizer()).next(100); 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "SerializableObject{" + 48 | "stringField='" + stringField + '\'' + 49 | ", integerField=" + integerField + 50 | ", stringList=" + stringList + 51 | '}'; 52 | } 53 | 54 | @Override 55 | public boolean equals(Object o) { 56 | if (this == o) return true; 57 | if (o == null || getClass() != o.getClass()) return false; 58 | SerializableObject that = (SerializableObject) o; 59 | return Objects.equals(stringField, that.stringField) && 60 | Objects.equals(integerField, that.integerField) && 61 | Objects.equals(stringList, that.stringList); 62 | } 63 | 64 | @Override 65 | public int hashCode() { 66 | 67 | return Objects.hash(stringField, integerField, stringList); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /basic-iostreams/src/mini/java/basic/iostreams/SerializableObjectWithTransients.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.iostreams; 2 | 3 | import com.google.gson.annotations.Expose; 4 | import mini.java.basic.interfaces.test.IntegerRandomizer; 5 | import mini.java.basic.interfaces.test.StringRandomizer; 6 | 7 | import java.io.Serializable; 8 | import java.util.List; 9 | import java.util.Objects; 10 | 11 | public class SerializableObjectWithTransients implements Serializable { 12 | private String stringField; 13 | private Integer integerField; 14 | transient private List stringList; 15 | 16 | public String getStringField() { 17 | return stringField; 18 | } 19 | 20 | public void setStringField(String stringField) { 21 | this.stringField = stringField; 22 | } 23 | 24 | public Integer getIntegerField() { 25 | return integerField; 26 | } 27 | 28 | public void setIntegerField(Integer integerField) { 29 | this.integerField = integerField; 30 | } 31 | 32 | public List getStringList() { 33 | return stringList; 34 | } 35 | 36 | public void setStringList(List stringList) { 37 | this.stringList = stringList; 38 | } 39 | 40 | public SerializableObjectWithTransients() { 41 | stringField = (new StringRandomizer()).next(10); 42 | stringList = (new StringRandomizer()).nextList(10,20); 43 | integerField = (new IntegerRandomizer()).next(100); 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "SerializableObject{" + 49 | "stringField='" + stringField + '\'' + 50 | ", integerField=" + integerField + 51 | ", stringList=" + stringList + 52 | '}'; 53 | } 54 | 55 | @Override 56 | public boolean equals(Object o) { 57 | if (this == o) return true; 58 | if (o == null || getClass() != o.getClass()) return false; 59 | SerializableObjectWithTransients that = (SerializableObjectWithTransients) o; 60 | return Objects.equals(stringField, that.stringField) && 61 | Objects.equals(integerField, that.integerField) && 62 | Objects.equals(stringList, that.stringList); 63 | } 64 | 65 | @Override 66 | public int hashCode() { 67 | 68 | return Objects.hash(stringField, integerField, stringList); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /basic-iostreams/src/mini/java/basic/iostreams/SerializationTests.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.iostreams; 2 | 3 | 4 | import com.google.gson.Gson; 5 | import com.google.gson.GsonBuilder; 6 | import org.junit.Assert; 7 | 8 | import java.io.*; 9 | import java.nio.file.Files; 10 | import java.nio.file.Paths; 11 | import java.util.LinkedHashMap; 12 | import java.util.Map; 13 | 14 | public class SerializationTests { 15 | 16 | @org.junit.Test 17 | public void serializeDeserializeJavaSerializableTest() throws IOException, ClassNotFoundException { 18 | if (Files.exists(Paths.get("java_serialized.bin"))) Files.delete(Paths.get("java_serialized.bin")); 19 | SerializableObject object = new SerializableObject(); 20 | try (FileOutputStream fileOut = new FileOutputStream("java_serialized.bin"); ObjectOutputStream objectOut = new ObjectOutputStream(fileOut)) { 21 | objectOut.writeObject(object); 22 | } 23 | 24 | ObjectInputStream objectIn = new ObjectInputStream(new FileInputStream("java_serialized.bin")); 25 | SerializableObject deserialized = (SerializableObject)objectIn.readObject(); 26 | Assert.assertEquals(object, deserialized); 27 | } 28 | 29 | @org.junit.Test 30 | public void serializeDeserializeJsonTest() throws IOException { 31 | if (Files.exists(Paths.get("gson_serialized.json"))) Files.delete(Paths.get("gson_serialized.json")); 32 | Gson serializer = new Gson(); 33 | SerializableObject object = new SerializableObject(); 34 | FileWriter writer = new FileWriter("gson_serialized.json"); 35 | serializer.toJson(object, writer); 36 | writer.close(); 37 | 38 | Gson deserializer = new Gson(); 39 | SerializableObject deserialized = deserializer.fromJson(new FileReader("gson_serialized.json"), SerializableObject.class); 40 | Assert.assertEquals(object, deserialized); 41 | } 42 | 43 | 44 | @org.junit.Test 45 | public void serializeDeserializeJavaSerializableTransientTest() throws IOException, ClassNotFoundException { 46 | if (Files.exists(Paths.get("java_serialized.bin"))) Files.delete(Paths.get("java_serialized.bin")); 47 | SerializableObjectWithTransients object = new SerializableObjectWithTransients(); 48 | FileOutputStream fileOut = new FileOutputStream("java_serialized.bin"); 49 | ObjectOutputStream objectOut = new ObjectOutputStream(fileOut); 50 | objectOut.writeObject(object); 51 | objectOut.close(); 52 | 53 | ObjectInputStream objectIn = new ObjectInputStream(new FileInputStream("java_serialized.bin")); 54 | SerializableObjectWithTransients deserialized = (SerializableObjectWithTransients)objectIn.readObject(); 55 | Assert.assertEquals(object.getIntegerField(), deserialized.getIntegerField()); 56 | Assert.assertEquals(object.getStringField(), deserialized.getStringField()); 57 | Assert.assertNull(deserialized.getStringList()); 58 | } 59 | 60 | @org.junit.Test 61 | public void serializeDeserializeJsonTransientTest() throws IOException { 62 | if (Files.exists(Paths.get("gson_serialized.json"))) Files.delete(Paths.get("gson_serialized.json")); 63 | Gson serializer = new Gson(); 64 | SerializableObjectWithTransients object = new SerializableObjectWithTransients(); 65 | FileWriter writer = new FileWriter("gson_serialized.json"); 66 | serializer.toJson(object, writer); 67 | writer.close(); 68 | 69 | Gson deserializer = new Gson(); 70 | SerializableObjectWithTransients deserialized = deserializer.fromJson(new FileReader("gson_serialized.json"), SerializableObjectWithTransients.class); 71 | Assert.assertEquals(object.getIntegerField(), deserialized.getIntegerField()); 72 | Assert.assertEquals(object.getStringField(), deserialized.getStringField()); 73 | Assert.assertNull(deserialized.getStringList()); 74 | } 75 | 76 | @org.junit.Test 77 | public void serializeDeserializeJsonMapTest() throws IOException { 78 | if (Files.exists(Paths.get("gson_serialized.json"))) Files.delete(Paths.get("gson_serialized.json")); 79 | Gson serializer = new Gson(); 80 | SerializableObject object = new SerializableObject(); 81 | FileWriter writer = new FileWriter("gson_serialized.json"); 82 | serializer.toJson(object, writer); 83 | writer.close(); 84 | 85 | Gson deserializer = new Gson(); 86 | Map deserialized = deserializer.fromJson(new FileReader("gson_serialized.json"), LinkedHashMap.class); 87 | 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /basic-iostreams/src/mini/java/basic/iostreams/TextFileStreamsTests.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.iostreams; 2 | 3 | 4 | import mini.java.basic.interfaces.test.StringRandomizer; 5 | 6 | import java.io.*; 7 | import java.nio.file.Files; 8 | import java.nio.file.Paths; 9 | 10 | public class TextFileStreamsTests { 11 | 12 | @org.junit.Test 13 | public void createTestTextFileTest() throws IOException { 14 | if (Files.exists(Paths.get("test.txt"))) Files.delete(Paths.get("test.txt")); 15 | File fout = new File("test.txt"); 16 | FileOutputStream fos = new FileOutputStream(fout); 17 | 18 | BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos)); 19 | bw.write("Test"); 20 | bw.newLine(); 21 | bw.write("Abc"); 22 | bw.close(); 23 | fos.close(); 24 | } 25 | 26 | @org.junit.Test 27 | public void createTestTextFileTestPrintWriter() throws IOException { 28 | if (Files.exists(Paths.get("test.txt"))) Files.delete(Paths.get("test.txt")); 29 | File fout = new File("test.txt"); 30 | FileOutputStream fos = new FileOutputStream(fout); 31 | PrintWriter bw = new PrintWriter(new OutputStreamWriter(fos)); 32 | bw.println("Test"); 33 | bw.println("Abc 2"); 34 | bw.close(); 35 | fos.close(); 36 | } 37 | 38 | @org.junit.Test 39 | public void readTestTextFileTest() throws IOException { 40 | if (Files.exists(Paths.get("test.txt"))) Files.delete(Paths.get("test.txt")); 41 | File fout = new File("test.txt"); 42 | FileOutputStream fos = new FileOutputStream(fout); 43 | BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos)); 44 | StringRandomizer stringRandomizer = new StringRandomizer(10); 45 | 46 | for (int i = 0; i < 100000; i++) { 47 | bw.write(stringRandomizer.next(1000)); 48 | bw.newLine(); 49 | } 50 | bw.close(); 51 | fos.close(); 52 | BufferedReader br = new BufferedReader(new FileReader("test.txt")); 53 | while (br.read() != -1) { 54 | } 55 | br.close(); 56 | BufferedReader br2 = new BufferedReader(new FileReader("test.txt")); 57 | for (int i = 0; i< 10; i++) { 58 | String a = br2.readLine(); 59 | System.out.println(a); 60 | } 61 | br2.close(); 62 | } 63 | 64 | @org.junit.Test 65 | public void readTestTextFileUnbufferedTest() throws IOException { 66 | if (Files.exists(Paths.get("test.txt"))) Files.delete(Paths.get("test.txt")); 67 | File fout = new File("test.txt"); 68 | FileOutputStream fos = new FileOutputStream(fout); 69 | BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos)); 70 | StringRandomizer stringRandomizer = new StringRandomizer(10); 71 | 72 | for (int i = 0; i < 100000; i++) { 73 | bw.write(stringRandomizer.next(1000)); 74 | bw.newLine(); 75 | } 76 | bw.close(); 77 | 78 | FileReader fr = new FileReader("test.txt"); 79 | while (fr.read() != -1) { 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /basic-iostreams/src/mini/java/basic/iostreams/test/CSVDataset.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.iostreams.test; 2 | 3 | import java.io.*; 4 | import java.util.*; 5 | 6 | /** 7 | * This class represents simple dataset bound to a CSV file. 8 | * Your task is to implement methods so tests in CSVSerializerDeserializerTest class pass. 9 | * 10 | * You can implement methods in any way you want. Data should be read in such a way that you can retrieve: 11 | * - header row 12 | * - data row 13 | * - data cell (column/row) 14 | * 15 | * Hints: 16 | * - If you look in previous labs code, you should find a lot of inspiration 17 | * - To serialize data to json you can use Gson library, as it was shown in examples. 18 | * To add library to project, use Project Project Structure -> Global Libraries -> + From Maven 19 | * and search for com.google.gson package. 20 | */ 21 | public class CSVDataset { 22 | /** 23 | * Creates new CSVDataset instance bound to a file. 24 | * @param filename name of CSV file 25 | * @param hasHeader true if CSV file has header. If true, column names are read from header, 26 | * if false, they are generated as Column N, where N is column index. 27 | * @throws IOException When file could nod be found or read properly 28 | */ 29 | public CSVDataset(String filename, boolean hasHeader) throws IOException { 30 | throw new RuntimeException("Not implemented! Implement this method!"); 31 | } 32 | 33 | 34 | /** 35 | * Deserializes object from java binary serialization file. Deserialized object should not be bound to CSV file. 36 | * @param filename serialized filename 37 | * @return CSVDataset deserialized object 38 | * @throws IOException on file read errors 39 | * @throws ClassNotFoundException if class is not found 40 | */ 41 | public static CSVDataset deserializeJava(String filename) { 42 | throw new RuntimeException("Not implemented! Implement this method!"); 43 | } 44 | 45 | /** 46 | * Deserialized object from json representation. Deserialized object should not be bound to CSV file. 47 | * @param filename serialized filename 48 | * @return CSVDataset deserialized object 49 | * @throws FileNotFoundException when file is not found 50 | */ 51 | public static CSVDataset deserializeJson(String filename) { 52 | throw new RuntimeException("Not implemented! Implement this method!"); 53 | } 54 | 55 | /** 56 | * Gets read data size 57 | * @return read data size (excluding header row if existing) 58 | */ 59 | public int dataLength() { 60 | throw new RuntimeException("Not implemented! Implement this method!"); 61 | } 62 | 63 | 64 | /** 65 | * Serialized object to binary java serialization file 66 | * @param filename serialized filename 67 | * @throws IOException on filesystem error 68 | */ 69 | public void serializeJava(String filename) { 70 | throw new RuntimeException("Not implemented! Implement this method!"); 71 | } 72 | 73 | /** 74 | * Serialized object to binary java serialization file 75 | * @param filename serialized filename 76 | * @throws IOException on filesystem error 77 | */ 78 | public void serializeJson(String filename) { 79 | throw new RuntimeException("Not implemented! Implement this method!"); 80 | } 81 | 82 | /** 83 | * Returns list of values from given row 84 | * @param row row number to read data from 85 | * @return values from given row 86 | */ 87 | public List getValues(int row) { 88 | throw new RuntimeException("Not implemented! Implement this method!"); 89 | } 90 | 91 | /** 92 | * Returns value for given column and row 93 | * @param row row number to read data from 94 | * @param column column name to read data from 95 | * @return value 96 | */ 97 | public String getValue(String column, int row) { 98 | throw new RuntimeException("Not implemented! Implement this method!"); 99 | } 100 | 101 | /** 102 | * Adds new column with data. Data is added to as many rows as it can be 103 | * (if there are ex. 3 elements in elements array, data is added to first 3 rows) 104 | * @param columnName new column name 105 | * @param elements elements to add 106 | * @return true if added 107 | */ 108 | public boolean addColumn(String columnName, String... elements) { 109 | throw new RuntimeException("Not implemented! Implement this method!"); 110 | } 111 | 112 | /** 113 | * Saves CSV data to file. If original data had headers, they should be saved as well. 114 | * @param filename name of new CSV file 115 | * @throws FileNotFoundException if file could not be found 116 | */ 117 | public void saveToFile(String filename) throws FileNotFoundException { 118 | throw new RuntimeException("Not implemented! Implement this method!"); 119 | } 120 | 121 | /** 122 | * Returns if insance is bound to a file - that means, it was directly created 123 | * from a file, not by deserialization. 124 | * @return true if instance was created from a file, false if not 125 | */ 126 | public boolean isBoundToFile() { 127 | throw new RuntimeException("Not implemented! Implement this method!"); 128 | } 129 | 130 | /** 131 | * Returns headers if existing, null if not 132 | * @return read headers if file read with headers, null otherwise 133 | */ 134 | public List getHeader() { 135 | throw new RuntimeException("Not implemented! Implement this method!"); 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /basic-iostreams/src/mini/java/basic/iostreams/test/CSVSerializerDeserializerTest.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.iostreams.test; 2 | 3 | import org.junit.Assert; 4 | 5 | import java.io.*; 6 | import java.nio.file.Files; 7 | import java.nio.file.OpenOption; 8 | import java.nio.file.Paths; 9 | import java.util.List; 10 | 11 | public class CSVSerializerDeserializerTest { 12 | @org.junit.Test 13 | public void createDummyFile() throws IOException { 14 | if (!Files.exists(Paths.get("test.csv"))) Files.write(Paths.get("test.csv"),"Place data here".getBytes()); 15 | } 16 | 17 | @org.junit.Test 18 | public void readDataLength() throws IOException { 19 | if (!Files.exists(Paths.get("test.csv"))) throw new RuntimeException("Place test.csv file in project root directory"); 20 | 21 | CSVDataset csvDataset = new CSVDataset("test.csv", true); 22 | int dataLength = csvDataset.dataLength(); 23 | CSVDataset csvDatasetNoHeader = new CSVDataset("test.csv", false); 24 | int dataLengthNoHeader = csvDatasetNoHeader.dataLength(); 25 | 26 | // Checks and assertions 27 | Assert.assertEquals(10, dataLength); 28 | Assert.assertEquals(11, dataLengthNoHeader); 29 | } 30 | 31 | @org.junit.Test(expected = IOException.class) 32 | public void readNonExsitingFile() throws IOException { 33 | CSVDataset csvDataset = new CSVDataset("nonexisting.csv", true); 34 | 35 | } 36 | 37 | @org.junit.Test 38 | public void readDataValues() throws IOException { 39 | if (!Files.exists(Paths.get("test.csv"))) throw new RuntimeException("Place test.csv file in project root directory"); 40 | 41 | CSVDataset csvDataset = new CSVDataset("test.csv", true); 42 | int dataLength = csvDataset.dataLength(); 43 | CSVDataset csvDatasetNoHeader = new CSVDataset("test.csv", false); 44 | int dataLengthNoHeader = csvDatasetNoHeader.dataLength(); 45 | 46 | // Checks and assertions 47 | int randomLine = (int) (Math.random() * 8); 48 | List randomTestLineData = List.of(String.format("A%s", randomLine + 1), String.format("B%s", randomLine + 1), String.format("C%s", randomLine + 1), String.format("D%s", randomLine + 1)); 49 | Assert.assertEquals(randomTestLineData, csvDataset.getValues(randomLine)); 50 | Assert.assertEquals(List.of("Kolumna 1","Kolumna 2","Kolumna 3","Kolumna 4"), csvDataset.getHeader()); 51 | Assert.assertEquals(String.format("A%s", randomLine + 1), csvDataset.getValue("Kolumna 1", randomLine)); 52 | } 53 | 54 | @org.junit.Test 55 | public void saveDataValues() throws IOException { 56 | if (!Files.exists(Paths.get("test.csv"))) throw new RuntimeException("Place test.csv file in project root directory"); 57 | if (Files.exists(Paths.get("test_saved.csv"))) Files.delete(Paths.get("test_saved.csv")); 58 | 59 | CSVDataset csvDataset = new CSVDataset("test.csv", true); 60 | boolean columnAdded = csvDataset.addColumn("Kolumna 5", "T1","T2","T3","T4","T5","T6","T7","T8","T9","T10"); 61 | csvDataset.saveToFile("test_saved.csv"); 62 | CSVDataset csvDatasetSaved = new CSVDataset("test_saved.csv", true); 63 | 64 | // Checks and assertions 65 | int randomLine = (int) (Math.random() * 8); 66 | List randomTestLineData = List.of(String.format("A%s", randomLine + 1), String.format("B%s", randomLine + 1), String.format("C%s", randomLine + 1), String.format("D%s", randomLine + 1), String.format("T%s", randomLine + 1)); 67 | Assert.assertEquals(randomTestLineData, csvDataset.getValues(randomLine)); 68 | Assert.assertEquals(String.format("T%s", randomLine + 1), csvDataset.getValue("Kolumna 5", randomLine)); 69 | Assert.assertTrue(columnAdded); 70 | } 71 | 72 | 73 | @org.junit.Test 74 | public void serializeDeserializeJavaSerializableTest() throws IOException, ClassNotFoundException { 75 | if (Files.exists(Paths.get("java_serialized.bin"))) Files.delete(Paths.get("java_serialized.bin")); 76 | 77 | CSVDataset csvDataset = new CSVDataset("test.csv", true); 78 | csvDataset.serializeJava("java_serialized.bin"); 79 | CSVDataset deserializedCsvDataset = CSVDataset.deserializeJava("java_serialized.bin"); 80 | 81 | // Checks and assertions 82 | int randomLine = (int) (Math.random() * 8); 83 | List randomTestLineData = List.of(String.format("A%s", randomLine + 1), String.format("B%s", randomLine + 1), String.format("C%s", randomLine + 1), String.format("D%s", randomLine + 1)); 84 | Assert.assertEquals(csvDataset, deserializedCsvDataset); 85 | Assert.assertTrue(csvDataset.isBoundToFile()); 86 | Assert.assertFalse(deserializedCsvDataset.isBoundToFile()); 87 | Assert.assertEquals(randomTestLineData, csvDataset.getValues(randomLine)); 88 | Assert.assertEquals(String.format("A%s", randomLine + 1), csvDataset.getValue("Kolumna 1", randomLine)); 89 | 90 | } 91 | 92 | @org.junit.Test 93 | public void serializeDeserializeJsonTest() throws IOException { 94 | if (Files.exists(Paths.get("json_serialized.json"))) Files.delete(Paths.get("json_serialized.json")); 95 | 96 | CSVDataset csvDataset = new CSVDataset("test.csv", true); 97 | csvDataset.serializeJson("json_serialized.json"); 98 | CSVDataset deserializedCsvDataset = CSVDataset.deserializeJson("json_serialized.json"); 99 | 100 | // Checks and assertions 101 | int randomLine = (int) (Math.random() * 8); 102 | List randomTestLineData = List.of(String.format("A%s", randomLine + 1), String.format("B%s", randomLine + 1), String.format("C%s", randomLine + 1), String.format("D%s", randomLine + 1)); 103 | Assert.assertTrue(csvDataset.isBoundToFile()); 104 | Assert.assertFalse(deserializedCsvDataset.isBoundToFile()); 105 | Assert.assertEquals(csvDataset, deserializedCsvDataset); 106 | Assert.assertEquals(randomTestLineData, csvDataset.getValues(randomLine)); 107 | Assert.assertEquals(String.format("A%s", randomLine + 1), csvDataset.getValue("Kolumna 1", randomLine)); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /basic-iostreams/src/mini/java/basic/iostreams/test/test.csv: -------------------------------------------------------------------------------- 1 | Kolumna 1,Kolumna 2,Kolumna 3,Kolumna 4 2 | A1,B1,C1,D1 3 | A2,B2,C2,D2 4 | A3,B3,C3,D3 5 | A4,B4,C4,D4 6 | A5,B5,C5,D5 7 | A6,B6,C6,D6 8 | A7,B7,C7,D7 9 | A8,B8,C8,D8 10 | A9,B9,C9,D9 11 | A10,B10,C10,D10 -------------------------------------------------------------------------------- /basic-objects/basic-objects.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /basic-objects/src/mini/java/basic/objects/Main.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.objects; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | System.out.println("Hello World!"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /basic-swing/basic-swing.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /basic-swing/src/BasicForm.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 |
75 | -------------------------------------------------------------------------------- /basic-swing/src/BasicForm.java: -------------------------------------------------------------------------------- 1 | import javax.swing.*; 2 | import java.awt.event.ActionEvent; 3 | import java.awt.event.ActionListener; 4 | import java.time.LocalDateTime; 5 | 6 | public class BasicForm { 7 | private final DefaultListModel listModel; 8 | private JCheckBox checkCheckBox; 9 | private JButton pushButton; 10 | private JLabel selectedLabel; 11 | private JPanel mainPanel; 12 | private JList list1; 13 | private JTextField textField1; 14 | private JRadioButton radioButton1; 15 | private JButton button1; 16 | 17 | public BasicForm() { 18 | listModel = new DefaultListModel(); 19 | list1.setModel(listModel); 20 | pushButton.addActionListener(new ActionListener() { 21 | @Override 22 | public void actionPerformed(ActionEvent e) { 23 | selectedLabel.setText(String.format("Selected = %s", checkCheckBox.isSelected())); 24 | listModel.addElement(String.format("%s: %s, %s", LocalDateTime.now(), textField1.getText(), checkCheckBox.isSelected())); 25 | } 26 | }); 27 | checkCheckBox.addActionListener(new ActionListener() { 28 | @Override 29 | public void actionPerformed(ActionEvent e) { 30 | listModel.addElement(String.format("%s: checkbox status changed to %s", LocalDateTime.now(), checkCheckBox.isSelected())); 31 | 32 | } 33 | }); 34 | button1.addActionListener(new ActionListener() { 35 | @Override 36 | public void actionPerformed(ActionEvent e) { 37 | 38 | } 39 | }); 40 | } 41 | 42 | public static void main(String[] args) { 43 | JFrame jFrame = new JFrame("App"); 44 | jFrame.setContentPane(new BasicForm().mainPanel); 45 | jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 46 | jFrame.pack(); 47 | jFrame.setVisible(true); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /basic-threading/basic-threading.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /basic-threading/src/mini/java/basic/threading/ThreadingTest.java: -------------------------------------------------------------------------------- 1 | package mini.java.basic.threading; 2 | 3 | import mini.java.basic.interfaces.test.StringRandomizer; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Map; 7 | import java.util.concurrent.*; 8 | import java.util.concurrent.atomic.AtomicInteger; 9 | 10 | public class ThreadingTest { 11 | final Object sync = new Object(); 12 | 13 | @org.junit.Test 14 | public void streamThreading() { 15 | ArrayList unsafeArrayList = new ArrayList<>(); 16 | for (int i = 0; i < 100; i++) { 17 | unsafeArrayList.add("A"); 18 | } 19 | // Nie polecam 20 | unsafeArrayList.parallelStream().forEach(p -> { 21 | System.out.println(p); 22 | }); 23 | } 24 | @org.junit.Test 25 | public void basicThreading() { 26 | ExecutorService executorService = Executors.newFixedThreadPool(2); 27 | 28 | for (int i = 0; i < 5; i++) { 29 | Runnable sleepThread = new Runnable() { 30 | @Override 31 | public void run() { 32 | System.out.println("Executing Task1 inside : " + Thread.currentThread().getName()); 33 | synchronizationTest(); 34 | } 35 | }; 36 | executorService.submit(sleepThread); 37 | } 38 | awaitTerminationAfterShutdown(executorService); 39 | System.out.println("Reached end of method"); 40 | } 41 | 42 | private void synchronizationTest() { 43 | synchronized (sync) { 44 | try { 45 | TimeUnit.SECONDS.sleep(2); 46 | } catch (InterruptedException ex) { 47 | throw new IllegalStateException(ex); 48 | } 49 | } 50 | } 51 | 52 | class CallableWithParameter implements Callable { 53 | 54 | @Override 55 | public String call() throws Exception { 56 | return null; 57 | } 58 | } 59 | 60 | @org.junit.Test 61 | public void callableTest() throws InterruptedException, ExecutionException { 62 | ExecutorService executorService = Executors.newFixedThreadPool(2); 63 | 64 | ArrayList> callables = new ArrayList<>(); 65 | for (int i = 0; i < 5; i++) { 66 | Callable callable = new Callable() { 67 | StringRandomizer stringRandomizer = new StringRandomizer(); 68 | @Override 69 | public String call() throws Exception { 70 | try { 71 | TimeUnit.SECONDS.sleep(2); 72 | } catch (InterruptedException ex) { 73 | throw new IllegalStateException(ex); 74 | } 75 | return stringRandomizer.next(10); 76 | } 77 | }; 78 | callables.add(callable); 79 | } 80 | var futures = executorService.invokeAll(callables); 81 | awaitTerminationAfterShutdown(executorService); 82 | System.out.println("Reached end of thread"); 83 | for (Future stringFuture : futures) { 84 | System.out.println(stringFuture.get()); 85 | } 86 | } 87 | 88 | public void awaitTerminationAfterShutdown(ExecutorService threadPool) { 89 | threadPool.shutdown(); 90 | try { 91 | if (!threadPool.awaitTermination(60, TimeUnit.SECONDS)) { 92 | threadPool.shutdownNow(); 93 | } 94 | } catch (InterruptedException ex) { 95 | threadPool.shutdownNow(); 96 | Thread.currentThread().interrupt(); 97 | } 98 | } 99 | 100 | @org.junit.Test 101 | public void unsafeCollectionAdd() { 102 | ArrayList unsafeArrayList = new ArrayList<>(); 103 | ExecutorService executorService = Executors.newFixedThreadPool(4); 104 | 105 | for (int i = 0; i < 10; i++) { 106 | Runnable addItemsThread = new Runnable() { 107 | @Override 108 | public void run() { 109 | StringRandomizer stringRandomizer = new StringRandomizer(); 110 | for (int i = 0; i < 100; i++) { 111 | unsafeArrayList.add(stringRandomizer.next(5)); 112 | } 113 | } 114 | }; 115 | executorService.submit(addItemsThread); 116 | } 117 | try { 118 | executorService.awaitTermination(10, TimeUnit.SECONDS); 119 | } catch (InterruptedException e) { 120 | e.printStackTrace(); 121 | } 122 | System.out.println("Reached end of method"); 123 | } 124 | 125 | @org.junit.Test 126 | public void unsafeCollectionDelete() { 127 | StringRandomizer stringRandomizer = new StringRandomizer(); 128 | ArrayList unsafeArrayList = new ArrayList<>(); 129 | ExecutorService executorService = Executors.newFixedThreadPool(4); 130 | for (int i = 0; i < 100; i++) { 131 | unsafeArrayList.add(stringRandomizer.next(5)); 132 | } 133 | 134 | for (String s : unsafeArrayList) { 135 | unsafeArrayList.remove(s); 136 | } 137 | 138 | 139 | System.out.println("Reached end of method"); 140 | } 141 | 142 | /*** 143 | * Przechwytywanie sygnału stop oraz wychodzenie z wątku 144 | */ 145 | @org.junit.Test 146 | public void handledInterruptException() { 147 | ExecutorService executorService = Executors.newFixedThreadPool(4); 148 | var runnables = new ArrayList(); 149 | for (int i = 0; i < 10; i++) { 150 | Runnable iterationsRunnable = new Runnable() { 151 | @Override 152 | public void run() { 153 | StringRandomizer stringRandomizer = new StringRandomizer(); 154 | for (int i = 0; i < 10000; i++) { 155 | try { 156 | TimeUnit.MILLISECONDS.sleep(2); 157 | } catch (InterruptedException e) { 158 | // We got forcibly interrupted while working 159 | System.out.println("Received interrupt signal, wait got interrupted, exiting"); 160 | return; 161 | } 162 | // We checked if we got intterupt signal 163 | if (Thread.currentThread().isInterrupted()) { 164 | System.out.println("Received interrupt signal, exiting"); 165 | return; 166 | } 167 | } 168 | System.out.println("Finished"); 169 | } 170 | }; 171 | runnables.add(iterationsRunnable); 172 | } 173 | // Wait 1 second, then stop all threads 174 | try { 175 | runnables.forEach(r -> executorService.submit(r)); 176 | TimeUnit.SECONDS.sleep(1); 177 | executorService.shutdownNow(); 178 | executorService.awaitTermination(10, TimeUnit.SECONDS); 179 | } catch (InterruptedException e) { 180 | e.printStackTrace(); 181 | } 182 | 183 | } 184 | 185 | @org.junit.Test 186 | public void handledInterruptNoException() { 187 | ExecutorService executorService = Executors.newFixedThreadPool(4); 188 | AtomicInteger atomicInteger = new AtomicInteger(0); 189 | var runnables = new ArrayList(); 190 | for (int i = 0; i < 10; i++) { 191 | // This should run long enough that it will be interrupted 192 | Runnable iterationsRunnable = new Runnable() { 193 | @Override 194 | public void run() { 195 | StringRandomizer stringRandomizer = new StringRandomizer(); 196 | for (int i = 0; i < 1000000000; i++) { 197 | atomicInteger.incrementAndGet(); 198 | // We checked if we got intterupt signal 199 | if (Thread.currentThread().isInterrupted()) { 200 | System.out.println("Received interrupt signal, exiting"); 201 | return; 202 | } 203 | } 204 | System.out.println("Finished"); 205 | } 206 | }; 207 | runnables.add(iterationsRunnable); 208 | } 209 | // Wait 1 second, then stop all threads 210 | try { 211 | runnables.forEach(r -> executorService.submit(r)); 212 | TimeUnit.SECONDS.sleep(1); 213 | executorService.shutdownNow(); 214 | executorService.awaitTermination(10, TimeUnit.SECONDS); 215 | } catch (InterruptedException e) { 216 | e.printStackTrace(); 217 | } 218 | 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /docs/images/add-test-file.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rughalt/mini-objective-java/b398d66063fd3e3e91b4a28ed9224f7a3962363a/docs/images/add-test-file.gif -------------------------------------------------------------------------------- /docs/images/create-project.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rughalt/mini-objective-java/b398d66063fd3e3e91b4a28ed9224f7a3962363a/docs/images/create-project.gif -------------------------------------------------------------------------------- /docs/images/debug-all-tests.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rughalt/mini-objective-java/b398d66063fd3e3e91b4a28ed9224f7a3962363a/docs/images/debug-all-tests.png -------------------------------------------------------------------------------- /docs/images/generate-class.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rughalt/mini-objective-java/b398d66063fd3e3e91b4a28ed9224f7a3962363a/docs/images/generate-class.gif -------------------------------------------------------------------------------- /lab-objective-basics.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /test.csv: -------------------------------------------------------------------------------- 1 | Kolumna 1,Kolumna 2,Kolumna 3,Kolumna 4 2 | A1,B1,C1,D1 3 | A2,B2,C2,D2 4 | A3,B3,C3,D3 5 | A4,B4,C4,D4 6 | A5,B5,C5,D5 7 | A6,B6,C6,D6 8 | A7,B7,C7,D7 9 | A8,B8,C8,D8 10 | A9,B9,C9,D9 11 | A10,B10,C10,D10 --------------------------------------------------------------------------------