Skip to content

Commit ea07c11

Browse files
committed
Merge branch 'master' into BAEL-7919
2 parents cef0aa6 + 17aa1b5 commit ea07c11

File tree

12 files changed

+294
-12
lines changed

12 files changed

+294
-12
lines changed

core-java-modules/core-java-reflection-3/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
<artifactId>reflections</artifactId>
3131
<version>${reflections.version}</version>
3232
</dependency>
33+
<dependency>
34+
<groupId>commons-beanutils</groupId>
35+
<artifactId>commons-beanutils</artifactId>
36+
<version>1.11.0</version>
37+
</dependency>
3338
</dependencies>
3439

3540
<build>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.baeldung.reflectionbeans;
2+
3+
import org.apache.commons.beanutils.BeanUtils;
4+
5+
import java.util.Map;
6+
7+
public class BeanUtilsDemo {
8+
9+
public static void main(String[] args) throws Exception {
10+
Post post = new Post();
11+
BeanUtils.setProperty(post, "title", "Commons BeanUtils Rocks");
12+
String title = BeanUtils.getProperty(post, "title");
13+
14+
Map<String, Object> data = Map.of(
15+
"title", "Map → Bean",
16+
"author", "Baeldung Team"
17+
);
18+
19+
BeanUtils.populate(post, data);
20+
Post source = new Post();
21+
source.setTitle("Source");
22+
source.setAuthor("Alice");
23+
24+
Post target = new Post();
25+
BeanUtils.copyProperties(target, source);
26+
System.out.println(title);
27+
}
28+
29+
public static void safeCopy(Object target, Object source) {
30+
try {
31+
BeanUtils.copyProperties(target, source);
32+
} catch (ReflectiveOperationException ex) {
33+
throw new IllegalStateException(ex);
34+
}
35+
}
36+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung.reflectionbeans;
2+
3+
public class Post {
4+
5+
private String title;
6+
private String author;
7+
8+
public String getTitle() { return title; }
9+
public void setTitle(String title) { this.title = title; }
10+
11+
public String getAuthor() { return author; }
12+
public void setAuthor(String author) { this.author = author; }
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.baeldung.reflectionbeans;
2+
3+
import java.beans.BeanInfo;
4+
import java.beans.Introspector;
5+
import java.beans.PropertyDescriptor;
6+
import java.lang.reflect.Method;
7+
8+
public class PropertyDescriptorDemo {
9+
10+
public static void main(String[] args) throws Exception {
11+
BeanInfo beanInfo = Introspector.getBeanInfo(Post.class);
12+
13+
for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
14+
System.out.println(pd.getName());
15+
}
16+
17+
Post post = new Post();
18+
PropertyDescriptor titlePd = new PropertyDescriptor("title", Post.class);
19+
20+
Method write = titlePd.getWriteMethod();
21+
Method read = titlePd.getReadMethod();
22+
23+
24+
write.invoke(post, "Reflections in Java");
25+
String value = (String) read.invoke(post);
26+
27+
System.out.println(value);
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.baeldung.reflectionbeans;
2+
3+
import org.apache.commons.beanutils.BeanUtils;
4+
import org.junit.Test;
5+
6+
import java.util.Map;
7+
8+
import static org.junit.Assert.assertEquals;
9+
10+
public class BeanUtilsUnitTest {
11+
12+
@Test
13+
public void givenPost_whenPopulate_thenFieldsAreSet() throws Exception {
14+
Post post = new Post();
15+
Map<String, Object> data = Map.of("title", "Populate Test", "author", "Dana");
16+
17+
BeanUtils.populate(post, data);
18+
19+
assertEquals("Populate Test", BeanUtils.getProperty(post, "title"));
20+
assertEquals("Dana", BeanUtils.getProperty(post, "author"));
21+
}
22+
23+
@Test
24+
public void givenTwoPosts_whenCopyProperties_thenTargetMatchesSource() throws Exception {
25+
Post source = new Post();
26+
source.setTitle("Copy");
27+
source.setAuthor("Eve");
28+
29+
Post target = new Post();
30+
BeanUtils.copyProperties(target, source);
31+
32+
assertEquals("Copy", target.getTitle());
33+
assertEquals("Eve", target.getAuthor());
34+
}
35+
}
36+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung.reflectionbeans;
2+
3+
import org.junit.Test;
4+
5+
import java.beans.PropertyDescriptor;
6+
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
public class PropertyDescriptorUnitTest {
10+
11+
@Test
12+
public void givenPost_whenUsingPropertyDescriptor_thenReadAndWrite() throws Exception {
13+
Post post = new Post();
14+
PropertyDescriptor pd = new PropertyDescriptor("author", Post.class);
15+
16+
pd.getWriteMethod().invoke(post, "Chris");
17+
assertEquals("Chris", pd.getReadMethod().invoke(post));
18+
}
19+
}

core-java-modules/core-java-security/pom.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,10 @@
4242
<groupId>org.apache.maven.plugins</groupId>
4343
<artifactId>maven-surefire-plugin</artifactId>
4444
<version>${maven-surefire-plugin.version}</version>
45-
<configuration>
46-
<argLine>--add-opens java.base/sun.security.x509=ALL-UNNAMED</argLine>
47-
<argLine>--add-exports java.base/sun.security.util=ALL-UNNAMED</argLine>
48-
</configuration>
4945
</plugin>
5046
<plugin>
5147
<groupId>org.apache.maven.plugins</groupId>
5248
<artifactId>maven-compiler-plugin</artifactId>
53-
<configuration>
54-
<compilerArgs>
55-
<arg>--add-exports</arg>
56-
<arg>java.base/sun.security.x509=ALL-UNNAMED</arg>
57-
<arg>--add-exports</arg>
58-
<arg>java.base/sun.security.util=ALL-UNNAMED</arg>
59-
</compilerArgs>
60-
</configuration>
6149
</plugin>
6250
</plugins>
6351
</build>

reactor-core-2/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@
3737
<version>${lombok.version}</version>
3838
<scope>test</scope>
3939
</dependency>
40+
<dependency>
41+
<groupId>org.openjdk.jmh</groupId>
42+
<artifactId>jmh-core</artifactId>
43+
<version>${jmh-core.version}</version>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.openjdk.jmh</groupId>
47+
<artifactId>jmh-generator-annprocess</artifactId>
48+
<version>${jmh-generator.version}</version>
49+
<scope>provided</scope>
50+
</dependency>
4051
</dependencies>
4152

4253
<properties>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.baeldung.reactor.flux.parallelflux;
2+
3+
public class Fibonacci {
4+
public static long fibonacci(int n) {
5+
if (n <= 1) return n;
6+
return fibonacci(n - 1) + fibonacci(n - 2);
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.baeldung.reactor.flux.parallelflux;
2+
3+
import org.openjdk.jmh.annotations.*;
4+
import reactor.core.publisher.Flux;
5+
import reactor.core.publisher.ParallelFlux;
6+
import reactor.core.scheduler.Schedulers;
7+
8+
import java.util.List;
9+
import java.util.concurrent.TimeUnit;
10+
11+
@BenchmarkMode(Mode.AverageTime)
12+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
13+
@State(Scope.Thread)
14+
public class FibonacciFluxParallelFluxBenchmark {
15+
16+
@Benchmark
17+
public List<Long> benchMarkParallelFluxSequential() {
18+
ParallelFlux<Long> parallelFluxFibonacci = Flux.just(43, 44, 45, 47, 48)
19+
.parallel(3)
20+
.runOn(Schedulers.parallel())
21+
.map(Fibonacci::fibonacci);
22+
23+
return parallelFluxFibonacci.sequential().collectList().block();
24+
}
25+
26+
@Benchmark
27+
public List<Long> benchMarkFluxSequential() {
28+
Flux<Long> fluxFibonacci = Flux.just(43, 44, 45, 47, 48)
29+
.map(Fibonacci::fibonacci);
30+
31+
return fluxFibonacci.collectList().block();
32+
}
33+
}

0 commit comments

Comments
 (0)