From ec674b7b5a9656cc2d1635f6530a54b0eb7ce25c Mon Sep 17 00:00:00 2001 From: Irvin Lim Date: Mon, 7 Nov 2016 03:35:48 +0800 Subject: [PATCH] Remove redundant files --- .../seedu/todo/commons/core/GuiSettings.java | 73 --------- .../seedu/todo/commons/core/Messages.java | 13 -- .../storage/DataSavingExceptionEvent.java | 21 --- .../events/ui/JumpToListRequestEvent.java | 21 --- .../events/ui/ShowHelpRequestEvent.java | 15 -- .../java/seedu/todo/commons/util/UrlUtil.java | 24 --- src/main/java/seedu/todo/ui/MainWindow.java | 9 -- .../seedu/todo/commons/util/UrlUtilTest.java | 54 ------- .../seedu/todo/testutil/EventsCollector.java | 42 ------ .../todo/testutil/SerializableTestClass.java | 73 --------- .../java/seedu/todo/testutil/TestUtil.java | 140 ------------------ 11 files changed, 485 deletions(-) delete mode 100644 src/main/java/seedu/todo/commons/core/GuiSettings.java delete mode 100644 src/main/java/seedu/todo/commons/core/Messages.java delete mode 100644 src/main/java/seedu/todo/commons/events/storage/DataSavingExceptionEvent.java delete mode 100644 src/main/java/seedu/todo/commons/events/ui/JumpToListRequestEvent.java delete mode 100644 src/main/java/seedu/todo/commons/events/ui/ShowHelpRequestEvent.java delete mode 100644 src/main/java/seedu/todo/commons/util/UrlUtil.java delete mode 100644 src/test/java/seedu/todo/commons/util/UrlUtilTest.java delete mode 100644 src/test/java/seedu/todo/testutil/EventsCollector.java delete mode 100644 src/test/java/seedu/todo/testutil/SerializableTestClass.java diff --git a/src/main/java/seedu/todo/commons/core/GuiSettings.java b/src/main/java/seedu/todo/commons/core/GuiSettings.java deleted file mode 100644 index d1851fb7a256..000000000000 --- a/src/main/java/seedu/todo/commons/core/GuiSettings.java +++ /dev/null @@ -1,73 +0,0 @@ -package seedu.todo.commons.core; - -import java.awt.*; -import java.io.Serializable; -import java.util.Objects; - -/** - * A Serializable class that contains the GUI settings. - */ -public class GuiSettings implements Serializable { - - private static final double DEFAULT_HEIGHT = 600; - private static final double DEFAULT_WIDTH = 740; - - private Double windowWidth; - private Double windowHeight; - private Point windowCoordinates; - - public GuiSettings() { - this.windowWidth = DEFAULT_WIDTH; - this.windowHeight = DEFAULT_HEIGHT; - this.windowCoordinates = null; // null represent no coordinates - } - - public GuiSettings(Double windowWidth, Double windowHeight, int xPosition, int yPosition) { - this.windowWidth = windowWidth; - this.windowHeight = windowHeight; - this.windowCoordinates = new Point(xPosition, yPosition); - } - - public Double getWindowWidth() { - return windowWidth; - } - - public Double getWindowHeight() { - return windowHeight; - } - - public Point getWindowCoordinates() { - return windowCoordinates; - } - - @Override - public boolean equals(Object other) { - if (other == this){ - return true; - } - if (!(other instanceof GuiSettings)){ //this handles null as well. - return false; - } - - GuiSettings o = (GuiSettings)other; - - return Objects.equals(windowWidth, o.windowWidth) - && Objects.equals(windowHeight, o.windowHeight) - && Objects.equals(windowCoordinates.x, o.windowCoordinates.x) - && Objects.equals(windowCoordinates.y, o.windowCoordinates.y); - } - - @Override - public int hashCode() { - return Objects.hash(windowWidth, windowHeight, windowCoordinates); - } - - @Override - public String toString(){ - StringBuilder sb = new StringBuilder(); - sb.append("Width : " + windowWidth + "\n"); - sb.append("Height : " + windowHeight + "\n"); - sb.append("Position : " + windowCoordinates); - return sb.toString(); - } -} diff --git a/src/main/java/seedu/todo/commons/core/Messages.java b/src/main/java/seedu/todo/commons/core/Messages.java deleted file mode 100644 index 45cdccebc137..000000000000 --- a/src/main/java/seedu/todo/commons/core/Messages.java +++ /dev/null @@ -1,13 +0,0 @@ -package seedu.todo.commons.core; - -/** - * Container for user visible messages. - */ -public class Messages { - - public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command"; - public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s"; - public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid"; - public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!"; - -} diff --git a/src/main/java/seedu/todo/commons/events/storage/DataSavingExceptionEvent.java b/src/main/java/seedu/todo/commons/events/storage/DataSavingExceptionEvent.java deleted file mode 100644 index 173ae964be14..000000000000 --- a/src/main/java/seedu/todo/commons/events/storage/DataSavingExceptionEvent.java +++ /dev/null @@ -1,21 +0,0 @@ -package seedu.todo.commons.events.storage; - -import seedu.todo.commons.events.BaseEvent; - -/** - * Indicates an exception during a file saving - */ -public class DataSavingExceptionEvent extends BaseEvent { - - public Exception exception; - - public DataSavingExceptionEvent(Exception exception) { - this.exception = exception; - } - - @Override - public String toString(){ - return exception.toString(); - } - -} diff --git a/src/main/java/seedu/todo/commons/events/ui/JumpToListRequestEvent.java b/src/main/java/seedu/todo/commons/events/ui/JumpToListRequestEvent.java deleted file mode 100644 index 1ee8989e8281..000000000000 --- a/src/main/java/seedu/todo/commons/events/ui/JumpToListRequestEvent.java +++ /dev/null @@ -1,21 +0,0 @@ -package seedu.todo.commons.events.ui; - -import seedu.todo.commons.events.BaseEvent; - -/** - * Indicates a request to jump to the list of persons - */ -public class JumpToListRequestEvent extends BaseEvent { - - public final int targetIndex; - - public JumpToListRequestEvent(int targetIndex) { - this.targetIndex = targetIndex; - } - - @Override - public String toString() { - return this.getClass().getSimpleName(); - } - -} diff --git a/src/main/java/seedu/todo/commons/events/ui/ShowHelpRequestEvent.java b/src/main/java/seedu/todo/commons/events/ui/ShowHelpRequestEvent.java deleted file mode 100644 index 30141357b355..000000000000 --- a/src/main/java/seedu/todo/commons/events/ui/ShowHelpRequestEvent.java +++ /dev/null @@ -1,15 +0,0 @@ -package seedu.todo.commons.events.ui; - -import seedu.todo.commons.events.BaseEvent; - -/** - * An event requesting to view the help page. - */ -public class ShowHelpRequestEvent extends BaseEvent { - - @Override - public String toString() { - return this.getClass().getSimpleName(); - } - -} diff --git a/src/main/java/seedu/todo/commons/util/UrlUtil.java b/src/main/java/seedu/todo/commons/util/UrlUtil.java deleted file mode 100644 index 7cdd1abcbd2f..000000000000 --- a/src/main/java/seedu/todo/commons/util/UrlUtil.java +++ /dev/null @@ -1,24 +0,0 @@ -package seedu.todo.commons.util; - -import java.net.URL; - -/** - * A utility class for URL - */ -public class UrlUtil { - - /** - * Returns true if both URLs have the same base URL - */ - public static boolean compareBaseUrls(URL url1, URL url2) { - - if (url1 == null || url2 == null) { - return false; - } - return url1.getHost().toLowerCase().replaceFirst("www.", "") - .equals(url2.getHost().replaceFirst("www.", "").toLowerCase()) - && url1.getPath().replaceAll("/", "").toLowerCase() - .equals(url2.getPath().replaceAll("/", "").toLowerCase()); - } - -} diff --git a/src/main/java/seedu/todo/ui/MainWindow.java b/src/main/java/seedu/todo/ui/MainWindow.java index 1fd77b42e320..3b57bf57b8a6 100644 --- a/src/main/java/seedu/todo/ui/MainWindow.java +++ b/src/main/java/seedu/todo/ui/MainWindow.java @@ -11,7 +11,6 @@ import seedu.todo.MainApp; import seedu.todo.commons.core.Config; import seedu.todo.commons.core.ConfigCenter; -import seedu.todo.commons.core.GuiSettings; import seedu.todo.commons.events.ui.ExitAppRequestEvent; import seedu.todo.commons.exceptions.ParseException; import seedu.todo.controllers.AliasController; @@ -121,14 +120,6 @@ public void setWindowMinSize() { primaryStage.setMinWidth(MIN_WIDTH); } - /** - * Returns the current size and the position of the main Window. - */ - public GuiSettings getCurrentGuiSetting() { - return new GuiSettings(primaryStage.getWidth(), primaryStage.getHeight(), - (int) primaryStage.getX(), (int) primaryStage.getY()); - } - protected T loadView(Class viewClass) { return load(primaryStage, getChildrenPlaceholder(), viewClass); } diff --git a/src/test/java/seedu/todo/commons/util/UrlUtilTest.java b/src/test/java/seedu/todo/commons/util/UrlUtilTest.java deleted file mode 100644 index 98a48af1ecbf..000000000000 --- a/src/test/java/seedu/todo/commons/util/UrlUtilTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package seedu.todo.commons.util; - -import org.junit.Test; - -import seedu.todo.commons.util.UrlUtil; - -import java.net.MalformedURLException; -import java.net.URL; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -/** - * Tests the UrlUtil methods. - */ -public class UrlUtilTest { - - @Test - public void compareBaseUrls_differentCapital_success() throws MalformedURLException { - URL url1 = new URL("https://www.Google.com/a"); - URL url2 = new URL("https://www.google.com/A"); - assertTrue(UrlUtil.compareBaseUrls(url1, url2)); - } - - @Test - public void compareBaseUrls_testWithAndWithoutWww_success() throws MalformedURLException { - URL url1 = new URL("https://google.com/a"); - URL url2 = new URL("https://www.google.com/a"); - assertTrue(UrlUtil.compareBaseUrls(url1, url2)); - } - - @Test - public void compareBaseUrls_differentSlashes_success() throws MalformedURLException { - URL url1 = new URL("https://www.Google.com/a/acb/"); - URL url2 = new URL("https://www.google.com/A/acb"); - assertTrue(UrlUtil.compareBaseUrls(url1, url2)); - } - - @Test - public void compareBaseUrls_differentUrl_fail() throws MalformedURLException { - URL url1 = new URL("https://www.Google.com/a/ac_b/"); - URL url2 = new URL("https://www.google.com/A/acb"); - assertFalse(UrlUtil.compareBaseUrls(url1, url2)); - } - - @Test - public void compareBaseUrls_null_false() throws MalformedURLException { - URL url1 = new URL("https://www.Google.com/a/ac_b/"); - URL url2 = new URL("https://www.google.com/A/acb"); - assertFalse(UrlUtil.compareBaseUrls(url1, null)); - assertFalse(UrlUtil.compareBaseUrls(null, url2)); - assertFalse(UrlUtil.compareBaseUrls(null, null)); - } -} diff --git a/src/test/java/seedu/todo/testutil/EventsCollector.java b/src/test/java/seedu/todo/testutil/EventsCollector.java deleted file mode 100644 index ea274b91d080..000000000000 --- a/src/test/java/seedu/todo/testutil/EventsCollector.java +++ /dev/null @@ -1,42 +0,0 @@ -package seedu.todo.testutil; - -import com.google.common.eventbus.Subscribe; - -import seedu.todo.commons.core.EventsCenter; -import seedu.todo.commons.events.BaseEvent; - -import java.util.ArrayList; -import java.util.List; - -/** - * A class that collects events raised by other classes. - */ -public class EventsCollector{ - List events = new ArrayList(); - - public EventsCollector(){ - EventsCenter.getInstance().registerHandler(this); - } - - /** - * Collects any event raised by any class - */ - @Subscribe - public void collectEvent(BaseEvent event){ - events.add(event); - } - - /** - * Removes collected events from the collected list - */ - public void reset(){ - events.clear(); - } - - /** - * Returns the event at the specified index - */ - public BaseEvent get(int index){ - return events.get(index); - } -} diff --git a/src/test/java/seedu/todo/testutil/SerializableTestClass.java b/src/test/java/seedu/todo/testutil/SerializableTestClass.java deleted file mode 100644 index c10d4c59cb61..000000000000 --- a/src/test/java/seedu/todo/testutil/SerializableTestClass.java +++ /dev/null @@ -1,73 +0,0 @@ -package seedu.todo.testutil; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -/** - * A class used to test serialization and deserialization - */ -public class SerializableTestClass { - public static final String JSON_STRING_REPRESENTATION = String.format("{%n" + - " \"name\" : \"This is a test class\",%n" + - " \"listOfLocalDateTimes\" : " + - "[ \"-999999999-01-01T00:00:00\", \"+999999999-12-31T23:59:59.999999999\", \"0001-01-01T01:01:00\" ],%n" + - " \"mapOfIntegerToString\" : {%n" + - " \"1\" : \"One\",%n" + - " \"2\" : \"Two\",%n" + - " \"3\" : \"Three\"%n" + - " }%n" + - "}"); - - private static final String NAME_TEST_VALUE = "This is a test class"; - - private String name; - - private List listOfLocalDateTimes; - private HashMap mapOfIntegerToString; - - public SerializableTestClass() {} - - public static String getNameTestValue() { - return NAME_TEST_VALUE; - } - - public static List getListTestValues() { - List listOfLocalDateTimes = new ArrayList<>(); - - listOfLocalDateTimes.add(LocalDateTime.MIN); - listOfLocalDateTimes.add(LocalDateTime.MAX); - listOfLocalDateTimes.add(LocalDateTime.of(1, 1, 1, 1, 1)); - - return listOfLocalDateTimes; - } - - public static HashMap getHashMapTestValues() { - HashMap mapOfIntegerToString = new HashMap<>(); - - mapOfIntegerToString.put(1, "One"); - mapOfIntegerToString.put(2, "Two"); - mapOfIntegerToString.put(3, "Three"); - - return mapOfIntegerToString; - } - - public void setTestValues() { - name = getNameTestValue(); - listOfLocalDateTimes = getListTestValues(); - mapOfIntegerToString = getHashMapTestValues(); - } - - public String getName() { - return name; - } - - public List getListOfLocalDateTimes() { - return listOfLocalDateTimes; - } - - public HashMap getMapOfIntegerToString() { - return mapOfIntegerToString; - } -} diff --git a/src/test/java/seedu/todo/testutil/TestUtil.java b/src/test/java/seedu/todo/testutil/TestUtil.java index e87ce1d4db8c..f988027bdf04 100644 --- a/src/test/java/seedu/todo/testutil/TestUtil.java +++ b/src/test/java/seedu/todo/testutil/TestUtil.java @@ -2,24 +2,9 @@ import java.io.File; import java.io.IOException; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import java.util.concurrent.TimeoutException; -import java.util.stream.Collectors; -import org.loadui.testfx.GuiTest; -import org.testfx.api.FxToolkit; - -import com.google.common.io.Files; - -import javafx.geometry.Bounds; -import javafx.geometry.Point2D; -import javafx.scene.Node; -import javafx.scene.Scene; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCodeCombination; import javafx.scene.input.KeyCombination; @@ -74,129 +59,4 @@ public static KeyCode[] scrub(KeyCodeCombination keyCodeCombination) { return keys.toArray(new KeyCode[]{}); } - public static boolean isHeadlessEnvironment() { - String headlessProperty = System.getProperty("testfx.headless"); - return headlessProperty != null && headlessProperty.equals("true"); - } - - public static void captureScreenShot(String fileName) { - File file = GuiTest.captureScreenshot(); - try { - Files.copy(file, new File(fileName + ".png")); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public static String descOnFail(Object... comparedObjects) { - return "Comparison failed \n" - + Arrays.asList(comparedObjects).stream() - .map(Object::toString) - .collect(Collectors.joining("\n")); - } - - public static void setFinalStatic(Field field, Object newValue) throws NoSuchFieldException, - IllegalAccessException { - field.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - // ~Modifier.FINAL is used to remove the final modifier from field so that its value is no longer - // final and can be changed - modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); - field.set(null, newValue); - } - - public static void initRuntime() throws TimeoutException { - FxToolkit.registerPrimaryStage(); - FxToolkit.hideStage(); - } - - public static void tearDownRuntime() throws Exception { - FxToolkit.cleanupStages(); - } - - /** - * Gets private method of a class - * Invoke the method using method.invoke(objectInstance, params...) - * - * Caveat: only find method declared in the current Class, not inherited from supertypes - */ - @SuppressWarnings({"rawtypes", "unchecked"}) - public static Method getPrivateMethod(Class objectClass, String methodName) throws NoSuchMethodException { - Method method = objectClass.getDeclaredMethod(methodName); - method.setAccessible(true); - return method; - } - - public static void renameFile(File file, String newFileName) { - try { - Files.copy(file, new File(newFileName)); - } catch (IOException e1) { - e1.printStackTrace(); - } - } - - /** - * Gets mid point of a node relative to the screen. - * @param node - * @return - */ - public static Point2D getScreenMidPoint(Node node) { - double x = getScreenPos(node).getMinX() + node.getLayoutBounds().getWidth() / 2; - double y = getScreenPos(node).getMinY() + node.getLayoutBounds().getHeight() / 2; - return new Point2D(x, y); - } - - /** - * Gets mid point of a node relative to its scene. - * @param node - * @return - */ - public static Point2D getSceneMidPoint(Node node) { - double x = getScenePos(node).getMinX() + node.getLayoutBounds().getWidth() / 2; - double y = getScenePos(node).getMinY() + node.getLayoutBounds().getHeight() / 2; - return new Point2D(x, y); - } - - /** - * Gets the bound of the node relative to the parent scene. - * @param node - * @return - */ - public static Bounds getScenePos(Node node) { - return node.localToScene(node.getBoundsInLocal()); - } - - public static Bounds getScreenPos(Node node) { - return node.localToScreen(node.getBoundsInLocal()); - } - - public static double getSceneMaxX(Scene scene) { - return scene.getX() + scene.getWidth(); - } - - public static double getSceneMaxY(Scene scene) { - return scene.getX() + scene.getHeight(); - } - - public static Object getLastElement(List list) { - return list.get(list.size() - 1); - } - - @SuppressWarnings("unchecked") - public static T[] appendTo(final T[] addTo, T... toAdd) { - List listAddTo = asList(addTo); - listAddTo.addAll(asList(toAdd)); - return (T[]) listAddTo.toArray(); - } - - private static List asList(T[] objs) { - List list = new ArrayList<>(); - for (T obj : objs) { - list.add(obj); - } - return list; - } - } \ No newline at end of file