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/05/26 00:26:23 UTC
svn commit: r1796229 - in /pivot/trunk:
charts/src/org/apache/pivot/charts/ChartView.java
core/src/org/apache/pivot/collections/HashSet.java
core/src/org/apache/pivot/collections/LinkedList.java
core/src/org/apache/pivot/collections/Sequence.java
Author: rwhitcomb
Date: Fri May 26 00:26:23 2017
New Revision: 1796229
URL: http://svn.apache.org/viewvc?rev=1796229&view=rev
Log:
More work on using the Utils.checkNull utility method and his brothers in other places.
Modified:
pivot/trunk/charts/src/org/apache/pivot/charts/ChartView.java
pivot/trunk/core/src/org/apache/pivot/collections/HashSet.java
pivot/trunk/core/src/org/apache/pivot/collections/LinkedList.java
pivot/trunk/core/src/org/apache/pivot/collections/Sequence.java
Modified: pivot/trunk/charts/src/org/apache/pivot/charts/ChartView.java
URL: http://svn.apache.org/viewvc/pivot/trunk/charts/src/org/apache/pivot/charts/ChartView.java?rev=1796229&r1=1796228&r2=1796229&view=diff
==============================================================================
--- pivot/trunk/charts/src/org/apache/pivot/charts/ChartView.java (original)
+++ pivot/trunk/charts/src/org/apache/pivot/charts/ChartView.java Fri May 26 00:26:23 2017
@@ -26,6 +26,7 @@ import org.apache.pivot.collections.List
import org.apache.pivot.collections.Sequence;
import org.apache.pivot.util.ListenerList;
import org.apache.pivot.util.Service;
+import org.apache.pivot.util.Utils;
import org.apache.pivot.wtk.Component;
/**
@@ -64,9 +65,7 @@ public abstract class ChartView extends
}
public void setKey(String key) {
- if (key == null) {
- throw new IllegalArgumentException("key is null.");
- }
+ Utils.checkNull(key, "key");
String previousKey = this.key;
@@ -85,9 +84,7 @@ public abstract class ChartView extends
}
public void setLabel(String label) {
- if (label == null) {
- throw new IllegalArgumentException("label is null.");
- }
+ Utils.checkNull(label, "label");
String previousLabel = this.label;
@@ -163,9 +160,7 @@ public abstract class ChartView extends
@Override
public void insert(Category category, int index) {
- if (category == null) {
- throw new IllegalArgumentException("category is null.");
- }
+ Utils.checkNull(category, "category");
if (category.getChartView() != null) {
throw new IllegalArgumentException(
@@ -478,9 +473,7 @@ public abstract class ChartView extends
@SuppressWarnings("unchecked")
public void setChartData(List<?> chartData) {
- if (chartData == null) {
- throw new IllegalArgumentException("chartData is null.");
- }
+ Utils.checkNull(chartData, "chartData");
List<?> previousChartData = this.chartData;
@@ -501,9 +494,7 @@ public abstract class ChartView extends
}
public void setSeriesNameKey(String seriesNameKey) {
- if (seriesNameKey == null) {
- throw new IllegalArgumentException("seriesNameKey is null.");
- }
+ Utils.checkNull(seriesNameKey, "seriesNameKey");
String previousSeriesNameKey = this.seriesNameKey;
Modified: pivot/trunk/core/src/org/apache/pivot/collections/HashSet.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/collections/HashSet.java?rev=1796229&r1=1796228&r2=1796229&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/collections/HashSet.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/collections/HashSet.java Fri May 26 00:26:23 2017
@@ -22,6 +22,7 @@ import java.util.Iterator;
import java.util.NoSuchElementException;
import org.apache.pivot.util.ListenerList;
+import org.apache.pivot.util.Utils;
/**
* Implementation of the {@link Set} interface that is backed by a hash table.
@@ -35,9 +36,7 @@ public class HashSet<E> implements Set<E
private E element = null;
public ElementIterator(Iterator<E> iterator) {
- if (iterator == null) {
- throw new IllegalArgumentException("iterator is null.");
- }
+ Utils.checkNull(iterator, "iterator");
this.iterator = iterator;
}
Modified: pivot/trunk/core/src/org/apache/pivot/collections/LinkedList.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/collections/LinkedList.java?rev=1796229&r1=1796228&r2=1796229&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/collections/LinkedList.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/collections/LinkedList.java Fri May 26 00:26:23 2017
@@ -301,7 +301,7 @@ public class LinkedList<T> implements Li
@Override
public void insert(T item, int index) {
- verifyIndexBounds(index, 0, length);
+ Utils.checkIndexBounds(index, 0, length);
Node<T> next = null;
Node<T> previous = null;
@@ -341,7 +341,7 @@ public class LinkedList<T> implements Li
@Override
public T update(int index, T item) {
- verifyIndexBounds(index, 0, length - 1);
+ Utils.checkIndexBounds(index, 0, length - 1);
// Get the previous item at index
Node<T> node = getNode(index);
@@ -397,7 +397,7 @@ public class LinkedList<T> implements Li
@Override
public Sequence<T> remove(int index, int count) {
- verifyIndexBounds(index, count, 0, length);
+ Utils.checkIndexBounds(index, count, 0, length);
LinkedList<T> removed = new LinkedList<>();
@@ -464,7 +464,7 @@ public class LinkedList<T> implements Li
@Override
public T get(int index) {
- verifyIndexBounds(index, 0, length - 1);
+ Utils.checkIndexBounds(index, 0, length - 1);
Node<T> node = getNode(index);
return node.item;
@@ -651,29 +651,4 @@ public class LinkedList<T> implements Li
return sb.toString();
}
- private static void verifyIndexBounds(int index, int start, int end) {
- if (end < start) {
- throw new IllegalArgumentException("end (" + end + ") < " + "start (" + start + ")");
- }
- if (index < start || index > end) {
- throw new IndexOutOfBoundsException("index " + index + " out of bounds.");
- }
- }
-
- private static void verifyIndexBounds(int index, int count, int start, int end) {
- if (end < start) {
- throw new IllegalArgumentException("end (" + end + ") < " + "start (" + start + ")");
- }
- if (count < 0 || start < 0) {
- throw new IllegalArgumentException("count (" + count + ") < 0 or start (" + start
- + ") < 0");
- }
- if (index < start) {
- throw new IndexOutOfBoundsException("index " + index + " out of bounds.");
- }
- if (index + count > end) {
- throw new IndexOutOfBoundsException("index + count " + index + "," + count
- + " out of range.");
- }
- }
}
Modified: pivot/trunk/core/src/org/apache/pivot/collections/Sequence.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/collections/Sequence.java?rev=1796229&r1=1796228&r2=1796229&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/collections/Sequence.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/collections/Sequence.java Fri May 26 00:26:23 2017
@@ -20,6 +20,7 @@ import java.util.Iterator;
import java.util.NoSuchElementException;
import org.apache.pivot.util.ImmutableIterator;
+import org.apache.pivot.util.Utils;
/**
* Interface representing an ordered sequence of items.
@@ -309,13 +310,8 @@ public interface Sequence<T> {
*/
@SuppressWarnings("unchecked")
public static <T> T update(final Sequence<T> sequence, final Path path, final T item) {
- if (sequence == null) {
- throw new IllegalArgumentException("sequence is null.");
- }
-
- if (path == null) {
- throw new IllegalArgumentException("path is null.");
- }
+ Utils.checkNull(sequence, "sequence");
+ Utils.checkNull(path, "path");
int i = 0, n = path.getLength() - 1;
Sequence<T> sequenceUpdated = sequence;
@@ -356,13 +352,8 @@ public interface Sequence<T> {
*/
@SuppressWarnings("unchecked")
public static <T> Sequence<T> remove(final Sequence<T> sequence, final Path path, int count) {
- if (sequence == null) {
- throw new IllegalArgumentException("sequence is null.");
- }
-
- if (path == null) {
- throw new IllegalArgumentException("path is null.");
- }
+ Utils.checkNull(sequence, "sequence");
+ Utils.checkNull(path, "path");
int i = 0, n = path.getLength() - 1;
Sequence<T> sequenceUpdated = sequence;
@@ -384,13 +375,8 @@ public interface Sequence<T> {
*/
@SuppressWarnings("unchecked")
public static <T> T get(final Sequence<T> sequence, final Path path) {
- if (sequence == null) {
- throw new IllegalArgumentException("sequence is null.");
- }
-
- if (path == null) {
- throw new IllegalArgumentException("path is null.");
- }
+ Utils.checkNull(sequence, "sequence");
+ Utils.checkNull(path, "path");
T item;
if (path.getLength() == 0) {
@@ -419,13 +405,8 @@ public interface Sequence<T> {
*/
@SuppressWarnings("unchecked")
public static <T> Path pathOf(final Sequence<T> sequence, final T item) {
- if (sequence == null) {
- throw new IllegalArgumentException("sequence is null.");
- }
-
- if (item == null) {
- throw new IllegalArgumentException("item is null.");
- }
+ Utils.checkNull(sequence, "sequence");
+ Utils.checkNull(item, "item");
Path path = null;
@@ -498,7 +479,7 @@ public interface Sequence<T> {
* @return The index at which the item was added, or <tt>-1</tt> if the item
* was not added to the sequence.
*/
- public int add(T item);
+ int add(T item);
/**
* Inserts an item into the sequence at a specific index.
@@ -507,7 +488,7 @@ public interface Sequence<T> {
* @param index The index at which the item should be inserted. Must be a
* value between <tt>0</tt> and <tt>getLength()</tt>.
*/
- public void insert(T item, int index);
+ void insert(T item, int index);
/**
* Updates the item at the given index.
@@ -517,7 +498,7 @@ public interface Sequence<T> {
* index.
* @return The item that was previously stored at the given index.
*/
- public T update(int index, T item);
+ T update(int index, T item);
/**
* Removes the first occurrence of the given item from the sequence.
@@ -527,7 +508,7 @@ public interface Sequence<T> {
* could not be found.
* @see #remove(int, int)
*/
- public int remove(T item);
+ int remove(T item);
/**
* Removes one or more items from the sequence.
@@ -536,7 +517,7 @@ public interface Sequence<T> {
* @param count The number of items to remove, beginning with <tt>index</tt>.
* @return A sequence containing the items that were removed.
*/
- public Sequence<T> remove(int index, int count);
+ Sequence<T> remove(int index, int count);
/**
* Retrieves the item at the given index.
@@ -544,7 +525,7 @@ public interface Sequence<T> {
* @param index The index of the item to retrieve.
* @return The item at this index in the sequence.
*/
- public T get(int index);
+ T get(int index);
/**
* Returns the index of an item in the sequence.
@@ -553,12 +534,13 @@ public interface Sequence<T> {
* @return The index of first occurrence of the item if it exists in the
* sequence; <tt>-1</tt>, otherwise.
*/
- public int indexOf(T item);
+ int indexOf(T item);
/**
* Returns the length of the sequence.
*
* @return The number of items in the sequence.
*/
- public int getLength();
+ int getLength();
+
}