Skip to content

Commit 39916c3

Browse files
committed
Merge branch 'masterEugen'
2 parents 0a29248 + eac1e3c commit 39916c3

203 files changed

Lines changed: 3172 additions & 888 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)

core-java/src/main/java/com/baeldung/linkedlist/MiddleElementLookup.java renamed to algorithms/src/main/java/com/baeldung/algorithms/middleelementlookup/MiddleElementLookup.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
package com.baeldung.linkedlist;
1+
package com.baeldung.algorithms.middleelementlookup;
22

33
import java.util.LinkedList;
44
import java.util.Optional;
55

6-
import com.baeldung.linkedlist.Node;
7-
86
public class MiddleElementLookup {
97

108
public static Optional<String> findMiddleElementLinkedList(LinkedList<String> linkedList) {

core-java/src/main/java/com/baeldung/linkedlist/Node.java renamed to algorithms/src/main/java/com/baeldung/algorithms/middleelementlookup/Node.java

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

33
public class Node {
44
private Node next;

core-java/src/test/java/com/baeldung/linkedlist/MiddleElementLookupUnitTest.java renamed to algorithms/src/test/java/algorithms/MiddleElementLookupUnitTest.java

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

3-
import static org.junit.Assert.assertEquals;
4-
import static org.junit.Assert.assertFalse;
3+
import com.baeldung.algorithms.middleelementlookup.MiddleElementLookup;
4+
import com.baeldung.algorithms.middleelementlookup.Node;
5+
import org.junit.Test;
56

67
import java.util.LinkedList;
78

8-
import org.junit.Test;
9+
import static org.junit.Assert.assertEquals;
10+
import static org.junit.Assert.assertFalse;
911

1012
public class MiddleElementLookupUnitTest {
1113

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+
}

‎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-8/src/test/java/com/baeldung/java8/UnsignedArithmeticUnitTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void whenDividingNumbers_thenNegativeIsInterpretedAsUnsigned() {
3838
assertEquals(1, Integer.divideUnsigned(negative, positive));
3939

4040
assertEquals(-1, negative % positive);
41-
assertEquals(1, Integer.divideUnsigned(negative, positive));
41+
assertEquals(1, Integer.remainderUnsigned(negative, positive));
4242
}
4343

4444
@Test

‎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)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.baeldung.accessmodifiers;
2+
3+
public class Public {
4+
public Public() {
5+
SuperPublic.publicMethod(); // Available everywhere.
6+
SuperPublic.protectedMethod(); // Available in the same package or subclass.
7+
SuperPublic.defaultMethod(); // Available in the same package.
8+
}
9+
}

0 commit comments

Comments
 (0)