Merge branch 'master' into BAEL-16646

# Conflicts:
#	pom.xml
This commit is contained in:
Alessio Stalla
2019-10-10 12:03:10 +02:00
474 changed files with 2552 additions and 1314 deletions

3
.gitignore vendored
View File

@@ -83,4 +83,5 @@ jta/transaction-logs/
software-security/sql-injection-samples/derby.log
spring-soap/src/main/java/com/baeldung/springsoap/gen/
/report-*.json
transaction.log
transaction.log
*-shell.log

View File

@@ -0,0 +1,179 @@
package com.baeldung.file;
import org.junit.Test;
import java.io.*;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.*;
public class FileClassDemoUnitTest {
@Test
public void givenDirectoryCreated_whenMkdirIsInvoked_thenDirectoryIsDeleted() {
File directory = new File("testDirectory");
if (!directory.isDirectory() || !directory.exists()) {
directory.mkdir();
}
assertTrue(directory.delete());
}
@Test
public void givenFileCreated_whenCreateNewFileIsInvoked_thenFileIsDeleted() throws IOException {
File file = new File("testFile.txt");
if (!file.isFile() || !file.exists()) {
file.createNewFile();
}
assertTrue(file.delete());
}
@Test
public void givenFileCreated_whenCreateNewFileInvoked_thenMetadataIsAsExpected() throws IOException {
// different Operating systems have different separator characters
String separatorCharacter = System.getProperty("file.separator");
File parentDirectory = makeDirectory("filesDirectory");
File childFile = new File(parentDirectory, "file1.txt");
childFile.createNewFile();
assertTrue(childFile.getName().equals("file1.txt"));
assertTrue(childFile.getParentFile().getName().equals(parentDirectory.getName()));
assertTrue(childFile.getPath().equals(parentDirectory.getPath() + separatorCharacter + "file1.txt"));
removeDirectory(parentDirectory);
}
@Test(expected = FileNotFoundException.class)
public void givenReadOnlyFileCreated_whenCreateNewFileInvoked_thenFileCannotBeWrittenTo() throws IOException {
File parentDirectory = makeDirectory("filesDirectory");
File childFile = new File(parentDirectory, "file1.txt");
childFile.createNewFile();
childFile.setWritable(false);
FileOutputStream fos = new FileOutputStream(childFile);
fos.write("Hello World".getBytes()); // write operation
fos.flush();
fos.close();
removeDirectory(parentDirectory);
}
@Test(expected = FileNotFoundException.class)
public void givenWriteOnlyFileCreated_whenCreateNewFileInvoked_thenFileCannotBeReadFrom() throws IOException {
File parentDirectory = makeDirectory("filesDirectory");
File childFile = new File(parentDirectory, "file1.txt");
childFile.createNewFile();
childFile.setReadable(false);
FileInputStream fis = new FileInputStream(childFile);
fis.read(); // read operation
fis.close();
removeDirectory(parentDirectory);
}
@Test
public void givenFilesCreatedInDirectory_whenCreateNewFileInvoked_thenTheyCanBeListedAsExpected() throws IOException {
File directory = makeDirectory("filtersDirectory");
File csvFile = new File(directory, "csvFile.csv");
csvFile.createNewFile();
File txtFile = new File(directory, "txtFile.txt");
txtFile.createNewFile();
//normal listing
assertEquals(2, directory.list().length);
//filtered listing
FilenameFilter csvFilter = (dir, ext) -> ext.endsWith(".csv");
assertEquals(1, directory.list(csvFilter).length);
removeDirectory(directory);
}
@Test
public void givenDirectoryIsCreated_whenMkdirInvoked_thenDirectoryCanBeRenamed() {
File source = makeDirectory("source");
File destination = makeDirectory("destination");
source.renameTo(destination);
assertFalse(source.isDirectory());
assertTrue(destination.isDirectory());
removeDirectory(destination);
}
@Test
public void givenDataIsWrittenToFile_whenWriteIsInvoked_thenFreeSpaceOnSystemDecreases() throws IOException {
String name = System.getProperty("user.home") + System.getProperty("file.separator") + "test";
File testDir = makeDirectory(name);
File sample = new File(testDir, "sample.txt");
long freeSpaceBeforeWrite = testDir.getFreeSpace();
writeSampleDataToFile(sample);
long freeSpaceAfterWrite = testDir.getFreeSpace();
assertTrue(freeSpaceAfterWrite < freeSpaceBeforeWrite);
removeDirectory(testDir);
}
private static File makeDirectory(String directoryName) {
File directory = new File(directoryName);
directory.mkdir();
if (directory.isDirectory()) {
return directory;
}
throw new RuntimeException("Directory not created for " + directoryName);
}
private static void removeDirectory(File directory) {
// make sure you don't delete your home directory here
if (directory.getPath().equals(System.getProperty("user.home"))) {
return;
}
// remove directory and its files from system
if (directory != null && directory.exists()) {
// delete all files inside the directory
File[] filesInDirectory = directory.listFiles();
if (filesInDirectory != null) {
List<File> files = Arrays.asList(filesInDirectory);
files.forEach(f -> deleteFile(f));
}
// finally delete the directory itself
deleteFile(directory);
}
}
private static void deleteFile(File fileToDelete) {
if (fileToDelete != null && fileToDelete.exists()) {
fileToDelete.delete();
}
}
private static void writeSampleDataToFile(File sample) throws IOException {
//write sample text to file
try (FileOutputStream out = new FileOutputStream(sample)) {
for (int i = 1; i <= 100000; i++) {
String sampleText = "Sample line number " + i + "\n";
out.write(sampleText.getBytes());
}
}
}
}

View File

@@ -7,7 +7,6 @@ This module contains articles about Object-oriented programming (OOP) in Java
- [Cannot Reference “X” Before Supertype Constructor Has Been Called](https://www.baeldung.com/java-cannot-reference-x-before-supertype-constructor-error)
- [Anonymous Classes in Java](https://www.baeldung.com/java-anonymous-classes)
- [Raw Types in Java](https://www.baeldung.com/raw-types-java)
- [Java private Access Modifier](https://www.baeldung.com/java-private-keyword)
- [Marker Interfaces in Java](https://www.baeldung.com/java-marker-interfaces)
- [Java equals() and hashCode() Contracts](https://www.baeldung.com/java-equals-hashcode-contracts)
- [Immutable Objects in Java](https://www.baeldung.com/java-immutable-object)

View File

@@ -4,3 +4,4 @@
- [The Modulo Operator in Java](https://www.baeldung.com/modulo-java)
- [Java instanceof Operator](https://www.baeldung.com/java-instanceof)
- [A Guide to Increment and Decrement Unary Operators in Java](https://www.baeldung.com/java-unary-operators)
- [Java Compound Operators](https://www.baeldung.com/java-compound-operators)

View File

@@ -1,4 +1,4 @@
package com.baeldung.java.diamond;
package com.baeldung.diamondoperator;
public class Car<T extends Engine> implements Vehicle<T> {

View File

@@ -1,4 +1,4 @@
package com.baeldung.java.diamond;
package com.baeldung.diamondoperator;
public class Diesel implements Engine {

View File

@@ -1,4 +1,4 @@
package com.baeldung.java.diamond;
package com.baeldung.diamondoperator;
public interface Vehicle<T extends Engine> {

View File

@@ -1,4 +1,4 @@
package com.baeldung.keyword.test;
package com.baeldung.keyword;
import org.junit.Assert;
import org.junit.jupiter.api.Test;

View File

@@ -5,4 +5,10 @@ This module contains articles about Java syntax
### Relevant Articles:
- [Java private Access Modifier](https://www.baeldung.com/java-private-keyword)
- [Guide to Java Packages](https://www.baeldung.com/java-packages)
- [If-Else Statement in Java](https://www.baeldung.com/java-if-else)
- [Control Structures in Java](https://www.baeldung.com/java-control-structures)
- [Java Double Brace Initialization](https://www.baeldung.com/java-double-brace-initialization)
- [The Java Native Keyword and Methods](https://www.baeldung.com/java-native)
- [Variable Scope in Java](https://www.baeldung.com/java-variable-scope)
- [[<-- Prev]](/core-java-modules/core-java-lang-syntax)

View File

@@ -1,4 +1,4 @@
package com.baeldung.controlstructures;
package com.baeldung.core.controlstructures;
public class ConditionalBranches {

View File

@@ -1,4 +1,4 @@
package com.baeldung.controlstructures;
package com.baeldung.core.controlstructures;
public class Loops {

View File

@@ -1,4 +1,4 @@
package com.baeldung.nativekeyword;
package com.baeldung.core.nativekeyword;
public class DateTimeUtils {

View File

@@ -1,6 +1,4 @@
package com.baeldung.nativekeyword;
import com.baeldung.nativekeyword.DateTimeUtils;
package com.baeldung.core.nativekeyword;
public class NativeMainApp {
public static void main(String[] args) {

View File

@@ -1,9 +1,9 @@
package com.baeldung.packages;
package com.baeldung.core.packages;
import com.baeldung.core.packages.domain.TodoItem;
import java.time.LocalDate;
import com.baeldung.packages.domain.TodoItem;
public class TodoApp {
public static void main(String[] args) {

View File

@@ -1,10 +1,10 @@
package com.baeldung.packages;
package com.baeldung.core.packages;
import com.baeldung.core.packages.domain.TodoItem;
import java.util.ArrayList;
import java.util.List;
import com.baeldung.packages.domain.TodoItem;
public class TodoList {
private List<TodoItem> todoItems;

View File

@@ -1,4 +1,4 @@
package com.baeldung.packages.domain;
package com.baeldung.core.packages.domain;
import java.time.LocalDate;

View File

@@ -1,4 +1,4 @@
package com.baeldung.scope;
package com.baeldung.core.scope;
import java.util.Arrays;
import java.util.List;

View File

@@ -1,11 +1,11 @@
package com.baeldung.nativekeyword;
import static org.junit.Assert.assertNotNull;
package com.baeldung.core.nativekeyword;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import static org.junit.Assert.assertNotNull;
public class DateTimeUtilsManualTest {
private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(DateTimeUtilsManualTest.class);

View File

@@ -1,12 +1,11 @@
package com.baeldung.packages;
package com.baeldung.core.packages;
import static org.junit.Assert.assertEquals;
import com.baeldung.core.packages.domain.TodoItem;
import org.junit.Test;
import java.time.LocalDate;
import org.junit.Test;
import com.baeldung.packages.domain.TodoItem;
import static org.junit.Assert.assertEquals;
public class PackagesUnitTest {

View File

@@ -3,20 +3,14 @@
This module contains articles about Java syntax
### Relevant Articles:
- [The Basics of Java Generics](http://www.baeldung.com/java-generics)
- [Java Primitive Conversions](http://www.baeldung.com/java-primitive-conversions)
- [Java Double Brace Initialization](http://www.baeldung.com/java-double-brace-initialization)
- [Guide to the Diamond Operator in Java](http://www.baeldung.com/java-diamond-operator)
- [The Java continue and break Keywords](http://www.baeldung.com/java-continue-and-break)
- [A Guide to Creating Objects in Java](http://www.baeldung.com/java-initialization)
- [A Guide to Java Loops](http://www.baeldung.com/java-loops)
- [Varargs in Java](http://www.baeldung.com/java-varargs)
- [A Guide to Java Enums](http://www.baeldung.com/a-guide-to-java-enums)
- [Infinite Loops in Java](http://www.baeldung.com/infinite-loops-java)
- [Quick Guide to java.lang.System](http://www.baeldung.com/java-lang-system)
- [The Basics of Java Generics](https://www.baeldung.com/java-generics)
- [Java Primitive Conversions](https://www.baeldung.com/java-primitive-conversions)
- [The Java continue and break Keywords](https://www.baeldung.com/java-continue-and-break)
- [A Guide to Creating Objects in Java](https://www.baeldung.com/java-initialization)
- [A Guide to Java Loops](https://www.baeldung.com/java-loops)
- [Varargs in Java](https://www.baeldung.com/java-varargs)
- [A Guide to Java Enums](https://www.baeldung.com/a-guide-to-java-enums)
- [Infinite Loops in Java](https://www.baeldung.com/infinite-loops-java)
- [Java Switch Statement](https://www.baeldung.com/java-switch)
- [The Modulo Operator in Java](https://www.baeldung.com/modulo-java)
- [Ternary Operator In Java](https://www.baeldung.com/java-ternary-operator)
- [Java instanceof Operator](https://www.baeldung.com/java-instanceof)
- [Breaking Out of Nested Loops](https://www.baeldung.com/java-breaking-out-nested-loop)
- [[More -->]](/core-java-modules/core-java-lang-syntax-2)

View File

@@ -12,7 +12,7 @@ import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
public class WhenUsingLoops {
public class LoopsUnitTest {
private LoopsInJava loops = new LoopsInJava();
private static List<String> list = new ArrayList<>();

View File

@@ -6,29 +6,19 @@ This module contains articles about core features in the Java language
- [Generate equals() and hashCode() with Eclipse](https://www.baeldung.com/java-eclipse-equals-and-hashcode)
- [Iterating Over Enum Values in Java](https://www.baeldung.com/java-enum-iteration)
- [Java Double Brace Initialization](https://www.baeldung.com/java-double-brace-initialization)
- [Guide to the Diamond Operator in Java](https://www.baeldung.com/java-diamond-operator)
- [Comparator and Comparable in Java](https://www.baeldung.com/java-comparator-comparable)
- [The Java continue and break Keywords](https://www.baeldung.com/java-continue-and-break)
- [Nested Classes in Java](https://www.baeldung.com/java-nested-classes)
- [A Guide to Inner Interfaces in Java](https://www.baeldung.com/java-inner-interfaces)
- [Recursion In Java](https://www.baeldung.com/java-recursion)
- [A Guide to the finalize Method in Java](https://www.baeldung.com/java-finalize)
- [Infinite Loops in Java](https://www.baeldung.com/infinite-loops-java)
- [Quick Guide to java.lang.System](https://www.baeldung.com/java-lang-system)
- [Using Java Assertions](https://www.baeldung.com/java-assert)
- [Static and Dynamic Binding in Java](https://www.baeldung.com/java-static-dynamic-binding)
- [Synthetic Constructs in Java](https://www.baeldung.com/java-synthetic)
- [How to Separate Double into Integer and Decimal Parts](https://www.baeldung.com/java-separate-double-into-integer-decimal-parts)
- [Retrieving a Class Name in Java](https://www.baeldung.com/java-class-name)
- [Java Compound Operators](https://www.baeldung.com/java-compound-operators)
- [Guide to Java Packages](https://www.baeldung.com/java-packages)
- [The Java Native Keyword and Methods](https://www.baeldung.com/java-native)
- [If-Else Statement in Java](https://www.baeldung.com/java-if-else)
- [Control Structures in Java](https://www.baeldung.com/java-control-structures)
- [Java Interfaces](https://www.baeldung.com/java-interfaces)
- [Attaching Values to Java Enum](https://www.baeldung.com/java-enum-values)
- [Variable Scope in Java](https://www.baeldung.com/java-variable-scope)
- [Java Classes and Objects](https://www.baeldung.com/java-classes-objects)
- [A Guide to Java Enums](https://www.baeldung.com/a-guide-to-java-enums)
- [[More --> ]](/core-java-modules/core-java-lang-2)

View File

@@ -1,4 +1,6 @@
## Couchbase SDK Tutorial Project
## Couchbase
This module contains articles about Couchbase
### Relevant Articles:
- [Introduction to Couchbase SDK for Java](https://www.baeldung.com/java-couchbase-sdk)

View File

@@ -1 +1,7 @@
## Custom PMD Rules
This module contains articles about PMD
### Relevant Articles:
- [Introduction To PMD](https://www.baeldung.com/pmd)

View File

@@ -1,3 +1,7 @@
## Dagger
This module contains articles about Dagger
### Relevant articles:
- [Introduction to Dagger 2](https://www.baeldung.com/dagger-2)

View File

@@ -1,3 +1,7 @@
## Data Structures
This module contains articles about data structures in Java
## Relevant articles:
- [The Trie Data Structure in Java](https://www.baeldung.com/trie-java)

View File

@@ -1,3 +1,7 @@
## Domain-driven Design (DDD)
This module contains articles about Domain-driven Design (DDD)
### Relevant articles
- [Persisting DDD Aggregates](https://www.baeldung.com/spring-persisting-ddd-aggregates)

View File

@@ -1,5 +1,6 @@
### Sample deeplearning4j Project
This is a sample project for the [deeplearning4j](https://deeplearning4j.org) library.
## Deeplearning4j
This module contains articles about Deeplearning4j
### Relevant Articles:
- [A Guide to Deeplearning4j](https://www.baeldung.com/deeplearning4j)

View File

@@ -1,3 +1,7 @@
## Relevant articles:
## Disruptor
This module contains articles about LMAX Disruptor
### Relevant articles:
- [Concurrency with LMAX Disruptor An Introduction](https://www.baeldung.com/lmax-disruptor-concurrency)

View File

@@ -1,2 +1,7 @@
## Dozer
This module contains articles about Dozer
### Relevant Articles:
- [A Guide to Mapping With Dozer](https://www.baeldung.com/dozer)

View File

@@ -1,4 +1,9 @@
## Drools
This module contains articles about Drools
### Relevant Articles:
- [Introduction to Drools](https://www.baeldung.com/drools)
- [Drools Using Rules from Excel Files](https://www.baeldung.com/drools-excel)
- [An Example of Backward Chaining in Drools](https://www.baeldung.com/drools-backward-chaining)

View File

@@ -1,4 +1,8 @@
## Relevant articles:
## Dubbo
This module contains articles about Dubbo
### Relevant articles:
- [Introduction to Dubbo](https://www.baeldung.com/dubbo)

View File

@@ -1,5 +1,7 @@
## Ethereum
This module contains articles about the Ethereum blockchain
### Relevant Articles:
- [Introduction to EthereumJ](https://www.baeldung.com/ethereumj)
- [Creating and Deploying Smart Contracts with Solidity](https://www.baeldung.com/smart-contracts-ethereum-solidity)

View File

@@ -1,10 +1,8 @@
## Feign Hypermedia Client ##
## Feign
This is the implementation of a [spring-hypermedia-api][1] client using Feign.
[1]: https://github.com/eugenp/spring-hypermedia-api
This module contains articles about Feign
### Relevant Articles:
- [Intro to Feign](https://www.baeldung.com/intro-to-feign)
- [Introduction to SLF4J](https://www.baeldung.com/slf4j-with-log4j2-logback)

View File

@@ -1,3 +1,7 @@
## Flyway CDI Extension
This module contains articles about context and dependency injection (CDI) with Flyway
### Relevant articles
- [CDI Portable Extension and Flyway](https://www.baeldung.com/cdi-portable-extension)

View File

@@ -1,3 +1,7 @@
## GeoTools
This module contains articles about GeoTools
### Relevant Articles
[Introduction to GeoTools](https://www.baeldung.com/geo-tools)

View File

@@ -1,16 +1,16 @@
## Google Cloud Tutorial Project
## Google Cloud
This module contains articles about Google Cloud
### Relevant Article:
- [Intro to Google Cloud Storage With Java](https://www.baeldung.com/java-google-cloud-storage)
### Overview
This Maven project contains the Java code for the article linked above.
### Package Organization
Java classes for the intro tutorial are in the org.baeldung.google.cloud package. Please note that Google Cloud requires
a user account and credentials, as explained in the tutorial.
### Running the tests
```

View File

@@ -1,2 +1,7 @@
## Google Web Toolkit
This module contains articles about Google Web Toolkit (GWT)
### Relevant Articles:
- [Introduction to GWT](https://www.baeldung.com/gwt)

View File

@@ -1,3 +1,7 @@
## Gradle
This module contains articles about Gradle
## Relevant articles:
- [Introduction to Gradle](https://www.baeldung.com/gradle)
- [Writing Custom Gradle Plugins](https://www.baeldung.com/gradle-create-plugin)

View File

@@ -1,3 +1,7 @@
## Grails
This module contains articles about Grails
### Relevant articles
- [Build an MVC Web Application with Grails](https://www.baeldung.com/grails-mvc-application)

View File

@@ -1,3 +1,7 @@
## GraphQL Java
This module contains articles about GraphQL with Java
## Relevant articles:
- [Introduction to GraphQL](https://www.baeldung.com/graphql)

View File

@@ -1,2 +1,6 @@
## gRPC
This module contains articles about gRPC
### Relevant Articles:
- [Introduction to gRPC](https://www.baeldung.com/grpc-introduction)

View File

@@ -1,9 +1,9 @@
=========
## GSON Cookbooks and Examples
## GSON
This module contains articles about Gson
### Relevant Articles:
- [Gson Deserialization Cookbook](https://www.baeldung.com/gson-deserialization-guide)
- [Jackson vs Gson](https://www.baeldung.com/jackson-vs-gson)
- [Exclude Fields from Serialization in Gson](https://www.baeldung.com/gson-exclude-fields-serialization)

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,4 +1,6 @@
# Guava
## Guava Collections Set
This module contains articles about Google Guava sets
## Relevant Articles:

View File

@@ -1,20 +1,16 @@
=========
## Guava and Hamcrest Cookbooks and Examples
## Guava Collections
This module contains articles about Google Guava collections
### 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,3 +1,7 @@
## Guava IO
This module contains articles about input/output (IO) with Google Guava
### Relevant Articles:
- [Using Guava CountingOutputStream](https://www.baeldung.com/guava-counting-outputstream)

View File

@@ -1,3 +1,4 @@
## Guava Modules
This module contains other modules about Google Guava

View File

@@ -1,9 +1,9 @@
## Guava
## Guava Examples
This module contains articles a Google Guava
### 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

@@ -1,5 +1,8 @@
## Google Guice Tutorials Project
## Google Guice
This module contains articles about Google Guice
### Relevant Articles
- [Guide to Google Guice](https://www.baeldung.com/guice)
- [Guice vs Spring Dependency Injection](https://www.baeldung.com/guice-spring-dependency-injection)

View File

@@ -1,3 +1,7 @@
## Hazelcast
This module contains articles about Hazelcast
### Relevant Articles:
- [Guide to Hazelcast with Java](https://www.baeldung.com/java-hazelcast)
- [Introduction to Hazelcast Jet](https://www.baeldung.com/hazelcast-jet)

View File

@@ -1,3 +1,7 @@
## Helidon
This module contains articles about Helidon
### Relevant articles
- [Microservices with Oracle Helidon](https://www.baeldung.com/microservices-oracle-helidon)

View File

@@ -1,9 +1,10 @@
=========
## HttpClient 4.x Cookbooks and Examples
## HttpClient 4.x
This module contains articles about HttpClient 4.x
###The Course
The "REST With Spring" Classes: http://bit.ly/restwithspring
The "REST With Spring" Classes: http://bit.ly/restwithspring
### Relevant Articles:

View File

@@ -18,4 +18,4 @@ This module contains articles about the Stream API in Java.
- [Counting Matches on a Stream Filter](https://www.baeldung.com/java-stream-filter-count)
- [Java 8 Streams peek() API](https://www.baeldung.com/java-streams-peek-api)
- [Working With Maps Using Streams](https://www.baeldung.com/java-maps-streams)
- More articles: [[next -->]](/../java-streams-2)
- More articles: [[next -->]](/java-streams-2)

View File

@@ -1,4 +1,8 @@
## Relevant articles:
## Java Microbenchmark Harness
This module contains articles about the Java Microbenchmark Harness (JMH).
### Relevant articles:
- [Microbenchmarking with Java](https://www.baeldung.com/java-microbenchmark-harness)

View File

@@ -1,3 +1,6 @@
## JNI
This module contains articles about the Java Native Interface (JNI).
### Relevant Articles:

View File

@@ -1,3 +1,7 @@
## Relevant articles:
## Jooby
This module contains articles about Jooby.
### Relevant articles:
- [Introduction to Jooby](https://www.baeldung.com/jooby)

Some files were not shown because too many files have changed in this diff Show More