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