Skip to content

Commit e4efd7e

Browse files
committed
added changes made to another branch and brought it here
2 parents b8f86ab + 046161e commit e4efd7e

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

src/main/java/TestUserDatabase2.csv

Whitespace-only changes.

src/main/java/UserDatabase.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.List;
44
public class UserDatabase implements UserExists, UserRetriever, UserCreator, IRetrieveList{
55
File accounts;
6+
<<<<<<< HEAD
67
public UserDatabase(){
78
this.accounts = new File("UserAccounts.csv");
89
}
@@ -12,12 +13,26 @@ public UserDatabase(File accounts){
1213
@Override
1314
public boolean UserExists(String username, String email) {
1415
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
1526
try(FileInputStream fileIn = new FileInputStream(accounts);
1627
ObjectInputStream in = new ObjectInputStream(fileIn)){
1728
do{
1829
try{
1930
user = (User)in.readObject();
2031
}catch(NullPointerException e){
32+
<<<<<<< HEAD
33+
=======
34+
user = null;
35+
>>>>>>> 15-userdatabase-and-user
2136
break;
2237
}
2338
}while(!user.getEmail().equals(email) && !user.getUsername().equals(username));
@@ -26,7 +41,17 @@ public boolean UserExists(String username, String email) {
2641
} catch (ClassNotFoundException e) {
2742
throw new RuntimeException(e);
2843
}
44+
<<<<<<< HEAD
2945
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
3055
}
3156

3257
// 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
3863
try(FileOutputStream fileOut = new FileOutputStream(accounts)){
3964
try(ObjectOutputStream out = new ObjectOutputStream(fileOut)){
4065
out.writeObject(newUser);
66+
<<<<<<< HEAD
67+
=======
68+
this.accountList.add(newUser);
69+
>>>>>>> 15-userdatabase-and-user
4170
out.close();
4271
fileOut.close();
4372
}catch(Exception e){
@@ -66,10 +95,21 @@ public List<User> getList() {
6695
List<User> users = new ArrayList<>();
6796
try(FileInputStream fileIn = new FileInputStream(accounts);
6897
ObjectInputStream in = new ObjectInputStream(fileIn)){
98+
<<<<<<< HEAD
6999
User user = (User) in.readObject();
70100
while(user != null){
71101
users.add(user);
72102
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
73113
}
74114
}catch(Exception e){
75115
e.printStackTrace();

src/test/java/UserDatabaseTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
import org.junit.jupiter.api.Test;
33

44
import java.io.File;
5+
<<<<<<< HEAD
56
import java.util.ArrayList;
7+
=======
8+
>>>>>>> 15-userdatabase-and-user
69
import java.util.List;
710

811
public class UserDatabaseTest {
@@ -24,6 +27,10 @@ public void addingMultipleFiles(){
2427
public void rightEmailWrongUser(){
2528
File accounts = new File("TestUserDatabase2.csv");
2629
UserDatabase accountDatabase = new UserDatabase(accounts);
30+
<<<<<<< HEAD
31+
=======
32+
accountDatabase.createUser("MadhavGopakumar", "123", "[email protected]", "Basic");
33+
>>>>>>> 15-userdatabase-and-user
2734
Assertions.assertTrue(accountDatabase.UserExists("MadG", "[email protected]"));
2835
}
2936
@Test

0 commit comments

Comments
 (0)