Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve code quality #352

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import seedu.address.model.tutorial.Tutorial;

/**
* Marks the attendance of a student identified using it's displayed index from the address book.
* Marks the attendance of a student identified using it's displayed index.
*/
public class MarkAttendanceByStudentCommand extends Command {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class MarkAttendanceByStudentCommandParser implements Parser<MarkAttendan
/**
* Parses the given {@code String} of arguments in the context of the MarkAttendanceByStudentCommand
* and returns a MarkAttendanceByStudentCommand object for execution.
*
* @throws ParseException if the user input does not conform the expected format
*/
public MarkAttendanceByStudentCommand parse(String args) throws ParseException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class MarkAttendanceByTutorialCommandParser implements Parser<MarkAttenda
/**
* Parses the given {@code String} of arguments in the context of the MarkAttendanceByTutorialCommand
* and returns a MarkAttendanceByTutorialCommand object for execution.
*
* @throws ParseException if the user input does not conform the expected format
*/
public MarkAttendanceByTutorialCommand parse(String args) throws ParseException {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static Attendance parseAttendance(String attendance) throws ParseExceptio
}

/**
* Parses a {@code String attendance} into an {@code Attendance}.
* Parses a {@code String tutorial} into an {@code Tutorial}.
* Leading and trailing whitespaces will be trimmed
*/
public static Tutorial parseTutorial(String subject) throws ParseException {
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/seedu/address/model/person/Attendance.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.time.temporal.IsoFields;

/**
* Represents a Person's attendance in the address book.
* Represents a Student's attendance.
* Guarantees: immutable; is valid as declared in {@link #isValidAttendance(String)}
*/
public class Attendance {
Expand All @@ -30,7 +30,7 @@ public Attendance(LocalDate date) {
}

/**
* Returns true if a given string is a valid date format.
* Returns true if a given string is in the valid date format.
*/
public static Boolean isValidAttendance(String test) {
try {
Expand All @@ -42,15 +42,15 @@ public static Boolean isValidAttendance(String test) {
}

/**
* Returns the date attended in the valid format
* Returns the date attended in the valid format.
*/
@Override
public String toString() {
return attendanceDate.format(VALID_DATE_FORMAT);
}

/**
* Returns the date in a different format to be displayed in the UI
* Returns the date in a different format to be displayed in the UI.
*/
public String toDisplayString() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("E dd MMM");
Expand Down Expand Up @@ -93,6 +93,5 @@ public boolean isSameWeek(Attendance attendanceToBeMarked) {
return attendanceWeek == weekOfAttendanceToBeMarked && attendanceYear == yearOfAttendanceToBeMarked;
}


}

7 changes: 4 additions & 3 deletions src/main/java/seedu/address/ui/AttendanceCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ public class AttendanceCard extends UiPart<Region> {

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

public final List<Attendance> attendanceList;
public final String tutorial;

private final Logger logger = LogsCenter.getLogger(AttendanceCard.class);

private final List<Attendance> attendanceList;
private final String tutorial;

@FXML
private VBox attendanceCard;
@FXML
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/ui/AttendanceContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ public class AttendanceContainer extends UiPart<Region> {

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

public final ObservableList<Participation> participationList;

private final Logger logger = LogsCenter.getLogger(AttendanceContainer.class);

private final ObservableList<Participation> participationList;

@FXML
private Label tutorial;
@FXML
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/ui/PaymentCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ public class PaymentCard extends UiPart<Region> {

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

public final int payment;

private final Logger logger = LogsCenter.getLogger(PaymentCard.class);

private final int payment;

@FXML
private Label month;
@FXML
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/ui/PersonCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

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

private final Logger logger = LogsCenter.getLogger(PersonCard.class);

Check warning on line 24 in src/main/java/seedu/address/ui/PersonCard.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/PersonCard.java#L24

Added line #L24 was not covered by tests

/**
* Note: Certain keywords such as "location" and "resources" are reserved keywords in JavaFX.
* As a consequence, UI elements' variable names cannot be set to such keywords
Expand All @@ -29,9 +31,8 @@
* @see <a href="https://github.com/se-edu/addressbook-level4/issues/336">The issue on AddressBook level 4</a>
*/

public final Person person;
private final Person person;

private final Logger logger = LogsCenter.getLogger(PersonCard.class);
@FXML
private HBox cardPane;
@FXML
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/ui/PersonListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class PersonListPanel extends UiPart<Region> {

@FXML
private ListView<Person> personListView;

/**
* Creates a {@code PersonListPanel} with the given {@code ObservableList}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@
import seedu.address.model.person.Attendance;
import seedu.address.model.person.Person;
import seedu.address.model.tutorial.Tutorial;
import seedu.address.testutil.ParticipationBuilder;

/**
* Contains integration tests (interaction with the Model) and unit tests for
* {@code MarkAttendanceByStudentCommand}.
*/
public class MarkAttendanceByStudentCommandTest {

private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
private final Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());

@BeforeEach
public void setUp() {
Expand All @@ -49,17 +50,12 @@ public void setUp() {
public void execute_validIndexUnfilteredList_success() {
Person studentToMarkAttendance = model.getFilteredPersonList().get(INDEX_SECOND_PERSON.getZeroBased());
Tutorial tutorial = new Tutorial("Math");
Attendance attendance = new Attendance(LocalDate.of(2024, 10, 17));

// current participation of second person
Participation currentParticipation = BENSON_MATH;

Attendance attendance = new Attendance(LocalDate.of(2024, 10, 17));

List<Attendance> updatedAttendance = new ArrayList<>(currentParticipation.getAttendanceList());
updatedAttendance.add(new Attendance(LocalDate.of(2024, 10, 17)));

Participation updatedParticipation = new Participation(currentParticipation.getStudent(),
currentParticipation.getTutorial(), updatedAttendance);
Participation updatedParticipation = createUpdatedParticipation(currentParticipation, attendance);

ModelManager expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModel.setParticipation(currentParticipation, updatedParticipation);
Expand All @@ -84,11 +80,7 @@ public void execute_markPreviousWeekUnfilteredList_success() {
// create participation to mark attendance for sun of previous week of 10/10/2024
Attendance attendance = new Attendance(LocalDate.of(2024, 10, 6));

List<Attendance> updatedAttendance = new ArrayList<>(currentParticipation.getAttendanceList());
updatedAttendance.add(new Attendance(LocalDate.of(2024, 10, 6)));

Participation updatedParticipation = new Participation(currentParticipation.getStudent(),
currentParticipation.getTutorial(), updatedAttendance);
Participation updatedParticipation = createUpdatedParticipation(currentParticipation, attendance);

ModelManager expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModel.setParticipation(currentParticipation, updatedParticipation);
Expand All @@ -113,11 +105,7 @@ public void execute_markNextWeekUnfilteredList_success() {
// create participation to mark attendance for mon of next week of 10/10/2024
Attendance attendance = new Attendance(LocalDate.of(2024, 10, 14));

List<Attendance> updatedAttendance = new ArrayList<>(currentParticipation.getAttendanceList());
updatedAttendance.add(new Attendance(LocalDate.of(2024, 10, 14)));

Participation updatedParticipation = new Participation(currentParticipation.getStudent(),
currentParticipation.getTutorial(), updatedAttendance);
Participation updatedParticipation = createUpdatedParticipation(currentParticipation, attendance);

ModelManager expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModel.setParticipation(currentParticipation, updatedParticipation);
Expand Down Expand Up @@ -192,12 +180,7 @@ public void execute_validIndexFilteredList_success() {
Attendance attendance = new Attendance(LocalDate.of(2024, 10, 17));

Participation currentParticipation = BENSON_MATH;

List<Attendance> updatedAttendance = new ArrayList<>(currentParticipation.getAttendanceList());
updatedAttendance.add(new Attendance(LocalDate.of(2024, 10, 17)));

Participation updatedParticipation = new Participation(currentParticipation.getStudent(),
currentParticipation.getTutorial(), updatedAttendance);
Participation updatedParticipation = createUpdatedParticipation(currentParticipation, attendance);

ModelManager expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
showPersonAtIndex(expectedModel, INDEX_SECOND_PERSON);
Expand Down Expand Up @@ -342,5 +325,13 @@ public void constructor_nullArgs_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> new MarkAttendanceByStudentCommand(
Index.fromZeroBased(0), attendance, null));
}

private Participation createUpdatedParticipation(Participation currentParticipation, Attendance attendance) {

List<Attendance> updatedAttendance = new ArrayList<>(currentParticipation.getAttendanceList());
updatedAttendance.add(new Attendance(attendance.attendanceDate));

return new ParticipationBuilder(currentParticipation).withAttendanceList(updatedAttendance).build();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public void execute_noStudentsWithDuplicateWeeklyAttendance_success() {

for (Participation currentParticipation : participationList) {
List<Attendance> updatedAttendance = new ArrayList<>(currentParticipation.getAttendanceList());
LocalDate attendanceDate = LocalDate.parse(attendance.toString(), Attendance.VALID_DATE_FORMAT);
updatedAttendance.add(new Attendance(attendanceDate));
updatedAttendance.add(new Attendance(LocalDate.of(2024, 10, 17)));

Participation updatedParticipation = new Participation(currentParticipation.getStudent(),
currentParticipation.getTutorial(), updatedAttendance);
Expand Down Expand Up @@ -88,8 +87,7 @@ public void execute_someStudentsWithDuplicateWeeklyAttendance_success() {

// add updated participation for Alice
List<Attendance> updatedAttendanceAlice = new ArrayList<>(ALICE_MATH.getAttendanceList());
updatedAttendanceAlice.add(
new Attendance(LocalDate.parse(attendance.toString(), Attendance.VALID_DATE_FORMAT)));
updatedAttendanceAlice.add(new Attendance(LocalDate.of(2024, 10, 17)));

Participation updatedParticipationAlice = new Participation(ALICE_MATH.getStudent(),
ALICE_MATH.getTutorial(), updatedAttendanceAlice);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public class MarkAttendanceByTutorialCommandParserTest {

private MarkAttendanceByTutorialCommandParser parser = new MarkAttendanceByTutorialCommandParser();
private final MarkAttendanceByTutorialCommandParser parser = new MarkAttendanceByTutorialCommandParser();

@Test
public void parse_validArgs_returnsMarkAttendanceByTutorialCommand() {
Expand Down