Skip to content

Commit

Permalink
Merge pull request #104 from KrashKart/branch-empty-starting-list
Browse files Browse the repository at this point in the history
Initialise CampusConnect with empty contact list
  • Loading branch information
yooplo authored Oct 21, 2024
2 parents cc91ccf + 26c133f commit d94478e
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 17 deletions.
7 changes: 3 additions & 4 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import seedu.address.model.ReadOnlyCampusConnect;
import seedu.address.model.ReadOnlyUserPrefs;
import seedu.address.model.UserPrefs;
import seedu.address.model.util.SampleDataUtil;
import seedu.address.model.util.EmptyDataUtil;
import seedu.address.storage.CampusConnectStorage;
import seedu.address.storage.JsonCampusConnectStorage;
import seedu.address.storage.JsonUserPrefsStorage;
Expand Down Expand Up @@ -80,10 +80,9 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
try {
campusConnectOptional = storage.readCampusConnect();
if (!campusConnectOptional.isPresent()) {
logger.info("Creating a new data file " + storage.getCampusConnectFilePath()
+ " populated with a sample CampusConnect.");
logger.info("Creating a new data file at: " + storage.getCampusConnectFilePath());
}
initialData = campusConnectOptional.orElseGet(SampleDataUtil::getSampleCampusConnect);
initialData = campusConnectOptional.orElseGet(EmptyDataUtil::getSampleCampusConnect);
} catch (DataLoadingException e) {
logger.warning("Data file at " + storage.getCampusConnectFilePath() + " could not be loaded."
+ " Will be starting with an empty CampusConnect.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public abstract class AbstractFindCommand extends Command {
+ COMMAND_WORD + PHONE_COMMAND_WORD + "12345678\n"
+ COMMAND_WORD + TAG_COMMAND_WORD + "CS2100_classmate\n";

public static final String MESSAGE_NO_PERSONS_FOUND = "No persons found!";

private final ContainsKeywordsPredicate predicate;

public AbstractFindCommand(ContainsKeywordsPredicate predicate) {
Expand All @@ -42,6 +44,12 @@ protected ContainsKeywordsPredicate getPredicate() {
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredPersonList(this.predicate);

// if the result find list is empty
if (model.getFilteredPersonList().isEmpty()) {
return new CommandResult(MESSAGE_NO_PERSONS_FOUND);
}

return new CommandResult(
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class DeleteCommand extends Command {

public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s";

public static final String MESSAGE_DELETE_LIST_EMPTY = "\nThe contact list is empty! :(";

private final Index targetIndex;

public DeleteCommand(Index targetIndex) {
Expand All @@ -42,7 +44,12 @@ public CommandResult execute(Model model) throws CommandException {

Person personToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deletePerson(personToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(personToDelete)));

String result = String.format(MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(personToDelete));
if (model.getFilteredPersonList().isEmpty()) {
result += MESSAGE_DELETE_LIST_EMPTY;
}
return new CommandResult(result);
}

@Override
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/seedu/address/model/util/EmptyDataUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package seedu.address.model.util;

import seedu.address.model.CampusConnect;
import seedu.address.model.ReadOnlyCampusConnect;

/**
* Contains utility method for populating {@code CampusConnect} with empty data.
*/
public class EmptyDataUtil {
public static ReadOnlyCampusConnect getSampleCampusConnect() {
return new CampusConnect();
}
}
9 changes: 5 additions & 4 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import java.util.Set;
import java.util.stream.Collectors;

import seedu.address.model.CampusConnect;
import seedu.address.model.ReadOnlyCampusConnect;
//import seedu.address.model.CampusConnect;
//import seedu.address.model.ReadOnlyCampusConnect;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
Expand Down Expand Up @@ -33,13 +33,15 @@ public static Person[] getSamplePersons() {
};
}

// Schedule for deletion
/*
public static ReadOnlyCampusConnect getSampleCampusConnect() {
CampusConnect sampleAb = new CampusConnect();
for (Person samplePerson : getSamplePersons()) {
sampleAb.addPerson(samplePerson);
}
return sampleAb;
}
}*/

/**
* Returns a tag set containing the list of strings given.
Expand All @@ -49,5 +51,4 @@ public static Set<Tag> getTagSet(String... strings) {
.map(Tag::new)
.collect(Collectors.toSet());
}

}
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class MainWindow extends UiPart<Stage> {

private static final String FXML = "MainWindow.fxml";

private static final String LIST_EMPTY_MESSAGE = "The contact list is empty! :(";

private final Logger logger = LogsCenter.getLogger(getClass());

private Stage primaryStage;
Expand Down Expand Up @@ -122,6 +124,9 @@ void fillInnerParts() {

resultDisplay = new ResultDisplay();
resultDisplayPlaceholder.getChildren().add(resultDisplay.getRoot());
if (logic.getFilteredPersonList().isEmpty()) {
resultDisplay.setFeedbackToUser(LIST_EMPTY_MESSAGE);
}

StatusBarFooter statusBarFooter = new StatusBarFooter(logic.getCampusConnectFilePath());
statusbarPlaceholder.getChildren().add(statusBarFooter.getRoot());
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/view/PersonListPanel.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
<?import javafx.scene.layout.VBox?>

<VBox xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1">
<ListView fx:id="personListView" VBox.vgrow="ALWAYS" />
<ListView fx:id="personListView" VBox.vgrow="ALWAYS" styleClass="background"/>
</VBox>
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void execute_validIndexFilteredList_success() {
DeleteCommand deleteCommand = new DeleteCommand(INDEX_FIRST_PERSON);

String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_PERSON_SUCCESS,
Messages.format(personToDelete));
Messages.format(personToDelete) + DeleteCommand.MESSAGE_DELETE_LIST_EMPTY);

Model expectedModel = new ModelManager(model.getCampusConnect(), new UserPrefs());
expectedModel.deletePerson(personToDelete);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void equals() {

@Test
public void execute_zeroKeywords_noPersonFound() {
String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0);
String expectedMessage = AbstractFindCommand.MESSAGE_NO_PERSONS_FOUND;
EmailContainsKeywordsPredicate predicate = preparePredicate(" ");
FindByEmailCommand command = new FindByEmailCommand(predicate);
expectedModel.updateFilteredPersonList(predicate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void equals() {

@Test
public void execute_zeroKeywords_noPersonFound() {
String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0);
String expectedMessage = AbstractFindCommand.MESSAGE_NO_PERSONS_FOUND;
NameContainsKeywordsPredicate predicate = preparePredicate(" ");
FindByNameCommand command = new FindByNameCommand(predicate);
expectedModel.updateFilteredPersonList(predicate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void equals() {

@Test
public void execute_zeroKeywords_noPersonFound() {
String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0);
String expectedMessage = AbstractFindCommand.MESSAGE_NO_PERSONS_FOUND;
PhoneContainsKeywordsPredicate predicate = preparePredicate(" ");
FindByPhoneCommand command = new FindByPhoneCommand(predicate);
expectedModel.updateFilteredPersonList(predicate);
Expand All @@ -82,8 +82,6 @@ public void execute_multipleKeywords_multiplePersonsFound() {
PhoneContainsKeywordsPredicate predicate = preparePredicate("9482 563");
FindByPhoneCommand command = new FindByPhoneCommand(predicate);
expectedModel.updateFilteredPersonList(predicate);
System.out.println(command);
System.out.println(expectedModel.getFilteredPersonList().toString());
assertCommandSuccess(command, model, expectedMessage, expectedModel);
assertEquals(Arrays.asList(CARL, ELLE, FIONA, GEORGE), model.getFilteredPersonList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void equals() {

@Test
public void execute_zeroKeywords_noPersonFound() {
String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0);
String expectedMessage = AbstractFindCommand.MESSAGE_NO_PERSONS_FOUND;
TagContainsKeywordsPredicate predicate = preparePredicate(" ");
FindByTagCommand command = new FindByTagCommand(predicate);
expectedModel.updateFilteredPersonList(predicate);
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/seedu/address/model/util/EmptyDataUtilTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package seedu.address.model.util;

import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

public class EmptyDataUtilTest {
@Test
public void getSampleCampusConnect_returnsEmptyCampusConnect() {
assertTrue(EmptyDataUtil.getSampleCampusConnect().getPersonList().isEmpty());
}
}

0 comments on commit d94478e

Please sign in to comment.