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/12/22 22:32:20 UTC
svn commit: r1819096 [1/2] - /pivot/trunk/wtk/src/org/apache/pivot/wtk/
Author: rwhitcomb
Date: Fri Dec 22 22:32:19 2017
New Revision: 1819096
URL: http://svn.apache.org/viewvc?rev=1819096&view=rev
Log:
PIVOT-1012, PIVOT-999: Many more places can use the "Utils" methods
to do parameter validation. Use the "forEach" method with a bunch of
ListenerList implementations.
Code cleanup: Add a "checkSkin" method in Component that does
the common check to make sure the skin being installed implements
the correct interface for the component.
Update all the places that were doing this check to use this new
method.
Some local variable renaming.
Add some message text to some exceptions that previously had none.
Add a new "setRange" method to Slider using the "Span(Sequence<?>)"
constructor. Add Javadoc to that constructor.
Reflow some comments that had been wrapped weirdly.
Modified:
pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButton.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/Clipboard.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/ColorChooserButton.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/Dialog.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/FileBrowser.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/FileBrowserSheet.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/FillPane.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/Form.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/GridPane.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/Label.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButton.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/LocalManifest.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuButton.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/Meter.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/Mouse.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/Prompt.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/RadioButtonGroup.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/ScrollBar.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/Sheet.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/Slider.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/Span.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/Spinner.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPane.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/TablePane.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/TableViewHeader.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/TextInput.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/TreeView.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/Viewport.java
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButton.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButton.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButton.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/CalendarButton.java Fri Dec 22 22:32:19 2017
@@ -139,10 +139,7 @@ public class CalendarButton extends Butt
@Override
protected void setSkin(org.apache.pivot.wtk.Skin skin) {
- if (!(skin instanceof CalendarButton.Skin)) {
- throw new IllegalArgumentException("Skin class must implement "
- + CalendarButton.Skin.class.getName());
- }
+ checkSkin(skin, CalendarButton.Skin.class);
super.setSkin(skin);
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Clipboard.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Clipboard.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Clipboard.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Clipboard.java Fri Dec 22 22:32:19 2017
@@ -20,6 +20,8 @@ import java.awt.Toolkit;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.Transferable;
+import org.apache.pivot.util.Utils;
+
/**
* Singleton class providing a means of sharing data between components and
* applications.
@@ -47,18 +49,18 @@ public final class Clipboard {
* @return The current clipboard content manifest.
*/
public static Manifest getContent() {
- Manifest contentLocal = Clipboard.content;
+ Manifest currentContent = Clipboard.content;
- if (contentLocal == null) {
+ if (currentContent == null) {
try {
java.awt.datatransfer.Clipboard awtClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
- contentLocal = new RemoteManifest(awtClipboard.getContents(null));
+ currentContent = new RemoteManifest(awtClipboard.getContents(null));
} catch (SecurityException exception) {
// No-op
}
}
- return contentLocal;
+ return currentContent;
}
/**
@@ -80,9 +82,7 @@ public final class Clipboard {
*/
public static void setContent(LocalManifest content,
ClipboardContentListener clipboardContentListener) {
- if (content == null) {
- throw new IllegalArgumentException("content is null");
- }
+ Utils.checkNull(content, "content");
try {
java.awt.datatransfer.Clipboard awtClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/ColorChooserButton.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/ColorChooserButton.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/ColorChooserButton.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/ColorChooserButton.java Fri Dec 22 22:32:19 2017
@@ -61,10 +61,7 @@ public class ColorChooserButton extends
@Override
protected void setSkin(org.apache.pivot.wtk.Skin skin) {
- if (!(skin instanceof ColorChooserButton.Skin)) {
- throw new IllegalArgumentException("Skin class must implement "
- + ColorChooserButton.Skin.class.getName());
- }
+ checkSkin(skin, ColorChooserButton.Skin.class);
super.setSkin(skin);
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java Fri Dec 22 22:32:19 2017
@@ -716,6 +716,21 @@ public abstract class Component implemen
}
/**
+ * Check if the given skin is correct with respect to the necessary skin class.
+ * <p> Meant to be called from the subclass' {@link #setSkin} method.
+ *
+ * @param skin The skin object to check.
+ * @param expectedClass What the skin class should be.
+ * @throws IllegalArgumentException if the skin object doesn't implement the given skin interface.
+ */
+ protected final void checkSkin(Skin skin, Class<?> expectedClass) {
+ if (!expectedClass.isInstance(skin)) {
+ throw new IllegalArgumentException("Skin class must implement "
+ + expectedClass.getName());
+ }
+ }
+
+ /**
* Installs the skin for the given component class, as defined by the
* current theme.
*
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java Fri Dec 22 22:32:19 2017
@@ -24,8 +24,10 @@ import java.util.Iterator;
import org.apache.pivot.collections.ArrayList;
import org.apache.pivot.collections.Sequence;
+import org.apache.pivot.util.BooleanResult;
import org.apache.pivot.util.ImmutableIterator;
import org.apache.pivot.util.ListenerList;
+import org.apache.pivot.util.Utils;
import org.apache.pivot.wtk.effects.Decorator;
/**
@@ -37,31 +39,23 @@ public abstract class Container extends
ContainerListener {
@Override
public void componentInserted(Container container, int index) {
- for (ContainerListener listener : this) {
- listener.componentInserted(container, index);
- }
+ forEach(listener -> listener.componentInserted(container, index));
}
@Override
public void componentsRemoved(Container container, int index, Sequence<Component> components) {
- for (ContainerListener listener : this) {
- listener.componentsRemoved(container, index, components);
- }
+ forEach(listener -> listener.componentsRemoved(container, index, components));
}
@Override
public void componentMoved(Container container, int from, int to) {
- for (ContainerListener listener : this) {
- listener.componentMoved(container, from, to);
- }
+ forEach(listener -> listener.componentMoved(container, from, to));
}
@Override
public void focusTraversalPolicyChanged(Container container,
FocusTraversalPolicy previousFocusTraversalPolicy) {
- for (ContainerListener listener : this) {
- listener.focusTraversalPolicyChanged(container, previousFocusTraversalPolicy);
- }
+ forEach(listener -> listener.focusTraversalPolicyChanged(container, previousFocusTraversalPolicy));
}
}
@@ -69,48 +63,40 @@ public abstract class Container extends
implements ContainerMouseListener {
@Override
public boolean mouseMove(Container container, int x, int y) {
- boolean consumed = false;
+ BooleanResult consumed = new BooleanResult(false);
- for (ContainerMouseListener listener : this) {
- consumed |= listener.mouseMove(container, x, y);
- }
+ forEach(listener -> consumed.or(listener.mouseMove(container, x, y)));
- return consumed;
+ return consumed.get();
}
@Override
public boolean mouseDown(Container container, Mouse.Button button, int x, int y) {
- boolean consumed = false;
+ BooleanResult consumed = new BooleanResult(false);
- for (ContainerMouseListener listener : this) {
- consumed |= listener.mouseDown(container, button, x, y);
- }
+ forEach(listener -> consumed.or(listener.mouseDown(container, button, x, y)));
- return consumed;
+ return consumed.get();
}
@Override
public boolean mouseUp(Container container, Mouse.Button button, int x, int y) {
- boolean consumed = false;
+ BooleanResult consumed = new BooleanResult(false);
- for (ContainerMouseListener listener : this) {
- consumed |= listener.mouseUp(container, button, x, y);
- }
+ forEach(listener -> consumed.or(listener.mouseUp(container, button, x, y)));
- return consumed;
+ return consumed.get();
}
@Override
public boolean mouseWheel(Container container, Mouse.ScrollType scrollType,
int scrollAmount, int wheelRotation, int x, int y) {
- boolean consumed = false;
+ BooleanResult consumed = new BooleanResult(false);
- for (ContainerMouseListener listener : this) {
- consumed |= listener.mouseWheel(container, scrollType, scrollAmount, wheelRotation,
- x, y);
- }
+ forEach(listener -> consumed.or(listener.mouseWheel(container, scrollType,
+ scrollAmount, wheelRotation, x, y)));
- return consumed;
+ return consumed.get();
}
}
@@ -144,9 +130,7 @@ public abstract class Container extends
@Override
public void insert(Component component, int index) {
assertEventDispatchThread();
- if (component == null) {
- throw new IllegalArgumentException("component is null.");
- }
+ Utils.checkNull(component, "component");
if (component instanceof Container && ((Container) component).isAncestor(this)) {
throw new IllegalArgumentException("Component already exists in ancestry.");
@@ -318,9 +302,7 @@ public abstract class Container extends
}
public Component getNamedComponent(String name) {
- if (name == null) {
- throw new IllegalArgumentException();
- }
+ Utils.checkNull(name, "name");
Component namedComponent = null;
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java Fri Dec 22 22:32:19 2017
@@ -40,6 +40,7 @@ import java.util.prefs.Preferences;
import org.apache.pivot.collections.HashMap;
import org.apache.pivot.collections.Sequence;
import org.apache.pivot.collections.immutable.ImmutableMap;
+import org.apache.pivot.util.Utils;
import org.apache.pivot.wtk.media.Image;
import org.apache.pivot.wtk.media.Picture;
@@ -836,12 +837,10 @@ public final class DesktopApplicationCon
* @throws IllegalStateException if the application is being displayed full screen.
*/
public static void sizeHostToFit(Window window) {
- if (window == null) {
- throw new IllegalArgumentException();
- }
+ Utils.checkNull(window, "window");
if (isFullScreen()) {
- throw new IllegalStateException();
+ throw new IllegalStateException("Full screen window cannot be sized to fit.");
}
Dimensions size = window.getPreferredSize();
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Dialog.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Dialog.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Dialog.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Dialog.java Fri Dec 22 22:32:19 2017
@@ -17,7 +17,9 @@
package org.apache.pivot.wtk;
import org.apache.pivot.util.ListenerList;
+import org.apache.pivot.util.Utils;
import org.apache.pivot.util.Vote;
+import org.apache.pivot.util.VoteResult;
/**
* Window class whose primary purpose is to facilitate interaction between an
@@ -28,9 +30,7 @@ public class Dialog extends Frame {
DialogListener {
@Override
public void modalChanged(Dialog dialog) {
- for (DialogListener listener : this) {
- listener.modalChanged(dialog);
- }
+ forEach(listener -> listener.modalChanged(dialog));
}
}
@@ -38,27 +38,21 @@ public class Dialog extends Frame {
implements DialogStateListener {
@Override
public Vote previewDialogClose(Dialog dialog, boolean result) {
- Vote vote = Vote.APPROVE;
+ VoteResult vote = new VoteResult(Vote.APPROVE);
- for (DialogStateListener listener : this) {
- vote = vote.tally(listener.previewDialogClose(dialog, result));
- }
+ forEach(listener -> vote.tally(listener.previewDialogClose(dialog, result)));
- return vote;
+ return vote.get();
}
@Override
public void dialogCloseVetoed(Dialog dialog, Vote reason) {
- for (DialogStateListener listener : this) {
- listener.dialogCloseVetoed(dialog, reason);
- }
+ forEach(listener -> listener.dialogCloseVetoed(dialog, reason));
}
@Override
public void dialogClosed(Dialog dialog, boolean modal) {
- for (DialogStateListener listener : this) {
- listener.dialogClosed(dialog, modal);
- }
+ forEach(listener -> listener.dialogClosed(dialog, modal));
}
}
@@ -150,9 +144,7 @@ public class Dialog extends Frame {
* dialog is closed.
*/
public final void open(Window owner, DialogCloseListener dialogCloseListenerArgument) {
- if (owner == null) {
- throw new IllegalArgumentException();
- }
+ Utils.checkNull(owner, "owner");
open(owner.getDisplay(), owner, dialogCloseListenerArgument);
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/FileBrowser.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/FileBrowser.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/FileBrowser.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/FileBrowser.java Fri Dec 22 22:32:19 2017
@@ -24,6 +24,7 @@ import org.apache.pivot.collections.immu
import org.apache.pivot.io.FileList;
import org.apache.pivot.util.Filter;
import org.apache.pivot.util.ListenerList;
+import org.apache.pivot.util.Utils;
/**
* Component representing a file browser.
@@ -42,46 +43,34 @@ public class FileBrowser extends Contain
implements FileBrowserListener {
@Override
public void rootDirectoryChanged(FileBrowser fileBrowser, File previousRootDirectory) {
- for (FileBrowserListener listener : this) {
- listener.rootDirectoryChanged(fileBrowser, previousRootDirectory);
- }
+ forEach(listener -> listener.rootDirectoryChanged(fileBrowser, previousRootDirectory));
}
@Override
public void selectedFileAdded(FileBrowser fileBrowser, File file) {
- for (FileBrowserListener listener : this) {
- listener.selectedFileAdded(fileBrowser, file);
- }
+ forEach(listener -> listener.selectedFileAdded(fileBrowser, file));
}
@Override
public void selectedFileRemoved(FileBrowser fileBrowser, File file) {
- for (FileBrowserListener listener : this) {
- listener.selectedFileRemoved(fileBrowser, file);
- }
+ forEach(listener -> listener.selectedFileRemoved(fileBrowser, file));
}
@Override
public void selectedFilesChanged(FileBrowser fileBrowser,
Sequence<File> previousSelectedFiles) {
- for (FileBrowserListener listener : this) {
- listener.selectedFilesChanged(fileBrowser, previousSelectedFiles);
- }
+ forEach(listener -> listener.selectedFilesChanged(fileBrowser, previousSelectedFiles));
}
@Override
public void multiSelectChanged(FileBrowser fileBrowser) {
- for (FileBrowserListener listener : this) {
- listener.multiSelectChanged(fileBrowser);
- }
+ forEach(listener -> listener.multiSelectChanged(fileBrowser));
}
@Override
public void disabledFileFilterChanged(FileBrowser fileBrowser,
Filter<File> previousDisabledFileFilter) {
- for (FileBrowserListener listener : this) {
- listener.disabledFileFilterChanged(fileBrowser, previousDisabledFileFilter);
- }
+ forEach(listener -> listener.disabledFileFilterChanged(fileBrowser, previousDisabledFileFilter));
}
}
@@ -107,13 +96,11 @@ public class FileBrowser extends Contain
* @param rootFolder The root folder full name.
*/
public FileBrowser(String rootFolder) {
- if (rootFolder == null) {
- throw new IllegalArgumentException();
- }
+ Utils.checkNull(rootFolder, "rootFolder");
rootDirectory = new File(rootFolder);
if (!rootDirectory.isDirectory()) {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException(rootFolder + " is not a directory.");
}
installSkin(FileBrowser.class);
@@ -136,8 +123,10 @@ public class FileBrowser extends Contain
* or is not a directory.
*/
public void setRootDirectory(File rootDirectory) {
- if (rootDirectory == null || !rootDirectory.isDirectory()) {
- throw new IllegalArgumentException();
+ Utils.checkNull(rootDirectory, "rootDirectory");
+
+ if (!rootDirectory.isDirectory()) {
+ throw new IllegalArgumentException(rootDirectory.getPath() + " is not a directory.");
}
if (rootDirectory.exists()) {
@@ -163,14 +152,12 @@ public class FileBrowser extends Contain
* or if the file is not in the current root directory.
*/
public boolean addSelectedFile(final File file) {
- if (file == null) {
- throw new IllegalArgumentException();
- }
+ Utils.checkNull(file, "file");
File fileMutable = file;
if (fileMutable.isAbsolute()) {
if (!fileMutable.getParentFile().equals(rootDirectory)) {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException(file.getPath() + " is not a child of the root directory.");
}
} else {
fileMutable = new File(rootDirectory, fileMutable.getPath());
@@ -193,9 +180,7 @@ public class FileBrowser extends Contain
* @throws IllegalArgumentException if the file argument is {@code null}.
*/
public boolean removeSelectedFile(File file) {
- if (file == null) {
- throw new IllegalArgumentException();
- }
+ Utils.checkNull(file, "file");
int index = selectedFiles.remove(file);
if (index != -1) {
@@ -258,9 +243,7 @@ public class FileBrowser extends Contain
* current root directory.
*/
public Sequence<File> setSelectedFiles(Sequence<File> selectedFiles) {
- if (selectedFiles == null) {
- throw new IllegalArgumentException("selectedFiles is null.");
- }
+ Utils.checkNull(selectedFiles, "selectedFiles");
if (!multiSelect && selectedFiles.getLength() > 1) {
throw new IllegalArgumentException("Multi-select is not enabled.");
@@ -273,16 +256,14 @@ public class FileBrowser extends Contain
for (int i = 0, n = selectedFiles.getLength(); i < n; i++) {
File file = selectedFiles.get(i);
- if (file == null) {
- throw new IllegalArgumentException("file is null.");
- }
+ Utils.checkNull(file, "file");
if (!file.isAbsolute()) {
file = new File(rootDirectory, file.getPath());
}
if (!file.getParentFile().equals(rootDirectory)) {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException(file.getPath() + " is not a child of the root directory.");
}
fileList.add(file);
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/FileBrowserSheet.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/FileBrowserSheet.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/FileBrowserSheet.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/FileBrowserSheet.java Fri Dec 22 22:32:19 2017
@@ -24,6 +24,7 @@ import org.apache.pivot.collections.immu
import org.apache.pivot.io.FileList;
import org.apache.pivot.util.Filter;
import org.apache.pivot.util.ListenerList;
+import org.apache.pivot.util.Utils;
/**
* File browser sheet.
@@ -119,13 +120,8 @@ public class FileBrowserSheet extends Sh
* @param rootFolder The root folder full name.
*/
public FileBrowserSheet(Mode mode, String rootFolder) {
- if (mode == null) {
- throw new IllegalArgumentException();
- }
-
- if (rootFolder == null) {
- throw new IllegalArgumentException();
- }
+ Utils.checkNull(mode, "mode");
+ Utils.checkNullOrEmpty(rootFolder, "rootFolder");
this.mode = mode;
@@ -139,9 +135,7 @@ public class FileBrowserSheet extends Sh
}
public void setMode(Mode mode) {
- if (mode == null) {
- throw new IllegalArgumentException();
- }
+ Utils.checkNull(mode, "mode");
Mode previousMode = this.mode;
@@ -162,26 +156,23 @@ public class FileBrowserSheet extends Sh
* @throws IllegalArgumentException if the folder argument is {@code null}.
*/
public void setRootFolder(String rootFolder) {
- if (rootFolder == null) {
- throw new IllegalArgumentException("Root folder is null.");
- }
+ Utils.checkNullOrEmpty(rootFolder, "rootFolder");
- rootDirectory = new File(rootFolder);
- if (!rootDirectory.isDirectory()) {
+ File rootFile = new File(rootFolder);
+ if (!rootFile.isDirectory()) {
// Give some grace here to allow setting the root directory
// to a regular file and have it work (by using its parent)
- rootDirectory = rootDirectory.getParentFile();
- if (rootDirectory == null || !rootDirectory.isDirectory()) {
- throw new IllegalArgumentException("Root folder is not a directory.");
+ rootFile = rootFile.getParentFile();
+ if (rootFile == null || !rootFile.isDirectory()) {
+ throw new IllegalArgumentException(rootFolder + " is not a directory.");
}
}
+ this.rootDirectory = rootFile;
}
public void setRootDirectory(File rootDirectory) {
- if (rootDirectory == null) {
- throw new IllegalArgumentException("Root directory is null.");
- }
+ Utils.checkNull(rootDirectory, "rootDirectory");
if (!rootDirectory.isDirectory()) {
// Give some grace here to allow setting the root directory
@@ -259,9 +250,7 @@ public class FileBrowserSheet extends Sh
* current root directory.
*/
public Sequence<File> setSelectedFiles(Sequence<File> selectedFiles) {
- if (selectedFiles == null) {
- throw new IllegalArgumentException("selectedFiles is null.");
- }
+ Utils.checkNull(selectedFiles, "selectedFiles");
if (mode != Mode.OPEN_MULTIPLE && selectedFiles.getLength() > 1) {
throw new IllegalArgumentException("Multi-select is not enabled.");
@@ -274,16 +263,14 @@ public class FileBrowserSheet extends Sh
for (int i = 0, n = selectedFiles.getLength(); i < n; i++) {
File file = selectedFiles.get(i);
- if (file == null) {
- throw new IllegalArgumentException("file is null.");
- }
+ Utils.checkNull(file, "file");
if (!file.isAbsolute()) {
file = new File(rootDirectory, file.getPath());
}
if (!file.getParentFile().equals(rootDirectory)) {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException(file.getPath() + " is not a child of the root directory.");
}
fileList.add(file);
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/FillPane.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/FillPane.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/FillPane.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/FillPane.java Fri Dec 22 22:32:19 2017
@@ -17,6 +17,7 @@
package org.apache.pivot.wtk;
import org.apache.pivot.util.ListenerList;
+import org.apache.pivot.util.Utils;
/**
* Container that fills the space it has been given inside its parent and then
@@ -67,9 +68,7 @@ public class FillPane extends Container
FillPaneListener {
@Override
public void orientationChanged(FillPane fillPane) {
- for (FillPaneListener listener : this) {
- listener.orientationChanged(fillPane);
- }
+ forEach(listener -> listener.orientationChanged(fillPane));
}
}
@@ -91,9 +90,7 @@ public class FillPane extends Container
}
public void setOrientation(Orientation orientation) {
- if (orientation == null) {
- throw new IllegalArgumentException();
- }
+ Utils.checkNull(orientation, "orientation");
if (this.orientation != orientation) {
this.orientation = orientation;
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Form.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Form.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Form.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Form.java Fri Dec 22 22:32:19 2017
@@ -27,6 +27,7 @@ import org.apache.pivot.json.JSONSeriali
import org.apache.pivot.serialization.SerializationException;
import org.apache.pivot.util.ImmutableIterator;
import org.apache.pivot.util.ListenerList;
+import org.apache.pivot.util.Utils;
/**
* A container that arranges field components in a form layout. Each field has
@@ -74,9 +75,7 @@ public class Form extends Container {
@Override
public void insert(Component field, int index) {
- if (field == null) {
- throw new IllegalArgumentException();
- }
+ Utils.checkNull(field, "field");
if (field.getParent() != null) {
throw new IllegalArgumentException("Field already has a parent.");
@@ -165,7 +164,7 @@ public class Form extends Container {
@Override
public void insert(Section section, int index) {
if (section.form != null) {
- throw new IllegalArgumentException("section already has a form.");
+ throw new IllegalArgumentException("Section already has a Form.");
}
sections.insert(section, index);
@@ -274,9 +273,7 @@ public class Form extends Container {
* <tt>null</tt> for no message.
*/
public Flag(MessageType messageType, String message) {
- if (messageType == null) {
- throw new IllegalArgumentException("messageType is null.");
- }
+ Utils.checkNull(messageType, "messageType");
this.messageType = messageType;
this.message = message;
@@ -298,9 +295,7 @@ public class Form extends Container {
* @throws IllegalArgumentException if the message type is {@code null}.
*/
public void setMessageType(MessageType messageType) {
- if (messageType == null) {
- throw new IllegalArgumentException();
- }
+ Utils.checkNull(messageType, "messageType");
this.messageType = messageType;
}
@@ -326,6 +321,8 @@ public class Form extends Container {
}
public static Flag decode(String flag) {
+ Utils.checkNullOrEmpty(flag, "flag");
+
Dictionary<String, ?> map;
try {
map = JSONSerializer.parseMap(flag);
@@ -333,13 +330,13 @@ public class Form extends Container {
throw new IllegalArgumentException(exception);
}
- String messageType = (String) map.get(MESSAGE_TYPE_KEY);
+ String messageType = map.getString(MESSAGE_TYPE_KEY);
if (messageType == null) {
throw new IllegalArgumentException(MESSAGE_TYPE_KEY + " is required.");
}
- Flag value = new Flag(MessageType.valueOf(messageType.toUpperCase(Locale.ENGLISH)),
- (String) map.get(MESSAGE_KEY));
+ Flag value = new Flag(MessageType.fromString(messageType),
+ map.getString(MESSAGE_KEY));
return value;
}
@@ -353,37 +350,27 @@ public class Form extends Container {
FormListener {
@Override
public void sectionInserted(Form form, int index) {
- for (FormListener listener : this) {
- listener.sectionInserted(form, index);
- }
+ forEach(listener -> listener.sectionInserted(form, index));
}
@Override
public void sectionsRemoved(Form form, int index, Sequence<Section> removed) {
- for (FormListener listener : this) {
- listener.sectionsRemoved(form, index, removed);
- }
+ forEach(listener -> listener.sectionsRemoved(form, index, removed));
}
@Override
public void sectionHeadingChanged(Form.Section section) {
- for (FormListener listener : this) {
- listener.sectionHeadingChanged(section);
- }
+ forEach(listener -> listener.sectionHeadingChanged(section));
}
@Override
public void fieldInserted(Section section, int index) {
- for (FormListener listener : this) {
- listener.fieldInserted(section, index);
- }
+ forEach(listener -> listener.fieldInserted(section, index));
}
@Override
public void fieldsRemoved(Section section, int index, Sequence<Component> fields) {
- for (FormListener listener : this) {
- listener.fieldsRemoved(section, index, fields);
- }
+ forEach(listener -> listener.fieldsRemoved(section, index, fields));
}
}
@@ -391,23 +378,17 @@ public class Form extends Container {
implements FormAttributeListener {
@Override
public void labelChanged(Form form, Component component, String previousLabel) {
- for (FormAttributeListener listener : this) {
- listener.labelChanged(form, component, previousLabel);
- }
+ forEach(listener -> listener.labelChanged(form, component, previousLabel));
}
@Override
public void requiredChanged(Form form, Component field) {
- for (FormAttributeListener listener : this) {
- listener.requiredChanged(form, field);
- }
+ forEach(listener -> listener.requiredChanged(form, field));
}
@Override
public void flagChanged(Form form, Component component, Form.Flag previousFlag) {
- for (FormAttributeListener listener : this) {
- listener.flagChanged(form, component, previousFlag);
- }
+ forEach(listener -> listener.flagChanged(form, component, previousFlag));
}
}
@@ -615,10 +596,6 @@ public class Form extends Container {
}
public static final void setFlag(Component component, String flag) {
- if (flag == null) {
- throw new IllegalArgumentException("flag is null.");
- }
-
setFlag(component, Flag.decode(flag));
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/GridPane.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/GridPane.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/GridPane.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/GridPane.java Fri Dec 22 22:32:19 2017
@@ -273,44 +273,32 @@ public class GridPane extends Container
GridPaneListener {
@Override
public void columnCountChanged(GridPane gridPane, int previousColumnCount) {
- for (GridPaneListener listener : this) {
- listener.columnCountChanged(gridPane, previousColumnCount);
- }
+ forEach(listener -> listener.columnCountChanged(gridPane, previousColumnCount));
}
@Override
public void rowInserted(GridPane gridPane, int index) {
- for (GridPaneListener listener : this) {
- listener.rowInserted(gridPane, index);
- }
+ forEach(listener -> listener.rowInserted(gridPane, index));
}
@Override
public void rowsRemoved(GridPane gridPane, int index, Sequence<GridPane.Row> rows) {
- for (GridPaneListener listener : this) {
- listener.rowsRemoved(gridPane, index, rows);
- }
+ forEach(listener -> listener.rowsRemoved(gridPane, index, rows));
}
@Override
public void cellInserted(GridPane.Row row, int column) {
- for (GridPaneListener listener : this) {
- listener.cellInserted(row, column);
- }
+ forEach(listener -> listener.cellInserted(row, column));
}
@Override
public void cellsRemoved(GridPane.Row row, int column, Sequence<Component> removed) {
- for (GridPaneListener listener : this) {
- listener.cellsRemoved(row, column, removed);
- }
+ forEach(listener -> listener.cellsRemoved(row, column, removed));
}
@Override
public void cellUpdated(GridPane.Row row, int column, Component previousComponent) {
- for (GridPaneListener listener : this) {
- listener.cellUpdated(row, column, previousComponent);
- }
+ forEach(listener -> listener.cellUpdated(row, column, previousComponent));
}
}
@@ -334,9 +322,7 @@ public class GridPane extends Container
* @param columnCount Number of columns for this grid.
*/
public GridPane(int columnCount) {
- if (columnCount < 0) {
- throw new IllegalArgumentException("columnCount is negative.");
- }
+ Utils.checkNonNegative(columnCount, "columnCount");
setColumnCount(columnCount);
@@ -345,10 +331,7 @@ public class GridPane extends Container
@Override
protected void setSkin(org.apache.pivot.wtk.Skin skin) {
- if (!(skin instanceof GridPane.Skin)) {
- throw new IllegalArgumentException("Skin class must implement "
- + GridPane.Skin.class.getName());
- }
+ checkSkin(skin, GridPane.Skin.class);
super.setSkin(skin);
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Label.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Label.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Label.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Label.java Fri Dec 22 22:32:19 2017
@@ -52,16 +52,12 @@ public class Label extends Component {
LabelListener {
@Override
public void textChanged(Label label, String previousText) {
- for (LabelListener listener : this) {
- listener.textChanged(label, previousText);
- }
+ forEach(listener -> listener.textChanged(label, previousText));
}
@Override
public void maximumLengthChanged(Label label, int previousMaximumLength) {
- for (LabelListener listener : this) {
- listener.maximumLengthChanged(label, previousMaximumLength);
- }
+ forEach(listener -> listener.maximumLengthChanged(label, previousMaximumLength));
}
}
@@ -70,24 +66,18 @@ public class Label extends Component {
implements LabelBindingListener {
@Override
public void textKeyChanged(Label label, String previousTextKey) {
- for (LabelBindingListener listener : this) {
- listener.textKeyChanged(label, previousTextKey);
- }
+ forEach(listener -> listener.textKeyChanged(label, previousTextKey));
}
@Override
public void textBindTypeChanged(Label label, BindType previousTextBindType) {
- for (LabelBindingListener listener : this) {
- listener.textBindTypeChanged(label, previousTextBindType);
- }
+ forEach(listener -> listener.textBindTypeChanged(label, previousTextBindType));
}
@Override
public void textBindMappingChanged(Label label,
Label.TextBindMapping previousTextBindMapping) {
- for (LabelBindingListener listener : this) {
- listener.textBindMappingChanged(label, previousTextBindMapping);
- }
+ forEach(listener -> listener.textBindMappingChanged(label, previousTextBindMapping));
}
}
@@ -174,9 +164,7 @@ public class Label extends Component {
* @throws IllegalArgumentException if the length given is negative.
*/
public void setMaximumLength(int maximumLength) {
- if (maximumLength < 0) {
- throw new IllegalArgumentException("maximumLength is negative.");
- }
+ Utils.checkNonNegative(maximumLength, "maximumLength");
int previousMaximumLength = this.maximumLength;
if (previousMaximumLength != maximumLength) {
@@ -245,7 +233,7 @@ public class Label extends Component {
value = textBindMapping.toString(value);
}
- setText(value != null ? (String) value : "");
+ setTextOrEmpty((String)value);
}
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButton.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButton.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButton.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButton.java Fri Dec 22 22:32:19 2017
@@ -45,39 +45,29 @@ public class ListButton extends Button {
implements ListButtonListener {
@Override
public void listDataChanged(ListButton listButton, List<?> previousListData) {
- for (ListButtonListener listener : this) {
- listener.listDataChanged(listButton, previousListData);
- }
+ forEach(listener -> listener.listDataChanged(listButton, previousListData));
}
@Override
public void itemRendererChanged(ListButton listButton,
ListView.ItemRenderer previousItemRenderer) {
- for (ListButtonListener listener : this) {
- listener.itemRendererChanged(listButton, previousItemRenderer);
- }
+ forEach(listener -> listener.itemRendererChanged(listButton, previousItemRenderer));
}
@Override
public void repeatableChanged(ListButton listButton) {
- for (ListButtonListener listener : this) {
- listener.repeatableChanged(listButton);
- }
+ forEach(listener -> listener.repeatableChanged(listButton));
}
@Override
public void disabledItemFilterChanged(ListButton listButton,
Filter<?> previousDisabledItemFilter) {
- for (ListButtonListener listener : this) {
- listener.disabledItemFilterChanged(listButton, previousDisabledItemFilter);
- }
+ forEach(listener -> listener.disabledItemFilterChanged(listButton, previousDisabledItemFilter));
}
@Override
public void listSizeChanged(ListButton listButton, int previousListSize) {
- for (ListButtonListener listener : this) {
- listener.listSizeChanged(listButton, previousListSize);
- }
+ forEach(listener -> listener.listSizeChanged(listButton, previousListSize));
}
}
@@ -85,37 +75,27 @@ public class ListButton extends Button {
implements ListButtonItemListener {
@Override
public void itemInserted(ListButton listButton, int index) {
- for (ListButtonItemListener listener : this) {
- listener.itemInserted(listButton, index);
- }
+ forEach(listener -> listener.itemInserted(listButton, index));
}
@Override
public void itemsRemoved(ListButton listButton, int index, int count) {
- for (ListButtonItemListener listener : this) {
- listener.itemsRemoved(listButton, index, count);
- }
+ forEach(listener -> listener.itemsRemoved(listButton, index, count));
}
@Override
public void itemUpdated(ListButton listButton, int index) {
- for (ListButtonItemListener listener : this) {
- listener.itemUpdated(listButton, index);
- }
+ forEach(listener -> listener.itemUpdated(listButton, index));
}
@Override
public void itemsCleared(ListButton listButton) {
- for (ListButtonItemListener listener : this) {
- listener.itemsCleared(listButton);
- }
+ forEach(listener -> listener.itemsCleared(listButton));
}
@Override
public void itemsSorted(ListButton listButton) {
- for (ListButtonItemListener listener : this) {
- listener.itemsSorted(listButton);
- }
+ forEach(listener -> listener.itemsSorted(listButton));
}
}
@@ -123,16 +103,12 @@ public class ListButton extends Button {
ListenerList<ListButtonSelectionListener> implements ListButtonSelectionListener {
@Override
public void selectedIndexChanged(ListButton listButton, int previousSelectedIndex) {
- for (ListButtonSelectionListener listener : this) {
- listener.selectedIndexChanged(listButton, previousSelectedIndex);
- }
+ forEach(listener -> listener.selectedIndexChanged(listButton, previousSelectedIndex));
}
@Override
public void selectedItemChanged(ListButton listButton, Object previousSelectedItem) {
- for (ListButtonSelectionListener listener : this) {
- listener.selectedItemChanged(listButton, previousSelectedItem);
- }
+ forEach(listener -> listener.selectedItemChanged(listButton, previousSelectedItem));
}
}
@@ -140,47 +116,35 @@ public class ListButton extends Button {
ListenerList<ListButtonBindingListener> implements ListButtonBindingListener {
@Override
public void listDataKeyChanged(ListButton listButton, String previousListDataKey) {
- for (ListButtonBindingListener listener : this) {
- listener.listDataKeyChanged(listButton, previousListDataKey);
- }
+ forEach(listener -> listener.listDataKeyChanged(listButton, previousListDataKey));
}
@Override
public void listDataBindTypeChanged(ListButton listButton, BindType previousListDataBindType) {
- for (ListButtonBindingListener listener : this) {
- listener.listDataBindTypeChanged(listButton, previousListDataBindType);
- }
+ forEach(listener -> listener.listDataBindTypeChanged(listButton, previousListDataBindType));
}
@Override
public void listDataBindMappingChanged(ListButton listButton,
ListView.ListDataBindMapping previousListDataBindMapping) {
- for (ListButtonBindingListener listener : this) {
- listener.listDataBindMappingChanged(listButton, previousListDataBindMapping);
- }
+ forEach(listener -> listener.listDataBindMappingChanged(listButton, previousListDataBindMapping));
}
@Override
public void selectedItemKeyChanged(ListButton listButton, String previousSelectedItemKey) {
- for (ListButtonBindingListener listener : this) {
- listener.selectedItemKeyChanged(listButton, previousSelectedItemKey);
- }
+ forEach(listener -> listener.selectedItemKeyChanged(listButton, previousSelectedItemKey));
}
@Override
public void selectedItemBindTypeChanged(ListButton listButton,
BindType previousSelectedItemBindType) {
- for (ListButtonBindingListener listener : this) {
- listener.selectedItemBindTypeChanged(listButton, previousSelectedItemBindType);
- }
+ forEach(listener -> listener.selectedItemBindTypeChanged(listButton, previousSelectedItemBindType));
}
@Override
public void selectedItemBindMappingChanged(ListButton listButton,
ListView.ItemBindMapping previousSelectedItemBindMapping) {
- for (ListButtonBindingListener listener : this) {
- listener.selectedItemBindMappingChanged(listButton, previousSelectedItemBindMapping);
- }
+ forEach(listener -> listener.selectedItemBindMappingChanged(listButton, previousSelectedItemBindMapping));
}
}
@@ -340,10 +304,7 @@ public class ListButton extends Button {
@Override
protected void setSkin(org.apache.pivot.wtk.Skin skin) {
- if (!(skin instanceof ListButton.Skin)) {
- throw new IllegalArgumentException("Skin class must implement "
- + ListButton.Skin.class.getName());
- }
+ checkSkin(skin, ListButton.Skin.class);
super.setSkin(skin);
}
@@ -440,9 +401,7 @@ public class ListButton extends Button {
try {
setListData((List<?>) jsonSerializer.readObject(listData.openStream()));
- } catch (SerializationException exception) {
- throw new IllegalArgumentException(exception);
- } catch (IOException exception) {
+ } catch (SerializationException | IOException exception) {
throw new IllegalArgumentException(exception);
}
}
@@ -633,9 +592,7 @@ public class ListButton extends Button {
}
public void setListDataBindType(BindType listDataBindType) {
- if (listDataBindType == null) {
- throw new IllegalArgumentException();
- }
+ Utils.checkNull(listDataBindType, "listDataBindType");
BindType previousListDataBindType = this.listDataBindType;
@@ -676,9 +633,7 @@ public class ListButton extends Button {
}
public void setSelectedItemBindType(BindType selectedItemBindType) {
- if (selectedItemBindType == null) {
- throw new IllegalArgumentException();
- }
+ Utils.checkNull(selectedItemBindType, "selectedItemBindType");
BindType previousSelectedItemBindType = this.selectedItemBindType;
if (previousSelectedItemBindType != selectedItemBindType) {
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java Fri Dec 22 22:32:19 2017
@@ -728,10 +728,7 @@ public class ListView extends Component
@Override
protected void setSkin(org.apache.pivot.wtk.Skin skin) {
- if (!(skin instanceof ListView.Skin)) {
- throw new IllegalArgumentException("Skin class must implement "
- + ListView.Skin.class.getName());
- }
+ checkSkin(skin, ListView.Skin.class);
super.setSkin(skin);
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/LocalManifest.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/LocalManifest.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/LocalManifest.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/LocalManifest.java Fri Dec 22 22:32:19 2017
@@ -24,6 +24,7 @@ import java.io.File;
import org.apache.pivot.collections.ArrayList;
import org.apache.pivot.collections.HashMap;
import org.apache.pivot.io.FileList;
+import org.apache.pivot.util.Utils;
import org.apache.pivot.wtk.media.Image;
import org.apache.pivot.wtk.media.Picture;
@@ -43,9 +44,7 @@ public class LocalManifest implements Ma
}
public void putText(String textArgument) {
- if (textArgument == null) {
- throw new IllegalArgumentException("text is null.");
- }
+ Utils.checkNull(textArgument, "text");
this.text = textArgument;
}
@@ -61,9 +60,7 @@ public class LocalManifest implements Ma
}
public void putImage(Image imageArgument) {
- if (imageArgument == null) {
- throw new IllegalArgumentException("image is null.");
- }
+ Utils.checkNull(imageArgument, "image");
this.image = imageArgument;
}
@@ -79,9 +76,7 @@ public class LocalManifest implements Ma
}
public void putFileList(FileList fileListArgument) {
- if (fileListArgument == null) {
- throw new IllegalArgumentException("fileList is null.");
- }
+ Utils.checkNull(fileListArgument, "fileList");
this.fileList = fileListArgument;
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuButton.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuButton.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuButton.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuButton.java Fri Dec 22 22:32:19 2017
@@ -63,10 +63,7 @@ public class MenuButton extends Button {
@Override
protected void setSkin(org.apache.pivot.wtk.Skin skin) {
- if (!(skin instanceof MenuButton.Skin)) {
- throw new IllegalArgumentException("Skin class must implement "
- + MenuButton.Skin.class.getName());
- }
+ checkSkin(skin, MenuButton.Skin.class);
super.setSkin(skin);
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Meter.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Meter.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Meter.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Meter.java Fri Dec 22 22:32:19 2017
@@ -17,6 +17,7 @@
package org.apache.pivot.wtk;
import org.apache.pivot.util.ListenerList;
+import org.apache.pivot.util.Utils;
/**
* Component that displays progress information.
@@ -26,23 +27,17 @@ public class Meter extends Component {
MeterListener {
@Override
public void orientationChanged(Meter meter) {
- for (MeterListener listener : this) {
- listener.orientationChanged(meter);
- }
+ forEach(listener -> listener.orientationChanged(meter));
}
@Override
public void percentageChanged(Meter meter, double oldPercentage) {
- for (MeterListener listener : this) {
- listener.percentageChanged(meter, oldPercentage);
- }
+ forEach(listener -> listener.percentageChanged(meter, oldPercentage));
}
@Override
public void textChanged(Meter meter, String oldText) {
- for (MeterListener listener : this) {
- listener.textChanged(meter, oldText);
- }
+ forEach(listener -> listener.textChanged(meter, oldText));
}
}
@@ -92,9 +87,7 @@ public class Meter extends Component {
}
public void setOrientation(Orientation orientation) {
- if (orientation == null) {
- throw new IllegalArgumentException("orientation is null.");
- }
+ Utils.checkNull(orientation, "orientation");
if (this.orientation != orientation) {
this.orientation = orientation;
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Mouse.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Mouse.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Mouse.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Mouse.java Fri Dec 22 22:32:19 2017
@@ -18,6 +18,8 @@ package org.apache.pivot.wtk;
import java.awt.MouseInfo;
+import org.apache.pivot.util.Utils;
+
/**
* Class representing the system mouse.
*/
@@ -80,9 +82,7 @@ public final class Mouse {
* The mouse pointer must currently be over the component.
*/
public static void capture(Component capturerArgument) {
- if (capturerArgument == null) {
- throw new IllegalArgumentException("capturer is null.");
- }
+ Utils.checkNull(capturerArgument, "capturer");
if (!capturerArgument.isMouseOver()) {
throw new IllegalArgumentException("Mouse pointer is not currently over capturer.");
@@ -228,7 +228,7 @@ public final class Mouse {
}
default: {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("Unknown mouse cursor type " + cursorID);
}
}
@@ -243,9 +243,7 @@ public final class Mouse {
* @throws IllegalStateException If the mouse is not currently captured.
*/
public static void setCursor(Cursor cursor) {
- if (cursor == null) {
- throw new IllegalArgumentException("cursor is null.");
- }
+ Utils.checkNull(cursor, "cursor");
if (capturer == null) {
throw new IllegalStateException("Mouse is not currently captured.");
@@ -264,12 +262,10 @@ public final class Mouse {
* if the component is not currently visible.
*/
public static void setCursor(final Component component) {
- if (component == null) {
- throw new IllegalArgumentException("component is null.");
- }
+ Utils.checkNull(component, "component");
if (!component.isVisible()) {
- throw new IllegalArgumentException("component is not visible.");
+ throw new IllegalArgumentException("Component for mouse cursor is not visible.");
}
Component componentOrParent = component;
@@ -369,7 +365,7 @@ public final class Mouse {
}
default: {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("Unknown mouse cursor type " + cursor.toString());
}
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Prompt.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Prompt.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Prompt.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Prompt.java Fri Dec 22 22:32:19 2017
@@ -26,6 +26,7 @@ import org.apache.pivot.serialization.Se
import org.apache.pivot.util.ImmutableIterator;
import org.apache.pivot.util.ListenerList;
import org.apache.pivot.util.Resources;
+import org.apache.pivot.util.Utils;
/**
* Class representing a "prompt", a sheet commonly used to facilitate simple
@@ -50,9 +51,7 @@ public class Prompt extends Sheet {
@Override
public void insert(Object option, int index) {
- if (option == null) {
- throw new IllegalArgumentException("option is null.");
- }
+ Utils.checkNull(option, "option");
options.insert(option, index);
@@ -122,44 +121,32 @@ public class Prompt extends Sheet {
PromptListener {
@Override
public void messageTypeChanged(Prompt prompt, MessageType previousMessageType) {
- for (PromptListener listener : this) {
- listener.messageTypeChanged(prompt, previousMessageType);
- }
+ forEach(listener -> listener.messageTypeChanged(prompt, previousMessageType));
}
@Override
public void messageChanged(Prompt prompt, String previousMessage) {
- for (PromptListener listener : this) {
- listener.messageChanged(prompt, previousMessage);
- }
+ forEach(listener -> listener.messageChanged(prompt, previousMessage));
}
@Override
public void bodyChanged(Prompt prompt, Component previousBody) {
- for (PromptListener listener : this) {
- listener.bodyChanged(prompt, previousBody);
- }
+ forEach(listener -> listener.bodyChanged(prompt, previousBody));
}
@Override
public void optionInserted(Prompt prompt, int index) {
- for (PromptListener listener : this) {
- listener.optionInserted(prompt, index);
- }
+ forEach(listener -> listener.optionInserted(prompt, index));
}
@Override
public void optionsRemoved(Prompt prompt, int index, Sequence<?> removed) {
- for (PromptListener listener : this) {
- listener.optionsRemoved(prompt, index, removed);
- }
+ forEach(listener -> listener.optionsRemoved(prompt, index, removed));
}
@Override
public void selectedOptionChanged(Prompt prompt, int previousSelectedOption) {
- for (PromptListener listener : this) {
- listener.selectedOptionChanged(prompt, previousSelectedOption);
- }
+ forEach(listener -> listener.selectedOptionChanged(prompt, previousSelectedOption));
}
}
@@ -209,9 +196,7 @@ public class Prompt extends Sheet {
}
public void setMessageType(MessageType messageType) {
- if (messageType == null) {
- throw new IllegalArgumentException();
- }
+ Utils.checkNull(messageType, "messageType");
MessageType previousMessageType = this.messageType;
if (previousMessageType != messageType) {
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/RadioButtonGroup.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/RadioButtonGroup.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/RadioButtonGroup.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/RadioButtonGroup.java Fri Dec 22 22:32:19 2017
@@ -24,6 +24,7 @@ import org.apache.pivot.collections.List
import org.apache.pivot.collections.Sequence;
import org.apache.pivot.util.Filter;
import org.apache.pivot.util.ImmutableIterator;
+import org.apache.pivot.util.Utils;
import org.apache.pivot.wtk.Keyboard.KeyCode;
import org.apache.pivot.wtk.Keyboard.KeyLocation;
import org.apache.pivot.wtk.Keyboard.Modifier;
@@ -297,9 +298,8 @@ public class RadioButtonGroup extends Bu
*/
@Override
public boolean add(Button button) {
- if (button == null) {
- throw new IllegalArgumentException("Button cannot be null");
- }
+ Utils.checkNull(button, "button");
+
boolean result = super.add(button);
if (result) {
buttonOrder.add(button);
@@ -347,9 +347,8 @@ public class RadioButtonGroup extends Bu
* @throws IllegalArgumentException if the button parameter is {@code null}.
*/
public void insert(Button button, int index) {
- if (button == null) {
- throw new IllegalArgumentException("Button cannot be null");
- }
+ Utils.checkNull(button, "button");
+
boolean result = super.add(button);
if (result) {
buttonOrder.insert(button, index);
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/ScrollBar.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/ScrollBar.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/ScrollBar.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/ScrollBar.java Fri Dec 22 22:32:19 2017
@@ -17,9 +17,11 @@
package org.apache.pivot.wtk;
import org.apache.pivot.collections.Dictionary;
+import org.apache.pivot.collections.Sequence;
import org.apache.pivot.json.JSONSerializer;
import org.apache.pivot.serialization.SerializationException;
import org.apache.pivot.util.ListenerList;
+import org.apache.pivot.util.Utils;
/**
* Component that allows a user to select one of a range of values. Most often
@@ -45,9 +47,7 @@ public class ScrollBar extends Container
}
public Scope(Dictionary<String, ?> scope) {
- if (scope == null) {
- throw new IllegalArgumentException("scope is null.");
- }
+ Utils.checkNull(scope, "scope");
if (!scope.containsKey(START_KEY)) {
throw new IllegalArgumentException(START_KEY + " is required.");
@@ -61,9 +61,17 @@ public class ScrollBar extends Container
throw new IllegalArgumentException(EXTENT_KEY + " is required.");
}
- start = ((Integer) scope.get(START_KEY)).intValue();
- end = ((Integer) scope.get(END_KEY)).intValue();
- extent = ((Integer) scope.get(EXTENT_KEY)).intValue();
+ start = scope.getInt(START_KEY);
+ end = scope.getInt(END_KEY);
+ extent = scope.getInt(EXTENT_KEY);
+ }
+
+ public Scope(Sequence<?> scope) {
+ Utils.checkNull(scope, "scope");
+
+ start = ((Number)scope.get(0)).intValue();
+ end = ((Number)scope.get(1)).intValue();
+ extent = ((Number)scope.get(2)).intValue();
}
@Override
@@ -72,15 +80,32 @@ public class ScrollBar extends Container
}
public static Scope decode(String value) {
- if (value == null) {
- throw new IllegalArgumentException();
- }
+ Utils.checkNullOrEmpty(value, "scope");
Scope scope;
- try {
- scope = new Scope(JSONSerializer.parseMap(value));
- } catch (SerializationException exception) {
- throw new IllegalArgumentException(exception);
+ if (value.startsWith("{")) {
+ try {
+ scope = new Scope(JSONSerializer.parseMap(value));
+ } catch (SerializationException exception) {
+ throw new IllegalArgumentException(exception);
+ }
+ } else if (value.startsWith("[")) {
+ try {
+ scope = new Scope(JSONSerializer.parseList(value));
+ } catch (SerializationException exception) {
+ throw new IllegalArgumentException(exception);
+ }
+ } else {
+ String[] parts = value.split("\\s*[,;]\\s*");
+ if (parts.length != 3) {
+ throw new IllegalArgumentException("Invalid format for ScrollBar.Scope: " + value);
+ }
+ try {
+ scope = new Scope(
+ Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2]));
+ } catch (NumberFormatException ex) {
+ throw new IllegalArgumentException(ex);
+ }
}
return scope;
@@ -91,31 +116,23 @@ public class ScrollBar extends Container
ScrollBarListener {
@Override
public void orientationChanged(ScrollBar scrollBar, Orientation previousOrientation) {
- for (ScrollBarListener listener : this) {
- listener.orientationChanged(scrollBar, previousOrientation);
- }
+ forEach(listener -> listener.orientationChanged(scrollBar, previousOrientation));
}
@Override
public void scopeChanged(ScrollBar scrollBar, int previousStart, int previousEnd,
int previousExtent) {
- for (ScrollBarListener listener : this) {
- listener.scopeChanged(scrollBar, previousStart, previousEnd, previousExtent);
- }
+ forEach(listener -> listener.scopeChanged(scrollBar, previousStart, previousEnd, previousExtent));
}
@Override
public void unitIncrementChanged(ScrollBar scrollBar, int previousUnitIncrement) {
- for (ScrollBarListener listener : this) {
- listener.unitIncrementChanged(scrollBar, previousUnitIncrement);
- }
+ forEach(listener -> listener.unitIncrementChanged(scrollBar, previousUnitIncrement));
}
@Override
public void blockIncrementChanged(ScrollBar scrollBar, int previousBlockIncrement) {
- for (ScrollBarListener listener : this) {
- listener.blockIncrementChanged(scrollBar, previousBlockIncrement);
- }
+ forEach(listener -> listener.blockIncrementChanged(scrollBar, previousBlockIncrement));
}
}
@@ -123,9 +140,7 @@ public class ScrollBar extends Container
implements ScrollBarValueListener {
@Override
public void valueChanged(ScrollBar scrollBar, int previousValue) {
- for (ScrollBarValueListener listener : this) {
- listener.valueChanged(scrollBar, previousValue);
- }
+ forEach(listener -> listener.valueChanged(scrollBar, previousValue));
}
}
@@ -145,9 +160,7 @@ public class ScrollBar extends Container
}
public ScrollBar(Orientation orientation) {
- if (orientation == null) {
- throw new IllegalArgumentException("orientation is null");
- }
+ Utils.checkNull(orientation, "orientation");
this.orientation = orientation;
@@ -159,9 +172,7 @@ public class ScrollBar extends Container
}
public void setOrientation(Orientation orientation) {
- if (orientation == null) {
- throw new IllegalArgumentException("orientation is null");
- }
+ Utils.checkNull(orientation, "orientation");
Orientation previousOrientation = this.orientation;
@@ -196,26 +207,16 @@ public class ScrollBar extends Container
}
public final void setRange(Span range) {
- if (range == null) {
- throw new IllegalArgumentException("range is null.");
- }
+ Utils.checkNull(range, "range");
setRange(range.start, range.end);
}
public final void setRange(Dictionary<String, ?> range) {
- if (range == null) {
- throw new IllegalArgumentException("range is null.");
- }
-
setRange(new Span(range));
}
public final void setRange(String range) {
- if (range == null) {
- throw new IllegalArgumentException("range is null.");
- }
-
setRange(Span.decode(range));
}
@@ -238,20 +239,15 @@ public class ScrollBar extends Container
if (start != previousStart || end != previousEnd || extent != previousExtent) {
if (start > value) {
- throw new IllegalArgumentException(String.format(
- "start (%d) is greater than value (%d)",
- Integer.valueOf(start), Integer.valueOf(value)));
+ throw new IllegalArgumentException(
+ "start (" + start + ") is greater than value (" + value + ")");
}
- if (extent < 0) {
- throw new IllegalArgumentException(String.format("extent (%d) is negative",
- Integer.valueOf(extent)));
- }
+ Utils.checkNonNegative(extent, "extent");
if (end < value + extent) {
- throw new IllegalArgumentException(String.format(
- "end (%d) is less than value (%d) + extent (%d)",
- Integer.valueOf(end), Integer.valueOf(value), Integer.valueOf(extent)));
+ throw new IllegalArgumentException(
+ "end (" + end + ") is less than value ("+ value + ") + extent (" + extent + ")");
}
this.start = start;
@@ -263,26 +259,20 @@ public class ScrollBar extends Container
}
public final void setScope(Scope scope) {
- if (scope == null) {
- throw new IllegalArgumentException("scope is null.");
- }
+ Utils.checkNull(scope, "scope");
setScope(scope.start, scope.end, scope.extent);
}
public final void setScope(Dictionary<String, ?> scope) {
- if (scope == null) {
- throw new IllegalArgumentException("scope is null.");
- }
+ setScope(new Scope(scope));
+ }
+ public final void setScope(Sequence<?> scope) {
setScope(new Scope(scope));
}
public final void setScope(String scope) {
- if (scope == null) {
- throw new IllegalArgumentException("scope is null.");
- }
-
setScope(Scope.decode(scope));
}
@@ -295,15 +285,13 @@ public class ScrollBar extends Container
if (value != previousValue) {
if (value < start) {
- throw new IllegalArgumentException(String.format(
- "value (%d) is less than start (%d)",
- Integer.valueOf(value), Integer.valueOf(start)));
+ throw new IllegalArgumentException(
+ "value (" + value + ") is less than start (" + start + ")");
}
if (value + extent > end) {
- throw new IllegalArgumentException(String.format(
- "value (%d) + extent (%d) is greater than end (%d)",
- Integer.valueOf(value), Integer.valueOf(extent), Integer.valueOf(end)));
+ throw new IllegalArgumentException(
+ "value (" + value + ") + extent (" + extent + ") is greater than end (" + end + ")");
}
this.value = value;
@@ -317,9 +305,7 @@ public class ScrollBar extends Container
}
public void setUnitIncrement(int unitIncrement) {
- if (unitIncrement < 0) {
- throw new IllegalArgumentException("unitIncrement is negative");
- }
+ Utils.checkNonNegative(unitIncrement, "unitIncrement");
int previousUnitIncrement = this.unitIncrement;
@@ -334,9 +320,7 @@ public class ScrollBar extends Container
}
public void setBlockIncrement(int blockIncrement) {
- if (blockIncrement < 0) {
- throw new IllegalArgumentException("blockIncrement is negative");
- }
+ Utils.checkNonNegative(blockIncrement, "blockIncrement");
int previousBlockIncrement = this.blockIncrement;
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Sheet.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Sheet.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Sheet.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Sheet.java Fri Dec 22 22:32:19 2017
@@ -17,7 +17,9 @@
package org.apache.pivot.wtk;
import org.apache.pivot.util.ListenerList;
+import org.apache.pivot.util.Utils;
import org.apache.pivot.util.Vote;
+import org.apache.pivot.util.VoteResult;
/**
* Window class representing a "sheet". A sheet behaves like a dialog that is
@@ -28,33 +30,26 @@ public class Sheet extends Window {
implements SheetStateListener {
@Override
public Vote previewSheetClose(Sheet sheet, boolean result) {
- Vote vote = Vote.APPROVE;
+ VoteResult vote = new VoteResult(Vote.APPROVE);
- for (SheetStateListener listener : this) {
- vote = vote.tally(listener.previewSheetClose(sheet, result));
- }
+ forEach(listener -> vote.tally(listener.previewSheetClose(sheet, result)));
- return vote;
+ return vote.get();
}
@Override
public void sheetCloseVetoed(Sheet sheet, Vote reason) {
- for (SheetStateListener listener : this) {
- listener.sheetCloseVetoed(sheet, reason);
- }
+ forEach(listener -> listener.sheetCloseVetoed(sheet, reason));
}
@Override
public void sheetClosed(Sheet sheet) {
- for (SheetStateListener listener : this) {
- listener.sheetClosed(sheet);
- }
+ forEach(listener -> listener.sheetClosed(sheet));
}
}
private SheetCloseListener sheetCloseListener = null;
private boolean result = false;
-
private boolean closing = false;
private SheetStateListenerList sheetStateListeners = new SheetStateListenerList();
@@ -78,9 +73,7 @@ public class Sheet extends Window {
}
public final void open(Window owner, SheetCloseListener sheetCloseListenerArgument) {
- if (owner == null) {
- throw new IllegalArgumentException("owner is null");
- }
+ Utils.checkNull(owner, "owner");
open(owner.getDisplay(), owner, sheetCloseListenerArgument);
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Slider.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Slider.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Slider.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Slider.java Fri Dec 22 22:32:19 2017
@@ -17,7 +17,9 @@
package org.apache.pivot.wtk;
import org.apache.pivot.collections.Dictionary;
+import org.apache.pivot.collections.Sequence;
import org.apache.pivot.util.ListenerList;
+import org.apache.pivot.util.Utils;
/**
* Allows a user to select one of a range of values.
@@ -27,16 +29,12 @@ public class Slider extends Container {
SliderListener {
@Override
public void orientationChanged(Slider slider) {
- for (SliderListener listener : this) {
- listener.orientationChanged(slider);
- }
+ forEach(listener -> listener.orientationChanged(slider));
}
@Override
public void rangeChanged(Slider slider, int previousStart, int previousEnd) {
- for (SliderListener listener : this) {
- listener.rangeChanged(slider, previousStart, previousEnd);
- }
+ forEach(listener -> listener.rangeChanged(slider, previousStart, previousEnd));
}
}
@@ -44,9 +42,7 @@ public class Slider extends Container {
implements SliderValueListener {
@Override
public void valueChanged(Slider slider, int previousValue) {
- for (SliderValueListener listener : this) {
- listener.valueChanged(slider, previousValue);
- }
+ forEach(listener -> listener.valueChanged(slider, previousValue));
}
}
@@ -90,8 +86,7 @@ public class Slider extends Container {
public void setRange(int start, int end) {
if (start > end) {
- throw new IllegalArgumentException("start " + start + " is greater than maximum " + end
- + ".");
+ throw new IllegalArgumentException("start " + start + " is greater than maximum " + end + ".");
}
int previousStart = this.start;
@@ -118,26 +113,20 @@ public class Slider extends Container {
}
public final void setRange(Span range) {
- if (range == null) {
- throw new IllegalArgumentException("range is null.");
- }
+ Utils.checkNull(range, "range");
setRange(range.start, range.end);
}
public final void setRange(Dictionary<String, ?> range) {
- if (range == null) {
- throw new IllegalArgumentException("range is null.");
- }
+ setRange(new Span(range));
+ }
+ public final void setRange(Sequence<?> range) {
setRange(new Span(range));
}
public final void setRange(String range) {
- if (range == null) {
- throw new IllegalArgumentException("range is null.");
- }
-
setRange(Span.decode(range));
}
@@ -147,13 +136,11 @@ public class Slider extends Container {
public void setValue(int value) {
if (value < start) {
- throw new IllegalArgumentException("value " + value + " is less than minimum " + start
- + ".");
+ throw new IllegalArgumentException("value " + value + " is less than minimum " + start + ".");
}
if (value > end) {
- throw new IllegalArgumentException("value " + value + " is greater than maximum " + end
- + ".");
+ throw new IllegalArgumentException("value " + value + " is greater than maximum " + end + ".");
}
int previousValue = this.value;
@@ -169,9 +156,7 @@ public class Slider extends Container {
}
public void setOrientation(Orientation orientation) {
- if (orientation == null) {
- throw new IllegalArgumentException("orientation is null.");
- }
+ Utils.checkNull(orientation, "orientation");
if (this.orientation != orientation) {
this.orientation = orientation;
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Span.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Span.java?rev=1819096&r1=1819095&r2=1819096&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Span.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Span.java Fri Dec 22 22:32:19 2017
@@ -92,6 +92,14 @@ public final class Span {
end = span.getInt(END_KEY);
}
+ /**
+ * Construct a new span from the given sequence with two
+ * numeric values corresponding to the start and end values
+ * respectively.
+ *
+ * @param span A sequence containing the start and end values.
+ * @throws IllegalArgumentException if the given span is {@code null}.
+ */
public Span(Sequence<?> span) {
Utils.checkNull(span, "span");
@@ -344,7 +352,7 @@ public final class Span {
* as a JSON list.
*/
public static Span decode(String value) {
- Utils.checkNull(value, "value");
+ Utils.checkNullOrEmpty(value, "value");
Span span;
if (value.startsWith("{")) {