Skip to content

Commit 3f52241

Browse files
committed
Merge branch 'master' into BAEL-1661_v2
2 parents 1fe7dc3 + ff9d4d4 commit 3f52241

92 files changed

Lines changed: 1740 additions & 198 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.

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ This tutorials project is being built **[>> HERE](https://rest-security.ci.cloud
3939

4040
- [Apache Maven Standard Directory Layout](http://www.baeldung.com/maven-directory-structure)
4141
- [Apache Maven Tutorial](http://www.baeldung.com/maven)
42+
- [Designing a User Friendly Java Library](http://www.baeldung.com/design-a-user-friendly-java-library)
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
package com.baeldung.algorithms.analysis;
2+
3+
import org.junit.Test;
4+
5+
public class AnalysisRunnerLiveTest {
6+
7+
int n = 10;
8+
int total = 0;
9+
10+
@Test
11+
public void whenConstantComplexity_thenConstantRuntime() {
12+
13+
System.out.println("**** n = " + n + " ****");
14+
System.out.println();
15+
16+
// Constant Time
17+
System.out.println("**** Constant time ****");
18+
19+
System.out.println("Hey - your input is: " + n);
20+
System.out.println("Running time not dependent on input size!");
21+
System.out.println();
22+
}
23+
24+
@Test
25+
public void whenLogarithmicComplexity_thenLogarithmicRuntime() {
26+
// Logarithmic Time
27+
System.out.println("**** Logarithmic Time ****");
28+
for (int i = 1; i < n; i = i * 2) {
29+
// System.out.println("Hey - I'm busy looking at: " + i);
30+
total++;
31+
}
32+
System.out.println("Total amount of times run: " + total);
33+
System.out.println();
34+
}
35+
36+
@Test
37+
public void whenLinearComplexity_thenLinearRuntime() {
38+
// Linear Time
39+
System.out.println("**** Linear Time ****");
40+
for (int i = 0; i < n; i++) {
41+
// System.out.println("Hey - I'm busy looking at: " + i);
42+
total++;
43+
}
44+
System.out.println("Total amount of times run: " + total);
45+
System.out.println();
46+
47+
}
48+
49+
@Test
50+
public void whenNLogNComplexity_thenNLogNRuntime() {
51+
// N Log N Time
52+
System.out.println("**** nlogn Time ****");
53+
total = 0;
54+
for (
55+
56+
int i = 1; i <= n; i++) {
57+
for (int j = 1; j < n; j = j * 2) {
58+
// System.out.println("Hey - I'm busy looking at: " + i + " and " + j);
59+
total++;
60+
}
61+
}
62+
System.out.println("Total amount of times run: " + total);
63+
System.out.println();
64+
}
65+
66+
@Test
67+
public void whenQuadraticComplexity_thenQuadraticRuntime() {
68+
// Quadratic Time
69+
System.out.println("**** Quadratic Time ****");
70+
total = 0;
71+
for (
72+
73+
int i = 1; i <= n; i++) {
74+
for (int j = 1; j <= n; j++) {
75+
// System.out.println("Hey - I'm busy looking at: " + i + " and " + j);
76+
total++;
77+
}
78+
}
79+
System.out.println("Total amount of times run: " + total);
80+
System.out.println();
81+
}
82+
83+
@Test
84+
public void whenCubicComplexity_thenCubicRuntime() {
85+
// Cubic Time
86+
System.out.println("**** Cubic Time ****");
87+
total = 0;
88+
for (
89+
90+
int i = 1; i <= n; i++) {
91+
for (int j = 1; j <= n; j++) {
92+
for (int k = 1; k <= n; k++) {
93+
// System.out.println("Hey - I'm busy looking at: " + i + " and " + j + " and " + k);
94+
total++;
95+
}
96+
}
97+
}
98+
System.out.println("Total amount of times run: " + total);
99+
System.out.println();
100+
}
101+
102+
@Test
103+
public void whenExponentialComplexity_thenExponentialRuntime() {
104+
// Exponential Time
105+
System.out.println("**** Exponential Time ****");
106+
total = 0;
107+
for (
108+
109+
int i = 1; i <= Math.pow(2, n); i++) {
110+
// System.out.println("Hey - I'm busy looking at: " + i);
111+
total++;
112+
}
113+
System.out.println("Total amount of times run: " + total);
114+
System.out.println();
115+
}
116+
117+
@Test
118+
public void whenFactorialComplexity_thenFactorialRuntime() {
119+
// Factorial Time
120+
System.out.println("**** Factorial Time ****");
121+
total = 0;
122+
for (
123+
124+
int i = 1; i <=
125+
126+
factorial(n); i++) {
127+
// System.out.println("Hey - I'm busy looking at: " + i);
128+
total++;
129+
}
130+
System.out.println("Total amount of times run: " + total);
131+
}
132+
133+
static int factorial(int n) {
134+
if (n == 0 || n == 1)
135+
return 1;
136+
else
137+
return n * factorial(n - 1);
138+
}
139+
}

‎apache-poi/src/test/java/com/baeldung/poi/powerpoint/PowerPointIntegrationTest.java‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
package com.baeldung.poi.powerpoint;
22

3+
import java.io.File;
4+
import java.util.List;
5+
36
import org.apache.poi.xslf.usermodel.XMLSlideShow;
47
import org.apache.poi.xslf.usermodel.XSLFShape;
58
import org.apache.poi.xslf.usermodel.XSLFSlide;
69
import org.junit.After;
710
import org.junit.Assert;
811
import org.junit.Before;
12+
import org.junit.Rule;
913
import org.junit.Test;
10-
11-
import java.io.File;
12-
import java.util.List;
14+
import org.junit.rules.TemporaryFolder;
1315

1416
public class PowerPointIntegrationTest {
1517

1618
private PowerPointHelper pph;
1719
private String fileLocation;
1820
private static final String FILE_NAME = "presentation.pptx";
21+
22+
@Rule
23+
public TemporaryFolder tempFolder = new TemporaryFolder();
1924

2025
@Before
2126
public void setUp() throws Exception {
22-
File currDir = new File(".");
27+
File currDir = tempFolder.newFolder();
2328
String path = currDir.getAbsolutePath();
2429
fileLocation = path.substring(0, path.length() - 1) + FILE_NAME;
2530

‎core-java-8/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@
5252
- [Measure Elapsed Time in Java](http://www.baeldung.com/java-measure-elapsed-time)
5353
- [Java Optional – orElse() vs orElseGet()](http://www.baeldung.com/java-optional-or-else-vs-or-else-get)
5454
- [An Introduction to Java.util.Hashtable Class](http://www.baeldung.com/java-hash-table)
55-
55+
- [Method Parameter Reflection in Java](http://www.baeldung.com/java-parameter-reflection)

‎core-java-9/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@
2525
- [Introduction to Chronicle Queue](http://www.baeldung.com/java-chronicle-queue)
2626
- [A Guide to Java 9 Modularity](http://www.baeldung.com/java-9-modularity)
2727
- [Optional orElse Optional](http://www.baeldung.com/java-optional-or-else-optional)
28+
- [Java 9 java.lang.Module API](http://www.baeldung.com/java-9-module-api)

‎core-java/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,7 @@
156156
- [Flyweight Pattern in Java](http://www.baeldung.com/java-flyweight)
157157
- [The Observer Pattern in Java](http://www.baeldung.com/java-observer-pattern)
158158
- [Service Locator Pattern](http://www.baeldung.com/java-service-locator-pattern)
159+
- [The Thread.join() Method in Java](http://www.baeldung.com/java-thread-join)
160+
- [Guide to the super Java Keyword](http://www.baeldung.com/java-super)
161+
- [Guide to the this Java Keyword](http://www.baeldung.com/java-this)
162+
- [Jagged Arrays In Java](http://www.baeldung.com/java-jagged-arrays)

‎core-java/src/main/java/com/baeldung/linkedlist/LinkedList.java‎

Lines changed: 0 additions & 58 deletions
This file was deleted.

‎core-java/src/main/java/com/baeldung/linkedlist/MiddleElementLookup.java‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
package com.baeldung.linkedlist;
22

33
import java.util.LinkedList;
4+
import java.util.Optional;
45

56
import com.baeldung.linkedlist.Node;
67

78
public class MiddleElementLookup {
89

9-
public static String findMiddleElementLinkedList(LinkedList<String> linkedList) {
10+
public static Optional<String> findMiddleElementLinkedList(LinkedList<String> linkedList) {
1011
if (linkedList == null || linkedList.isEmpty()) {
11-
return null;
12+
return Optional.empty();
1213
}
1314

14-
return linkedList.get((linkedList.size() - 1) / 2);
15+
return Optional.ofNullable(linkedList.get((linkedList.size() - 1) / 2));
1516
}
1617

17-
public static String findMiddleElementFromHead(Node head) {
18+
public static Optional<String> findMiddleElementFromHead(Node head) {
1819
if (head == null) {
19-
return null;
20+
return Optional.empty();
2021
}
2122

2223
// calculate the size of the list
@@ -33,17 +34,17 @@ public static String findMiddleElementFromHead(Node head) {
3334
current = current.next();
3435
}
3536

36-
return current.data();
37+
return Optional.ofNullable(current.data());
3738
}
3839

39-
public static String findMiddleElementFromHead1PassRecursively(Node head) {
40+
public static Optional<String> findMiddleElementFromHead1PassRecursively(Node head) {
4041
if (head == null) {
41-
return null;
42+
return Optional.empty();
4243
}
4344

4445
MiddleAuxRecursion middleAux = new MiddleAuxRecursion();
4546
findMiddleRecursively(head, middleAux);
46-
return middleAux.middle.data();
47+
return Optional.ofNullable(middleAux.middle.data());
4748
}
4849

4950
private static void findMiddleRecursively(Node node, MiddleAuxRecursion middleAux) {
@@ -63,9 +64,9 @@ private static void findMiddleRecursively(Node node, MiddleAuxRecursion middleAu
6364
middleAux.length--;
6465
}
6566

66-
public static String findMiddleElementFromHead1PassIteratively(Node head) {
67+
public static Optional<String> findMiddleElementFromHead1PassIteratively(Node head) {
6768
if (head == null) {
68-
return null;
69+
return Optional.empty();
6970
}
7071

7172
Node slowPointer = head;
@@ -78,7 +79,7 @@ public static String findMiddleElementFromHead1PassIteratively(Node head) {
7879
slowPointer = slowPointer.next();
7980
}
8081

81-
return slowPointer.data();
82+
return Optional.ofNullable(slowPointer.data());
8283
}
8384

8485
private static class MiddleAuxRecursion {

‎core-java/src/test/java/com/baeldung/array/JaggedArrayUnitTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void givenJaggedArray_whenUsingArraysAPI_thenVerifyPrintedElements() {
4646
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
4747
System.setOut(new PrintStream(outContent));
4848
obj.printElements(jaggedArr);
49-
assertEquals("[1, 2]\n[3, 4, 5]\n[6, 7, 8, 9]\n", outContent.toString());
49+
assertEquals("[1, 2][3, 4, 5][6, 7, 8, 9]", outContent.toString().replace("\r", "").replace("\n", ""));
5050
System.setOut(System.out);
5151
}
5252

0 commit comments

Comments
 (0)