[jboss-svn-commits] JBoss Common SVN: r2884 - in common-core/trunk/src: test/java/org/jboss/test/util/test/propertyeditor and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Jul 4 17:02:11 EDT 2008
Author: alesj
Date: 2008-07-04 17:02:11 -0400 (Fri, 04 Jul 2008)
New Revision: 2884
Added:
common-core/trunk/src/main/java/org/jboss/util/propertyeditor/AtomicBooleanEditor.java
common-core/trunk/src/main/java/org/jboss/util/propertyeditor/AtomicIntegerEditor.java
common-core/trunk/src/main/java/org/jboss/util/propertyeditor/AtomicLongEditor.java
Modified:
common-core/trunk/src/test/java/org/jboss/test/util/test/propertyeditor/PropertyEditorsUnitTestCase.java
Log:
[JBCOMMON-59]; add atomic editors.
Added: common-core/trunk/src/main/java/org/jboss/util/propertyeditor/AtomicBooleanEditor.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/propertyeditor/AtomicBooleanEditor.java (rev 0)
+++ common-core/trunk/src/main/java/org/jboss/util/propertyeditor/AtomicBooleanEditor.java 2008-07-04 21:02:11 UTC (rev 2884)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.util.propertyeditor;
+
+import java.beans.PropertyEditorSupport;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * AtomicBoolean property editor.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class AtomicBooleanEditor extends PropertyEditorSupport
+{
+ public void setAsText(final String text)
+ {
+ if (PropertyEditors.isNull(text))
+ setValue(null);
+ else
+ setValue(new AtomicBoolean(Boolean.parseBoolean(text)));
+ }
+}
\ No newline at end of file
Added: common-core/trunk/src/main/java/org/jboss/util/propertyeditor/AtomicIntegerEditor.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/propertyeditor/AtomicIntegerEditor.java (rev 0)
+++ common-core/trunk/src/main/java/org/jboss/util/propertyeditor/AtomicIntegerEditor.java 2008-07-04 21:02:11 UTC (rev 2884)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.util.propertyeditor;
+
+import java.beans.PropertyEditorSupport;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * AtomicInteger property editor.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class AtomicIntegerEditor extends PropertyEditorSupport
+{
+ public void setAsText(final String text)
+ {
+ if (PropertyEditors.isNull(text))
+ setValue(null);
+ else
+ setValue(new AtomicInteger(Integer.parseInt(text)));
+ }
+}
Added: common-core/trunk/src/main/java/org/jboss/util/propertyeditor/AtomicLongEditor.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/propertyeditor/AtomicLongEditor.java (rev 0)
+++ common-core/trunk/src/main/java/org/jboss/util/propertyeditor/AtomicLongEditor.java 2008-07-04 21:02:11 UTC (rev 2884)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.util.propertyeditor;
+
+import java.beans.PropertyEditorSupport;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * AtomicLong property editor.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class AtomicLongEditor extends PropertyEditorSupport
+{
+ public void setAsText(final String text)
+ {
+ if (PropertyEditors.isNull(text))
+ setValue(null);
+ else
+ setValue(new AtomicLong(Long.parseLong(text)));
+ }
+}
\ No newline at end of file
Modified: common-core/trunk/src/test/java/org/jboss/test/util/test/propertyeditor/PropertyEditorsUnitTestCase.java
===================================================================
--- common-core/trunk/src/test/java/org/jboss/test/util/test/propertyeditor/PropertyEditorsUnitTestCase.java 2008-07-02 14:24:16 UTC (rev 2883)
+++ common-core/trunk/src/test/java/org/jboss/test/util/test/propertyeditor/PropertyEditorsUnitTestCase.java 2008-07-04 21:02:11 UTC (rev 2884)
@@ -36,7 +36,11 @@
import java.util.Locale;
import java.util.Properties;
import java.util.TimeZone;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+import junit.framework.TestCase;
import org.jboss.logging.Logger;
import org.jboss.util.propertyeditor.DateEditor;
import org.jboss.util.propertyeditor.DocumentEditor;
@@ -45,8 +49,6 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import junit.framework.TestCase;
-
/**
* Unit tests for the custom JBoss property editors
*
@@ -113,6 +115,22 @@
return compare;
}
}
+ static class NumberComparator implements Comparator<Number>
+ {
+ public int compare(Number o1, Number o2)
+ {
+ return o1.intValue() - o2.intValue();
+ }
+ }
+ static class ToStringComparator implements Comparator
+ {
+ public int compare(Object o1, Object o2)
+ {
+ String s1 = o1.toString();
+ String s2 = o2.toString();
+ return s1.compareTo(s2);
+ }
+ }
public PropertyEditorsUnitTestCase(String name)
{
@@ -216,6 +234,9 @@
Date.class,
java.util.Properties.class,
Locale.class,
+ AtomicInteger.class,
+ AtomicLong.class,
+ AtomicBoolean.class,
};
// The input string data for each type
String[][] inputData = {
@@ -242,6 +263,9 @@
// java.util.Properties.class
{"prop1=value1\nprop2=value2\nprop3=value3\nprop32=${prop3}\nprop4=${user.home}\nprop5=${some.win32.path}"},
{Locale.getDefault().toString(), "ja_JP"},
+ {"-1", "0", "1"},
+ {"-1", "0", "1"},
+ {"true", "false"},
};
// The expected instance for each inputData value
calendar.set(2005, 0, 4, 0, 0, 0);
@@ -275,6 +299,9 @@
{date1, date2, date3},
{props},
{Locale.getDefault(), Locale.JAPAN},
+ {new AtomicInteger(-1), new AtomicInteger(0), new AtomicInteger(1)},
+ {new AtomicLong(-1), new AtomicLong(0), new AtomicLong(1)},
+ {new AtomicBoolean(true), new AtomicBoolean(false)},
};
// The expected string output from getAsText()
String[][] expectedStringData = {
@@ -297,10 +324,13 @@
// int[].class
{"0,291,-123"},
// Date.class
- {"Jan 4, 2005", "Tue Jan 4 23:38:21 PST 2005", "Tue, 04 Jan 2005 23:38:48 -0800"},
+ {"Jan 4, 2005", "Tue Jan 4 23:38:21 PST 2005", "Tue, 04 Jan 2005 23:38:48 -0800"},
// java.util.Properties.class
{props.toString()},
{Locale.getDefault().toString(), Locale.JAPAN.toString()},
+ {"-1", "0", "1"},
+ {"-1", "0", "1"},
+ {"true", "false"},
};
// The Comparator for non-trival types
Comparator[] comparators = {
@@ -316,6 +346,9 @@
null, // Date
null, // Properties
null, // Locale
+ new NumberComparator(),
+ new NumberComparator(),
+ new ToStringComparator(),
};
doTests(types, inputData, expectedData, expectedStringData, comparators);
@@ -334,7 +367,7 @@
// An important date
String text = "Fri, 25 Jun 1971 00:30:00 +0200";
- DateFormat format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
+ DateFormat format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
Date date = format.parse(text);
PropertyEditor editor = new DateEditor();
@@ -346,8 +379,7 @@
editor.setValue(date);
log.debug("setValue('" + date + "') --> getAsText() - '" + editor.getAsText() + "'");
Date date2 = format.parse(editor.getAsText());
- assertTrue("Compare date1: " + date + ", date2: " + date2,
- date.compareTo(date2) == 0);
+ assertTrue("Compare date1: " + date + ", date2: " + date2, date.compareTo(date2) == 0);
// Try in French
Locale.setDefault(Locale.FRENCH);
@@ -362,14 +394,12 @@
editor = new DateEditor();
editor.setAsText(text);
log.debug("setAsText('" + text + "') --> getValue() = '" + editor.getValue() + "'");
- assertTrue("Compare date1: " + date + ", date2: " + editor.getValue(),
- date.compareTo((Date)editor.getValue()) == 0);
+ assertTrue("Compare date1: " + date + ", date2: " + editor.getValue(), date.compareTo((Date)editor.getValue()) == 0);
editor.setValue(date);
log.debug("setValue('" + date + "') --> getAsText() = '" + editor.getAsText() + "'");
date2 = format.parse(editor.getAsText());
- assertTrue("Compare date1: " + date + ", date2: " + date2,
- date.compareTo(date2) == 0);
+ assertTrue("Compare date1: " + date + ", date2: " + date2, date.compareTo(date2) == 0);
}
finally
{
More information about the jboss-svn-commits
mailing list