public class UserFactory
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private int |
id |
private java.lang.String |
userFilename |
private java.util.List<User> |
users |
Constructor and Description |
---|
UserFactory()
Create a new empty UserFactory
|
UserFactory(java.lang.String userFilename)
Create a new UserFactory and fill it with information from a JSON file
|
Modifier and Type | Method and Description |
---|---|
(package private) User |
getUser(int index)
Looks for a User with the given id
|
User |
getUser(java.lang.String name)
Looks for the User with the given name
|
(package private) User |
newUser(java.lang.String name,
int limit)
Adds a new User into this class
|
private User |
search(int index,
int start,
int end)
Recursive binary search through the array list for the User with the given id
|
(package private) void |
setUserFileName(java.lang.String userFilename)
Update the output filename for the object
|
(package private) void |
toJsonFile()
Output the data into a JSON file replacing the input file (or if filename not given, "users.json")
|
void |
update(User oldUser,
User newUser)
Replacing a User in the array list with a new User
|
private int id
private java.lang.String userFilename
private java.util.List<User> users
public UserFactory()
public UserFactory(java.lang.String userFilename)
userFilename
- Name of the input JSON fileUser getUser(int index)
index
- id of the User to be foundpublic User getUser(java.lang.String name)
name
- Name of the User to be foundUser newUser(java.lang.String name, int limit)
name
- Name of the Userlimit
- Limit of Book the User can borrowprivate User search(int index, int start, int end)
index
- id of the User to be foundstart
- Starting point to searchend
- Ending point to searchvoid setUserFileName(java.lang.String userFilename)
userFilename
- The new filenamevoid toJsonFile()