[Java 11502] (#12625)

* [JAVA-11502] Added vavr-modules (parent)

* [JAVA-11502] Added vavr(submodule) to vavr-modules(parent)

* [JAVA-11502] Added vavr-2(submodule) to vavr-modules(parent)

* [JAVA-11502] Added java-vavr-stream(submodule) to vavr-modules(parent)

* [JAVA-11502] deleted modules that were moved + cleanup

Co-authored-by: panagiotiskakos <panagiotis.kakos@libra-is.com>
Co-authored-by: Dhawal Kapil <dhawalkapil@gmail.com>
This commit is contained in:
panos-kakos 2022-08-25 16:47:55 +01:00 committed by GitHub
parent 18d1cb40dc
commit 3ce04cafd5
40 changed files with 239 additions and 206 deletions

10
pom.xml
View File

@ -410,7 +410,6 @@
<module>java-jdi</module>
<module>java-rmi</module>
<module>java-spi</module>
<module>java-vavr-stream</module>
<module>java-websocket</module>
<module>javax-sound</module>
<module>javaxval</module>
@ -488,6 +487,7 @@
<module>reactive-systems</module>
<module>security-modules</module>
<module>slack</module>
<module>vavr-modules</module>
<module>web-modules</module>
</modules>
@ -692,8 +692,7 @@
<module>spring-ejb-modules/ejb-beans</module>
<module>vaadin</module>
<module>vavr</module>
<module>vavr-2</module>
<module>vavr-modules</module>
</modules>
</profile>
@ -809,7 +808,6 @@
<module>java-jdi</module>
<module>java-rmi</module>
<module>java-spi</module>
<module>java-vavr-stream</module>
<module>java-websocket</module>
<module>javax-sound</module>
<module>javaxval</module>
@ -889,6 +887,7 @@
<module>reactive-systems</module>
<module>security-modules</module>
<module>slack</module>
<module>vavr-modules</module>
<module>web-modules</module>
</modules>
@ -1079,8 +1078,7 @@
<module>spring-ejb-modules/ejb-beans</module>
<module>vaadin</module>
<module>vavr</module>
<module>vavr-2</module>
<module>vavr-modules</module>
</modules>
</profile>

3
vavr-modules/README.md Normal file
View File

@ -0,0 +1,3 @@
## VAVR
This module contains modules about vavr.

View File

@ -11,7 +11,7 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<artifactId>vavr-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

33
vavr-modules/pom.xml Normal file
View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
<artifactId>vavr-modules</artifactId>
<name>vavr-modules</name>
<packaging>pom</packaging>
<parent>
<artifactId>parent-modules</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modules>
<module>vavr</module>
<module>vavr-2</module>
<module>java-vavr-stream</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -1,18 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
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>
<artifactId>vavr-2</artifactId>
<name>vavr-2</name>
<packaging>jar</packaging>
<parent>
<artifactId>parent-modules</artifactId>
<groupId>com.baeldung</groupId>
<artifactId>vavr-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>io.vavr</groupId>

View File

@ -11,7 +11,7 @@
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-2</relativePath>
<relativePath>../../parent-boot-2</relativePath>
</parent>
<dependencies>

View File

@ -1,107 +1,107 @@
package com.baeldung.vavr.collections;
import static io.vavr.API.Array;
import static io.vavr.API.Failure;
import static io.vavr.API.List;
import static io.vavr.API.None;
import static io.vavr.API.Some;
import static io.vavr.API.Stream;
import static io.vavr.API.Success;
import static io.vavr.API.Tuple;
import static io.vavr.API.Vector;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import io.vavr.Tuple3;
import io.vavr.collection.Array;
import io.vavr.collection.List;
import io.vavr.collection.Stream;
import io.vavr.collection.Vector;
import io.vavr.control.Option;
import io.vavr.control.Try;
public class CollectionFactoryMethodsUnitTest {
@Test
public void givenANoneOptionElement_whenCreated_thenCorrect() {
Option<Integer> none = None();
assertFalse(none == null);
assertEquals(none, Option.none());
}
@Test
public void givenASomeOptionElement_whenCreated_thenCorrect() {
Option<Integer> some = Some(1);
assertFalse(some == null);
assertTrue(some.contains(1));
}
@Test
public void givenATupleElement_whenCreated_thenCorrect() {
Tuple3<Character, String, Integer> tuple = Tuple('a', "chain", 2);
assertTrue(tuple!=null);
assertEquals(tuple._1(), new Character('a'));
assertEquals(tuple._2(), "chain");
assertEquals(tuple._3().intValue(), 2);
}
@Test
public void givenASuccessObject_whenEvaluated_thenSuccess() {
Try<Integer> integer = Success(55);
assertEquals(integer.get().intValue(), 55);
}
@Test
public void givenAFailureObject_whenEvaluated_thenExceptionThrown() {
Try<Integer> failure = Failure(new Exception("Exception X encapsulated here"));
try {
Integer i = failure.get();// evaluate a failure raise the exception
System.out.println(i);// not executed
} catch (Exception e) {
assertEquals(e.getMessage(), "Exception X encapsulated here");
}
}
@Test
public void givenAList_whenCreated_thenCorrect() {
List<Integer> list = List(1, 2, 3, 4, 5);
assertEquals(list.size(), 5);
assertEquals(list.get(0).intValue(), 1);
}
@Test
public void givenAnEmptyList_whenCreated_thenCorrect() {
List<Integer> empty = List();
assertEquals(empty.size(), 0);
assertEquals(empty, List.empty());
}
@Test
public void givenAnArray_whenCreated_thenCorrect() {
Array<Integer> array = Array(1, 2, 3, 4, 5);
assertEquals(array.size(), 5);
assertEquals(array.get(0).intValue(), 1);
}
@Test
public void givenAStream_whenCreated_thenCorrect() {
Stream<Integer> stream = Stream(1, 2, 3, 4, 5);
assertEquals(stream.size(), 5);
assertEquals(stream.get(0).intValue(), 1);
}
@Test
public void givenAVector_whenCreated_thenCorrect() {
Vector<Integer> vector = Vector(1, 2, 3, 4, 5);
assertEquals(vector.size(), 5);
assertEquals(vector.get(0).intValue(), 1);
}
}
package com.baeldung.vavr.collections;
import static io.vavr.API.Array;
import static io.vavr.API.Failure;
import static io.vavr.API.List;
import static io.vavr.API.None;
import static io.vavr.API.Some;
import static io.vavr.API.Stream;
import static io.vavr.API.Success;
import static io.vavr.API.Tuple;
import static io.vavr.API.Vector;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import io.vavr.Tuple3;
import io.vavr.collection.Array;
import io.vavr.collection.List;
import io.vavr.collection.Stream;
import io.vavr.collection.Vector;
import io.vavr.control.Option;
import io.vavr.control.Try;
public class CollectionFactoryMethodsUnitTest {
@Test
public void givenANoneOptionElement_whenCreated_thenCorrect() {
Option<Integer> none = None();
assertFalse(none == null);
assertEquals(none, Option.none());
}
@Test
public void givenASomeOptionElement_whenCreated_thenCorrect() {
Option<Integer> some = Some(1);
assertFalse(some == null);
assertTrue(some.contains(1));
}
@Test
public void givenATupleElement_whenCreated_thenCorrect() {
Tuple3<Character, String, Integer> tuple = Tuple('a', "chain", 2);
assertTrue(tuple!=null);
assertEquals(tuple._1(), new Character('a'));
assertEquals(tuple._2(), "chain");
assertEquals(tuple._3().intValue(), 2);
}
@Test
public void givenASuccessObject_whenEvaluated_thenSuccess() {
Try<Integer> integer = Success(55);
assertEquals(integer.get().intValue(), 55);
}
@Test
public void givenAFailureObject_whenEvaluated_thenExceptionThrown() {
Try<Integer> failure = Failure(new Exception("Exception X encapsulated here"));
try {
Integer i = failure.get();// evaluate a failure raise the exception
System.out.println(i);// not executed
} catch (Exception e) {
assertEquals(e.getMessage(), "Exception X encapsulated here");
}
}
@Test
public void givenAList_whenCreated_thenCorrect() {
List<Integer> list = List(1, 2, 3, 4, 5);
assertEquals(list.size(), 5);
assertEquals(list.get(0).intValue(), 1);
}
@Test
public void givenAnEmptyList_whenCreated_thenCorrect() {
List<Integer> empty = List();
assertEquals(empty.size(), 0);
assertEquals(empty, List.empty());
}
@Test
public void givenAnArray_whenCreated_thenCorrect() {
Array<Integer> array = Array(1, 2, 3, 4, 5);
assertEquals(array.size(), 5);
assertEquals(array.get(0).intValue(), 1);
}
@Test
public void givenAStream_whenCreated_thenCorrect() {
Stream<Integer> stream = Stream(1, 2, 3, 4, 5);
assertEquals(stream.size(), 5);
assertEquals(stream.get(0).intValue(), 1);
}
@Test
public void givenAVector_whenCreated_thenCorrect() {
Vector<Integer> vector = Vector(1, 2, 3, 4, 5);
assertEquals(vector.size(), 5);
assertEquals(vector.get(0).intValue(), 1);
}
}

View File

@ -1,87 +1,87 @@
package com.baeldung.vavr.exception.handling;
import io.vavr.API;
import io.vavr.CheckedFunction1;
import io.vavr.Value;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
public class VavrExceptionHandlingUnitTest {
private static final Logger LOG = LoggerFactory.getLogger(VavrExceptionHandlingUnitTest.class);
private List<Integer> integers;
private List<Integer> validIntegersOnly;
@Before
public void init() {
integers = Arrays.asList(3, 9, 7, 0, 10, 20);
validIntegersOnly = Arrays.asList(3, 9, 7, 5, 10, 20);
}
@Test
public void exceptionCausingMethod_UsingCheckedFunction_ThenSuccess() {
CheckedFunction1<Integer, Integer> fn = i -> readFromFile(i);
validIntegersOnly.stream().map(fn.unchecked()).forEach(i -> LOG.debug("{}", i));
}
@Test(expected = IOException.class)
public void exceptionCausingMethod_UsingCheckedFunction_ThenFailure() {
CheckedFunction1<Integer, Integer> fn = i -> readFromFile(i);
integers.stream().map(fn.unchecked()).forEach(i -> LOG.debug("{}", i));
}
@Test
public void exceptionCausingMethod_UsingAPI_ThenSuccess() {
validIntegersOnly.stream().map(API.unchecked(i -> readFromFile(i))).forEach(i -> LOG.debug("{}", i));
}
@Test(expected = IOException.class)
public void exceptionCausingMethod_UsingAPI_ThenFailure() {
integers.stream().map(API.unchecked(i -> readFromFile(i))).forEach(i -> LOG.debug("{}", i));
}
@Test
public void exceptionCausingMethod_UsingLift_ThenSuccess() {
validIntegersOnly.stream().map(CheckedFunction1.lift(i -> readFromFile(i)))
.map(i -> i.getOrElse(-1))
.forEach(i -> {
Assert.assertNotSame(-1, i);
LOG.debug("{}", i);
});
}
@Test
public void exceptionCausingMethod_UsingLift_ThenFailure() {
integers.stream()
.map(CheckedFunction1.lift(i -> readFromFile(i)))
.map(i -> i.getOrElse(-1))
.forEach(i -> LOG.debug("{}", i));
}
@Test
public void exceptionCausingMethod_UsingTry_ThenSuccess() {
integers.stream()
.map(CheckedFunction1.liftTry(VavrExceptionHandlingUnitTest::readFromFile))
.flatMap(Value::toJavaStream)
.forEach(i -> LOG.debug("{}", i));
}
private static Integer readFromFile(Integer i) throws IOException {
if (i == 0) {
throw new IOException(); // mock IOException
}
return i * i;
}
}
package com.baeldung.vavr.exception.handling;
import io.vavr.API;
import io.vavr.CheckedFunction1;
import io.vavr.Value;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
public class VavrExceptionHandlingUnitTest {
private static final Logger LOG = LoggerFactory.getLogger(VavrExceptionHandlingUnitTest.class);
private List<Integer> integers;
private List<Integer> validIntegersOnly;
@Before
public void init() {
integers = Arrays.asList(3, 9, 7, 0, 10, 20);
validIntegersOnly = Arrays.asList(3, 9, 7, 5, 10, 20);
}
@Test
public void exceptionCausingMethod_UsingCheckedFunction_ThenSuccess() {
CheckedFunction1<Integer, Integer> fn = i -> readFromFile(i);
validIntegersOnly.stream().map(fn.unchecked()).forEach(i -> LOG.debug("{}", i));
}
@Test(expected = IOException.class)
public void exceptionCausingMethod_UsingCheckedFunction_ThenFailure() {
CheckedFunction1<Integer, Integer> fn = i -> readFromFile(i);
integers.stream().map(fn.unchecked()).forEach(i -> LOG.debug("{}", i));
}
@Test
public void exceptionCausingMethod_UsingAPI_ThenSuccess() {
validIntegersOnly.stream().map(API.unchecked(i -> readFromFile(i))).forEach(i -> LOG.debug("{}", i));
}
@Test(expected = IOException.class)
public void exceptionCausingMethod_UsingAPI_ThenFailure() {
integers.stream().map(API.unchecked(i -> readFromFile(i))).forEach(i -> LOG.debug("{}", i));
}
@Test
public void exceptionCausingMethod_UsingLift_ThenSuccess() {
validIntegersOnly.stream().map(CheckedFunction1.lift(i -> readFromFile(i)))
.map(i -> i.getOrElse(-1))
.forEach(i -> {
Assert.assertNotSame(-1, i);
LOG.debug("{}", i);
});
}
@Test
public void exceptionCausingMethod_UsingLift_ThenFailure() {
integers.stream()
.map(CheckedFunction1.lift(i -> readFromFile(i)))
.map(i -> i.getOrElse(-1))
.forEach(i -> LOG.debug("{}", i));
}
@Test
public void exceptionCausingMethod_UsingTry_ThenSuccess() {
integers.stream()
.map(CheckedFunction1.liftTry(VavrExceptionHandlingUnitTest::readFromFile))
.flatMap(Value::toJavaStream)
.forEach(i -> LOG.debug("{}", i));
}
private static Integer readFromFile(Integer i) throws IOException {
if (i == 0) {
throw new IOException(); // mock IOException
}
return i * i;
}
}