-
Notifications
You must be signed in to change notification settings - Fork 948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hometask done #898
base: master
Are you sure you want to change the base?
Hometask done #898
Conversation
int i = 0; | ||
while (i < users.length) { | ||
if (users[i].getEmail().equals(email)) { | ||
return users[i]; | ||
} | ||
i++; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you better use for each loop
*/ | ||
public boolean login(String email, String password) { | ||
return false; | ||
UserService userService = new UserService(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UserService should be class field
return Objects.requireNonNull(UserService.findByEmail(email)).getEmail().equals(email) | ||
&& Objects.requireNonNull(UserService.findByEmail(email)).getPassword() | ||
.equals(password); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don`t need use class Objects here, at first you can get user form UserService.findByEmail(email) anf after this compare his password
|
||
for (User user: users) { | ||
if (user.getEmail().equals(email)) { | ||
return user; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant blank lines
for (User user: users) { | |
if (user.getEmail().equals(email)) { | |
return user; | |
} | |
} | |
for (User user: users) { | |
if (user.getEmail().equals(email)) { | |
return user; | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not fixed
|
||
if (userService.findByEmail(email).getPassword().equals(password)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- many redundant blank lines
- we will get NPE if
userService.findByEmail(email)
returns null. save returneduser
to the variable and check for nullability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not fixed
@@ -1,16 +1,20 @@ | |||
package mate.academy.service; | |||
|
|||
public class AuthenticationService { | |||
private static final UserService userService = new UserService(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private static final UserService userService = new UserService(); | |
private final UserService userService = new UserService(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not fixed
@@ -1,16 +1,20 @@ | |||
package mate.academy.service; | |||
|
|||
public class AuthenticationService { | |||
private static final UserService userService = new UserService(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not fixed
|
||
if (userService.findByEmail(email).getPassword().equals(password)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not fixed
|
||
for (User user: users) { | ||
if (user.getEmail().equals(email)) { | ||
return user; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not fixed
private final String email; | ||
private final String password; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don`t change it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I need to remove final? What can I do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (userService.findByEmail(email).getPassword().equals(password)) { | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (userService.findByEmail(email).getPassword().equals(password)) { | |
return true; | |
} | |
if (user.getPassword().equals(password)) { | |
return true; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You already have a user, you don`t need use "userService.findByEmail(email)" anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After this write the return condition in one line, you don`t need write return 2 times
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nox fixed
@@ -3,18 +3,17 @@ | |||
import mate.academy.model.User; | |||
|
|||
public class UserService { | |||
private static final User[] users = new User[] { | |||
private final User[] users = new User[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don`t change it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed and removed static. What should I do else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed static a long time ago. I don't understand why you don't see it
if (userService.findByEmail(email).getPassword().equals(password)) { | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nox fixed
# Conflicts: # src/main/java/mate/academy/service/AuthenticationService.java
if (user.getPassword().equals(password)) { | ||
return true; | ||
} | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- add check for
user != null
- inline it
@@ -3,18 +3,17 @@ | |||
import mate.academy.model.User; | |||
|
|||
public class UserService { | |||
private static final User[] users = new User[] { | |||
private final User[] users = new User[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private final String email; | ||
private final String password; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (user != null && user.getPassword().equals(password)) { | ||
return true; | ||
} | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, it looks great, can you simplify it by writing in one line with return? After this you don`t need to write return 2 times) If you need some help better ask it in chat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not fixed prev comments
if (user != null && user.getPassword().equals(password)) { | ||
return true; | ||
} | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not fixed
No description provided.