📄 users.java
字号:
package forum;
import java.util.*;
/**
* Represents all users in the discussion forum.
* <p>
* In a real system there would be a database containing the users.
*
* @author Simon Brown
*/
public class Users {
/** a collection of all users in the system */
private static HashMap users = new HashMap();
/**
* Populates the collection of all users when the class is loaded.
*/
static {
User user;
user = new User("Simon", "password");
users.put(user.getId(), user);
user = new User("Sam", "password");
users.put(user.getId(), user);
}
/**
* Determines whether a user with the specified id and password exists.
*
* @param id a user id
* @param password a password
* @return true if a user exists in the system with the specified
* id and password, false otherwise
*/
public static boolean exists(String id, String password) {
User user = (User)users.get(id);
return (user != null) && (user.getPassword().equals(password));
}
/**
* Gets the user with the specified user id.
*
* @param id a user id
* @return a User instance, could be null
*/
public static User getUser(String id) {
return (User)users.get(id);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -