From 05e589cc663bde4864936690fcb38d4fe1b418d2 Mon Sep 17 00:00:00 2001 From: lamfalusy Date: Mon, 12 Oct 2020 23:57:47 +0200 Subject: [PATCH 1/6] Add skeletons for week 6 exercises --- pom.xml | 2 ++ week-6/collection-meter/pom.xml | 21 +++++++++++++++++++ .../src/main/java/com/epam/training/Main.java | 9 ++++++++ week-6/matrix/pom.xml | 21 +++++++++++++++++++ .../src/main/java/com/epam/training/Main.java | 9 ++++++++ 5 files changed, 62 insertions(+) create mode 100644 week-6/collection-meter/pom.xml create mode 100644 week-6/collection-meter/src/main/java/com/epam/training/Main.java create mode 100644 week-6/matrix/pom.xml create mode 100644 week-6/matrix/src/main/java/com/epam/training/Main.java diff --git a/pom.xml b/pom.xml index 992f202..ed556ce 100644 --- a/pom.xml +++ b/pom.xml @@ -44,6 +44,8 @@ week-5/kindof-equal week-5/its-gone-or-is-it week-6/refactoring + week-6/matrix + week-6/collection-meter week-7/xml-parsing week-8/exception-handling week-8/json-serialization diff --git a/week-6/collection-meter/pom.xml b/week-6/collection-meter/pom.xml new file mode 100644 index 0000000..a44a147 --- /dev/null +++ b/week-6/collection-meter/pom.xml @@ -0,0 +1,21 @@ + + + + unideb-prog2-parent + com.epam.training + 1.0-SNAPSHOT + ../../pom.xml + + 4.0.0 + + collection-meter + + + + org.junit.jupiter + junit-jupiter + + + \ No newline at end of file diff --git a/week-6/collection-meter/src/main/java/com/epam/training/Main.java b/week-6/collection-meter/src/main/java/com/epam/training/Main.java new file mode 100644 index 0000000..6753e9f --- /dev/null +++ b/week-6/collection-meter/src/main/java/com/epam/training/Main.java @@ -0,0 +1,9 @@ +package com.epam.training; + +public class Main { + + public static void main(String[] args) { + + } + +} diff --git a/week-6/matrix/pom.xml b/week-6/matrix/pom.xml new file mode 100644 index 0000000..8629e1e --- /dev/null +++ b/week-6/matrix/pom.xml @@ -0,0 +1,21 @@ + + + + unideb-prog2-parent + com.epam.training + 1.0-SNAPSHOT + ../../pom.xml + + 4.0.0 + + matrix + + + + org.junit.jupiter + junit-jupiter + + + \ No newline at end of file diff --git a/week-6/matrix/src/main/java/com/epam/training/Main.java b/week-6/matrix/src/main/java/com/epam/training/Main.java new file mode 100644 index 0000000..6753e9f --- /dev/null +++ b/week-6/matrix/src/main/java/com/epam/training/Main.java @@ -0,0 +1,9 @@ +package com.epam.training; + +public class Main { + + public static void main(String[] args) { + + } + +} From b500605b0f13809ab2bcd9cb6eb4051fe67c6c6a Mon Sep 17 00:00:00 2001 From: lamfalusy Date: Tue, 13 Oct 2020 00:00:01 +0200 Subject: [PATCH 2/6] Add exercises description to the main README.md --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index c505c89..3131daf 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,13 @@ a firstMatchesThirdWithEqualToOperator értéke pedig false legyen. Magyarázd m ## Hatodik hét +### Mátrix szorzás Stream API-val +Implementáld le a mátrix szorzást Java-ban for és while ciklusok használata nélkül. + +### LinkedList vs ArrayList +Mutass rá konkrét esetekre amikor a Java-beli LinkedList és ArrayList rosszabb performanciát eredményezhet a másikhoz képest. (Lásd még +LinkedList és ArrayList forráskódja). Végezz méréseket is. (mit csinál az ArrayList amikor megtelik) + ### Refactoring Adott egy “legacy” kód mely tartalmaz anonymus interface implementációkat, ciklusokat és feltételes kifejezések. Ebben a feladatban ezt a “legacy” kódot szeretnénk átírni lambda kifejezések segítségével (metódus referencia használata előnyt jelent). From e48b86a39c8677ce8759733e68d8ea5723b2711e Mon Sep 17 00:00:00 2001 From: lamfalusy Date: Tue, 13 Oct 2020 11:52:28 +0200 Subject: [PATCH 3/6] Add solution for matrix multiply exercise --- .../java/com/epam/training/matrix/Matrix.java | 9 +++ .../training/matrix/impl/AbstractMatrix.java | 77 +++++++++++++++++++ .../epam/training/matrix/impl/ForMatrix.java | 35 +++++++++ .../training/matrix/impl/LambdaMatrix.java | 28 +++++++ .../epam/training/matrix/ForMatrixTest.java | 44 +++++++++++ .../training/matrix/LambdaMatrixTest.java | 44 +++++++++++ 6 files changed, 237 insertions(+) create mode 100644 week-6/matrix/src/main/java/com/epam/training/matrix/Matrix.java create mode 100644 week-6/matrix/src/main/java/com/epam/training/matrix/impl/AbstractMatrix.java create mode 100644 week-6/matrix/src/main/java/com/epam/training/matrix/impl/ForMatrix.java create mode 100644 week-6/matrix/src/main/java/com/epam/training/matrix/impl/LambdaMatrix.java create mode 100644 week-6/matrix/src/test/java/com/epam/training/matrix/ForMatrixTest.java create mode 100644 week-6/matrix/src/test/java/com/epam/training/matrix/LambdaMatrixTest.java diff --git a/week-6/matrix/src/main/java/com/epam/training/matrix/Matrix.java b/week-6/matrix/src/main/java/com/epam/training/matrix/Matrix.java new file mode 100644 index 0000000..7aa7e8a --- /dev/null +++ b/week-6/matrix/src/main/java/com/epam/training/matrix/Matrix.java @@ -0,0 +1,9 @@ +package com.epam.training.matrix; + +public interface Matrix { + + void setElement(int x, int y, int value); + + Matrix multiply(Matrix input); + +} diff --git a/week-6/matrix/src/main/java/com/epam/training/matrix/impl/AbstractMatrix.java b/week-6/matrix/src/main/java/com/epam/training/matrix/impl/AbstractMatrix.java new file mode 100644 index 0000000..fb0e6e4 --- /dev/null +++ b/week-6/matrix/src/main/java/com/epam/training/matrix/impl/AbstractMatrix.java @@ -0,0 +1,77 @@ +package com.epam.training.matrix.impl; + +import java.util.Arrays; + +import com.epam.training.matrix.Matrix; + +public abstract class AbstractMatrix implements Matrix { + + protected final int[][] matrix; + protected final int rowsLenght; + protected final int columnsLenght; + + public AbstractMatrix(int[][] matrix) { + this.matrix = matrix; + this.rowsLenght = matrix.length; + this.columnsLenght = matrix[0].length; + } + + public AbstractMatrix(int rowsLenght, int columnsLenght) { + this.matrix = new int[rowsLenght][columnsLenght]; + this.rowsLenght = rowsLenght; + this.columnsLenght = columnsLenght; + } + + @Override + public void setElement(int x, int y, int value) { + matrix[x][y] = value; + } + + @Override + public Matrix multiply(Matrix input) { + if (input instanceof AbstractMatrix) { + return multiply((AbstractMatrix) input); + } + throw new IllegalArgumentException("The input matrix should be an instance of AbstractMatrix"); + } + + abstract protected Matrix multiply(AbstractMatrix input); + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + columnsLenght; + result = prime * result + Arrays.deepHashCode(matrix); + result = prime * result + rowsLenght; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof AbstractMatrix)) { + return false; + } + AbstractMatrix other = (AbstractMatrix) obj; + if (columnsLenght != other.columnsLenght) { + return false; + } + if (!Arrays.deepEquals(matrix, other.matrix)) { + return false; + } + if (rowsLenght != other.rowsLenght) { + return false; + } + return true; + } + + @Override + public String toString() { + return "Matrix [matrix=" + Arrays.toString(matrix) + ", rowsLenght=" + rowsLenght + ", columnsLenght=" + + columnsLenght + "]"; + } + +} diff --git a/week-6/matrix/src/main/java/com/epam/training/matrix/impl/ForMatrix.java b/week-6/matrix/src/main/java/com/epam/training/matrix/impl/ForMatrix.java new file mode 100644 index 0000000..662eaec --- /dev/null +++ b/week-6/matrix/src/main/java/com/epam/training/matrix/impl/ForMatrix.java @@ -0,0 +1,35 @@ +package com.epam.training.matrix.impl; + +import com.epam.training.matrix.Matrix; + +public class ForMatrix extends AbstractMatrix { + + public ForMatrix(int[][] matrix) { + super(matrix); + } + + public ForMatrix(int rowsLenght, int columnsLenght) { + super(rowsLenght, columnsLenght); + } + + public Matrix multiply(AbstractMatrix input) { + int[][] result = new int[this.rowsLenght][input.columnsLenght]; + + for (int row = 0; row < result.length; row++) { + for (int col = 0; col < result[row].length; col++) { + result[row][col] = multiplyMatricesCell(this.matrix, input.matrix, row, col); + } + } + + return new ForMatrix(result); + } + + private int multiplyMatricesCell(int[][] firstMatrix, int[][] secondMatrix, int row, int col) { + int cell = 0; + for (int i = 0; i < secondMatrix.length; i++) { + cell += firstMatrix[row][i] * secondMatrix[i][col]; + } + return cell; + } + +} diff --git a/week-6/matrix/src/main/java/com/epam/training/matrix/impl/LambdaMatrix.java b/week-6/matrix/src/main/java/com/epam/training/matrix/impl/LambdaMatrix.java new file mode 100644 index 0000000..6bf9601 --- /dev/null +++ b/week-6/matrix/src/main/java/com/epam/training/matrix/impl/LambdaMatrix.java @@ -0,0 +1,28 @@ +package com.epam.training.matrix.impl; + +import java.util.Arrays; +import java.util.stream.IntStream; + +import com.epam.training.matrix.Matrix; + +public class LambdaMatrix extends AbstractMatrix { + + public LambdaMatrix(int[][] matrix) { + super(matrix); + } + + public LambdaMatrix(int rowsLenght, int columnsLenght) { + super(rowsLenght, columnsLenght); + } + + @Override + protected Matrix multiply(AbstractMatrix input) { + int[][] result = Arrays.stream(this.matrix) + .map(r -> IntStream.range(0, input.columnsLenght) + .map(i -> IntStream.range(0, input.rowsLenght).map(j -> r[j] * input.matrix[j][i]).sum()) + .toArray()) + .toArray(int[][]::new); + return new LambdaMatrix(result); + } + +} diff --git a/week-6/matrix/src/test/java/com/epam/training/matrix/ForMatrixTest.java b/week-6/matrix/src/test/java/com/epam/training/matrix/ForMatrixTest.java new file mode 100644 index 0000000..2eee12e --- /dev/null +++ b/week-6/matrix/src/test/java/com/epam/training/matrix/ForMatrixTest.java @@ -0,0 +1,44 @@ +package com.epam.training.matrix; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +import com.epam.training.matrix.impl.ForMatrix; + +public class ForMatrixTest { + + @Test + public void testMultiplyShouldReturnWithCorrectValue() { + // Given + Matrix matrixA = new ForMatrix(new int[][] {{1, 5}, + {2, 3}, + {1, 7}}); + Matrix matrixB = new ForMatrix(new int[][] {{1, 2, 3, 7}, + {5, 2, 8, 1}}); + Matrix expected = new ForMatrix(new int[][] {{26, 12, 43, 12}, + {17, 10, 30, 17}, + {36, 16, 59, 14}}); + + // When + Matrix actual = matrixA.multiply(matrixB); + + // Then + assertEquals(expected, actual); + } + + @Test + public void testSetElementShouldSetTheRightCoordinateOfTheMatrix() { + // Given + Matrix matrix = new ForMatrix(2, 3); + Matrix expected = new ForMatrix(new int[][] {{0, 0, 0}, + {0, 0, 5}}); + + // When + matrix.setElement(1, 2, 5);; + + // Then + assertEquals(expected, matrix); + } + +} diff --git a/week-6/matrix/src/test/java/com/epam/training/matrix/LambdaMatrixTest.java b/week-6/matrix/src/test/java/com/epam/training/matrix/LambdaMatrixTest.java new file mode 100644 index 0000000..e0427e5 --- /dev/null +++ b/week-6/matrix/src/test/java/com/epam/training/matrix/LambdaMatrixTest.java @@ -0,0 +1,44 @@ +package com.epam.training.matrix; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +import com.epam.training.matrix.impl.LambdaMatrix; + +public class LambdaMatrixTest { + + @Test + public void testMultiplyShouldReturnWithCorrectValue() { + // Given + Matrix matrixA = new LambdaMatrix(new int[][] {{1, 5}, + {2, 3}, + {1, 7}}); + Matrix matrixB = new LambdaMatrix(new int[][] {{1, 2, 3, 7}, + {5, 2, 8, 1}}); + Matrix expected = new LambdaMatrix(new int[][] {{26, 12, 43, 12}, + {17, 10, 30, 17}, + {36, 16, 59, 14}}); + + // When + Matrix actual = matrixA.multiply(matrixB); + + // Then + assertEquals(expected, actual); + } + + @Test + public void testSetElementShouldSetTheRightCoordinateOfTheMatrix() { + // Given + Matrix matrix = new LambdaMatrix(2, 3); + Matrix expected = new LambdaMatrix(new int[][] {{0, 0, 0}, + {0, 0, 5}}); + + // When + matrix.setElement(1, 2, 5); + + // Then + assertEquals(expected, matrix); + } + +} From 8725c4736b3c129e0af3a99ecb779502e820fb28 Mon Sep 17 00:00:00 2001 From: lamfalusy Date: Sun, 18 Oct 2020 16:14:55 +0200 Subject: [PATCH 4/6] Refactor collection-meter module --- week-6/collection-meter/pom.xml | 6 -- .../src/main/java/com/epam/training/Main.java | 48 +++++++++++++- .../training/measurement/Measurement.java | 38 +++++++++++ .../meter/AbstractCollectionMeter.java | 64 +++++++++++++++++++ .../epam/training/meter/CollectionMeter.java | 11 ++++ .../epam/training/meter/list/ListMeter.java | 29 +++++++++ .../com/epam/training/meter/map/MapMeter.java | 29 +++++++++ .../meter/map/MapWithWrongKeyMeter.java | 49 ++++++++++++++ 8 files changed, 265 insertions(+), 9 deletions(-) create mode 100644 week-6/collection-meter/src/main/java/com/epam/training/measurement/Measurement.java create mode 100644 week-6/collection-meter/src/main/java/com/epam/training/meter/AbstractCollectionMeter.java create mode 100644 week-6/collection-meter/src/main/java/com/epam/training/meter/CollectionMeter.java create mode 100644 week-6/collection-meter/src/main/java/com/epam/training/meter/list/ListMeter.java create mode 100644 week-6/collection-meter/src/main/java/com/epam/training/meter/map/MapMeter.java create mode 100644 week-6/collection-meter/src/main/java/com/epam/training/meter/map/MapWithWrongKeyMeter.java diff --git a/week-6/collection-meter/pom.xml b/week-6/collection-meter/pom.xml index a44a147..6fb6b90 100644 --- a/week-6/collection-meter/pom.xml +++ b/week-6/collection-meter/pom.xml @@ -12,10 +12,4 @@ collection-meter - - - org.junit.jupiter - junit-jupiter - - \ No newline at end of file diff --git a/week-6/collection-meter/src/main/java/com/epam/training/Main.java b/week-6/collection-meter/src/main/java/com/epam/training/Main.java index 6753e9f..477ab33 100644 --- a/week-6/collection-meter/src/main/java/com/epam/training/Main.java +++ b/week-6/collection-meter/src/main/java/com/epam/training/Main.java @@ -1,9 +1,51 @@ package com.epam.training; -public class Main { +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.TreeMap; + +import com.epam.training.measurement.Measurement; +import com.epam.training.meter.list.ListMeter; +import com.epam.training.meter.map.MapMeter; +import com.epam.training.meter.map.MapWithWrongKeyMeter; - public static void main(String[] args) { +public class Main { - } + private static final int SIZE_10M = 10_000_000; + private static final int SIZE_1M = 1_000_000; + private static final int SIZE_100K = 100_000; + private static final int SIZE_10K = 10_000; + + public static void main(String[] args) { + System.out.println(" --- List measurement ---"); + new Measurement( + new ListMeter(() -> new ArrayList<>()), + new ListMeter(() -> new ArrayList<>(SIZE_10M)), + new ListMeter(() -> new LinkedList<>()) + ).measureCollectionSetup(SIZE_10M) + .measureFrequentChanges(SIZE_100K) + .measureGet(SIZE_10M); + + System.out.println(" --- Map measurement ---"); + new Measurement( + new MapMeter(() -> new HashMap<>()), + new MapMeter(() -> new LinkedHashMap<>()), + new MapMeter(() -> new TreeMap<>()) + ).measureCollectionSetup(SIZE_1M) + .measureFrequentChanges(SIZE_1M) + .measureGet(SIZE_1M); + + System.out.println(" --- Map with wrong key measurement ---"); + new Measurement( + new MapWithWrongKeyMeter(() -> new HashMap<>()), + new MapWithWrongKeyMeter(() -> new LinkedHashMap<>()), + new MapWithWrongKeyMeter(() -> new TreeMap<>(Comparator.comparing(MapWithWrongKeyMeter.WrongClass::getString))) + ).measureCollectionSetup(SIZE_10K) + .measureFrequentChanges(SIZE_10K) + .measureGet(SIZE_10K); + } } diff --git a/week-6/collection-meter/src/main/java/com/epam/training/measurement/Measurement.java b/week-6/collection-meter/src/main/java/com/epam/training/measurement/Measurement.java new file mode 100644 index 0000000..d028f30 --- /dev/null +++ b/week-6/collection-meter/src/main/java/com/epam/training/measurement/Measurement.java @@ -0,0 +1,38 @@ +package com.epam.training.measurement; + +import java.util.Arrays; +import java.util.List; + +import com.epam.training.meter.CollectionMeter; + +public class Measurement { + + private final List meters; + + public Measurement(List meters) { + this.meters = meters; + } + + public Measurement(CollectionMeter... meters) { + this.meters = Arrays.asList(meters); + } + + public Measurement measureCollectionSetup(Integer size) { + System.out.println("Starting 'collection setup' measuring"); + meters.stream().forEach(meter -> meter.meterCollectionSetup(size)); + return this; + } + + public Measurement measureFrequentChanges(Integer size) { + System.out.println("Starting 'frequent change' measuring"); + meters.stream().forEach(meter -> meter.meterFrequentChanges(size)); + return this; + } + + public Measurement measureGet(Integer size) { + System.out.println("Starting 'get' measuring"); + meters.stream().forEach(meter -> meter.meterGet(size)); + return this; + } + +} diff --git a/week-6/collection-meter/src/main/java/com/epam/training/meter/AbstractCollectionMeter.java b/week-6/collection-meter/src/main/java/com/epam/training/meter/AbstractCollectionMeter.java new file mode 100644 index 0000000..c4b8925 --- /dev/null +++ b/week-6/collection-meter/src/main/java/com/epam/training/meter/AbstractCollectionMeter.java @@ -0,0 +1,64 @@ +package com.epam.training.meter; + +import java.util.function.BiConsumer; +import java.util.function.Supplier; + +public abstract class AbstractCollectionMeter implements CollectionMeter { + + private Supplier collectionSupplier; + + public AbstractCollectionMeter(Supplier collectionSupplier) { + this.collectionSupplier = collectionSupplier; + } + + @Override + public void meterCollectionSetup(Integer size) { + T collection = collectionSupplier.get(); + meter(collection, size, this::doCollectionSetup); + } + + @Override + public void meterFrequentChanges(Integer size) { + T collection = collectionSupplier.get(); + meter(collection, size, this::doFrequentChanges); + } + + @Override + public void meterGet(Integer size) { + T collection = collectionSupplier.get(); + doCollectionSetup(collection, size); + meter(collection, size, this::doGet); + } + + public abstract void addElement(T collection, Integer element); + + public abstract void removeElement(T collection, Integer element); + + public abstract void getElement(T collection, Integer element); + + private void doCollectionSetup(T collection, Integer size) { + for (int i = 0; i < size; i++) { + addElement(collection, i); + } + } + + private void doFrequentChanges(T collection, Integer size) { + doCollectionSetup(collection, size); + for (int i = 0; i < size; i++) { + removeElement(collection, i); + } + } + + private void doGet(T collection, Integer size) { + getElement(collection, size / 2); + } + + private void meter(T collection, Integer size, BiConsumer meteredAction) { + long before = System.currentTimeMillis(); + meteredAction.accept(collection, size); + long after = System.currentTimeMillis(); + long delta = after - before; + System.out.println(collection.getClass().getSimpleName() + ", Millisec: " + delta); + } + +} diff --git a/week-6/collection-meter/src/main/java/com/epam/training/meter/CollectionMeter.java b/week-6/collection-meter/src/main/java/com/epam/training/meter/CollectionMeter.java new file mode 100644 index 0000000..54c25a0 --- /dev/null +++ b/week-6/collection-meter/src/main/java/com/epam/training/meter/CollectionMeter.java @@ -0,0 +1,11 @@ +package com.epam.training.meter; + +public interface CollectionMeter { + + void meterCollectionSetup(Integer size); + + void meterFrequentChanges(Integer size); + + void meterGet(Integer size); + +} diff --git a/week-6/collection-meter/src/main/java/com/epam/training/meter/list/ListMeter.java b/week-6/collection-meter/src/main/java/com/epam/training/meter/list/ListMeter.java new file mode 100644 index 0000000..24c7eee --- /dev/null +++ b/week-6/collection-meter/src/main/java/com/epam/training/meter/list/ListMeter.java @@ -0,0 +1,29 @@ +package com.epam.training.meter.list; + +import java.util.List; +import java.util.function.Supplier; + +import com.epam.training.meter.AbstractCollectionMeter; + +public class ListMeter extends AbstractCollectionMeter> { + + public ListMeter(Supplier> listSupplier) { + super(listSupplier); + } + + @Override + public void addElement(List list, Integer element) { + list.add(String.valueOf(element)); + } + + @Override + public void removeElement(List list, Integer element) { + list.remove(String.valueOf(element)); + } + + @Override + public void getElement(List list, Integer element) { + list.get(element); + } + +} diff --git a/week-6/collection-meter/src/main/java/com/epam/training/meter/map/MapMeter.java b/week-6/collection-meter/src/main/java/com/epam/training/meter/map/MapMeter.java new file mode 100644 index 0000000..2d07e77 --- /dev/null +++ b/week-6/collection-meter/src/main/java/com/epam/training/meter/map/MapMeter.java @@ -0,0 +1,29 @@ +package com.epam.training.meter.map; + +import java.util.Map; +import java.util.function.Supplier; + +import com.epam.training.meter.AbstractCollectionMeter; + +public class MapMeter extends AbstractCollectionMeter> { + + public MapMeter(Supplier> mapSupplier) { + super(mapSupplier); + } + + @Override + public void addElement(Map map, Integer element) { + map.put(String.valueOf(element), element); + } + + @Override + public void removeElement(Map map, Integer element) { + map.remove(String.valueOf(element)); + } + + @Override + public void getElement(Map map, Integer element) { + map.get(String.valueOf(element)); + } + +} diff --git a/week-6/collection-meter/src/main/java/com/epam/training/meter/map/MapWithWrongKeyMeter.java b/week-6/collection-meter/src/main/java/com/epam/training/meter/map/MapWithWrongKeyMeter.java new file mode 100644 index 0000000..637a5ef --- /dev/null +++ b/week-6/collection-meter/src/main/java/com/epam/training/meter/map/MapWithWrongKeyMeter.java @@ -0,0 +1,49 @@ +package com.epam.training.meter.map; + +import java.util.Map; +import java.util.function.Supplier; + +import com.epam.training.meter.AbstractCollectionMeter; + +public class MapWithWrongKeyMeter extends AbstractCollectionMeter> { + + public MapWithWrongKeyMeter(Supplier> mapSupplier) { + super(mapSupplier); + } + + @Override + public void addElement(Map map, Integer element) { + map.put(new WrongClass(String.valueOf(element)), element); + } + + @Override + public void removeElement(Map map, Integer element) { + map.remove(new WrongClass(String.valueOf(element))); + } + + @Override + public void getElement(Map map, Integer element) { + map.get(new WrongClass(String.valueOf(element))); + } + + public static class WrongClass { + + private String string; + + public WrongClass(String string) { + super(); + this.string = string; + } + + public String getString() { + return string; + } + + @Override + public int hashCode() { + return 1; + } + + } + +} From 95aa36fea0bf978b7b2f60e5e68a41430b58a1b2 Mon Sep 17 00:00:00 2001 From: lamfalusy Date: Sun, 18 Oct 2020 16:18:44 +0200 Subject: [PATCH 5/6] Fix typo in handout.md of week 6 --- week-6/handout.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-6/handout.md b/week-6/handout.md index 2ea3361..113cff3 100644 --- a/week-6/handout.md +++ b/week-6/handout.md @@ -83,7 +83,7 @@ egy jó választás lehet ## Funkcionális nyelvi elemek. Lambda kifejezések. -### Funkcionális Inerfészek +### Funkcionális Interfészek A funkcionális interfészek olyan interfészek melyek csak egyetlen egy absztrakt metódust tartalmaznak. Példák beépített funkcionális interfészekre: From c93ecc12eb2e19fd17b571304895b9f045022c4e Mon Sep 17 00:00:00 2001 From: lamfalusy Date: Sun, 18 Oct 2020 16:24:05 +0200 Subject: [PATCH 6/6] Minor fixes: delete empty Main class --- pom.xml | 4 ++-- week-6/matrix/src/main/java/com/epam/training/Main.java | 9 --------- 2 files changed, 2 insertions(+), 11 deletions(-) delete mode 100644 week-6/matrix/src/main/java/com/epam/training/Main.java diff --git a/pom.xml b/pom.xml index 8632d1c..d511c4a 100644 --- a/pom.xml +++ b/pom.xml @@ -44,8 +44,8 @@ week-5/kindof-equal week-5/its-gone-or-is-it week-6/refactoring - week-6/matrix - week-6/collection-meter + week-6/matrix + week-6/collection-meter week-7/xml-parsing week-8/exception-handling week-8/json-serialization diff --git a/week-6/matrix/src/main/java/com/epam/training/Main.java b/week-6/matrix/src/main/java/com/epam/training/Main.java deleted file mode 100644 index 6753e9f..0000000 --- a/week-6/matrix/src/main/java/com/epam/training/Main.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.epam.training; - -public class Main { - - public static void main(String[] args) { - - } - -}