You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2017/10/05 22:15:41 UTC
svn commit: r1811267 - in /pivot/trunk/core/src/org/apache/pivot:
collections/immutable/ImmutableList.java util/Utils.java
Author: rwhitcomb
Date: Thu Oct 5 22:15:41 2017
New Revision: 1811267
URL: http://svn.apache.org/viewvc?rev=1811267&view=rev
Log:
Add error message text and Javadoc to ImmutableList to make things clearer.
Also use Utils method to check null parameter.
Update one message for Utils.checkNonNegative to be the same wording as other
exception messages in that class.
Modified:
pivot/trunk/core/src/org/apache/pivot/collections/immutable/ImmutableList.java
pivot/trunk/core/src/org/apache/pivot/util/Utils.java
Modified: pivot/trunk/core/src/org/apache/pivot/collections/immutable/ImmutableList.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/collections/immutable/ImmutableList.java?rev=1811267&r1=1811266&r2=1811267&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/collections/immutable/ImmutableList.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/collections/immutable/ImmutableList.java Thu Oct 5 22:15:41 2017
@@ -24,6 +24,7 @@ import org.apache.pivot.collections.List
import org.apache.pivot.collections.Sequence;
import org.apache.pivot.util.ImmutableIterator;
import org.apache.pivot.util.ListenerList;
+import org.apache.pivot.util.Utils;
/**
* Unmodifiable implementation of the {@link List} interface.
@@ -33,42 +34,42 @@ public final class ImmutableList<T> impl
private ListListenerList<T> listListeners = new ListListenerList<>();
+ private static final String ERROR_MSG = "Immutable list cannot be modified.";
+
public ImmutableList(List<T> list) {
- if (list == null) {
- throw new IllegalArgumentException("list is null.");
- }
+ Utils.checkNull(list, "list");
this.list = list;
}
@Override
public int add(T item) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException(ERROR_MSG);
}
@Override
public void insert(T item, int index) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException(ERROR_MSG);
}
@Override
public T update(int index, T item) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException(ERROR_MSG);
}
@Override
public int remove(T item) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException(ERROR_MSG);
}
@Override
public Sequence<T> remove(int index, int count) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException(ERROR_MSG);
}
@Override
public void clear() {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException(ERROR_MSG);
}
@Override
@@ -98,7 +99,7 @@ public final class ImmutableList<T> impl
@Override
public void setComparator(Comparator<T> comparator) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException(ERROR_MSG);
}
@Override
@@ -111,6 +112,14 @@ public final class ImmutableList<T> impl
return list.toString();
}
+ /**
+ * Get the list of listeners for this list.
+ * <p> Not clear why this would be used, since the listener(s)
+ * would only be called on changes to the list, which can't happen
+ * on an immutable list.
+ *
+ * @return The list listener list.
+ */
@Override
public ListenerList<ListListener<T>> getListListeners() {
return listListeners;
Modified: pivot/trunk/core/src/org/apache/pivot/util/Utils.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/util/Utils.java?rev=1811267&r1=1811266&r2=1811267&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/util/Utils.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/util/Utils.java Thu Oct 5 22:15:41 2017
@@ -140,7 +140,7 @@ public class Utils {
if (isNullOrEmpty(argument)) {
throw new IllegalArgumentException();
} else {
- throw new IllegalArgumentException(argument + " cannot be negative.");
+ throw new IllegalArgumentException(argument + " must not be negative.");
}
}
}