Skip to content

Commit c23c128

Browse files
authored
Merge branch 'master' into bael-1908
2 parents 2c7729c + cab2e35 commit c23c128

461 files changed

Lines changed: 12353 additions & 1394 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.

‎.gitmodules‎

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

‎algorithms/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@
2222
- [Displaying Money Amounts in Words](http://www.baeldung.com/java-money-into-words)
2323
- [A Collaborative Filtering Recommendation System in Java](http://www.baeldung.com/java-collaborative-filtering-recommendations)
2424
- [Find All Pairs of Numbers in an Array That Add Up to a Given Sum](http://www.baeldung.com/java-algorithm-number-pairs-sum)
25+
- [Converting Between Roman and Arabic Numerals in Java](http://www.baeldung.com/java-convert-roman-arabic)
26+
- [Practical Java Examples of the Big O Notation](http://www.baeldung.com/java-algorithm-complexity)
27+
- [Find the Middle Element of a Linked List](http://www.baeldung.com/java-linked-list-middle-element)

‎algorithms/src/main/java/com/baeldung/algorithms/mcts/montecarlo/MonteCarloTreeSearch.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class MonteCarloTreeSearch {
1010

1111
private static final int WIN_SCORE = 10;
1212
private int level;
13-
private int oponent;
13+
private int opponent;
1414

1515
public MonteCarloTreeSearch() {
1616
this.level = 3;
@@ -32,11 +32,11 @@ public Board findNextMove(Board board, int playerNo) {
3232
long start = System.currentTimeMillis();
3333
long end = start + 60 * getMillisForCurrentLevel();
3434

35-
oponent = 3 - playerNo;
35+
opponent = 3 - playerNo;
3636
Tree tree = new Tree();
3737
Node rootNode = tree.getRoot();
3838
rootNode.getState().setBoard(board);
39-
rootNode.getState().setPlayerNo(oponent);
39+
rootNode.getState().setPlayerNo(opponent);
4040

4141
while (System.currentTimeMillis() < end) {
4242
// Phase 1 - Selection
@@ -93,7 +93,7 @@ private int simulateRandomPlayout(Node node) {
9393
State tempState = tempNode.getState();
9494
int boardStatus = tempState.getBoard().checkStatus();
9595

96-
if (boardStatus == oponent) {
96+
if (boardStatus == opponent) {
9797
tempNode.getParent().getState().setWinScore(Integer.MIN_VALUE);
9898
return boardStatus;
9999
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.baeldung.algorithms.romannumerals;
2+
3+
import java.util.List;
4+
5+
class RomanArabicConverter {
6+
7+
public static int romanToArabic(String input) {
8+
String romanNumeral = input.toUpperCase();
9+
int result = 0;
10+
11+
List<RomanNumeral> romanNumerals = RomanNumeral.getReverseSortedValues();
12+
13+
int i = 0;
14+
15+
while ((romanNumeral.length() > 0) && (i < romanNumerals.size())) {
16+
RomanNumeral symbol = romanNumerals.get(i);
17+
if (romanNumeral.startsWith(symbol.name())) {
18+
result += symbol.getValue();
19+
romanNumeral = romanNumeral.substring(symbol.name().length());
20+
} else {
21+
i++;
22+
}
23+
}
24+
if (romanNumeral.length() > 0) {
25+
throw new IllegalArgumentException(input + " cannot be converted to a Roman Numeral");
26+
}
27+
28+
return result;
29+
}
30+
31+
public static String arabicToRoman(int number) {
32+
if ((number <= 0) || (number > 4000)) {
33+
throw new IllegalArgumentException(number + " is not in range (0,4000]");
34+
}
35+
36+
List<RomanNumeral> romanNumerals = RomanNumeral.getReverseSortedValues();
37+
38+
int i = 0;
39+
StringBuilder sb = new StringBuilder();
40+
41+
while (number > 0 && i < romanNumerals.size()) {
42+
RomanNumeral currentSymbol = romanNumerals.get(i);
43+
if (currentSymbol.getValue() <= number) {
44+
sb.append(currentSymbol.name());
45+
number -= currentSymbol.getValue();
46+
} else {
47+
i++;
48+
}
49+
}
50+
return sb.toString();
51+
}
52+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.baeldung.algorithms.romannumerals;
2+
3+
import java.util.Arrays;
4+
import java.util.Comparator;
5+
import java.util.List;
6+
import java.util.stream.Collectors;
7+
8+
enum RomanNumeral {
9+
I(1), IV(4), V(5), IX(9), X(10), XL(40), L(50), XC(90), C(100), CD(400), D(500), CM(900), M(1000);
10+
11+
private int value;
12+
13+
RomanNumeral(int value) {
14+
this.value = value;
15+
}
16+
17+
public int getValue() {
18+
return value;
19+
}
20+
21+
public static List<RomanNumeral> getReverseSortedValues() {
22+
return Arrays.stream(values())
23+
.sorted(Comparator.comparing((RomanNumeral e) -> e.value).reversed())
24+
.collect(Collectors.toList());
25+
}
26+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.baeldung.algorithms.romannumerals;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import org.junit.Test;
6+
7+
public class RomanArabicConverterUnitTest {
8+
9+
@Test
10+
public void given2018Roman_WhenConvertingToArabic_ThenReturn2018() {
11+
12+
String roman2018 = "MMXVIII";
13+
14+
int result = RomanArabicConverter.romanToArabic(roman2018);
15+
16+
assertThat(result).isEqualTo(2018);
17+
}
18+
19+
@Test
20+
public void given1999Arabic_WhenConvertingToRoman_ThenReturnMCMXCIX() {
21+
22+
int arabic1999 = 1999;
23+
24+
String result = RomanArabicConverter.arabicToRoman(arabic1999);
25+
26+
assertThat(result).isEqualTo("MCMXCIX");
27+
}
28+
29+
}

‎antlr/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Relevant Articles:
2+
3+
- [Java with ANTLR](http://www.baeldung.com/java-antlr)

‎apache-meecrowave/pom.xml‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.baeldung</groupId>
5+
<artifactId>apache-meecrowave</artifactId>
6+
<version>0.0.1</version>
7+
<name>apache-meecrowave</name>
8+
<description>A sample REST API application with Meecrowave</description>
9+
10+
<properties>
11+
<maven.compiler.source>1.8</maven.compiler.source>
12+
<maven.compiler.target>1.8</maven.compiler.target>
13+
</properties>
14+
<dependencies>
15+
<!-- https://mvnrepository.com/artifact/org.apache.meecrowave/meecrowave-core -->
16+
<dependency>
17+
<groupId>org.apache.meecrowave</groupId>
18+
<artifactId>meecrowave-core</artifactId>
19+
<version>1.2.1</version>
20+
</dependency>
21+
<!-- https://mvnrepository.com/artifact/org.apache.meecrowave/meecrowave-jpa -->
22+
<dependency>
23+
<groupId>org.apache.meecrowave</groupId>
24+
<artifactId>meecrowave-jpa</artifactId>
25+
<version>1.2.1</version>
26+
</dependency>
27+
28+
<dependency>
29+
<groupId>com.squareup.okhttp3</groupId>
30+
<artifactId>okhttp</artifactId>
31+
<version>3.10.0</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.apache.meecrowave</groupId>
35+
<artifactId>meecrowave-junit</artifactId>
36+
<version>1.2.0</version>
37+
<scope>test</scope>
38+
</dependency>
39+
<!-- https://mvnrepository.com/artifact/junit/junit -->
40+
<dependency>
41+
<groupId>junit</groupId>
42+
<artifactId>junit</artifactId>
43+
<version>4.10</version>
44+
<scope>test</scope>
45+
</dependency>
46+
47+
</dependencies>
48+
<build>
49+
<plugins>
50+
<plugin>
51+
<groupId>org.apache.meecrowave</groupId>
52+
<artifactId>meecrowave-maven-plugin</artifactId>
53+
<version>1.2.1</version>
54+
</plugin>
55+
</plugins>
56+
</build>
57+
</project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.baeldung.meecrowave;
2+
3+
public class Article {
4+
private String name;
5+
private String author;
6+
7+
public Article() {
8+
}
9+
10+
public Article(String name, String author) {
11+
this.author = author;
12+
this.name = name;
13+
}
14+
15+
public String getName() {
16+
return name;
17+
}
18+
19+
public void setName(String name) {
20+
this.name = name;
21+
}
22+
23+
public String getAuthor() {
24+
return author;
25+
}
26+
27+
public void setAuthor(String author) {
28+
this.author = author;
29+
}
30+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.baeldung.meecrowave;
2+
3+
import javax.enterprise.context.RequestScoped;
4+
import javax.inject.Inject;
5+
import javax.ws.rs.GET;
6+
import javax.ws.rs.POST;
7+
import javax.ws.rs.Path;
8+
import javax.ws.rs.core.Response;
9+
import javax.ws.rs.core.Response.Status;
10+
11+
@RequestScoped
12+
@Path("article")
13+
public class ArticleEndpoints {
14+
15+
@Inject
16+
ArticleService articleService;
17+
18+
@GET
19+
public Response getArticle() {
20+
return Response.ok()
21+
.entity(new Article("name", "author"))
22+
.build();
23+
24+
}
25+
26+
@POST
27+
public Response createArticle(Article article) {
28+
return Response.status(Status.CREATED)
29+
.entity(articleService.createArticle(article))
30+
.build();
31+
}
32+
}

0 commit comments

Comments
 (0)