Skip to content

Commit 3a049aa

Browse files
author
Dassi Orleando
committed
Merge branch 'master' of https://github.com/eugenp/tutorials
2 parents 16613e5 + c977b6f commit 3a049aa

113 files changed

Lines changed: 3576 additions & 876 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.

‎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)

‎core-java-concurrency/src/test/java/com/baeldung/concurrent/stopping/StopThreadTest.java‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
package com.baeldung.concurrent.stopping;
22

3-
import com.jayway.awaitility.Awaitility;
4-
import org.junit.Test;
5-
6-
import java.util.concurrent.TimeUnit;
7-
83
import static com.jayway.awaitility.Awaitility.await;
94
import static org.junit.Assert.assertFalse;
105
import static org.junit.Assert.assertTrue;
116

7+
import java.util.concurrent.TimeUnit;
8+
9+
import org.junit.Test;
10+
11+
import com.jayway.awaitility.Awaitility;
12+
1213
public class StopThreadTest {
1314

1415
@Test
1516
public void whenStoppedThreadIsStopped() throws InterruptedException {
1617

17-
int interval = 100;
18+
int interval = 5;
1819

1920
ControlSubThread controlSubThread = new ControlSubThread(interval);
2021
controlSubThread.start();
@@ -33,13 +34,13 @@ public void whenStoppedThreadIsStopped() throws InterruptedException {
3334
@Test
3435
public void whenInterruptedThreadIsStopped() throws InterruptedException {
3536

36-
int interval = 5000;
37+
int interval = 50;
3738

3839
ControlSubThread controlSubThread = new ControlSubThread(interval);
3940
controlSubThread.start();
4041

4142
// Give things a chance to get set up
42-
Thread.sleep(100);
43+
Thread.sleep(interval);
4344
assertTrue(controlSubThread.isRunning());
4445
assertFalse(controlSubThread.isStopped());
4546

@@ -48,6 +49,7 @@ public void whenInterruptedThreadIsStopped() throws InterruptedException {
4849

4950
// Wait less than the time we would normally sleep, and make sure we exited.
5051
Awaitility.await()
52+
.pollDelay(2, TimeUnit.MILLISECONDS)
5153
.atMost(interval/ 10, TimeUnit.MILLISECONDS)
5254
.until(controlSubThread::isStopped);
5355
}

‎core-java/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,4 @@
133133
- [A Guide to Java Initialization](http://www.baeldung.com/java-initialization)
134134
- [Implementing a Binary Tree in Java](http://www.baeldung.com/java-binary-tree)
135135
- [A Guide to ThreadLocalRandom in Java](http://www.baeldung.com/java-thread-local-random)
136+
- [RegEx for matching Date Pattern in Java](http://www.baeldung.com/java-date-regular-expressions)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.baeldung.iteratorguide;
2+
3+
import java.util.ArrayList;
4+
import java.util.Iterator;
5+
import java.util.List;
6+
import java.util.ListIterator;
7+
8+
public class IteratorGuide {
9+
10+
public static void main(String[] args) {
11+
List<String> items = new ArrayList<>();
12+
items.add("ONE");
13+
items.add("TWO");
14+
items.add("THREE");
15+
Iterator<String> iter = items.iterator();
16+
while (iter.hasNext()) {
17+
String next = iter.next();
18+
System.out.println(next);
19+
iter.remove();
20+
}
21+
ListIterator<String> listIterator = items.listIterator();
22+
while(listIterator.hasNext()) {
23+
String nextWithIndex = items.get(listIterator.nextIndex());
24+
String next = listIterator.next();
25+
if( "ONE".equals(next)) {
26+
listIterator.set("SWAPPED");
27+
}
28+
}
29+
listIterator.add("FOUR");
30+
while(listIterator.hasPrevious()) {
31+
String previousWithIndex = items.get(listIterator.previousIndex());
32+
String previous = listIterator.previous();
33+
System.out.println(previous);
34+
}
35+
listIterator.forEachRemaining(e -> {
36+
System.out.println(e);
37+
});
38+
}
39+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.baeldung.regexp.datepattern;
2+
3+
public interface DateMatcher {
4+
5+
boolean matches(String date);
6+
7+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.regexp.datepattern;
2+
3+
import java.util.regex.Pattern;
4+
5+
class FormattedDateMatcher implements DateMatcher {
6+
7+
private static final Pattern DATE_PATTERN = Pattern.compile(
8+
"^\\d{4}-\\d{2}-\\d{2}$");
9+
10+
@Override
11+
public boolean matches(String date) {
12+
return DATE_PATTERN.matcher(date).matches();
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.regexp.datepattern;
2+
3+
import java.util.regex.Pattern;
4+
5+
class RangedDateMatcher implements DateMatcher {
6+
7+
private static final Pattern DATE_PATTERN = Pattern.compile(
8+
"^((19|2[0-9])[0-9]{2})-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$");
9+
10+
@Override
11+
public boolean matches(String date) {
12+
return DATE_PATTERN.matcher(date).matches();
13+
}
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.regexp.datepattern.gregorian;
2+
3+
import com.baeldung.regexp.datepattern.DateMatcher;
4+
5+
import java.util.regex.Pattern;
6+
7+
public class February29thMatcher implements DateMatcher {
8+
9+
private static final Pattern DATE_PATTERN = Pattern.compile(
10+
"^((2000|2400|2800|(19|2[0-9](0[48]|[2468][048]|[13579][26])))-02-29)$");
11+
12+
@Override
13+
public boolean matches(String date) {
14+
return DATE_PATTERN.matcher(date).matches();
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.regexp.datepattern.gregorian;
2+
3+
import com.baeldung.regexp.datepattern.DateMatcher;
4+
5+
import java.util.regex.Pattern;
6+
7+
public class FebruaryGeneralMatcher implements DateMatcher {
8+
9+
private static final Pattern DATE_PATTERN = Pattern.compile(
10+
"^(((19|2[0-9])[0-9]{2})-02-(0[1-9]|1[0-9]|2[0-8]))$");
11+
12+
@Override
13+
public boolean matches(String date) {
14+
return DATE_PATTERN.matcher(date).matches();
15+
}
16+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung.regexp.datepattern.gregorian;
2+
3+
import com.baeldung.regexp.datepattern.DateMatcher;
4+
5+
import java.util.regex.Pattern;
6+
7+
class GregorianDateMatcher implements DateMatcher {
8+
9+
private static final Pattern DATE_PATTERN = Pattern.compile(
10+
"^((2000|2400|2800|(19|2[0-9](0[48]|[2468][048]|[13579][26])))-02-29)$"
11+
+ "|^(((19|2[0-9])[0-9]{2})-02-(0[1-9]|1[0-9]|2[0-8]))$"
12+
+ "|^(((19|2[0-9])[0-9]{2})-(0[13578]|10|12)-(0[1-9]|[12][0-9]|3[01]))$"
13+
+ "|^(((19|2[0-9])[0-9]{2})-(0[469]|11)-(0[1-9]|[12][0-9]|30))$");
14+
15+
@Override
16+
public boolean matches(String date) {
17+
return DATE_PATTERN.matcher(date).matches();
18+
}
19+
}

0 commit comments

Comments
 (0)