From b42c2d3a5fe278be65c77e6d3cec44a7b98e6557 Mon Sep 17 00:00:00 2001 From: mherbaghinyan Date: Fri, 8 Mar 2019 15:33:10 +0400 Subject: [PATCH] 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); + } +}