Skip to content

Commit bf95d0a

Browse files
author
eugenp
committed
minor formatting cleanup
1 parent c565173 commit bf95d0a

11 files changed

Lines changed: 80 additions & 105 deletions

File tree

disruptor/src/main/java/com/baeldung/disruptor/MultiEventPrintConsumer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public class MultiEventPrintConsumer implements EventConsumer {
99

1010
private final Logger logger = LoggerFactory.getLogger(this.getClass());
11-
11+
1212
@Override
1313
@SuppressWarnings("unchecked")
1414
public EventHandler<ValueEvent>[] getEventHandler() {

disruptor/src/main/java/com/baeldung/disruptor/SingleEventPrintConsumer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public class SingleEventPrintConsumer implements EventConsumer {
99

1010
private final Logger logger = LoggerFactory.getLogger(this.getClass());
11-
11+
1212
@Override
1313
@SuppressWarnings("unchecked")
1414
public EventHandler<ValueEvent>[] getEventHandler() {
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.baeldung.sparkjava;
2+
23
import static spark.Spark.*;
34

45
public class HelloWorldService {
56
public static void main(String[] args) {
6-
get("/hello", (req,res)->"Hello, Baeldung");
7-
8-
get("/hello/:name", (req,res)->{
9-
return "Hello: "+ req.params(":name");
7+
get("/hello", (req, res) -> "Hello, Baeldung");
8+
9+
get("/hello/:name", (req, res) -> {
10+
return "Hello: " + req.params(":name");
1011
});
1112
}
1213
}

spark-java/src/main/java/com/baeldung/sparkjava/SparkRestExample.java

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
public class SparkRestExample {
1212
public static void main(String[] args) {
1313
final UserService userService = new UserServiceMapImpl();
14-
14+
1515
post("/users", (request, response) -> {
1616
response.type("application/json");
17-
17+
1818
User user = new Gson().fromJson(request.body(), User.class);
1919
userService.addUser(user);
2020

@@ -23,52 +23,40 @@ public static void main(String[] args) {
2323

2424
get("/users", (request, response) -> {
2525
response.type("application/json");
26-
27-
return new Gson().toJson(
28-
new StandardResponse(StatusResponse.SUCCESS,new Gson()
29-
.toJsonTree(userService.getUsers())));
26+
27+
return new Gson().toJson(new StandardResponse(StatusResponse.SUCCESS, new Gson().toJsonTree(userService.getUsers())));
3028
});
3129

3230
get("/users/:id", (request, response) -> {
3331
response.type("application/json");
34-
35-
return new Gson().toJson(
36-
new StandardResponse(StatusResponse.SUCCESS,new Gson()
37-
.toJsonTree(userService.getUser(request.params(":id")))));
32+
33+
return new Gson().toJson(new StandardResponse(StatusResponse.SUCCESS, new Gson().toJsonTree(userService.getUser(request.params(":id")))));
3834
});
3935

4036
put("/users/:id", (request, response) -> {
4137
response.type("application/json");
42-
38+
4339
User toEdit = new Gson().fromJson(request.body(), User.class);
4440
User editedUser = userService.editUser(toEdit);
45-
41+
4642
if (editedUser != null) {
47-
return new Gson().toJson(
48-
new StandardResponse(StatusResponse.SUCCESS,new Gson()
49-
.toJsonTree(editedUser)));
50-
}else {
51-
return new Gson().toJson(
52-
new StandardResponse(StatusResponse.ERROR,new Gson()
53-
.toJson("User not found or error in edit")));
43+
return new Gson().toJson(new StandardResponse(StatusResponse.SUCCESS, new Gson().toJsonTree(editedUser)));
44+
} else {
45+
return new Gson().toJson(new StandardResponse(StatusResponse.ERROR, new Gson().toJson("User not found or error in edit")));
5446
}
5547
});
5648

5749
delete("/users/:id", (request, response) -> {
5850
response.type("application/json");
59-
51+
6052
userService.deleteUser(request.params(":id"));
61-
return new Gson().toJson(
62-
new StandardResponse(StatusResponse.SUCCESS, "user deleted"));
53+
return new Gson().toJson(new StandardResponse(StatusResponse.SUCCESS, "user deleted"));
6354
});
6455

6556
options("/users/:id", (request, response) -> {
6657
response.type("application/json");
67-
68-
return new Gson().toJson(
69-
new StandardResponse(StatusResponse.SUCCESS,
70-
(userService.userExist(
71-
request.params(":id"))) ? "User exists" : "User does not exists" ));
58+
59+
return new Gson().toJson(new StandardResponse(StatusResponse.SUCCESS, (userService.userExist(request.params(":id"))) ? "User exists" : "User does not exists"));
7260
});
7361

7462
}

spark-java/src/main/java/com/baeldung/sparkjava/StatusResponse.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package com.baeldung.sparkjava;
22

33
public enum StatusResponse {
4-
SUCCESS ("Success"),
5-
ERROR ("Error");
6-
4+
SUCCESS("Success"), ERROR("Error");
5+
76
final private String status;
8-
7+
98
StatusResponse(String status) {
109
this.status = status;
1110
}
12-
11+
1312
public String getStatus() {
1413
return status;
1514
}

spark-java/src/main/java/com/baeldung/sparkjava/User.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public String getEmail() {
5151
public void setEmail(String email) {
5252
this.email = email;
5353
}
54-
54+
5555
@Override
5656
public String toString() {
5757
return new StringBuffer().append(getEmail()).toString();

spark-java/src/main/java/com/baeldung/sparkjava/UserException.java

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

3-
public class UserException extends Exception{
4-
3+
public class UserException extends Exception {
4+
55
public UserException() {
66
super();
77
}
8-
8+
99
public UserException(String message) {
1010
super(message);
1111
}

spark-java/src/main/java/com/baeldung/sparkjava/UserService.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
import java.util.Collection;
44

55
public interface UserService {
6-
public void addUser (User user) ;
7-
public Collection<User> getUsers () ;
8-
public User getUser (String id) ;
9-
public User editUser (User user) throws UserException;
10-
public void deleteUser (String id) ;
11-
public boolean userExist (String id);
6+
public void addUser(User user);
7+
8+
public Collection<User> getUsers();
9+
10+
public User getUser(String id);
11+
12+
public User editUser(User user) throws UserException;
13+
14+
public void deleteUser(String id);
15+
16+
public boolean userExist(String id);
1217
}

spark-java/src/main/java/com/baeldung/sparkjava/UserServiceMapImpl.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,65 @@
33
import java.util.Collection;
44
import java.util.HashMap;
55

6-
public class UserServiceMapImpl implements UserService{
6+
public class UserServiceMapImpl implements UserService {
77
private HashMap<String, User> userMap;
8-
8+
99
public UserServiceMapImpl() {
1010
userMap = new HashMap<>();
1111
}
1212

1313
@Override
14-
public void addUser (User user) {
14+
public void addUser(User user) {
1515
userMap.put(user.getId(), user);
1616
}
17-
17+
1818
@Override
19-
public Collection<User> getUsers () {
20-
return userMap.values();
19+
public Collection<User> getUsers() {
20+
return userMap.values();
2121
}
22-
22+
2323
@Override
24-
public User getUser (String id) {
24+
public User getUser(String id) {
2525
return userMap.get(id);
2626
}
27-
27+
2828
@Override
29-
public User editUser (User forEdit) throws UserException{
30-
try{
31-
if (forEdit.getId() == null)
29+
public User editUser(User forEdit) throws UserException {
30+
try {
31+
if (forEdit.getId() == null)
3232
throw new UserException("ID cannot be blank");
33-
33+
3434
User toEdit = userMap.get(forEdit.getId());
35-
36-
if (toEdit == null )
35+
36+
if (toEdit == null)
3737
throw new UserException("User not found");
38-
39-
if (forEdit.getEmail()!=null) {
38+
39+
if (forEdit.getEmail() != null) {
4040
toEdit.setEmail(forEdit.getEmail());
4141
}
42-
if (forEdit.getFirstName()!=null) {
42+
if (forEdit.getFirstName() != null) {
4343
toEdit.setFirstName(forEdit.getFirstName());
4444
}
45-
if (forEdit.getLastName()!=null) {
45+
if (forEdit.getLastName() != null) {
4646
toEdit.setLastName(forEdit.getLastName());
4747
}
48-
if (forEdit.getId()!=null) {
48+
if (forEdit.getId() != null) {
4949
toEdit.setId(forEdit.getId());
5050
}
5151

5252
return toEdit;
53-
}catch (Exception ex) {
53+
} catch (Exception ex) {
5454
throw new UserException(ex.getMessage());
5555
}
5656
}
57-
57+
5858
@Override
59-
public void deleteUser (String id) {
59+
public void deleteUser(String id) {
6060
userMap.remove(id);
6161
}
62-
62+
6363
@Override
64-
public boolean userExist (String id) {
64+
public boolean userExist(String id) {
6565
return userMap.containsKey(id);
6666
}
6767

spring-security-core/src/main/java/org/baeldung/config/WebSecurityConfig.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,11 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
1515

1616
@Override
1717
protected void configure(HttpSecurity http) throws Exception {
18-
http
19-
.authorizeRequests()
20-
.antMatchers("/css/**", "/js/**", "/loggedout").permitAll()
21-
.anyRequest().authenticated()
22-
.and()
23-
.httpBasic()
24-
.and()
25-
.logout().disable()
26-
.csrf().disable();
18+
http.authorizeRequests().antMatchers("/css/**", "/js/**", "/loggedout").permitAll().anyRequest().authenticated().and().httpBasic().and().logout().disable().csrf().disable();
2719
}
2820

2921
@Autowired
3022
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
31-
auth
32-
.inMemoryAuthentication()
33-
.withUser("jim").password("jim").roles("USER")
34-
.and()
35-
.withUser("pam").password("pam").roles("USER")
36-
.and()
37-
.withUser("michael").password("michael").roles("MANAGER");
23+
auth.inMemoryAuthentication().withUser("jim").password("jim").roles("USER").and().withUser("pam").password("pam").roles("USER").and().withUser("michael").password("michael").roles("MANAGER");
3824
}
3925
}

0 commit comments

Comments
 (0)