Skip to content

Commit 777e107

Browse files
authored
Merge branch 'master' into lor6-patch-3
2 parents a61bdbc + 0f6d947 commit 777e107

14 files changed

Lines changed: 303 additions & 2 deletions

File tree

‎core-java/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,4 @@
140140
- [Introduction to SSL in Java](http://www.baeldung.com/java-ssl)
141141
- [Java KeyStore API](http://www.baeldung.com/java-keystore)
142142
- [Using Java Assertions](http://www.baeldung.com/java-assert)
143+
- [Guide to Java Clock Class](http://www.baeldung.com/java-clock)

‎core-java/src/main/java/com/baeldung/stringisnumeric/IsNumericDriver.java‎

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

3-
import static com.baeldung.designpatterns.util.LogerUtil.LOG;
3+
import org.apache.log4j.Logger;
44

55
public class IsNumericDriver {
66
private static IsNumeric isNumeric;
7-
7+
private static Logger LOG = Logger.getLogger(IsNumericDriver.class);
88
static {
99
isNumeric =new IsNumeric();
10+
1011
}
1112

1213
public static void main(String[] args) {

‎libraries/pom.xml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,12 @@
680680
<version>${unirest.version}</version>
681681
</dependency>
682682

683+
<!-- javalin -->
684+
<dependency>
685+
<groupId>io.javalin</groupId>
686+
<artifactId>javalin</artifactId>
687+
<version>1.6.0</version>
688+
</dependency>
683689
<!-- Atlassian Fugue -->
684690
<dependency>
685691
<groupId>io.atlassian.fugue</groupId>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.javalin;
2+
3+
import com.baeldung.javalin.User.UserController;
4+
import io.javalin.Javalin;
5+
6+
public class JavalinApp {
7+
public static void main(String[] args) {
8+
Javalin app = Javalin.create()
9+
.port(7000)
10+
.start();
11+
12+
app.get("/hello", ctx -> ctx.html("Hello, Javalin!"));
13+
app.get("/users", UserController.fetchAllUsernames);
14+
app.get("/users/:id", UserController.fetchById);
15+
}
16+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.baeldung.javalin.User;
2+
3+
public class User {
4+
public final int id;
5+
public final String name;
6+
7+
public User(int id, String name) {
8+
this.id = id;
9+
this.name = name;
10+
}
11+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.baeldung.javalin.User;
2+
3+
import io.javalin.Handler;
4+
5+
import java.util.Objects;
6+
7+
public class UserController {
8+
public static Handler fetchAllUsernames = ctx -> {
9+
UserDao dao = UserDao.instance();
10+
Iterable<String> allUsers = dao.getAllUsernames();
11+
ctx.json(allUsers);
12+
};
13+
14+
public static Handler fetchById = ctx -> {
15+
int id = Integer.parseInt(Objects.requireNonNull(ctx.param("id")));
16+
UserDao dao = UserDao.instance();
17+
User user = dao.getUserById(id);
18+
if (user == null) {
19+
ctx.html("Not Found");
20+
} else {
21+
ctx.json(user);
22+
}
23+
};
24+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.baeldung.javalin.User;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
import java.util.Optional;
6+
import java.util.stream.Collectors;
7+
8+
class UserDao {
9+
10+
private final List<User> users = Arrays.asList(
11+
new User(0, "Steve Rogers"),
12+
new User(1, "Tony Stark"),
13+
new User(2, "Carol Danvers")
14+
);
15+
16+
private static UserDao userDao = null;
17+
18+
private UserDao() {
19+
}
20+
21+
static UserDao instance() {
22+
if (userDao == null) {
23+
userDao = new UserDao();
24+
}
25+
return userDao;
26+
}
27+
28+
Optional<User> getUserById(int id) { return users.stream().filter(u -> u.id == id).findFirst(); }
29+
30+
Iterable<String> getAllUsernames() {
31+
return users.stream().map(user -> user.name).collect(Collectors.toList());
32+
}
33+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.baeldung.propertyeditor;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class PropertyEditorApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(PropertyEditorApplication.class, args);
11+
}
12+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.baeldung.propertyeditor;
2+
3+
import org.springframework.http.MediaType;
4+
import org.springframework.web.bind.WebDataBinder;
5+
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.InitBinder;
7+
import org.springframework.web.bind.annotation.PathVariable;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RestController;
10+
11+
import com.baeldung.propertyeditor.creditcard.CreditCard;
12+
import com.baeldung.propertyeditor.exotictype.editor.CustomExoticTypeEditor;
13+
import com.baeldung.propertyeditor.exotictype.model.ExoticType;
14+
15+
@RestController
16+
@RequestMapping(value = "/property-editor")
17+
public class PropertyEditorRestController {
18+
19+
@GetMapping(value = "/credit-card/{card-no}",
20+
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
21+
public CreditCard parseCreditCardNumber(@PathVariable("card-no") CreditCard creditCard) {
22+
return creditCard;
23+
}
24+
25+
@GetMapping(value = "/exotic-type/{value}",
26+
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
27+
public ExoticType parseExoticType(@PathVariable("value") ExoticType exoticType) {
28+
return exoticType;
29+
}
30+
31+
@InitBinder
32+
public void initBinder(WebDataBinder binder) {
33+
binder.registerCustomEditor(ExoticType.class, new CustomExoticTypeEditor());
34+
}
35+
36+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.baeldung.propertyeditor.creditcard;
2+
3+
public class CreditCard {
4+
5+
private String rawCardNumber;
6+
7+
private Integer bankIdNo;
8+
9+
private Integer accountNo;
10+
11+
private Integer checkCode;
12+
13+
public String getRawCardNumber() {
14+
return rawCardNumber;
15+
}
16+
public void setRawCardNumber(String rawCardNumber) {
17+
this.rawCardNumber = rawCardNumber;
18+
}
19+
20+
public Integer getBankIdNo() {
21+
return bankIdNo;
22+
}
23+
public void setBankIdNo(Integer bankIdNo) {
24+
this.bankIdNo = bankIdNo;
25+
}
26+
27+
public Integer getAccountNo() {
28+
return accountNo;
29+
}
30+
public void setAccountNo(Integer accountNo) {
31+
this.accountNo = accountNo;
32+
}
33+
34+
public Integer getCheckCode() {
35+
return checkCode;
36+
}
37+
public void setCheckCode(Integer checkCode) {
38+
this.checkCode = checkCode;
39+
}
40+
41+
}

0 commit comments

Comments
 (0)