|
| 1 | +## **Alternative java collections overview** |
| 2 | +*In progress* |
| 3 | + |
| 4 | +### 1. General overview |
| 5 | +*In progress* |
| 6 | + |
| 7 | +### 2. New collections types |
| 8 | +#### 2.1 MultiSet/Bag in Guava, Apache Commons Collections and Eclipse (GS) Collections |
| 9 | + |
| 10 | +| **Type** | **Guava** | **Apache Commons Collections** | **GS Collections** | **JDK** | |
| 11 | +| ------------- | -------------| -------------| -------------| -------------| |
| 12 | +| Order not defined | [HashMultiset](http://google.github.io/guava/releases/snapshot/api/docs/com/google/common/collect/HashMultiset.html) | [HashBag](http://commons.apache.org/proper/commons-collections/javadocs/api-3.2.1/org/apache/commons/collections/bag/HashBag.html) | [HashBag](http://www.goldmansachs.com/gs-collections/javadoc/6.1.0/com/gs/collections/impl/bag/mutable/HashBag.html) | [HashMap](https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html) | |
| 13 | +| Sorted | [TreeMultiset](http://google.github.io/guava/releases/snapshot/api/docs/com/google/common/collect/TreeMultiset.html) | [TreeBag](http://commons.apache.org/proper/commons-collections/javadocs/api-3.2.1/org/apache/commons/collections/TreeBag.html) | [TreeBag](http://www.goldmansachs.com/gs-collections/javadoc/6.1.0/com/gs/collections/impl/bag/sorted/mutable/TreeBag.html) | [TreeMap](https://docs.oracle.com/javase/8/docs/api/java/util/TreeMap.html) | |
| 14 | +| Insertion-order | [LinkedHashMultiset](http://google.github.io/guava/releases/snapshot/api/docs/com/google/common/collect/LinkedHashMultiset.html) | - | - | [LinkedHashMap](https://docs.oracle.com/javase/8/docs/api/java/util/LinkedHashMap.html) | |
| 15 | +| Concurrent variant | [ConcurrentHashMultiset](http://google.github.io/guava/releases/snapshot/api/docs/com/google/common/collect/ConcurrentHashMultiset.html) | [SynchronizedBag](http://commons.apache.org/proper/commons-collections/javadocs/api-3.2.1/org/apache/commons/collections/bag/SynchronizedBag.html) | [SynchronizedBag](http://www.goldmansachs.com/gs-collections/javadoc/6.1.0/com/gs/collections/impl/bag/mutable/SynchronizedBag.html) | [Collections.synchronizedMap(HashMap<string, integer="">)</string,>](https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html) | |
| 16 | +| Concurrent and sorted | - | [SynchronizedSortedBag](http://commons.apache.org/proper/commons-collections/javadocs/api-3.2.1/org/apache/commons/collections/bag/SynchronizedSortedBag.html) | [SynchronizedSortedBag](http://www.goldmansachs.com/gs-collections/javadoc/6.1.0/com/gs/collections/impl/bag/sorted/mutable/SynchronizedSortedBag.html) | [Collections.synchronizedSortedMap(TreeMap<string ,="" integer="">)</string>](https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html) | |
| 17 | +| Immutable collection | [ImmutableMultiset](http://google.github.io/guava/releases/snapshot/api/docs/com/google/common/collect/ImmutableMultiset.html) | [UnmodifiableBag](http://commons.apache.org/proper/commons-collections/javadocs/api-3.2.1/org/apache/commons/collections/bag/UnmodifiableBag.html) | [UnmodifiableBag](http://www.goldmansachs.com/gs-collections/javadoc/6.1.0/com/gs/collections/impl/bag/mutable/UnmodifiableBag.html) | [Collections.unmodifiableMap(HashMap<string, integer="">)</string,>](https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html) | |
| 18 | +| Immutable and sorted | [ImmutableSortedMultiset](http://google.github.io/guava/releases/snapshot/api/docs/com/google/common/collect/ImmutableSortedMultiset.html) | [UnmodifiableSortedBag](http://commons.apache.org/proper/commons-collections/javadocs/api-3.2.1/org/apache/commons/collections/bag/UnmodifiableSortedBag.html) | [UnmodifiableSortedBag](UnmodifiableSortedBag) | [Collections.unmodifiableSortedMap(TreeMap<string, integer="">)</string,>](https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html) | |
| 19 | + |
| 20 | +##### **Examples using MultiSet/Bag** |
| 21 | +*In progress* |
| 22 | + |
| 23 | + |
| 24 | +#### 2.2 Multimap in Guava, Apache Commons Collections and Eclipse (GS) Collections |
| 25 | + |
| 26 | +| Key's order | Value's order | Duplicate | Analog key | Analog value | Guava | Apache | Eclipse (GS) Collections | JDK | |
| 27 | +| ---------- | ------------- | ----------| -----------| ----------|-------| -------| -------------------------|-----| |
| 28 | +| not defined | Insertion-order | yes | `HashMap` | `ArrayList` | `ArrayListMultimap` | `MultiValueMap` | `FastListMultimap` | `HashMap<K, ArrayList<V>>` | |
| 29 | +| not defined | not defined | no | `HashMap` | `HashSet` | `HashMultimap` | `MultiValueMap. multiValueMap( new HashMap<K, Set>(), HashSet.class);` | `UnifiedSetMultimap` | `HashMap<K, HashSet<V>>` | |
| 30 | +| not defined | sorted | no | `HashMap` | `TreeSet` | `Multimaps. newMultimap( HashMap, Supplier <TreeSet>)` | `MultiValueMap. multiValueMap( new HashMap<K, Set>(), TreeSet.class)` | `TreeSortedSet- Multimap` | `HashMap<K, TreeSet<V>>` | |
| 31 | +| Insertion-order | Insertion-order | yes | Linked HashMap | ArrayList | LinkedList- Multimap | MultiValueMap. multiValueMap(new LinkedHashMap<K, List>(), ArrayList.class); | |LinkedHashMap< K, ArrayList<V>> | |
| 32 | +| Insertion-order | Insertion-order | no | `LinkedHash- Multimap` | `Linked- HashSet` | `LinkedHash- Multimap` | `MultiValueMap. multiValueMap(new LinkedHashMap<K, Set>(), LinkedHashSet.class)` | |`LinkedHashMap<K, LinkedHashSet<V>>` | |
| 33 | +| sorted | sorted | no | `TreeMap` | `TreeSet` | `TreeMultima` | `MultiValueMap. multiValueMap( new TreeMap<K, Set>(),TreeSet.class)` | |`TreeMap<K, TreeSet<V>>` | |
| 34 | + |
| 35 | + |
| 36 | +##### **Examples using Multimap** |
| 37 | +*In progress* |
| 38 | + |
| 39 | +#### **2.3 Using BiMap in Guava, Apache Commons Collections and GS Collections** |
| 40 | + |
| 41 | +##### **Examples using BiMap** |
| 42 | +*In progress* |
| 43 | + |
| 44 | +### 3. Compare operation with collections |
| 45 | + |
| 46 | +#### 3.1 Create collections |
| 47 | + |
| 48 | +| Description | JDK | guava | gs-collections | |
| 49 | +| ------------- | -------------| -------------| -------------| |
| 50 | +| Create empty list | new ArrayList<>() | Lists.newArrayList() | FastList.newList() | |
| 51 | +| Create list from values | Arrays.asList("1", "2", "3") | Lists.newArrayList("1", "2", "3") | FastList.newListWith("1", "2", "3") | |
| 52 | +| Create list with capacity = 100 | new ArrayList<>(100) | Lists.newArrayListWithCapacity(100) | FastList.newList(100) | |
| 53 | +| Create list from any collectin | new ArrayList<>(collection) | Lists.newArrayList(collection) | FastList.newList(collection) | |
| 54 | +| Create list from any Iterable | - | Lists.newArrayList(iterable) | FastList.newList(iterable) | |
| 55 | +| Create list from Iterator | - | Lists.newArrayList(iterator) | - | |
| 56 | +| Create list from array | Arrays.asList(array) | Lists.newArrayList(array) | FastList.newListWith(array) | |
| 57 | +| Create list using factory | - | - | FastList.newWithNValues(10, () -> "1") | |
| 58 | + |
| 59 | +**Examples:** |
| 60 | +*In progress* |
| 61 | + |
| 62 | +| Description | JDK | guava | gs-collections | |
| 63 | +| ------------- | -------------| -------------| -------------| |
| 64 | +| Create empty set | new HashSet<>() | Sets.newHashSet() | UnifiedSet.newSet() | |
| 65 | +| Creatre set from values | new HashSet<>(Arrays.asList("alpha", "beta", "gamma")) | Sets.newHashSet("alpha", "beta", "gamma") | UnifiedSet.newSetWith("alpha", "beta", "gamma") | |
| 66 | +| Create set from any collections | new HashSet<>(collection) | Sets.newHashSet(collection) | UnifiedSet.newSet(collection) | |
| 67 | +| Create set from any Iterable | - | Sets.newHashSet(iterable) | UnifiedSet.newSet(iterable) | |
| 68 | +| Create set from any Iterator | - | Sets.newHashSet(iterator); | - | |
| 69 | +| Create set from Array | new HashSet<>(Arrays.asList(array)) | Sets.newHashSet(array) | UnifiedSet.newSetWith(array) | |
| 70 | + |
| 71 | +**Examples:** |
| 72 | +*In progress* |
| 73 | + |
| 74 | +| Description | JDK | guava | gs-collections | |
| 75 | +| ------------- | -------------| -------------| -------------| |
| 76 | +| Create empty map | new HashMap<>() | Maps.newHashMap() | UnifiedMap.newMap() | |
| 77 | +| Create map with capacity = 130 | new HashMap<>(130) | Maps.newHashMapWithExpectedSize(100) | UnifiedMap.newMap(130) | |
| 78 | +| Create map from other map | new HashMap<>(map) | Maps.newHashMap(map) | UnifiedMap.newMap(map) | |
| 79 | +| Create map from keys | - | - | UnifiedMap.newWithKeysValues("1", "a", "2", "b") | |
| 80 | + |
| 81 | +**Examples:** |
| 82 | +*In progress* |
| 83 | + |
0 commit comments