Skip to content

Commit 1c0e0c6

Browse files
Merge remote-tracking branch 'upstream/master' into craedel-log4j2
2 parents e26d9ff + f84ba52 commit 1c0e0c6

121 files changed

Lines changed: 2914 additions & 303 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.
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/src/main/java/org/baeldung/equalshashcode/entities/ComplexClass.java renamed to core-java/src/main/java/com/baeldung/equalshashcode/entities/ComplexClass.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.baeldung.equalshashcode.entities;
1+
package com.baeldung.equalshashcode.entities;
22

33
import java.util.List;
44
import java.util.Set;

core-java/src/main/java/org/baeldung/equalshashcode/entities/PrimitiveClass.java renamed to core-java/src/main/java/com/baeldung/equalshashcode/entities/PrimitiveClass.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.baeldung.equalshashcode.entities;
1+
package com.baeldung.equalshashcode.entities;
22

33
public class PrimitiveClass {
44

core-java/src/main/java/org/baeldung/equalshashcode/entities/Rectangle.java renamed to core-java/src/main/java/com/baeldung/equalshashcode/entities/Rectangle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.baeldung.equalshashcode.entities;
1+
package com.baeldung.equalshashcode.entities;
22

33
public class Rectangle extends Shape {
44
private double width;

core-java/src/main/java/org/baeldung/equalshashcode/entities/Shape.java renamed to core-java/src/main/java/com/baeldung/equalshashcode/entities/Shape.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.baeldung.equalshashcode.entities;
1+
package com.baeldung.equalshashcode.entities;
22

33
public abstract class Shape {
44
public abstract double area();

core-java/src/main/java/org/baeldung/equalshashcode/entities/Square.java renamed to core-java/src/main/java/com/baeldung/equalshashcode/entities/Square.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.baeldung.equalshashcode.entities;
1+
package com.baeldung.equalshashcode.entities;
22

33
import java.awt.Color;
44

core-java/src/main/java/org/baeldung/executable/ExecutableMavenJar.java renamed to core-java/src/main/java/com/baeldung/executable/ExecutableMavenJar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.baeldung.executable;
1+
package com.baeldung.executable;
22

33
import javax.swing.JOptionPane;
44

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.baeldung.java.conversion;
2+
3+
import java.text.ParseException;
4+
import java.text.SimpleDateFormat;
5+
import java.time.LocalDateTime;
6+
import java.util.Date;
7+
8+
import com.baeldung.datetime.UseLocalDateTime;
9+
10+
public class StringConversion {
11+
12+
public static int getInt(String str) {
13+
return Integer.parseInt(str);
14+
}
15+
16+
public static int getInteger(String str) {
17+
return Integer.valueOf(str);
18+
}
19+
20+
public static long getLongPrimitive(String str) {
21+
return Long.parseLong(str);
22+
}
23+
24+
public static Long getLong(String str) {
25+
return Long.valueOf(str);
26+
}
27+
28+
public static double getDouble(String str) {
29+
return Double.parseDouble(str);
30+
}
31+
32+
public static double getDoublePrimitive(String str) {
33+
return Double.valueOf(str);
34+
}
35+
36+
public static byte[] getByteArray(String str) {
37+
return str.getBytes();
38+
}
39+
40+
public static char[] getCharArray(String str) {
41+
return str.toCharArray();
42+
}
43+
44+
public static boolean getBooleanPrimitive(String str) {
45+
return Boolean.parseBoolean(str);
46+
}
47+
48+
public static boolean getBoolean(String str) {
49+
return Boolean.valueOf(str);
50+
}
51+
52+
public static Date getJava6Date(String str, String format) throws ParseException {
53+
SimpleDateFormat formatter = new SimpleDateFormat(format);
54+
return formatter.parse(str);
55+
}
56+
57+
public static LocalDateTime getJava8Date(String str) throws ParseException {
58+
return new UseLocalDateTime().getLocalDateTimeUsingParseMethod(str);
59+
}
60+
}

‎core-java/src/main/java/com/baeldung/java/networking/udp/EchoClient.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public EchoClient() {
2424
public String sendEcho(String msg) {
2525
DatagramPacket packet = null;
2626
try {
27-
buf=msg.getBytes();
27+
buf = msg.getBytes();
2828
packet = new DatagramPacket(buf, buf.length, address, 4445);
2929
socket.send(packet);
3030
packet = new DatagramPacket(buf, buf.length);

0 commit comments

Comments
 (0)