diff --git a/src/main/java/seedu/address/model/contact/Role.java b/src/main/java/seedu/address/model/contact/Role.java index 75b684d09f3..67368dc8e38 100644 --- a/src/main/java/seedu/address/model/contact/Role.java +++ b/src/main/java/seedu/address/model/contact/Role.java @@ -66,7 +66,7 @@ public Role(String roleName) { public static boolean isValidRoleName(String test) { requireNonNull(test); return Arrays.stream(AVAILABLE_ROLES) - .map(role -> role.toLowerCase()) + .map(String::toLowerCase) .anyMatch(role -> role.equals(test.trim().toLowerCase())); } @@ -82,13 +82,7 @@ private String toOfficialCase(String input) { } private int assignRoleIndex(String roleName) { - assert roleName.equals(PRESIDENT) // must be case sensitive - || roleName.equals(VICE_PRESIDENT) - || roleName.equals(ADMIN) - || roleName.equals(MARKETING) - || roleName.equals(EVENTS_INTERNAL) - || roleName.equals(EVENTS_EXTERNAL) - || roleName.equals(EXTERNAL_RELATIONS); + assert Arrays.asList(AVAILABLE_ROLES).contains(roleName); int errorStatus = -1; diff --git a/src/main/java/seedu/address/ui/PaginationPanel.java b/src/main/java/seedu/address/ui/PaginationPanel.java index 92a421a0923..f8420144853 100644 --- a/src/main/java/seedu/address/ui/PaginationPanel.java +++ b/src/main/java/seedu/address/ui/PaginationPanel.java @@ -1,12 +1,16 @@ package seedu.address.ui; +import static java.util.Objects.requireNonNull; + import java.util.List; +import java.util.logging.Logger; import javafx.collections.FXCollections; import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; import javafx.scene.Node; import javafx.scene.control.Pagination; +import seedu.address.commons.core.LogsCenter; import seedu.address.model.contact.Contact; /** @@ -15,6 +19,7 @@ public class PaginationPanel extends Pagination { public static final int ROWS_PER_PAGE = 10; private static int currentPageIndex = 0; + private static final Logger logger = LogsCenter.getLogger(PaginationPanel.class); private final ObservableList contactList; /** @@ -23,8 +28,9 @@ public class PaginationPanel extends Pagination { */ public PaginationPanel(ObservableList contactList) { super(); + requireNonNull(contactList); this.contactList = contactList; - this.contactList.addListener(this::onListItemsChanged); // enables UI update to ContactPagination + this.contactList.addListener(this::onListItemsChanged); this.initPagination(); } @@ -34,18 +40,21 @@ public PaginationPanel(ObservableList contactList) { * @return The index of the item in {@code contactList}. */ public static int convertItemIndexToDisplayIndex(int itemIndex) { - return (currentPageIndex) * ROWS_PER_PAGE + itemIndex + 1; + assert itemIndex >= 0; + return currentPageIndex * ROWS_PER_PAGE + itemIndex + 1; } private void initPagination() { final int minPageCount = 1; - int pageCount = Math.max((int) Math.ceil((double) contactList.size() / ROWS_PER_PAGE), minPageCount); + int expectedPageCount = (int) Math.ceil((double) contactList.size() / ROWS_PER_PAGE); + int pageCount = Math.max(expectedPageCount, minPageCount); this.setPageCount(pageCount); - this.setStyle("-fx-page-information-alignment: bottom;"); this.setPageFactory(this::createPage); + logger.info("A pagination which contains " + pageCount + " page(s) has been created."); } private Node createPage(int pageIndex) { + assert pageIndex >= 0; PaginationPanel.currentPageIndex = pageIndex; int fromIndex = pageIndex * PaginationPanel.ROWS_PER_PAGE; int endIndex = Math.min(fromIndex + PaginationPanel.ROWS_PER_PAGE, contactList.size()); @@ -59,5 +68,6 @@ private Node createPage(int pageIndex) { private void onListItemsChanged(ListChangeListener.Change unused) { this.initPagination(); + logger.info("Re-render pagination due to the change of list items."); } }