Skip to content

Commit 52a6632

Browse files
committed
Merge branch 'master' of https://github.com/eugenp/tutorials.git
2 parents 04bdeb6 + 106177b commit 52a6632

72 files changed

Lines changed: 2736 additions & 104 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎core-java-9/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
## Core Java 9 Examples
44

5-
http://inprogress.baeldung.com/java-9-new-features/
5+
[Java 9 New Features](http://www.baeldung.com/new-java-9)
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package com.baeldung.java9.language.stream;
2+
3+
import org.junit.Test;
4+
5+
import java.util.Arrays;
6+
import java.util.HashMap;
7+
import java.util.List;
8+
import java.util.Map;
9+
import java.util.stream.Collectors;
10+
import java.util.stream.Stream;
11+
12+
import static java.lang.Integer.*;
13+
import static org.junit.Assert.assertEquals;
14+
15+
public class StreamFeaturesTest {
16+
17+
public static class TakeAndDropWhileTest {
18+
19+
public Stream<String> getStreamAfterTakeWhileOperation() {
20+
return Stream
21+
.iterate("", s -> s + "s")
22+
.takeWhile(s -> s.length() < 10);
23+
}
24+
25+
public Stream<String> getStreamAfterDropWhileOperation() {
26+
return Stream
27+
.iterate("", s -> s + "s")
28+
.takeWhile(s -> s.length() < 10)
29+
.dropWhile(s -> !s.contains("sssss"));
30+
}
31+
32+
@Test
33+
public void testTakeWhileOperation() {
34+
List<String> list = getStreamAfterTakeWhileOperation().collect(Collectors.toList());
35+
36+
assertEquals(10, list.size());
37+
38+
assertEquals("", list.get(0));
39+
assertEquals("ss", list.get(2));
40+
assertEquals("sssssssss", list.get(list.size() - 1));
41+
}
42+
43+
@Test
44+
public void testDropWhileOperation() {
45+
List<String> list = getStreamAfterDropWhileOperation().collect(Collectors.toList());
46+
47+
assertEquals(5, list.size());
48+
49+
assertEquals("sssss", list.get(0));
50+
assertEquals("sssssss", list.get(2));
51+
assertEquals("sssssssss", list.get(list.size() - 1));
52+
}
53+
54+
}
55+
56+
public static class IterateTest {
57+
58+
private Stream<Integer> getStream() {
59+
return Stream.iterate(0, i -> i < 10, i -> i + 1);
60+
}
61+
62+
@Test
63+
public void testIterateOperation() {
64+
List<Integer> list = getStream().collect(Collectors.toList());
65+
66+
assertEquals(10, list.size());
67+
68+
assertEquals(valueOf(0), list.get(0));
69+
assertEquals(valueOf(5), list.get(5));
70+
assertEquals(valueOf(9), list.get(list.size() - 1));
71+
}
72+
73+
}
74+
75+
public static class OfNullableTest {
76+
77+
private List<String> collection = Arrays.asList("A", "B", "C");
78+
private Map<String, Integer> map = new HashMap<>() {{
79+
put("A", 10);
80+
put("C", 30);
81+
}};
82+
83+
private Stream<Integer> getStreamWithOfNullable() {
84+
return collection.stream()
85+
.flatMap(s -> Stream.ofNullable(map.get(s)));
86+
}
87+
88+
private Stream<Integer> getStream() {
89+
return collection.stream()
90+
.flatMap(s -> {
91+
Integer temp = map.get(s);
92+
return temp != null ? Stream.of(temp) : Stream.empty();
93+
});
94+
}
95+
96+
private List<Integer> testOfNullableFrom(Stream<Integer> stream) {
97+
List<Integer> list = stream.collect(Collectors.toList());
98+
99+
assertEquals(2, list.size());
100+
101+
assertEquals(valueOf(10), list.get(0));
102+
assertEquals(valueOf(30), list.get(list.size() - 1));
103+
104+
return list;
105+
}
106+
107+
@Test
108+
public void testOfNullable() {
109+
110+
assertEquals(
111+
testOfNullableFrom(getStream()),
112+
testOfNullableFrom(getStreamWithOfNullable())
113+
);
114+
115+
}
116+
117+
}
118+
119+
}

‎core-java/0.12457740242410742‎

Whitespace-only changes.

‎core-java/README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@
3535
- [Java 8 Streams Advanced](http://www.baeldung.com/java-8-streams)
3636
- [Introduction to Thread Pools in Java](http://www.baeldung.com/thread-pool-java-and-guava)
3737
- [Introduction to Java 8 Streams](http://www.baeldung.com/java-8-streams-introduction)
38-
- [Guide to the Fork/Join Framework in Java](http://www.baeldung.com/java-fork-join)
38+
- [Guide to the Fork/Join Framework in Java](http://www.baeldung.com/java-fork-join)
39+
- [How to Print Screen in Java](http://www.baeldung.com/print-screen-in-java)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.baeldung.java.conversion;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import java.io.UnsupportedEncodingException;
6+
import java.text.ParseException;
7+
import java.text.SimpleDateFormat;
8+
import java.time.LocalDateTime;
9+
import java.time.Month;
10+
import java.util.Arrays;
11+
import java.util.Calendar;
12+
import java.util.Date;
13+
import java.util.GregorianCalendar;
14+
15+
import org.junit.Test;
16+
17+
import com.baeldung.datetime.UseLocalDateTime;
18+
19+
public class StringConversionTest {
20+
21+
@Test
22+
public void whenConvertedToInt_thenCorrect() {
23+
assertEquals(Integer.parseInt("1"), 1);
24+
}
25+
26+
@Test
27+
public void whenConvertedToInteger_thenCorrect() {
28+
assertEquals(Integer.valueOf("12").equals(12), true);
29+
}
30+
31+
@Test
32+
public void whenConvertedTolong_thenCorrect() {
33+
assertEquals(Long.parseLong("12345"), 12345);
34+
}
35+
36+
@Test
37+
public void whenConvertedToLong_thenCorrect() {
38+
assertEquals(Long.valueOf("14567").equals(14567L), true);
39+
}
40+
41+
@Test
42+
public void whenConvertedTodouble_thenCorrect() {
43+
assertEquals(Double.parseDouble("1.4"), 1.4, 0.0);
44+
}
45+
46+
@Test
47+
public void whenConvertedToDouble_thenCorrect() {
48+
assertEquals(Double.valueOf("145.67").equals(145.67d), true);
49+
}
50+
51+
@Test
52+
public void whenConvertedToByteArray_thenCorrect() throws UnsupportedEncodingException {
53+
byte[] byteArray1 = new byte[] { 'a', 'b', 'c' };
54+
String string = new String(byteArray1, "UTF-8");
55+
56+
assertEquals(Arrays.equals(string.getBytes(), byteArray1), true);
57+
}
58+
59+
@Test
60+
public void whenConvertedToboolean_thenCorrect() {
61+
assertEquals(Boolean.parseBoolean("true"), true);
62+
}
63+
64+
@Test
65+
public void whenConvertedToBoolean_thenCorrect() {
66+
assertEquals(Boolean.valueOf("true"), true);
67+
}
68+
69+
@Test
70+
public void whenConvertedToCharArray_thenCorrect() {
71+
String str = "hello";
72+
char[] charArray = { 'h', 'e', 'l', 'l', 'o' };
73+
74+
assertEquals(Arrays.equals(charArray, str.toCharArray()), true);
75+
}
76+
77+
@Test
78+
public void whenConvertedToDate_thenCorrect() throws ParseException {
79+
String str = "15/10/2013";
80+
SimpleDateFormat formatter = new SimpleDateFormat("dd/M/yyyy");
81+
Date date1 = formatter.parse(str);
82+
Calendar calendar = new GregorianCalendar(2013, 9, 15);
83+
Date date2 = calendar.getTime();
84+
85+
assertEquals(date1.compareTo(date2), 0);
86+
}
87+
88+
@Test
89+
public void whenConvertedToLocalDateTime_thenCorrect() throws ParseException {
90+
String str = "2007-12-03T10:15:30";
91+
LocalDateTime localDateTime = new UseLocalDateTime().getLocalDateTimeUsingParseMethod(str);
92+
93+
assertEquals(localDateTime.getDayOfMonth(), 3);
94+
assertEquals(localDateTime.getMonth(), Month.DECEMBER);
95+
assertEquals(localDateTime.getYear(), 2007);
96+
}
97+
}

‎httpclient/src/test/java/org/baeldung/httpclient/HttpsClientSslLiveTest.java‎

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,28 @@
11
package org.baeldung.httpclient;
22

3-
import static org.hamcrest.CoreMatchers.equalTo;
4-
import static org.junit.Assert.assertThat;
5-
6-
import java.io.IOException;
7-
import java.security.GeneralSecurityException;
8-
import java.security.KeyManagementException;
9-
import java.security.KeyStoreException;
10-
import java.security.NoSuchAlgorithmException;
11-
12-
import javax.net.ssl.SSLContext;
13-
import javax.net.ssl.SSLException;
14-
153
import org.apache.http.HttpResponse;
164
import org.apache.http.client.methods.HttpGet;
175
import org.apache.http.conn.ClientConnectionManager;
186
import org.apache.http.conn.scheme.Scheme;
197
import org.apache.http.conn.scheme.SchemeRegistry;
20-
import org.apache.http.conn.ssl.NoopHostnameVerifier;
21-
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
22-
import org.apache.http.conn.ssl.SSLContextBuilder;
23-
import org.apache.http.conn.ssl.SSLContexts;
24-
import org.apache.http.conn.ssl.SSLSocketFactory;
25-
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
26-
import org.apache.http.conn.ssl.TrustStrategy;
8+
import org.apache.http.conn.ssl.*;
279
import org.apache.http.impl.client.CloseableHttpClient;
2810
import org.apache.http.impl.client.DefaultHttpClient;
2911
import org.apache.http.impl.client.HttpClientBuilder;
3012
import org.apache.http.impl.client.HttpClients;
3113
import org.apache.http.impl.conn.PoolingClientConnectionManager;
14+
import org.apache.http.ssl.SSLContextBuilder;
15+
import org.apache.http.ssl.SSLContexts;
3216
import org.junit.Test;
3317

18+
import javax.net.ssl.SSLContext;
19+
import javax.net.ssl.SSLException;
20+
import java.io.IOException;
21+
import java.security.GeneralSecurityException;
22+
23+
import static org.hamcrest.CoreMatchers.equalTo;
24+
import static org.junit.Assert.assertThat;
25+
3426
/**
3527
* This test requires a localhost server over HTTPS <br>
3628
* It should only be manually run, not part of the automated build
@@ -101,17 +93,9 @@ public final void givenHttpClientPost4_3_whenAcceptingAllCertificates_thenCanCon
10193
}
10294

10395
@Test
104-
public final void givenIgnoringCertificates_whenHttpsUrlIsConsumed_thenCorrect() throws IOException {
105-
106-
final TrustStrategy acceptingTrustStrategy = (certificate, authType) -> true;
107-
108-
SSLContext sslContext = null;
109-
try {
110-
sslContext = new SSLContextBuilder().loadTrustMaterial(null, acceptingTrustStrategy).build();
111-
112-
} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
113-
e.printStackTrace();
114-
}
96+
public final void givenIgnoringCertificates_whenHttpsUrlIsConsumed_thenCorrect() throws Exception {
97+
SSLContext sslContext = new SSLContextBuilder()
98+
.loadTrustMaterial(null, (certificate, authType) -> true).build();
11599

116100
final CloseableHttpClient client = HttpClients.custom().setSSLContext(sslContext).setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
117101
final HttpGet httpGet = new HttpGet(HOST_WITH_SSL);

‎pdf/pom.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
<artifactId>batik-transcoder</artifactId>
5555
<version>1.8</version>
5656
</dependency>
57+
<dependency>
58+
<groupId>org.apache.poi</groupId>
59+
<artifactId>poi-ooxml</artifactId>
60+
<version>3.15</version>
61+
</dependency>
5762
</dependencies>
5863

5964
<build>

‎pom.xml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
<module>spring-data-neo4j</module>
9696
<module>spring-data-redis</module>
9797
<module>spring-data-rest</module>
98+
<module>spring-data-solr</module>
9899
<module>spring-dispatcher-servlet</module>
99100
<module>spring-exceptions</module>
100101
<module>spring-freemarker</module>
@@ -132,6 +133,7 @@
132133
<module>spring-security-rest-full</module>
133134
<module>spring-security-rest</module>
134135
<module>spring-security-x509</module>
136+
<module>spring-session</module>
135137
<module>spring-spel</module>
136138
<module>spring-thymeleaf</module>
137139
<module>spring-userservice</module>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.baeldung.camel.file;
2+
3+
import java.text.SimpleDateFormat;
4+
import java.util.Date;
5+
6+
import org.apache.camel.Exchange;
7+
import org.apache.camel.Processor;
8+
9+
public class FileProcessor implements Processor {
10+
11+
public void process(Exchange exchange) throws Exception {
12+
String originalFileName = (String) exchange.getIn().getHeader(Exchange.FILE_NAME, String.class);
13+
14+
Date date = new Date();
15+
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
16+
String changedFileName = dateFormat.format(date) + originalFileName;
17+
exchange.getIn().setHeader(Exchange.FILE_NAME, changedFileName);
18+
}
19+
20+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.baeldung.camel.file;
2+
3+
import org.apache.camel.builder.RouteBuilder;
4+
5+
public class FileRouter extends RouteBuilder {
6+
7+
private static final String SOURCE_FOLDER = "src/test/source-folder";
8+
private static final String DESTINATION_FOLDER = "src/test/destination-folder";
9+
10+
@Override
11+
public void configure() throws Exception {
12+
from("file://" + SOURCE_FOLDER + "?delete=true").process(new FileProcessor()).to("file://" + DESTINATION_FOLDER);
13+
}
14+
15+
}

0 commit comments

Comments
 (0)