-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Use an empty collection instead of null return value
- Loading branch information
Showing
5 changed files
with
23 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,37 +24,44 @@ | |
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import org.springframework.util.CollectionUtils; | ||
|
||
/** | ||
* @author Jason Song([email protected]) | ||
*/ | ||
public class DefaultUserService implements UserService { | ||
|
||
private static final String DEFAULT_USER_ID = "apollo"; | ||
|
||
@Override | ||
public List<UserInfo> searchUsers(String keyword, int offset, int limit, boolean includeInactiveUsers) { | ||
return Collections.singletonList(assembleDefaultUser()); | ||
} | ||
|
||
@Override | ||
public UserInfo findByUserId(String userId) { | ||
if (Objects.equals(userId, "apollo")) { | ||
if (Objects.equals(userId, DEFAULT_USER_ID)) { | ||
return assembleDefaultUser(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public List<UserInfo> findByUserIds(List<String> userIds) { | ||
if (userIds.contains("apollo")) { | ||
if (CollectionUtils.isEmpty(userIds)) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
if (userIds.contains(DEFAULT_USER_ID)) { | ||
return Lists.newArrayList(assembleDefaultUser()); | ||
} | ||
return null; | ||
return Collections.emptyList(); | ||
} | ||
|
||
private UserInfo assembleDefaultUser() { | ||
UserInfo defaultUser = new UserInfo(); | ||
defaultUser.setUserId("apollo"); | ||
defaultUser.setName("apollo"); | ||
defaultUser.setUserId(DEFAULT_USER_ID); | ||
defaultUser.setName(DEFAULT_USER_ID); | ||
defaultUser.setEmail("[email protected]"); | ||
|
||
return defaultUser; | ||
|