From b42c2d3a5fe278be65c77e6d3cec44a7b98e6557 Mon Sep 17 00:00:00 2001 From: mherbaghinyan Date: Fri, 8 Mar 2019 15:33:10 +0400 Subject: [PATCH 1/6] primitive map libraries --- libraries/pom.xml | 15 ++++++ .../baeldung/primitives/PrimitiveMaps.java | 54 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 libraries/src/main/java/com/baeldung/primitives/PrimitiveMaps.java diff --git a/libraries/pom.xml b/libraries/pom.xml index c7ef64bc59..a49570b029 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -373,6 +373,21 @@ eclipse-collections ${eclipse-collections.version} + + net.sf.trove4j + trove4j + 3.0.2 + + + it.unimi.dsi + fastutil + 8.1.0 + + + colt + colt + 1.2.0 + io.vavr vavr diff --git a/libraries/src/main/java/com/baeldung/primitives/PrimitiveMaps.java b/libraries/src/main/java/com/baeldung/primitives/PrimitiveMaps.java new file mode 100644 index 0000000000..4ee10997c2 --- /dev/null +++ b/libraries/src/main/java/com/baeldung/primitives/PrimitiveMaps.java @@ -0,0 +1,54 @@ +package com.baeldung.primitives; + +import cern.colt.map.AbstractIntDoubleMap; +import cern.colt.map.OpenIntDoubleHashMap; +import gnu.trove.map.TDoubleIntMap; +import gnu.trove.map.hash.TDoubleIntHashMap; +import org.eclipse.collections.api.map.primitive.*; +import org.eclipse.collections.impl.factory.primitive.*; + +public class PrimitiveMaps { + + public static void main(String[] args) { + + eclipseCollectionsMap(); + troveMap(); + coltMap(); + } + + private static void coltMap() { + AbstractIntDoubleMap map = new OpenIntDoubleHashMap(); + map.put(1, 4.5); + } + + private static void eclipseCollectionsMap() { + MutableObjectDoubleMap doubleMap = ObjectDoubleMaps.mutable.empty(); + doubleMap.put("1", 1.0d); + doubleMap.put("2", 2.0d); + + MutableObjectIntMap booleanMap = ObjectIntMaps.mutable.empty(); + booleanMap.put("ok", 1); + + MutableIntIntMap mutableIntIntMap = IntIntMaps.mutable.empty(); + mutableIntIntMap.addToValue(1, 1); + + ImmutableIntIntMap immutableIntIntMap = IntIntMaps.immutable.empty(); + + MutableObjectIntMap intObject = ObjectIntMaps.mutable.empty(); + intObject.addToValue("price", 2); + } + + private static void troveMap() { + + double[] doubles = new double[] {1.2, 4.5, 0.3}; + int[] ints = new int[] {1, 4, 0}; + + TDoubleIntMap doubleIntMap = new TDoubleIntHashMap(doubles, ints); + + doubleIntMap.adjustValue(1.2, 1); + doubleIntMap.adjustValue(4.5, 4); + doubleIntMap.adjustValue(0.3, 0); + + System.out.println(doubleIntMap); + } +} From d03c2181eca532c6af7de71a13c29c7fd41669d1 Mon Sep 17 00:00:00 2001 From: mherbaghinyan Date: Sun, 10 Mar 2019 13:27:47 +0400 Subject: [PATCH 2/6] fastutil code --- .../java/com/baeldung/primitives/PrimitiveMaps.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libraries/src/main/java/com/baeldung/primitives/PrimitiveMaps.java b/libraries/src/main/java/com/baeldung/primitives/PrimitiveMaps.java index 4ee10997c2..eaa7e308bb 100644 --- a/libraries/src/main/java/com/baeldung/primitives/PrimitiveMaps.java +++ b/libraries/src/main/java/com/baeldung/primitives/PrimitiveMaps.java @@ -4,6 +4,7 @@ import cern.colt.map.AbstractIntDoubleMap; import cern.colt.map.OpenIntDoubleHashMap; import gnu.trove.map.TDoubleIntMap; import gnu.trove.map.hash.TDoubleIntHashMap; +import it.unimi.dsi.fastutil.ints.*; import org.eclipse.collections.api.map.primitive.*; import org.eclipse.collections.impl.factory.primitive.*; @@ -14,6 +15,17 @@ public class PrimitiveMaps { eclipseCollectionsMap(); troveMap(); coltMap(); + fastutilMap(); + } + + private static void fastutilMap() { + Int2BooleanMap int2BooleanMap = new Int2BooleanOpenHashMap(); + int2BooleanMap.put(1, true); + + Int2BooleanSortedMap int2BooleanSorted = Int2BooleanSortedMaps.EMPTY_MAP; + int2BooleanSorted.putIfAbsent(7, true); + int2BooleanSorted.putIfAbsent(1, true); + int2BooleanSorted.putIfAbsent(4, true); } private static void coltMap() { From 0530d5c59fe8fcd814d5eaf5fb2ff8ed43f26a9c Mon Sep 17 00:00:00 2001 From: mherbaghinyan Date: Mon, 11 Mar 2019 11:15:52 +0400 Subject: [PATCH 3/6] primitive maps final --- .../baeldung/primitives/PrimitiveMaps.java | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/libraries/src/main/java/com/baeldung/primitives/PrimitiveMaps.java b/libraries/src/main/java/com/baeldung/primitives/PrimitiveMaps.java index eaa7e308bb..89e99acfc7 100644 --- a/libraries/src/main/java/com/baeldung/primitives/PrimitiveMaps.java +++ b/libraries/src/main/java/com/baeldung/primitives/PrimitiveMaps.java @@ -21,37 +21,33 @@ public class PrimitiveMaps { private static void fastutilMap() { Int2BooleanMap int2BooleanMap = new Int2BooleanOpenHashMap(); int2BooleanMap.put(1, true); + int2BooleanMap.put(7, false); + int2BooleanMap.put(4, true); + + boolean value = int2BooleanMap.get(1); Int2BooleanSortedMap int2BooleanSorted = Int2BooleanSortedMaps.EMPTY_MAP; - int2BooleanSorted.putIfAbsent(7, true); - int2BooleanSorted.putIfAbsent(1, true); - int2BooleanSorted.putIfAbsent(4, true); } private static void coltMap() { AbstractIntDoubleMap map = new OpenIntDoubleHashMap(); map.put(1, 4.5); + double value = map.get(1); } private static void eclipseCollectionsMap() { - MutableObjectDoubleMap doubleMap = ObjectDoubleMaps.mutable.empty(); - doubleMap.put("1", 1.0d); - doubleMap.put("2", 2.0d); - - MutableObjectIntMap booleanMap = ObjectIntMaps.mutable.empty(); - booleanMap.put("ok", 1); - MutableIntIntMap mutableIntIntMap = IntIntMaps.mutable.empty(); mutableIntIntMap.addToValue(1, 1); ImmutableIntIntMap immutableIntIntMap = IntIntMaps.immutable.empty(); - MutableObjectIntMap intObject = ObjectIntMaps.mutable.empty(); - intObject.addToValue("price", 2); + MutableObjectDoubleMap dObject = ObjectDoubleMaps.mutable.empty(); + dObject.addToValue("price", 150.5); + dObject.addToValue("quality", 4.4); + dObject.addToValue("stability", 0.8); } private static void troveMap() { - double[] doubles = new double[] {1.2, 4.5, 0.3}; int[] ints = new int[] {1, 4, 0}; @@ -60,7 +56,5 @@ public class PrimitiveMaps { doubleIntMap.adjustValue(1.2, 1); doubleIntMap.adjustValue(4.5, 4); doubleIntMap.adjustValue(0.3, 0); - - System.out.println(doubleIntMap); } } From 327f00f4d97fff317dbdd566c15b861bde19147f Mon Sep 17 00:00:00 2001 From: mherbaghinyan Date: Wed, 13 Mar 2019 15:17:18 +0400 Subject: [PATCH 4/6] move primitive maps code to java-collections-maps-2 --- java-collections-maps-2/pom.xml | 45 +++++++++++++++++++ .../java/com/baeldung/map}/PrimitiveMaps.java | 14 ++++-- libraries/pom.xml | 15 ------- 3 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 java-collections-maps-2/pom.xml rename {libraries/src/main/java/com/baeldung/primitives => java-collections-maps-2/src/main/java/com/baeldung/map}/PrimitiveMaps.java (73%) diff --git a/java-collections-maps-2/pom.xml b/java-collections-maps-2/pom.xml new file mode 100644 index 0000000000..b025c5e32d --- /dev/null +++ b/java-collections-maps-2/pom.xml @@ -0,0 +1,45 @@ + + + 4.0.0 + java-collections-maps-2 + 0.1.0-SNAPSHOT + java-collections-maps-2 + jar + + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../parent-java + + + + + org.eclipse.collections + eclipse-collections + ${eclipse-collections.version} + + + net.sf.trove4j + trove4j + 3.0.2 + + + it.unimi.dsi + fastutil + 8.1.0 + + + colt + colt + 1.2.0 + + + + + 8.2.0 + + + \ No newline at end of file diff --git a/libraries/src/main/java/com/baeldung/primitives/PrimitiveMaps.java b/java-collections-maps-2/src/main/java/com/baeldung/map/PrimitiveMaps.java similarity index 73% rename from libraries/src/main/java/com/baeldung/primitives/PrimitiveMaps.java rename to java-collections-maps-2/src/main/java/com/baeldung/map/PrimitiveMaps.java index 89e99acfc7..c13aa19424 100644 --- a/libraries/src/main/java/com/baeldung/primitives/PrimitiveMaps.java +++ b/java-collections-maps-2/src/main/java/com/baeldung/map/PrimitiveMaps.java @@ -1,12 +1,18 @@ -package com.baeldung.primitives; +package com.baeldung.map; import cern.colt.map.AbstractIntDoubleMap; import cern.colt.map.OpenIntDoubleHashMap; import gnu.trove.map.TDoubleIntMap; import gnu.trove.map.hash.TDoubleIntHashMap; -import it.unimi.dsi.fastutil.ints.*; -import org.eclipse.collections.api.map.primitive.*; -import org.eclipse.collections.impl.factory.primitive.*; +import it.unimi.dsi.fastutil.ints.Int2BooleanMap; +import it.unimi.dsi.fastutil.ints.Int2BooleanOpenHashMap; +import it.unimi.dsi.fastutil.ints.Int2BooleanSortedMap; +import it.unimi.dsi.fastutil.ints.Int2BooleanSortedMaps; +import org.eclipse.collections.api.map.primitive.ImmutableIntIntMap; +import org.eclipse.collections.api.map.primitive.MutableIntIntMap; +import org.eclipse.collections.api.map.primitive.MutableObjectDoubleMap; +import org.eclipse.collections.impl.factory.primitive.IntIntMaps; +import org.eclipse.collections.impl.factory.primitive.ObjectDoubleMaps; public class PrimitiveMaps { diff --git a/libraries/pom.xml b/libraries/pom.xml index a3a87876d1..7823732224 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -385,21 +385,6 @@ eclipse-collections ${eclipse-collections.version} - - net.sf.trove4j - trove4j - 3.0.2 - - - it.unimi.dsi - fastutil - 8.1.0 - - - colt - colt - 1.2.0 - io.vavr vavr From 1699e4c3bd50ab03f5e61830bfe7ce266d49f289 Mon Sep 17 00:00:00 2001 From: mherbaghinyan Date: Sat, 23 Mar 2019 15:24:57 +0400 Subject: [PATCH 5/6] Trove put values --- .../src/main/java/com/baeldung/map/PrimitiveMaps.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/java-collections-maps-2/src/main/java/com/baeldung/map/PrimitiveMaps.java b/java-collections-maps-2/src/main/java/com/baeldung/map/PrimitiveMaps.java index c13aa19424..10245ce6e0 100644 --- a/java-collections-maps-2/src/main/java/com/baeldung/map/PrimitiveMaps.java +++ b/java-collections-maps-2/src/main/java/com/baeldung/map/PrimitiveMaps.java @@ -59,8 +59,8 @@ public class PrimitiveMaps { TDoubleIntMap doubleIntMap = new TDoubleIntHashMap(doubles, ints); - doubleIntMap.adjustValue(1.2, 1); - doubleIntMap.adjustValue(4.5, 4); - doubleIntMap.adjustValue(0.3, 0); + doubleIntMap.put(1.2, 1); + doubleIntMap.put(4.5, 4); + doubleIntMap.put(0.3, 0); } } From 8b491802f4774fdf337e0a7043d119dbddea14a1 Mon Sep 17 00:00:00 2001 From: mherbaghinyan Date: Sun, 24 Mar 2019 11:05:18 +0400 Subject: [PATCH 6/6] Trove adjustValue --- .../src/main/java/com/baeldung/map/PrimitiveMaps.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/java-collections-maps-2/src/main/java/com/baeldung/map/PrimitiveMaps.java b/java-collections-maps-2/src/main/java/com/baeldung/map/PrimitiveMaps.java index 10245ce6e0..d835950c68 100644 --- a/java-collections-maps-2/src/main/java/com/baeldung/map/PrimitiveMaps.java +++ b/java-collections-maps-2/src/main/java/com/baeldung/map/PrimitiveMaps.java @@ -59,8 +59,11 @@ public class PrimitiveMaps { TDoubleIntMap doubleIntMap = new TDoubleIntHashMap(doubles, ints); - doubleIntMap.put(1.2, 1); - doubleIntMap.put(4.5, 4); - doubleIntMap.put(0.3, 0); + doubleIntMap.put(1.2, 22); + doubleIntMap.put(4.5, 16); + + doubleIntMap.adjustValue(1.2, 1); + doubleIntMap.adjustValue(4.5, 4); + doubleIntMap.adjustValue(0.3, 7); } }