Merge pull request #7916 from catalin-burcea/BAEL-16642

[BAEL-16642] Split or move guava-collections module
This commit is contained in:
Josh Cummings 2019-10-09 09:40:15 -06:00 committed by GitHub
commit 4b62fb6cef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 149 additions and 149 deletions

View File

@ -0,0 +1,12 @@
=========
## Guava Collections Map examples
This module contains articles about map collections in Guava
### Relevant Articles:
- [Guava Maps](https://www.baeldung.com/guava-maps)
- [Guide to Guava Multimap](https://www.baeldung.com/guava-multimap)
- [Guide to Guava RangeMap](https://www.baeldung.com/guava-rangemap)
- [Initialize a HashMap in Java](https://www.baeldung.com/java-initialize-hashmap)
- [Guide to Guava ClassToInstanceMap](https://www.baeldung.com/guava-class-to-instance-map)

View File

@ -0,0 +1,32 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung.guava</groupId>
<artifactId>guava-collections-map</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>guava-collections-map</name>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-java</relativePath>
</parent>
<dependencies>
</dependencies>
<build>
<finalName>guava-collections-map</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<properties>
</properties>
</project>

View File

@ -1,4 +1,4 @@
package org.baeldung.guava;
package com.baeldung.guava.classtoinstancemap;
import com.google.common.collect.ClassToInstanceMap;
import com.google.common.collect.ImmutableClassToInstanceMap;
import com.google.common.collect.MutableClassToInstanceMap;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava.maps.initialize;
package com.baeldung.guava.initializemaps;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.*;

View File

@ -1,115 +1,18 @@
package org.baeldung.guava;
package com.baeldung.guava.maps;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.junit.Test;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Predicates;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.BiMap;
import com.google.common.collect.ClassToInstanceMap;
import com.google.common.collect.ContiguousSet;
import com.google.common.collect.DiscreteDomain;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.Multiset;
import com.google.common.collect.Multisets;
import com.google.common.collect.MutableClassToInstanceMap;
import com.google.common.collect.Ordering;
import com.google.common.collect.Range;
import com.google.common.collect.RangeSet;
import com.google.common.collect.Sets;
import com.google.common.collect.Table;
import com.google.common.collect.Tables;
import com.google.common.collect.TreeRangeSet;
import com.google.common.collect.*;
public class GuavaCollectionTypesUnitTest {
@Test
public void whenCreateList_thenCreated() {
final List<String> names = Lists.newArrayList("John", "Adam", "Jane");
names.add("Tom");
assertEquals(4, names.size());
names.remove("Adam");
assertThat(names, contains("John", "Jane", "Tom"));
}
@Test
public void whenReverseList_thenReversed() {
final List<String> names = Lists.newArrayList("John", "Adam", "Jane");
final List<String> reversed = Lists.reverse(names);
assertThat(reversed, contains("Jane", "Adam", "John"));
}
@Test
public void whenCreateCharacterListFromString_thenCreated() {
final List<Character> chars = Lists.charactersOf("John");
assertEquals(4, chars.size());
assertThat(chars, contains('J', 'o', 'h', 'n'));
}
@Test
public void whenPartitionList_thenPartitioned() {
final List<String> names = Lists.newArrayList("John", "Jane", "Adam", "Tom", "Viki", "Tyler");
final List<List<String>> result = Lists.partition(names, 2);
assertEquals(3, result.size());
assertThat(result.get(0), contains("John", "Jane"));
assertThat(result.get(1), contains("Adam", "Tom"));
assertThat(result.get(2), contains("Viki", "Tyler"));
}
@Test
public void whenRemoveDuplicatesFromList_thenRemoved() {
final List<Character> chars = Lists.newArrayList('h', 'e', 'l', 'l', 'o');
assertEquals(5, chars.size());
final List<Character> result = ImmutableSet.copyOf(chars).asList();
assertThat(result, contains('h', 'e', 'l', 'o'));
}
@Test
public void whenRemoveNullFromList_thenRemoved() {
final List<String> names = Lists.newArrayList("John", null, "Adam", null, "Jane");
Iterables.removeIf(names, Predicates.isNull());
assertEquals(3, names.size());
assertThat(names, contains("John", "Adam", "Jane"));
}
@Test
public void whenCreateImmutableList_thenCreated() {
final List<String> names = Lists.newArrayList("John", "Adam", "Jane");
names.add("Tom");
assertEquals(4, names.size());
final ImmutableList<String> immutable = ImmutableList.copyOf(names);
assertThat(immutable, contains("John", "Adam", "Jane", "Tom"));
}
public class GuavaMapsUnitTest {
@Test
public void whenCreateImmutableMap_thenCreated() {

View File

@ -1,4 +1,4 @@
package org.baeldung.guava;
package com.baeldung.guava.multimap;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava;
package com.baeldung.guava.rangemap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

View File

@ -1,13 +0,0 @@
*.class
#folders#
/target
/neoDb*
/data
/src/main/webapp/WEB-INF/classes
*/META-INF/*
# Packaged files #
*.jar
*.war
*.ear

View File

@ -6,15 +6,11 @@
### Relevant Articles:
- [Guava Collections Cookbook](https://www.baeldung.com/guava-collections)
- [Guava Ordering Cookbook](https://www.baeldung.com/guava-order)
- [Guide to Guavas Ordering](https://www.baeldung.com/guava-ordering)
- [Hamcrest Collections Cookbook](https://www.baeldung.com/hamcrest-collections-arrays)
- [Partition a List in Java](https://www.baeldung.com/java-list-split)
- [Filtering and Transforming Collections in Guava](https://www.baeldung.com/guava-filter-and-transform-a-collection)
- [Guava Join and Split Collections](https://www.baeldung.com/guava-joiner-and-splitter-tutorial)
- [Guava Lists](https://www.baeldung.com/guava-lists)
- [Guava Maps](https://www.baeldung.com/guava-maps)
- [Guide to Guava Multimap](https://www.baeldung.com/guava-multimap)
- [Guide to Guava RangeMap](https://www.baeldung.com/guava-rangemap)
- [Guide to Guava MinMaxPriorityQueue and EvictingQueue](https://www.baeldung.com/guava-minmax-priority-queue-and-evicting-queue)
- [Initialize a HashMap in Java](https://www.baeldung.com/java-initialize-hashmap)
- [Guide to Guava Table](https://www.baeldung.com/guava-table)
- [Guide to Guava ClassToInstanceMap](https://www.baeldung.com/guava-class-to-instance-map)

View File

@ -43,7 +43,7 @@
</dependencies>
<build>
<finalName>guava</finalName>
<finalName>guava-collections</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>

View File

@ -1,4 +1,4 @@
package org.baeldung.guava;
package com.baeldung.guava.collections;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava;
package com.baeldung.guava.filtertransform;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava;
package com.baeldung.guava.joinsplit;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString;

View File

@ -0,0 +1,82 @@
package com.baeldung.guava.lists;
import com.google.common.base.Predicates;
import com.google.common.collect.*;
import org.junit.Test;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.contains;
public class GuavaListsUnitTest {
@Test
public void whenCreateList_thenCreated() {
final List<String> names = Lists.newArrayList("John", "Adam", "Jane");
names.add("Tom");
assertEquals(4, names.size());
names.remove("Adam");
assertThat(names, contains("John", "Jane", "Tom"));
}
@Test
public void whenReverseList_thenReversed() {
final List<String> names = Lists.newArrayList("John", "Adam", "Jane");
final List<String> reversed = Lists.reverse(names);
assertThat(reversed, contains("Jane", "Adam", "John"));
}
@Test
public void whenCreateCharacterListFromString_thenCreated() {
final List<Character> chars = Lists.charactersOf("John");
assertEquals(4, chars.size());
assertThat(chars, contains('J', 'o', 'h', 'n'));
}
@Test
public void whenPartitionList_thenPartitioned() {
final List<String> names = Lists.newArrayList("John", "Jane", "Adam", "Tom", "Viki", "Tyler");
final List<List<String>> result = Lists.partition(names, 2);
assertEquals(3, result.size());
assertThat(result.get(0), contains("John", "Jane"));
assertThat(result.get(1), contains("Adam", "Tom"));
assertThat(result.get(2), contains("Viki", "Tyler"));
}
@Test
public void whenRemoveDuplicatesFromList_thenRemoved() {
final List<Character> chars = Lists.newArrayList('h', 'e', 'l', 'l', 'o');
assertEquals(5, chars.size());
final List<Character> result = ImmutableSet.copyOf(chars).asList();
assertThat(result, contains('h', 'e', 'l', 'o'));
}
@Test
public void whenRemoveNullFromList_thenRemoved() {
final List<String> names = Lists.newArrayList("John", null, "Adam", null, "Jane");
Iterables.removeIf(names, Predicates.isNull());
assertEquals(3, names.size());
assertThat(names, contains("John", "Adam", "Jane"));
}
@Test
public void whenCreateImmutableList_thenCreated() {
final List<String> names = Lists.newArrayList("John", "Adam", "Jane");
names.add("Tom");
assertEquals(4, names.size());
final ImmutableList<String> immutable = ImmutableList.copyOf(names);
assertThat(immutable, contains("John", "Adam", "Jane", "Tom"));
}
}

View File

@ -1,4 +1,4 @@
package org.baeldung.guava;
package com.baeldung.guava.ordering;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava;
package com.baeldung.guava.ordering;
import com.google.common.base.Function;
import com.google.common.collect.Ordering;

View File

@ -1,4 +1,4 @@
package org.baeldung.java;
package com.baeldung.guava.partition;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

View File

@ -1,4 +1,4 @@
package org.baeldung.java;
package com.baeldung.guava.partition;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

View File

@ -1,4 +1,4 @@
package org.baeldung.java;
package com.baeldung.guava.partition;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava;
package com.baeldung.guava.queues;
import com.google.common.collect.EvictingQueue;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava;
package com.baeldung.guava.queues;
import com.google.common.collect.MinMaxPriorityQueue;

View File

@ -1,4 +1,4 @@
package org.baeldung.guava;
package com.baeldung.guava.table;
import static org.assertj.core.api.Assertions.*;
import java.util.List;

View File

@ -1,4 +1,4 @@
package org.baeldung.hamcrest;
package com.baeldung.hamcrest;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;

View File

@ -1,13 +0,0 @@
*.class
#folders#
/target
/neoDb*
/data
/src/main/webapp/WEB-INF/classes
*/META-INF/*
# Packaged files #
*.jar
*.war
*.ear

View File

@ -3,7 +3,6 @@
### Relevant Articles:
- [Guava Functional Cookbook](https://www.baeldung.com/guava-functions-predicates)
- [Guide to Guavas Ordering](https://www.baeldung.com/guava-ordering)
- [Guide to Guavas PreConditions](https://www.baeldung.com/guava-preconditions)
- [Introduction to Guava CacheLoader](https://www.baeldung.com/guava-cacheloader)
- [Introduction to Guava Memoizer](https://www.baeldung.com/guava-memoizer)

View File

@ -459,6 +459,7 @@
<module>guava</module>
<module>guava-io</module>
<module>guava-collections</module>
<module>guava-collections-map</module>
<module>guava-collections-set</module>
<module>guava-modules</module>
<!-- <module>guest</module> --> <!-- not to be built as its for guest articles -->
@ -1204,6 +1205,7 @@
<module>guava</module>
<module>guava-io</module>
<module>guava-collections</module>
<module>guava-collections-map</module>
<module>guava-collections-set</module>
<module>guava-modules</module>
<!-- <module>guest</module> --> <!-- not to be built as its for guest articles -->