[Japi-cvs] SF.net SVN: japi: [546] libs/swing-list/trunk/src/net/sf/japi/swing/list/ ArrayListModel
Status: Beta
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2007-07-14 16:57:15
|
Revision: 546
http://svn.sourceforge.net/japi/?rev=546&view=rev
Author: christianhujer
Date: 2007-07-14 09:57:14 -0700 (Sat, 14 Jul 2007)
Log Message:
-----------
Improved synchronization code.
Modified Paths:
--------------
libs/swing-list/trunk/src/net/sf/japi/swing/list/ArrayListModel.java
Modified: libs/swing-list/trunk/src/net/sf/japi/swing/list/ArrayListModel.java
===================================================================
--- libs/swing-list/trunk/src/net/sf/japi/swing/list/ArrayListModel.java 2007-07-14 16:51:38 UTC (rev 545)
+++ libs/swing-list/trunk/src/net/sf/japi/swing/list/ArrayListModel.java 2007-07-14 16:57:14 UTC (rev 546)
@@ -95,9 +95,7 @@
/** {@inheritDoc} */
public boolean moveToTop(final int index) {
- synchronized (list) {
- return move(null, index, 0);
- }
+ return move(null, index, 0);
}
/** {@inheritDoc} */
@@ -114,9 +112,7 @@
/** {@inheritDoc} */
public boolean moveUp(final int index) {
- synchronized (list) {
- return move(null, index, index - 1);
- }
+ return move(null, index, index - 1);
}
/** {@inheritDoc} */
@@ -133,9 +129,7 @@
/** {@inheritDoc} */
public boolean moveDown(final int index) {
- synchronized (list) {
- return move(null, index, index + 1);
- }
+ return move(null, index, index + 1);
}
/** {@inheritDoc} */
@@ -152,9 +146,7 @@
/** {@inheritDoc} */
public boolean moveToBottom(final int index) {
- synchronized (list) {
- return move(null, index, list.size() - 1);
- }
+ return move(null, index, list.size() - 1);
}
/** Performs the move operation of an element.
@@ -164,15 +156,17 @@
* @return <code>true</code> if the element was moved and the event was fired, otherwise <code>false</code>.
*/
private boolean move(@Nullable final E e, final int oldIndex, final int newIndex) {
- if (oldIndex == newIndex || oldIndex < 0 || newIndex < 0 || newIndex >= list.size()) {
- return false;
+ synchronized (list) {
+ if (oldIndex == newIndex || oldIndex < 0 || newIndex < 0 || newIndex >= list.size()) {
+ return false;
+ }
+ assert e == null || list.indexOf(e) == oldIndex;
+ final E moving = list.remove(oldIndex);
+ list.add(newIndex, moving);
+ assert e == null || list.indexOf(e) == newIndex;
+ fireContentsChanged(this, oldIndex, newIndex);
+ return true;
}
- assert e == null || list.indexOf(e) == oldIndex;
- final E moving = list.remove(oldIndex);
- list.add(newIndex, moving);
- assert e == null || list.indexOf(e) == newIndex;
- fireContentsChanged(this, oldIndex, newIndex);
- return true;
}
/** {@inheritDoc} */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|