JAVA-1470 Move 10 articles to libraries-4 module
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
## Libraries
|
||||
|
||||
This module contains articles about various Java libraries.
|
||||
These are small libraries that are relatively easy to use and do not require any separate module of their own.
|
||||
|
||||
The code examples related to different libraries are each in their own module.
|
||||
|
||||
Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-modules) we already have separate modules. Please make sure to have a look at the existing modules in such cases.
|
||||
|
||||
### Relevant articles
|
||||
|
||||
- [Introduction to Javatuples](https://www.baeldung.com/java-tuples)
|
||||
- [Introduction to Javassist](https://www.baeldung.com/javassist)
|
||||
- [Introduction to Apache Flink with Java](https://www.baeldung.com/apache-flink)
|
||||
- [Intro to JaVers](https://www.baeldung.com/javers)
|
||||
- [Merging Streams in Java](https://www.baeldung.com/java-merge-streams)
|
||||
- [Introduction to Quartz](https://www.baeldung.com/quartz)
|
||||
- [How to Warm Up the JVM](https://www.baeldung.com/java-jvm-warmup)
|
||||
- [Software Transactional Memory in Java Using Multiverse](https://www.baeldung.com/java-multiverse-stm)
|
||||
- [Locality-Sensitive Hashing in Java Using Java-LSH](https://www.baeldung.com/locality-sensitive-hashing)
|
||||
- [Introduction to Neuroph](https://www.baeldung.com/neuroph)
|
||||
|
||||
#5
|
||||
- [Introduction to Caffeine](https://www.baeldung.com/java-caching-caffeine)
|
||||
- [Introduction to StreamEx](https://www.baeldung.com/streamex)
|
||||
- [A Docker Guide for Java](https://www.baeldung.com/docker-java-api)
|
||||
- [Introduction to Akka Actors in Java](https://www.baeldung.com/akka-actors-java)
|
||||
- [A Guide to Byte Buddy](https://www.baeldung.com/byte-buddy)
|
||||
- [Introduction to jOOL](https://www.baeldung.com/jool)
|
||||
- [Consumer Driven Contracts with Pact](https://www.baeldung.com/pact-junit-consumer-driven-contracts)
|
||||
- [Introduction to Atlassian Fugue](https://www.baeldung.com/java-fugue)
|
||||
- [Publish and Receive Messages with Nats Java Client](https://www.baeldung.com/nats-java-client)
|
||||
- [Java Concurrency Utility with JCTools](https://www.baeldung.com/java-concurrency-jc-tools)
|
||||
|
||||
#6
|
||||
- [Introduction to JavaPoet](https://www.baeldung.com/java-poet)
|
||||
- [Guide to Resilience4j](https://www.baeldung.com/resilience4j)
|
||||
- [Implementing a FTP-Client in Java](https://www.baeldung.com/java-ftp-client)
|
||||
- [Introduction to Functional Java](https://www.baeldung.com/java-functional-library)
|
||||
- [A Guide to the Reflections Library](https://www.baeldung.com/reflections-library)
|
||||
|
||||
- [Exactly Once Processing in Kafka](https://www.baeldung.com/kafka-exactly-once)
|
||||
- More articles [[next -->]](/libraries-2)
|
||||
@@ -0,0 +1,111 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>libraries-4</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jdeferred</groupId>
|
||||
<artifactId>jdeferred-core</artifactId>
|
||||
<version>${jdeferred.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.collections</groupId>
|
||||
<artifactId>eclipse-collections</artifactId>
|
||||
<version>${eclipse-collections.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.haulmont.yarg</groupId>
|
||||
<artifactId>yarg</artifactId>
|
||||
<version>${yarg.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.engio</groupId>
|
||||
<artifactId>mbassador</artifactId>
|
||||
<version>${mbassador.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.machinezoo.noexception</groupId>
|
||||
<artifactId>noexception</artifactId>
|
||||
<version>${noexception.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>rome</groupId>
|
||||
<artifactId>rome</artifactId>
|
||||
<version>${rome.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.datanucleus</groupId>
|
||||
<artifactId>javax.jdo</artifactId>
|
||||
<version>${javax.jdo.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>${javax.servlet.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.vavr</groupId>
|
||||
<artifactId>vavr</artifactId>
|
||||
<version>${vavr.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.pcollections</groupId>
|
||||
<artifactId>pcollections</artifactId>
|
||||
<version>${pcollections.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.awaitility</groupId>
|
||||
<artifactId>awaitility</artifactId>
|
||||
<version>${awaitility.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>one.util</groupId>
|
||||
<artifactId>streamex</artifactId>
|
||||
<version>${streamex.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.el</groupId>
|
||||
<artifactId>javax.el-api</artifactId>
|
||||
<version>${javax.el.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<jdeferred.version>1.2.6</jdeferred.version>
|
||||
<eclipse-collections.version>8.2.0</eclipse-collections.version>
|
||||
<noexception.version>1.1.0</noexception.version>
|
||||
<yarg.version>2.0.12</yarg.version>
|
||||
<mbassador.version>1.3.1</mbassador.version>
|
||||
<rome.version>1.0</rome.version>
|
||||
<spring.version>4.3.8.RELEASE</spring.version>
|
||||
<javax.servlet.version>2.5</javax.servlet.version>
|
||||
<javax.jdo.version>3.2.0-m7</javax.jdo.version>
|
||||
<vavr.version>0.9.0</vavr.version>
|
||||
<assertj.version>3.6.2</assertj.version>
|
||||
<pcollections.version>2.1.2</pcollections.version>
|
||||
<awaitility.version>3.0.0</awaitility.version>
|
||||
<streamex.version>0.6.5</streamex.version>
|
||||
<javax.el.version>3.0.0</javax.el.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.distinct;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class DistinctWithJavaFunction {
|
||||
|
||||
public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
|
||||
Map<Object, Boolean> seen = new ConcurrentHashMap<>();
|
||||
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.baeldung.distinct;
|
||||
|
||||
public class Person {
|
||||
int age;
|
||||
String name;
|
||||
String email;
|
||||
|
||||
public Person(int age, String name, String email) {
|
||||
super();
|
||||
this.age = age;
|
||||
this.name = name;
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("Person [age=");
|
||||
builder.append(age);
|
||||
builder.append(", name=");
|
||||
builder.append(name);
|
||||
builder.append(", email=");
|
||||
builder.append(email);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((email == null) ? 0 : email.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Person other = (Person) obj;
|
||||
if (email == null) {
|
||||
if (other.email != null)
|
||||
return false;
|
||||
} else if (!email.equals(other.email))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.baeldung.eclipsecollections;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.collections.impl.set.mutable.UnifiedSet;
|
||||
|
||||
public class ConvertContainerToAnother {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static List convertToList() {
|
||||
UnifiedSet<String> cars = new UnifiedSet<>();
|
||||
|
||||
cars.add("Toyota");
|
||||
cars.add("Mercedes");
|
||||
cars.add("Volkswagen");
|
||||
|
||||
return cars.toList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.baeldung.eclipsecollections;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Student {
|
||||
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private List<String> addresses;
|
||||
|
||||
public Student(String firstName, String lastName) {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public Student(String firstName, String lastName, List<String> addresses) {
|
||||
super();
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
this.addresses = addresses;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return this.firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return this.lastName;
|
||||
}
|
||||
|
||||
public List<String> getAddresses() {
|
||||
return addresses;
|
||||
}
|
||||
|
||||
public void setAddresses(List<String> addresses) {
|
||||
this.addresses = addresses;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.jdeffered;
|
||||
|
||||
import org.jdeferred.Deferred;
|
||||
import org.jdeferred.Promise;
|
||||
import org.jdeferred.impl.DeferredObject;
|
||||
|
||||
class FilterDemo {
|
||||
|
||||
private static String modifiedMsg;
|
||||
|
||||
static String filter(String msg) {
|
||||
|
||||
Deferred<String, ?, ?> d = new DeferredObject<>();
|
||||
Promise<String, ?, ?> p = d.promise();
|
||||
Promise<String, ?, ?> filtered = p.then((result) -> {
|
||||
modifiedMsg = "Hello " + result;
|
||||
});
|
||||
|
||||
filtered.done(r -> System.out.println("filtering done"));
|
||||
|
||||
d.resolve(msg);
|
||||
return modifiedMsg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.baeldung.jdeffered;
|
||||
|
||||
import org.jdeferred.Deferred;
|
||||
import org.jdeferred.DonePipe;
|
||||
import org.jdeferred.Promise;
|
||||
import org.jdeferred.impl.DeferredObject;
|
||||
|
||||
class PipeDemo {
|
||||
|
||||
public enum Result {
|
||||
SUCCESS, FAILURE
|
||||
};
|
||||
|
||||
private static Result status;
|
||||
|
||||
static Result validate(int num) {
|
||||
Deferred<Integer, ?, ?> d = new DeferredObject<>();
|
||||
Promise<Integer, ?, ?> p = d.promise();
|
||||
|
||||
p.then((DonePipe<Integer, Integer, Exception, Void>) result -> {
|
||||
if (result < 90) {
|
||||
return new DeferredObject<Integer, Exception, Void>().resolve(result);
|
||||
} else {
|
||||
return new DeferredObject<Integer, Exception, Void>().reject(new Exception("Unacceptable value"));
|
||||
}
|
||||
}).done(r -> status = Result.SUCCESS).fail(r -> status = Result.FAILURE);
|
||||
|
||||
d.resolve(num);
|
||||
|
||||
return status;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.baeldung.jdeffered;
|
||||
|
||||
import org.jdeferred.Deferred;
|
||||
import org.jdeferred.Promise;
|
||||
import org.jdeferred.impl.DeferredObject;
|
||||
|
||||
class PromiseDemo {
|
||||
|
||||
static void startJob(String jobName) {
|
||||
|
||||
Deferred<String, String, String> deferred = new DeferredObject<>();
|
||||
Promise<String, String, String> promise = deferred.promise();
|
||||
|
||||
promise.done(result -> System.out.println("Job done")).fail(rejection -> System.out.println("Job fail")).progress(progress -> System.out.println("Job is in progress")).always((state, result, rejection) -> System.out.println("Job execution started"));
|
||||
|
||||
deferred.resolve(jobName);
|
||||
// deferred.notify("");
|
||||
// deferred.reject("oops");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.baeldung.jdeffered;
|
||||
|
||||
import org.jdeferred.Deferred;
|
||||
import org.jdeferred.DeferredManager;
|
||||
import org.jdeferred.Promise;
|
||||
import org.jdeferred.impl.DefaultDeferredManager;
|
||||
import org.jdeferred.impl.DeferredObject;
|
||||
|
||||
public class ThreadSafeDemo {
|
||||
|
||||
public static void task() {
|
||||
DeferredManager dm = new DefaultDeferredManager();
|
||||
Deferred<String, String, String> deferred = new DeferredObject<>();
|
||||
Promise<String, String, String> p1 = deferred.promise();
|
||||
Promise<String, String, String> p = dm.when(p1).done(r -> System.out.println("done")).fail(r -> System.out.println("fail"));
|
||||
|
||||
synchronized (p) {
|
||||
while (p.isPending()) {
|
||||
try {
|
||||
p.wait();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
p.waitSafely();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
deferred.resolve("Hello Baeldung");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.baeldung.jdeffered.manager;
|
||||
|
||||
import org.jdeferred.Deferred;
|
||||
import org.jdeferred.DeferredManager;
|
||||
import org.jdeferred.Promise;
|
||||
import org.jdeferred.impl.DefaultDeferredManager;
|
||||
import org.jdeferred.impl.DeferredObject;
|
||||
|
||||
class DeferredManagerDemo {
|
||||
|
||||
public static void initiate() {
|
||||
Deferred<String, String, String> deferred = new DeferredObject<>();
|
||||
DeferredManager dm = new DefaultDeferredManager();
|
||||
Promise<String, String, String> p1 = deferred.promise(), p2 = deferred.promise(), p3 = deferred.promise();
|
||||
dm.when(p1, p2, p3).done((result) -> {
|
||||
System.out.println("done");
|
||||
}).fail((result) -> {
|
||||
System.out.println("fail");
|
||||
});
|
||||
deferred.resolve("Hello Baeldung");
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.baeldung.jdeffered.manager;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.jdeferred.Deferred;
|
||||
import org.jdeferred.DeferredManager;
|
||||
import org.jdeferred.Promise;
|
||||
import org.jdeferred.impl.DefaultDeferredManager;
|
||||
import org.jdeferred.impl.DeferredObject;
|
||||
|
||||
class DeferredManagerWithExecutorDemo {
|
||||
|
||||
public static void initiate() {
|
||||
ExecutorService executor = Executors.newFixedThreadPool(10);
|
||||
Deferred<String, String, String> deferred = new DeferredObject<>();
|
||||
DeferredManager dm = new DefaultDeferredManager(executor);
|
||||
Promise<String, String, String> p1 = deferred.promise(), p2 = deferred.promise(), p3 = deferred.promise();
|
||||
dm.when(p1, p2, p3).done(r -> System.out.println("done")).fail(r -> System.out.println("fail"));
|
||||
deferred.resolve("done");
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.jdeffered.manager;
|
||||
|
||||
import org.jdeferred.DeferredManager;
|
||||
import org.jdeferred.impl.DefaultDeferredManager;
|
||||
|
||||
class SimpleDeferredManagerDemo {
|
||||
|
||||
public static void initiate() {
|
||||
DeferredManager dm = new DefaultDeferredManager();
|
||||
dm.when(() -> 1).done(r -> System.out.println("done")).fail(Throwable::printStackTrace);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.baeldung.mbassador;
|
||||
|
||||
public class AckMessage extends Message {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.baeldung.mbassador;
|
||||
|
||||
public class Message {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.mbassador;
|
||||
|
||||
public class RejectMessage extends Message {
|
||||
|
||||
int code;
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.baeldung.noexception;
|
||||
|
||||
import com.machinezoo.noexception.ExceptionHandler;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CustomExceptionHandler extends ExceptionHandler {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(CustomExceptionHandler.class);
|
||||
|
||||
@Override
|
||||
public boolean handle(Throwable throwable) {
|
||||
|
||||
if (throwable.getClass().isAssignableFrom(RuntimeException.class) || throwable.getClass().isAssignableFrom(Error.class)) {
|
||||
return false;
|
||||
} else {
|
||||
logger.error("Caught Exception ", throwable);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.baeldung.pairs;
|
||||
|
||||
public class CustomPair {
|
||||
|
||||
private String key;
|
||||
private String value;
|
||||
|
||||
public CustomPair(String key, String value) {
|
||||
super();
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Object[] getPair() {
|
||||
return new Object[] { this.key, this.value};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.baeldung.rome;
|
||||
|
||||
import com.sun.syndication.feed.synd.*;
|
||||
import com.sun.syndication.io.FeedException;
|
||||
import com.sun.syndication.io.SyndFeedInput;
|
||||
import com.sun.syndication.io.SyndFeedOutput;
|
||||
import com.sun.syndication.io.XmlReader;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class RSSRomeExample {
|
||||
|
||||
public static void main(String[] args) throws IOException, FeedException {
|
||||
SyndFeed feed = createFeed();
|
||||
addEntryToFeed(feed);
|
||||
publishFeed(feed);
|
||||
readFeed();
|
||||
}
|
||||
|
||||
private static SyndFeed createFeed() {
|
||||
SyndFeed feed = new SyndFeedImpl();
|
||||
feed.setFeedType("rss_1.0");
|
||||
feed.setTitle("Test title");
|
||||
feed.setLink("http://www.somelink.com");
|
||||
feed.setDescription("Basic description");
|
||||
|
||||
return feed;
|
||||
}
|
||||
|
||||
private static void addEntryToFeed(SyndFeed feed) {
|
||||
SyndEntry entry = new SyndEntryImpl();
|
||||
entry.setTitle("Entry title");
|
||||
entry.setLink("http://www.somelink.com/entry1");
|
||||
|
||||
addDescriptionToEntry(entry);
|
||||
addCategoryToEntry(entry);
|
||||
|
||||
feed.setEntries(Arrays.asList(entry));
|
||||
}
|
||||
|
||||
private static void addDescriptionToEntry(SyndEntry entry) {
|
||||
SyndContent description = new SyndContentImpl();
|
||||
description.setType("text/html");
|
||||
description.setValue("First entry");
|
||||
|
||||
entry.setDescription(description);
|
||||
}
|
||||
|
||||
private static void addCategoryToEntry(SyndEntry entry) {
|
||||
List<SyndCategory> categories = new ArrayList<>();
|
||||
SyndCategory category = new SyndCategoryImpl();
|
||||
category.setName("Sophisticated category");
|
||||
categories.add(category);
|
||||
|
||||
entry.setCategories(categories);
|
||||
}
|
||||
|
||||
private static void publishFeed(SyndFeed feed) throws IOException, FeedException {
|
||||
Writer writer = new FileWriter("xyz.txt");
|
||||
SyndFeedOutput syndFeedOutput = new SyndFeedOutput();
|
||||
syndFeedOutput.output(feed, writer);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
private static SyndFeed readFeed() throws IOException, FeedException {
|
||||
URL feedSource = new URL("http://rssblog.whatisrss.com/feed/");
|
||||
SyndFeedInput input = new SyndFeedInput();
|
||||
return input.build(new XmlReader(feedSource));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.baeldung.yarg;
|
||||
|
||||
import com.haulmont.yarg.formatters.factory.DefaultFormatterFactory;
|
||||
import com.haulmont.yarg.loaders.factory.DefaultLoaderFactory;
|
||||
import com.haulmont.yarg.loaders.impl.JsonDataLoader;
|
||||
import com.haulmont.yarg.reporting.Reporting;
|
||||
import com.haulmont.yarg.reporting.RunParams;
|
||||
import com.haulmont.yarg.structure.Report;
|
||||
import com.haulmont.yarg.structure.ReportBand;
|
||||
import com.haulmont.yarg.structure.ReportOutputType;
|
||||
import com.haulmont.yarg.structure.impl.BandBuilder;
|
||||
import com.haulmont.yarg.structure.impl.ReportBuilder;
|
||||
import com.haulmont.yarg.structure.impl.ReportTemplateBuilder;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class DocumentController {
|
||||
|
||||
@RequestMapping(path = "/generate/doc", method = RequestMethod.GET)
|
||||
public void generateDocument(HttpServletResponse response) throws IOException {
|
||||
ReportBuilder reportBuilder = new ReportBuilder();
|
||||
ReportTemplateBuilder reportTemplateBuilder = new ReportTemplateBuilder().documentPath("./src/main/resources/Letter.docx").documentName("Letter.docx").outputType(ReportOutputType.docx).readFileFromPath();
|
||||
reportBuilder.template(reportTemplateBuilder.build());
|
||||
BandBuilder bandBuilder = new BandBuilder();
|
||||
String json = FileUtils.readFileToString(new File("./src/main/resources/Data.json"));
|
||||
ReportBand main = bandBuilder.name("Main").query("Main", "parameter=param1 $.main", "json").build();
|
||||
reportBuilder.band(main);
|
||||
Report report = reportBuilder.build();
|
||||
|
||||
Reporting reporting = new Reporting();
|
||||
reporting.setFormatterFactory(new DefaultFormatterFactory());
|
||||
reporting.setLoaderFactory(new DefaultLoaderFactory().setJsonDataLoader(new JsonDataLoader()));
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
|
||||
reporting.runReport(new RunParams(report).param("param1", json), response.getOutputStream());
|
||||
}
|
||||
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.baeldung.distinct;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.collections.impl.block.factory.HashingStrategies;
|
||||
import org.eclipse.collections.impl.utility.ListIterate;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DistinctWithEclipseCollectionsUnitTest {
|
||||
List<Person> personList;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
personList = PersonDataGenerator.getPersonListWithFakeValues();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFilterListByName_thenSizeShouldBe4() {
|
||||
List<Person> personListFiltered = ListIterate.distinct(personList, HashingStrategies.fromFunction(Person::getName));
|
||||
assertTrue(personListFiltered.size() == 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFilterListByAge_thenSizeShouldBe2() {
|
||||
List<Person> personListFiltered = ListIterate.distinct(personList, HashingStrategies.fromIntFunction(Person::getAge));
|
||||
assertTrue(personListFiltered.size() == 2);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.baeldung.distinct;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static com.baeldung.distinct.DistinctWithJavaFunction.distinctByKey;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DistinctWithJavaFunctionUnitTest {
|
||||
List<Person> personList;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
personList = PersonDataGenerator.getPersonListWithFakeValues();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFilterListByName_thenSizeShouldBe4() {
|
||||
List<Person> personListFiltered = personList.stream().filter(distinctByKey(p -> p.getName())).collect(Collectors.toList());
|
||||
assertTrue(personListFiltered.size() == 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFilterListByAge_thenSizeShouldBe2() {
|
||||
List<Person> personListFiltered = personList.stream().filter(distinctByKey(p -> p.getAge())).collect(Collectors.toList());
|
||||
assertTrue(personListFiltered.size() == 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFilterListWithDefaultDistinct_thenSizeShouldBe5() {
|
||||
List<Person> personListFiltered = personList.stream().distinct().collect(Collectors.toList());
|
||||
assertTrue(personListFiltered.size() == 5);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.baeldung.distinct;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import one.util.streamex.StreamEx;
|
||||
|
||||
public class DistinctWithStreamexUnitTest {
|
||||
List<Person> personList;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
personList = PersonDataGenerator.getPersonListWithFakeValues();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFilterListByName_thenSizeShouldBe4() {
|
||||
List<Person> personListFiltered = StreamEx.of(personList).distinct(Person::getName).toList();
|
||||
assertTrue(personListFiltered.size() == 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFilterListByAge_thenSizeShouldBe2() {
|
||||
List<Person> personListFiltered = StreamEx.of(personList).distinct(Person::getAge).toList();
|
||||
assertTrue(personListFiltered.size() == 2);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.baeldung.distinct;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DistinctWithVavrUnitTest {
|
||||
List<Person> personList;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
personList = PersonDataGenerator.getPersonListWithFakeValues();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFilterListByName_thenSizeShouldBe4() {
|
||||
List<Person> personListFiltered = io.vavr.collection.List.ofAll(personList).distinctBy(Person::getName).toJavaList();
|
||||
assertTrue(personListFiltered.size() == 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFilterListByAge_thenSizeShouldBe2() {
|
||||
List<Person> personListFiltered = io.vavr.collection.List.ofAll(personList).distinctBy(Person::getAge).toJavaList();
|
||||
assertTrue(personListFiltered.size() == 2);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.baeldung.distinct;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class PersonDataGenerator {
|
||||
|
||||
public static List<Person> getPersonListWithFakeValues() {
|
||||
// @formatter:off
|
||||
return Arrays.asList(
|
||||
new Person(20, "Jhon", "[email protected]"),
|
||||
new Person(20, "Jhon", "[email protected]"),
|
||||
new Person(20, "Jhon", "[email protected]"),
|
||||
new Person(21, "Tom", "[email protected]"),
|
||||
new Person(21, "Mark", "[email protected]"),
|
||||
new Person(20, "Julia", "[email protected]"));
|
||||
// @formatter:on
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.baeldung.eclipsecollections;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.eclipse.collections.api.list.MutableList;
|
||||
import org.eclipse.collections.impl.block.factory.Predicates;
|
||||
import org.eclipse.collections.impl.list.mutable.FastList;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AllSatisfyPatternUnitTest {
|
||||
|
||||
MutableList<Integer> list;
|
||||
|
||||
@Before
|
||||
public void getList() {
|
||||
this.list = FastList.newListWith(1, 8, 5, 41, 31, 17, 23, 38);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAnySatisfiesCondition_thenCorrect() {
|
||||
boolean result = list.allSatisfy(Predicates.greaterThan(0));
|
||||
|
||||
assertTrue(result);
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.baeldung.eclipsecollections;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.eclipse.collections.api.list.MutableList;
|
||||
import org.eclipse.collections.impl.block.factory.Predicates;
|
||||
import org.eclipse.collections.impl.list.mutable.FastList;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AnySatisfyPatternUnitTest {
|
||||
|
||||
MutableList<Integer> list;
|
||||
|
||||
@Before
|
||||
public void getList() {
|
||||
this.list = FastList.newListWith(1, 8, 5, 41, 31, 17, 23, 38);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAnySatisfiesCondition_thenCorrect() {
|
||||
boolean result = list.anySatisfy(Predicates.greaterThan(30));
|
||||
|
||||
assertTrue(result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.baeldung.eclipsecollections;
|
||||
|
||||
import org.eclipse.collections.api.list.MutableList;
|
||||
import org.eclipse.collections.impl.list.mutable.FastList;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CollectPatternUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCollect_thenCorrect() {
|
||||
Student student1 = new Student("John", "Hopkins");
|
||||
Student student2 = new Student("George", "Adams");
|
||||
|
||||
MutableList<Student> students = FastList.newListWith(student1, student2);
|
||||
|
||||
MutableList<String> lastNames = students.collect(Student::getLastName);
|
||||
|
||||
Assertions.assertThat(lastNames).containsExactly("Hopkins", "Adams");
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.eclipsecollections;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.eclipse.collections.api.list.MutableList;
|
||||
import org.eclipse.collections.impl.list.mutable.FastList;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ConvertContainerToAnotherUnitTest {
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Test
|
||||
public void whenConvertContainerToAnother_thenCorrect() {
|
||||
MutableList<String> cars = (MutableList) ConvertContainerToAnother.convertToList();
|
||||
|
||||
Assertions.assertThat(cars).containsExactlyElementsOf(FastList.newListWith("Volkswagen", "Toyota", "Mercedes"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.baeldung.eclipsecollections;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.eclipse.collections.api.list.MutableList;
|
||||
import org.eclipse.collections.impl.block.factory.Predicates;
|
||||
import org.eclipse.collections.impl.list.mutable.FastList;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DetectPatternUnitTest {
|
||||
|
||||
MutableList<Integer> list;
|
||||
|
||||
@Before
|
||||
public void getList() {
|
||||
this.list = FastList.newListWith(1, 8, 5, 41, 31, 17, 23, 38);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDetect_thenCorrect() {
|
||||
Integer result = list.detect(Predicates.greaterThan(30));
|
||||
|
||||
Assertions.assertThat(result).isEqualTo(41);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user