Skip to content

Commit 5e3ab6f

Browse files
committed
Merge remote-tracking branch 'eugenp/master'
2 parents e11d08b + d74c882 commit 5e3ab6f

31 files changed

Lines changed: 1204 additions & 538 deletions

File tree

‎algorithms/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
- [Introduction to JGraphT](http://www.baeldung.com/jgrapht)
1616
- [Introduction to Minimax Algorithm](http://www.baeldung.com/java-minimax-algorithm)
1717
- [How to Calculate Levenshtein Distance in Java?](http://www.baeldung.com/java-levenshtein-distance)
18+
- [How to Find the Kth Largest Element in Java](http://www.baeldung.com/java-kth-largest-element)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.baeldung.staticclass;
2+
3+
public class Pizza {
4+
5+
private static String cookedCount;
6+
private boolean isThinCrust;
7+
8+
// Accessible globally
9+
public static class PizzaSalesCounter {
10+
11+
private static String orderedCount;
12+
public static String deliveredCount;
13+
14+
PizzaSalesCounter() {
15+
System.out.println("Static field of enclosing class is "
16+
+ Pizza.cookedCount);
17+
System.out.println("Non-static field of enclosing class is "
18+
+ new Pizza().isThinCrust);
19+
}
20+
}
21+
22+
Pizza() {
23+
System.out.println("Non private static field of static class is "
24+
+ PizzaSalesCounter.deliveredCount);
25+
System.out.println("Private static field of static class is "
26+
+ PizzaSalesCounter.orderedCount);
27+
}
28+
29+
public static void main(String[] a) {
30+
// Create instance of the static class without an instance of enclosing class
31+
new Pizza.PizzaSalesCounter();
32+
}
33+
}

‎java-vavr-stream/pom.xml‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.baeldung.samples</groupId>
5+
<artifactId>java-vavr-stream</artifactId>
6+
<version>1.0</version>
7+
<packaging>jar</packaging>
8+
<properties>
9+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10+
<maven.compiler.source>1.8</maven.compiler.source>
11+
<maven.compiler.target>1.8</maven.compiler.target>
12+
</properties>
13+
<dependencies>
14+
<dependency>
15+
<groupId>io.vavr</groupId>
16+
<artifactId>vavr</artifactId>
17+
<version>0.9.2</version>
18+
</dependency>
19+
</dependencies>
20+
</project>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package com.baeldung.samples.java.vavr;
2+
3+
import io.vavr.collection.Stream;
4+
import java.util.ArrayList;
5+
import java.util.Arrays;
6+
import java.util.List;
7+
import java.util.stream.IntStream;
8+
9+
/**
10+
*
11+
* @author baeldung
12+
*/
13+
public class VavrSampler {
14+
15+
static int[] intArray = new int[]{1, 2, 4};
16+
static List<Integer> intList = new ArrayList<Integer>();
17+
static int[][] intOfInts = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
18+
19+
public static void main(String[] args) {
20+
vavrStreamElementAccess();
21+
System.out.println("====================================");
22+
vavrParallelStreamAccess();
23+
System.out.println("====================================");
24+
jdkFlatMapping();
25+
System.out.println("====================================");
26+
vavrStreamManipulation();
27+
System.out.println("====================================");
28+
vavrStreamDistinct();
29+
}
30+
31+
public static void vavrStreamElementAccess() {
32+
System.out.println("Vavr Element Access");
33+
System.out.println("====================================");
34+
Stream<Integer> vavredStream = Stream.ofAll(intArray);
35+
System.out.println("Vavr index access: " + vavredStream.get(2));
36+
System.out.println("Vavr head element access: " + vavredStream.get());
37+
38+
Stream<String> vavredStringStream = Stream.of("foo", "bar", "baz");
39+
System.out.println("Find foo " + vavredStringStream.indexOf("foo"));
40+
}
41+
42+
public static void vavrParallelStreamAccess() {
43+
try {
44+
System.out.println("Vavr Stream Concurrent Modification");
45+
System.out.println("====================================");
46+
Stream<Integer> vavrStream = Stream.ofAll(intList);
47+
intList.add(5);
48+
vavrStream.forEach(i -> System.out.println("in a Vavr Stream: " + i));
49+
} catch (Exception ex) {
50+
ex.printStackTrace();
51+
}
52+
53+
Stream<Integer> wrapped = Stream.ofAll(intArray);
54+
intArray[2] = 5;
55+
wrapped.forEach(i -> System.out.println("Vavr looped " + i));
56+
}
57+
58+
public static void jdkFlatMapping() {
59+
System.out.println("JDK FlatMap -> Uncomment line 68 to test");
60+
System.out.println("====================================");
61+
int[][] intOfInts = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
62+
63+
IntStream mapToInt = Arrays.stream(intOfInts)
64+
.map(intArr -> Arrays.stream(intArr))
65+
.flatMapToInt(val -> val.map(n -> {
66+
return n * n;
67+
}))
68+
.peek(n -> System.out.println("Peeking at " + n));
69+
//Uncomment to execute pipeline
70+
//mapToInt.forEach(n -> System.out.println("FlatMapped Result "+n));
71+
}
72+
73+
public static void vavrStreamManipulation() {
74+
System.out.println("Vavr Stream Manipulation");
75+
System.out.println("====================================");
76+
List<String> stringList = new ArrayList<>();
77+
stringList.add("foo");
78+
stringList.add("bar");
79+
stringList.add("baz");
80+
Stream<String> vavredStream = Stream.ofAll(stringList);
81+
vavredStream.forEach(item -> System.out.println("Vavr Stream item: " + item));
82+
Stream<String> vavredStream2 = vavredStream.insert(2, "buzz");
83+
vavredStream2.forEach(item -> System.out.println("Vavr Stream item after stream addition: " + item));
84+
stringList.forEach(item -> System.out.println("List item after stream addition: " + item));
85+
Stream<String> deletionStream = vavredStream.remove("bar");
86+
deletionStream.forEach(item -> System.out.println("Vavr Stream item after stream item deletion: " + item));
87+
88+
}
89+
90+
public static void vavrStreamDistinct() {
91+
Stream<String> vavredStream = Stream.of("foo", "bar", "baz", "buxx", "bar", "bar", "foo");
92+
Stream<String> distinctVavrStream = vavredStream.distinctBy((y, z) -> {
93+
return y.compareTo(z);
94+
});
95+
distinctVavrStream.forEach(item -> System.out.println("Vavr Stream item after distinct query " + item));
96+
97+
}
98+
}

‎pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
<!-- <module>persistence-modules/java-cassandra</module> -->
8888
<module>vavr</module>
8989
<module>java-lite</module>
90+
<module>java-vavr-stream</module>
9091
<module>javax-servlets</module>
9192
<module>javaxval</module>
9293
<module>jaxb</module>
@@ -203,7 +204,6 @@
203204
<module>spring-protobuf</module>
204205
<module>spring-quartz</module>
205206
<module>spring-rest-angular</module>
206-
<module>spring-rest-docs</module>
207207
<module>spring-rest-full</module>
208208
<module>spring-rest-query-language</module>
209209
<module>spring-rest</module>

‎spring-5/README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
1212
- [Spring 5 Functional Bean Registration](http://www.baeldung.com/spring-5-functional-beans)
1313
- [The SpringJUnitConfig and SpringJUnitWebConfig Annotations in Spring 5](http://www.baeldung.com/spring-5-junit-config)
1414
- [Spring Security 5 for Reactive Applications](http://www.baeldung.com/spring-security-5-reactive)
15-
- [Spring 5 Testing with @EnabledIf Annotation](https://github.com/eugenp/tutorials/tree/master/spring-5)
15+
- [Spring 5 Testing with @EnabledIf Annotation](http://www.baeldung.com/sring-5-enabledif)
16+
- [Introduction to Spring REST Docs](http://www.baeldung.com/spring-rest-docs)

‎spring-5/pom.xml‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@
3939
<groupId>org.springframework.boot</groupId>
4040
<artifactId>spring-boot-starter-webflux</artifactId>
4141
</dependency>
42+
<dependency>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-starter-hateoas</artifactId>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.springframework.boot</groupId>
48+
<artifactId>spring-boot-starter-actuator</artifactId>
49+
</dependency>
4250
<dependency>
4351
<groupId>org.projectreactor</groupId>
4452
<artifactId>reactor-spring</artifactId>
@@ -135,6 +143,23 @@
135143
<version>${junit.platform.version}</version>
136144
<scope>test</scope>
137145
</dependency>
146+
<!-- restdocs -->
147+
<dependency>
148+
<groupId>org.springframework.restdocs</groupId>
149+
<artifactId>spring-restdocs-mockmvc</artifactId>
150+
<scope>test</scope>
151+
</dependency>
152+
<dependency>
153+
<groupId>org.springframework.restdocs</groupId>
154+
<artifactId>spring-restdocs-webtestclient</artifactId>
155+
<scope>test</scope>
156+
</dependency>
157+
<dependency>
158+
<groupId>org.springframework.restdocs</groupId>
159+
<artifactId>spring-restdocs-restassured</artifactId>
160+
<scope>test</scope>
161+
</dependency>
162+
138163

139164
</dependencies>
140165

@@ -163,6 +188,29 @@
163188
</excludes>
164189
</configuration>
165190
</plugin>
191+
<plugin>
192+
<groupId>org.asciidoctor</groupId>
193+
<artifactId>asciidoctor-maven-plugin</artifactId>
194+
<version>${asciidoctor-plugin.version}</version>
195+
<executions>
196+
<execution>
197+
<id>generate-docs</id>
198+
<phase>package</phase>
199+
<goals>
200+
<goal>process-asciidoc</goal>
201+
</goals>
202+
<configuration>
203+
<backend>html</backend>
204+
<doctype>book</doctype>
205+
<attributes>
206+
<snippets>${snippetsDirectory}</snippets>
207+
</attributes>
208+
<sourceDirectory>src/docs/asciidocs</sourceDirectory>
209+
<outputDirectory>target/generated-docs</outputDirectory>
210+
</configuration>
211+
</execution>
212+
</executions>
213+
</plugin>
166214
</plugins>
167215
</build>
168216

@@ -199,6 +247,8 @@
199247
<johnzon.version>1.1.3</johnzon.version>
200248
<jsonb-api.version>1.0</jsonb-api.version>
201249
<geronimo-json_1.1_spec.version>1.0</geronimo-json_1.1_spec.version>
250+
<asciidoctor-plugin.version>1.5.6</asciidoctor-plugin.version>
251+
<snippetsDirectory>${project.build.directory}/generated-snippets</snippetsDirectory>
202252
</properties>
203253

204254
</project>

spring-rest-docs/src/docs/asciidocs/api-guide.adoc renamed to spring-5/src/docs/asciidocs/api-guide.adoc

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@ use of HTTP status codes.
5555
| The requested resource did not exist
5656
|===
5757

58-
[[overview-headers]]
59-
== Headers
60-
61-
Every response has the following header(s):
62-
63-
include::{snippets}/headers-example/response-headers.adoc[]
64-
6558
[[overview-hypermedia]]
6659
== Hypermedia
6760

@@ -86,18 +79,14 @@ The index provides the entry point into the service.
8679

8780
A `GET` request is used to access the index
8881

89-
==== Response structure
82+
==== Request structure
9083

91-
include::{snippets}/index-example/http-response.adoc[]
84+
include::{snippets}/index-example/http-request.adoc[]
9285

9386
==== Example response
9487

9588
include::{snippets}/index-example/http-response.adoc[]
9689

97-
==== Example request
98-
99-
include::{snippets}/index-example/http-request.adoc[]
100-
10190
==== CURL request
10291

10392
include::{snippets}/index-example/curl-request.adoc[]
@@ -113,12 +102,12 @@ include::{snippets}/index-example/links.adoc[]
113102

114103
The CRUD provides the entry point into the service.
115104

116-
[[resources-crud-access]]
105+
[[resources-crud-get]]
117106
=== Accessing the crud GET
118107

119-
A `GET` request is used to access the CRUD read
108+
A `GET` request is used to access the CRUD read.
120109

121-
==== Response structure
110+
==== Request structure
122111

123112
include::{snippets}/crud-get-example/http-request.adoc[]
124113

@@ -130,12 +119,12 @@ include::{snippets}/crud-get-example/http-response.adoc[]
130119

131120
include::{snippets}/crud-get-example/curl-request.adoc[]
132121

133-
[[resources-crud-access]]
122+
[[resources-crud-post]]
134123
=== Accessing the crud POST
135124

136-
A `POST` request is used to access the CRUD create
125+
A `POST` request is used to access the CRUD create.
137126

138-
==== Response structure
127+
==== Request structure
139128

140129
include::{snippets}/crud-create-example/http-request.adoc[]
141130

@@ -147,15 +136,18 @@ include::{snippets}/crud-create-example/http-response.adoc[]
147136

148137
include::{snippets}/crud-create-example/curl-request.adoc[]
149138

150-
[[resources-crud-access]]
139+
[[resources-crud-delete]]
151140
=== Accessing the crud DELETE
152141

153-
A `DELETE` request is used to access the CRUD create
142+
A `DELETE` request is used to access the CRUD delete.
154143

155-
==== Response structure
144+
==== Request structure
156145

157146
include::{snippets}/crud-delete-example/http-request.adoc[]
158147

148+
==== Path Parameters
149+
include::{snippets}/crud-delete-example/path-parameters.adoc[]
150+
159151
==== Example response
160152

161153
include::{snippets}/crud-delete-example/http-response.adoc[]
@@ -164,12 +156,12 @@ include::{snippets}/crud-delete-example/http-response.adoc[]
164156

165157
include::{snippets}/crud-delete-example/curl-request.adoc[]
166158

167-
[[resources-crud-access]]
159+
[[resources-crud-patch]]
168160
=== Accessing the crud PATCH
169161

170-
A `PATCH` request is used to access the CRUD create
162+
A `PATCH` request is used to access the CRUD update.
171163

172-
==== Response structure
164+
==== Request structure
173165

174166
include::{snippets}/crud-patch-example/http-request.adoc[]
175167

@@ -181,12 +173,12 @@ include::{snippets}/crud-patch-example/http-response.adoc[]
181173

182174
include::{snippets}/crud-patch-example/curl-request.adoc[]
183175

184-
[[resources-crud-access]]
176+
[[resources-crud-put]]
185177
=== Accessing the crud PUT
186178

187-
A `PUT` request is used to access the CRUD create
179+
A `PUT` request is used to access the CRUD update.
188180

189-
==== Response structure
181+
==== Request structure
190182

191183
include::{snippets}/crud-put-example/http-request.adoc[]
192184

0 commit comments

Comments
 (0)