Skip to content

Commit 1e5d4cc

Browse files
author
d.bogatko
committed
expanded lambda expression to if/else to solve type interference
1 parent cbdba6d commit 1e5d4cc

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main/java/main/view/CrudServlet.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import javax.servlet.http.HttpServletRequest;
1313
import javax.servlet.http.HttpServletResponse;
1414
import java.util.List;
15+
import java.util.Optional;
1516

1617
public class CrudServlet<T extends BaseDto & IProjectEntity, D extends DAO<T>> extends BaseServlet implements IGet, IPost, IDelete {
1718

@@ -73,8 +74,15 @@ protected boolean delete(ProjectEntityController<T, D> controller, T entity) thr
7374

7475
private T createAndInit(HttpServletRequest req) {
7576
T entity = controllerType.createDto();
76-
getIntegerParameter(req, DtoFields.ID).ifPresent(entity::setId);
77-
getIntegerParameter(req, DtoFields.PROJECT_ID).ifPresent(entity::setProjectId);
77+
Optional<Integer> optId = getIntegerParameter(req, DtoFields.ID);
78+
if(optId.isPresent()){
79+
entity.setId(optId.get());
80+
}
81+
82+
Optional<Integer> optPrId = getIntegerParameter(req, DtoFields.PROJECT_ID);
83+
if(optPrId.isPresent()){
84+
entity.setProjectId(optPrId.get());
85+
}
7886
return entity;
7987
}
8088

0 commit comments

Comments
 (0)