3
3
import java .util .List ;
4
4
public class UserDatabase implements UserExists , UserRetriever , UserCreator , IRetrieveList {
5
5
File accounts ;
6
- <<<<<<< HEAD
6
+ List < User > accountList ;
7
7
public UserDatabase (){
8
8
this .accounts = new File ("UserAccounts.csv" );
9
+ this .accountList = this .getList ();
9
10
}
10
- public UserDatabase (File accounts ){
11
- this .accounts = accounts ;
12
- }
13
- @ Override
14
- public boolean UserExists (String username , String email ) {
15
- User user = null ;
16
- =======
17
- List <User > accountList ;
18
11
public UserDatabase (File accounts ){
19
12
this .accounts = accounts ;
20
13
this .accountList = this .getList ();
21
14
}
22
15
@ Override
23
16
public boolean UserExists (String username , String email ) {
24
- /*User user = null;
25
- >>>>>>> 15-userdatabase-and-user
26
- try(FileInputStream fileIn = new FileInputStream(accounts);
27
- ObjectInputStream in = new ObjectInputStream(fileIn)){
28
- do{
29
- try{
30
- user = (User)in.readObject();
31
- }catch(NullPointerException e){
32
- <<<<<<< HEAD
33
- =======
34
- user = null;
35
- >>>>>>> 15-userdatabase-and-user
36
- break;
37
- }
38
- }while(!user.getEmail().equals(email) && !user.getUsername().equals(username));
39
- }catch(IOException e){
40
- e.printStackTrace();
41
- } catch (ClassNotFoundException e) {
42
- throw new RuntimeException(e);
43
- }
44
- <<<<<<< HEAD
45
- return user != null;
46
- =======
47
- return user != null;*/
48
17
for (User user : this .accountList ){
49
18
if (user .getUsername ().equals (username ) || user .getEmail ().equals (email )){
50
19
return true ;
51
20
}
52
21
}
53
22
return false ;
54
- >>>>>>> 15 -userdatabase -and -user
55
23
}
56
24
57
25
// Creates a new user with a username and password, and an email address
@@ -63,10 +31,7 @@ public void createUser(String username, String password, String email, String ty
63
31
try (FileOutputStream fileOut = new FileOutputStream (accounts )){
64
32
try (ObjectOutputStream out = new ObjectOutputStream (fileOut )){
65
33
out .writeObject (newUser );
66
- <<<<<<< HEAD
67
- =======
68
34
this .accountList .add (newUser );
69
- >>>>>>> 15 -userdatabase -and -user
70
35
out .close ();
71
36
fileOut .close ();
72
37
}catch (Exception e ){
@@ -95,12 +60,6 @@ public List<User> getList() {
95
60
List <User > users = new ArrayList <>();
96
61
try (FileInputStream fileIn = new FileInputStream (accounts );
97
62
ObjectInputStream in = new ObjectInputStream (fileIn )){
98
- <<<<<<< HEAD
99
- User user = (User ) in .readObject ();
100
- while (user != null ){
101
- users .add (user );
102
- user = (User )in .readObject ();
103
- =======
104
63
/*User user = (User) in.readObject();*/
105
64
while (true ){
106
65
try {
@@ -109,7 +68,6 @@ public List<User> getList() {
109
68
catch (EOFException e ){
110
69
break ;
111
70
}
112
- >>>>>>> 15 -userdatabase -and -user
113
71
}
114
72
}catch (Exception e ){
115
73
e .printStackTrace ();
0 commit comments