From 5941b8c4d6e75ead93370629dd537fd7ec67690c Mon Sep 17 00:00:00 2001 From: louietyj Date: Sat, 5 Nov 2016 20:35:09 +0800 Subject: [PATCH] Remove unnecessary files --- .../core/UnmodifiableObservableList.java | 311 ------------------ .../exceptions/DuplicateDataException.java | 10 - .../todo/commons/util/CollectionUtil.java | 47 --- .../java/seedu/todo/commons/util/XmlUtil.java | 67 ---- src/main/java/seedu/todo/logic/Logic.java | 10 - 5 files changed, 445 deletions(-) delete mode 100644 src/main/java/seedu/todo/commons/core/UnmodifiableObservableList.java delete mode 100644 src/main/java/seedu/todo/commons/exceptions/DuplicateDataException.java delete mode 100644 src/main/java/seedu/todo/commons/util/CollectionUtil.java delete mode 100644 src/main/java/seedu/todo/commons/util/XmlUtil.java delete mode 100644 src/main/java/seedu/todo/logic/Logic.java diff --git a/src/main/java/seedu/todo/commons/core/UnmodifiableObservableList.java b/src/main/java/seedu/todo/commons/core/UnmodifiableObservableList.java deleted file mode 100644 index fc9f8c710894..000000000000 --- a/src/main/java/seedu/todo/commons/core/UnmodifiableObservableList.java +++ /dev/null @@ -1,311 +0,0 @@ -package seedu.todo.commons.core; - -import javafx.beans.InvalidationListener; -import javafx.collections.ListChangeListener; -import javafx.collections.ObservableList; -import javafx.collections.transformation.FilteredList; -import javafx.collections.transformation.SortedList; - -import java.text.Collator; -import java.util.*; -import java.util.function.Consumer; -import java.util.function.Predicate; -import java.util.function.UnaryOperator; -import java.util.stream.Stream; - -/** - * Unmodifiable view of an observable list - */ -public class UnmodifiableObservableList implements ObservableList { - - public static final String MUTATION_OP_EXCEPTION_MESSAGE = "Attempted to modify an unmodifiable view"; - - private final ObservableList backingList; - - public UnmodifiableObservableList(ObservableList backingList) { - if (backingList == null) { - throw new NullPointerException(); - } - this.backingList = backingList; - } - - @Override - public final void addListener(ListChangeListener listener) { - backingList.addListener(listener); - } - - @Override - public final void removeListener(ListChangeListener listener) { - backingList.removeListener(listener); - } - - @Override - public final void addListener(InvalidationListener listener) { - backingList.addListener(listener); - } - - @Override - public final void removeListener(InvalidationListener listener) { - backingList.removeListener(listener); - } - - @Override - public final boolean addAll(Object... elements) { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - - @Override - public final boolean setAll(Object... elements) { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - - @Override - public final boolean setAll(Collection col) { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - - @Override - public final boolean removeAll(Object... elements) { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - - @Override - public final boolean retainAll(Object... elements) { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - - @Override - public final void remove(int from, int to) { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - - - @Override - public final FilteredList filtered(Predicate predicate) { - return new FilteredList<>(this, predicate); - } - - @Override - public final SortedList sorted(Comparator comparator) { - return new SortedList<>(this, comparator); - } - - @SuppressWarnings("unchecked") - @Override - public final SortedList sorted() { - return sorted(Comparator.nullsFirst((o1, o2) -> { - if (o1 instanceof Comparable) { - return ((Comparable) o1).compareTo(o2); - } - return Collator.getInstance().compare(o1.toString(), o2.toString()); - })); - } - - @Override - public final int size() { - return backingList.size(); - } - - @Override - public final boolean isEmpty() { - return backingList.isEmpty(); - } - - @Override - public final boolean contains(Object o) { - return backingList.contains(o); - } - - @Override - public final Iterator iterator() { - return new Iterator() { - private final Iterator i = backingList.iterator(); - - public final boolean hasNext() { - return i.hasNext(); - } - public final E next() { - return i.next(); - } - public final void remove() { - throw new UnsupportedOperationException(); - } - @Override - public final void forEachRemaining(Consumer action) { - // Use backing collection version - i.forEachRemaining(action); - } - }; - } - - @Override - public final Object[] toArray() { - return backingList.toArray(); - } - - @Override - public final T[] toArray(T[] a) { - return backingList.toArray(a); - } - - @Override - public final boolean add(E o) { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - - @Override - public final boolean remove(Object o) { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - - @Override - public final boolean containsAll(Collection c) { - return backingList.containsAll(c); - } - - @Override - public final boolean addAll(Collection c) { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - - @Override - public final boolean addAll(int index, Collection c) { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - - @Override - public final boolean removeAll(Collection c) { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - - @Override - public final boolean retainAll(Collection c) { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - - @Override - public final void replaceAll(UnaryOperator operator) { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - - @Override - public final void sort(Comparator c) { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - - @Override - public final void clear() { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - - - @Override - public final boolean equals(Object o) { - return o == this || backingList.equals(o); - } - - @Override - public final int hashCode() { - return backingList.hashCode(); - } - - - @Override - public final E get(int index) { - return backingList.get(index); - } - - @SuppressWarnings("unchecked") - @Override - public final Object set(int index, Object element) { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - - @Override - public final void add(int index, Object element) { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - - @Override - public final E remove(int index) { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - - @Override - public final int indexOf(Object o) { - return backingList.indexOf(o); - } - - @Override - public final int lastIndexOf(Object o) { - return backingList.lastIndexOf(o); - } - - @Override - public final ListIterator listIterator() { - return listIterator(0); - } - - @Override - public final ListIterator listIterator(int index) { - return new ListIterator() { - private final ListIterator i = backingList.listIterator(index); - - public final boolean hasNext() { - return i.hasNext(); - } - public final E next() { - return i.next(); - } - public final boolean hasPrevious() { - return i.hasPrevious(); - } - public final E previous() { - return i.previous(); - } - public final int nextIndex() { - return i.nextIndex(); - } - public final int previousIndex() { - return i.previousIndex(); - } - - public final void remove() { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - public final void set(E e) { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - public final void add(E e) { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - - @Override - public final void forEachRemaining(Consumer action) { - i.forEachRemaining(action); - } - }; - } - - @Override - public final List subList(int fromIndex, int toIndex) { - return Collections.unmodifiableList(backingList.subList(fromIndex, toIndex)); - } - - @Override - public final boolean removeIf(Predicate filter) { - throw new UnsupportedOperationException(MUTATION_OP_EXCEPTION_MESSAGE); - } - - @SuppressWarnings("unchecked") - @Override - public final Stream stream() { - return (Stream) backingList.stream(); - } - - @Override - public final void forEach(Consumer action) { - backingList.forEach(action); - } - -} diff --git a/src/main/java/seedu/todo/commons/exceptions/DuplicateDataException.java b/src/main/java/seedu/todo/commons/exceptions/DuplicateDataException.java deleted file mode 100644 index 175783d7a348..000000000000 --- a/src/main/java/seedu/todo/commons/exceptions/DuplicateDataException.java +++ /dev/null @@ -1,10 +0,0 @@ -package seedu.todo.commons.exceptions; - -/** - * Signals an error caused by duplicate data where there should be none. - */ -public abstract class DuplicateDataException extends IllegalValueException { - public DuplicateDataException(String message) { - super(message); - } -} diff --git a/src/main/java/seedu/todo/commons/util/CollectionUtil.java b/src/main/java/seedu/todo/commons/util/CollectionUtil.java deleted file mode 100644 index 7b2264fc9c97..000000000000 --- a/src/main/java/seedu/todo/commons/util/CollectionUtil.java +++ /dev/null @@ -1,47 +0,0 @@ -package seedu.todo.commons.util; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -/** - * Utility methods related to Collections - */ -public class CollectionUtil { - - /** - * Returns true if any of the given items are null. - */ - public static boolean isAnyNull(Object... items) { - for (Object item : items) { - if (item == null) { - return true; - } - } - return false; - } - - - - /** - * Throws an assertion error if the collection or any item in it is null. - */ - public static void assertNoNullElements(Collection items) { - assert items != null; - assert !isAnyNull(items); - } - - /** - * Returns true if every element in a collection are unique by {@link Object#equals(Object)}. - */ - public static boolean elementsAreUnique(Collection items) { - final Set testSet = new HashSet<>(); - for (Object item : items) { - final boolean itemAlreadyExists = !testSet.add(item); // see Set documentation - if (itemAlreadyExists) { - return false; - } - } - return true; - } -} diff --git a/src/main/java/seedu/todo/commons/util/XmlUtil.java b/src/main/java/seedu/todo/commons/util/XmlUtil.java deleted file mode 100644 index 4bbcce988737..000000000000 --- a/src/main/java/seedu/todo/commons/util/XmlUtil.java +++ /dev/null @@ -1,67 +0,0 @@ -package seedu.todo.commons.util; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import java.io.File; -import java.io.FileNotFoundException; - -/** - * Helps with reading from and writing to XML files. - */ -public class XmlUtil { - - /** - * Returns the xml data in the file as an object of the specified type. - * - * @param file Points to a valid xml file containing data that match the {@code classToConvert}. - * Cannot be null. - * @param classToConvert The class corresponding to the xml data. - * Cannot be null. - * @throws FileNotFoundException Thrown if the file is missing. - * @throws JAXBException Thrown if the file is empty or does not have the correct format. - */ - @SuppressWarnings("unchecked") - public static T getDataFromFile(File file, Class classToConvert) - throws FileNotFoundException, JAXBException { - - assert file != null; - assert classToConvert != null; - - if (!FileUtil.isFileExists(file)) { - throw new FileNotFoundException("File not found : " + file.getAbsolutePath()); - } - - JAXBContext context = JAXBContext.newInstance(classToConvert); - Unmarshaller um = context.createUnmarshaller(); - - return ((T) um.unmarshal(file)); - } - - /** - * Saves the data in the file in xml format. - * - * @param file Points to a valid xml file containing data that match the {@code classToConvert}. - * Cannot be null. - * @throws FileNotFoundException Thrown if the file is missing. - * @throws JAXBException Thrown if there is an error during converting the data - * into xml and writing to the file. - */ - public static void saveDataToFile(File file, T data) throws FileNotFoundException, JAXBException { - - assert file != null; - assert data != null; - - if (!file.exists()) { - throw new FileNotFoundException("File not found : " + file.getAbsolutePath()); - } - - JAXBContext context = JAXBContext.newInstance(data.getClass()); - Marshaller m = context.createMarshaller(); - m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - - m.marshal(data, file); - } - -} diff --git a/src/main/java/seedu/todo/logic/Logic.java b/src/main/java/seedu/todo/logic/Logic.java deleted file mode 100644 index 282c0483c516..000000000000 --- a/src/main/java/seedu/todo/logic/Logic.java +++ /dev/null @@ -1,10 +0,0 @@ -package seedu.todo.logic; - - -/** - * API of the Logic component - */ -public interface Logic { - - -}