[jboss-cvs] JBossAS SVN: r81164 - in projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api: types/helpers and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Nov 17 06:04:36 EST 2008
Author: alesj
Date: 2008-11-17 06:04:36 -0500 (Mon, 17 Nov 2008)
New Revision: 81164
Added:
projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/
projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/BigDecimalComparator.java
projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/BigIntegerComparator.java
projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/BooleanComparator.java
projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/ByteComparator.java
projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/CharacterComparator.java
projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/DateComparator.java
projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/DoubleComparator.java
projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/FloatComparator.java
projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/IntegerComparator.java
projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/LongComparator.java
projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/NamedComparator.java
projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/ShortComparator.java
projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/StringComparator.java
Modified:
projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/SimpleMetaType.java
projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/values/SimpleValueComparator.java
Log:
Make simple value compare OO.
Modified: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/SimpleMetaType.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/SimpleMetaType.java 2008-11-17 10:35:33 UTC (rev 81163)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/SimpleMetaType.java 2008-11-17 11:04:36 UTC (rev 81164)
@@ -24,14 +24,29 @@
import java.io.ObjectStreamException;
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.util.Comparator;
import java.util.Date;
+import org.jboss.metatype.api.types.helpers.BigDecimalComparator;
+import org.jboss.metatype.api.types.helpers.BigIntegerComparator;
+import org.jboss.metatype.api.types.helpers.BooleanComparator;
+import org.jboss.metatype.api.types.helpers.ByteComparator;
+import org.jboss.metatype.api.types.helpers.CharacterComparator;
+import org.jboss.metatype.api.types.helpers.DateComparator;
+import org.jboss.metatype.api.types.helpers.DoubleComparator;
+import org.jboss.metatype.api.types.helpers.FloatComparator;
+import org.jboss.metatype.api.types.helpers.IntegerComparator;
+import org.jboss.metatype.api.types.helpers.LongComparator;
+import org.jboss.metatype.api.types.helpers.NamedComparator;
+import org.jboss.metatype.api.types.helpers.ShortComparator;
+import org.jboss.metatype.api.types.helpers.StringComparator;
import org.jboss.metatype.api.values.SimpleValue;
/**
* SimpleMetaType.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
* @version $Revision: 1.1 $
*/
public class SimpleMetaType extends AbstractMetaType
@@ -87,22 +102,25 @@
/** The simple type for java.lang.Void */
public static final SimpleMetaType VOID;
+ /** The comparator */
+ private transient Comparator comparator;
+
static
{
- BIGDECIMAL = new SimpleMetaType(BigDecimal.class.getName());
- BIGINTEGER = new SimpleMetaType(BigInteger.class.getName());
- BOOLEAN = new SimpleMetaType(Boolean.class.getName());
- BYTE = new SimpleMetaType(Byte.class.getName());
- CHARACTER = new SimpleMetaType(Character.class.getName());
- DATE = new SimpleMetaType(Date.class.getName());
- DOUBLE = new SimpleMetaType(Double.class.getName());
- FLOAT = new SimpleMetaType(Float.class.getName());
- INTEGER = new SimpleMetaType(Integer.class.getName());
- LONG = new SimpleMetaType(Long.class.getName());
- SHORT = new SimpleMetaType(Short.class.getName());
- STRING = new SimpleMetaType(String.class.getName());
- NAMEDOBJECT = new SimpleMetaType(Name.class.getName());
- VOID = new SimpleMetaType(Void.class.getName());
+ BIGDECIMAL = new SimpleMetaType(BigDecimal.class, BigDecimalComparator.INSTANCE);
+ BIGINTEGER = new SimpleMetaType(BigInteger.class, BigIntegerComparator.INSTANCE);
+ BOOLEAN = new SimpleMetaType(Boolean.class, BooleanComparator.INSTANCE);
+ BYTE = new SimpleMetaType(Byte.class, ByteComparator.INSTANCE);
+ CHARACTER = new SimpleMetaType(Character.class, CharacterComparator.INSTANCE);
+ DATE = new SimpleMetaType(Date.class, DateComparator.INSTANCE);
+ DOUBLE = new SimpleMetaType(Double.class, DoubleComparator.INSTANCE);
+ FLOAT = new SimpleMetaType(Float.class, FloatComparator.INSTANCE);
+ INTEGER = new SimpleMetaType(Integer.class, IntegerComparator.INSTANCE);
+ LONG = new SimpleMetaType(Long.class, LongComparator.INSTANCE);
+ SHORT = new SimpleMetaType(Short.class, ShortComparator.INSTANCE);
+ STRING = new SimpleMetaType(String.class, StringComparator.INSTANCE);
+ NAMEDOBJECT = new SimpleMetaType(Name.class, NamedComparator.INSTANCE);
+ VOID = new SimpleMetaType(Void.class, null);
}
/**
@@ -180,6 +198,37 @@
cachedToString = buffer.toString();
}
+ /**
+ * Construct a simple meta type.
+ *
+ * @param clazz the class
+ * @param comparator class's comparator
+ */
+ private <T> SimpleMetaType(Class<T> clazz, Comparator<T> comparator)
+ {
+ this(clazz.getName());
+ this.comparator = comparator;
+ }
+
+ /**
+ * Compare objects.
+ *
+ * @param first the first object
+ * @param second the second object
+ * @return compare result
+ */
+ @SuppressWarnings("unchecked")
+ public int compare(Object first, Object second)
+ {
+ if (comparator == null)
+ return 0;
+
+ if (first == null || second == null)
+ throw new IllegalArgumentException("Null objects to compare.");
+
+ return comparator.compare(first, second);
+ }
+
@Override
public boolean isSimple()
{
Added: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/BigDecimalComparator.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/BigDecimalComparator.java (rev 0)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/BigDecimalComparator.java 2008-11-17 11:04:36 UTC (rev 81164)
@@ -0,0 +1,40 @@
+/*
+* 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.metatype.api.types.helpers;
+
+import java.util.Comparator;
+import java.math.BigDecimal;
+
+/**
+ * BigDecimal comparator.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class BigDecimalComparator implements Comparator<BigDecimal>
+{
+ public final static Comparator<BigDecimal> INSTANCE = new BigDecimalComparator();
+
+ public int compare(BigDecimal o1, BigDecimal o2)
+ {
+ return o1.compareTo(o2);
+ }
+}
Added: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/BigIntegerComparator.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/BigIntegerComparator.java (rev 0)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/BigIntegerComparator.java 2008-11-17 11:04:36 UTC (rev 81164)
@@ -0,0 +1,40 @@
+/*
+* 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.metatype.api.types.helpers;
+
+import java.math.BigInteger;
+import java.util.Comparator;
+
+/**
+ * BigInteger comparator.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class BigIntegerComparator implements Comparator<BigInteger>
+{
+ public final static Comparator<BigInteger> INSTANCE = new BigIntegerComparator();
+
+ public int compare(BigInteger o1, BigInteger o2)
+ {
+ return o1.compareTo(o2);
+ }
+}
\ No newline at end of file
Added: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/BooleanComparator.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/BooleanComparator.java (rev 0)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/BooleanComparator.java 2008-11-17 11:04:36 UTC (rev 81164)
@@ -0,0 +1,39 @@
+/*
+* 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.metatype.api.types.helpers;
+
+import java.util.Comparator;
+
+/**
+ * Boolean comparator.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class BooleanComparator implements Comparator<Boolean>
+{
+ public final static Comparator<Boolean> INSTANCE = new BooleanComparator();
+
+ public int compare(Boolean o1, Boolean o2)
+ {
+ return o1.compareTo(o2);
+ }
+}
\ No newline at end of file
Added: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/ByteComparator.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/ByteComparator.java (rev 0)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/ByteComparator.java 2008-11-17 11:04:36 UTC (rev 81164)
@@ -0,0 +1,39 @@
+/*
+* 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.metatype.api.types.helpers;
+
+import java.util.Comparator;
+
+/**
+ * Byte comparator.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ByteComparator implements Comparator<Byte>
+{
+ public final static Comparator<Byte> INSTANCE = new ByteComparator();
+
+ public int compare(Byte o1, Byte o2)
+ {
+ return o1.compareTo(o2);
+ }
+}
\ No newline at end of file
Added: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/CharacterComparator.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/CharacterComparator.java (rev 0)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/CharacterComparator.java 2008-11-17 11:04:36 UTC (rev 81164)
@@ -0,0 +1,39 @@
+/*
+* 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.metatype.api.types.helpers;
+
+import java.util.Comparator;
+
+/**
+ * Character comparator.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class CharacterComparator implements Comparator<Character>
+{
+ public final static Comparator<Character> INSTANCE = new CharacterComparator();
+
+ public int compare(Character o1, Character o2)
+ {
+ return o1.compareTo(o2);
+ }
+}
\ No newline at end of file
Added: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/DateComparator.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/DateComparator.java (rev 0)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/DateComparator.java 2008-11-17 11:04:36 UTC (rev 81164)
@@ -0,0 +1,40 @@
+/*
+* 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.metatype.api.types.helpers;
+
+import java.util.Comparator;
+import java.util.Date;
+
+/**
+ * Date comparator.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class DateComparator implements Comparator<Date>
+{
+ public final static Comparator<Date> INSTANCE = new DateComparator();
+
+ public int compare(Date o1, Date o2)
+ {
+ return o1.compareTo(o2);
+ }
+}
\ No newline at end of file
Added: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/DoubleComparator.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/DoubleComparator.java (rev 0)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/DoubleComparator.java 2008-11-17 11:04:36 UTC (rev 81164)
@@ -0,0 +1,39 @@
+/*
+* 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.metatype.api.types.helpers;
+
+import java.util.Comparator;
+
+/**
+ * Double comparator.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class DoubleComparator implements Comparator<Double>
+{
+ public final static Comparator<Double> INSTANCE = new DoubleComparator();
+
+ public int compare(Double o1, Double o2)
+ {
+ return o1.compareTo(o2);
+ }
+}
\ No newline at end of file
Added: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/FloatComparator.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/FloatComparator.java (rev 0)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/FloatComparator.java 2008-11-17 11:04:36 UTC (rev 81164)
@@ -0,0 +1,39 @@
+/*
+* 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.metatype.api.types.helpers;
+
+import java.util.Comparator;
+
+/**
+ * Float comparator.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class FloatComparator implements Comparator<Float>
+{
+ public final static Comparator<Float> INSTANCE = new FloatComparator();
+
+ public int compare(Float o1, Float o2)
+ {
+ return o1.compareTo(o2);
+ }
+}
\ No newline at end of file
Added: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/IntegerComparator.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/IntegerComparator.java (rev 0)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/IntegerComparator.java 2008-11-17 11:04:36 UTC (rev 81164)
@@ -0,0 +1,39 @@
+/*
+* 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.metatype.api.types.helpers;
+
+import java.util.Comparator;
+
+/**
+ * Integer comparator.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class IntegerComparator implements Comparator<Integer>
+{
+ public final static Comparator<Integer> INSTANCE = new IntegerComparator();
+
+ public int compare(Integer o1, Integer o2)
+ {
+ return o1.compareTo(o2);
+ }
+}
\ No newline at end of file
Added: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/LongComparator.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/LongComparator.java (rev 0)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/LongComparator.java 2008-11-17 11:04:36 UTC (rev 81164)
@@ -0,0 +1,39 @@
+/*
+* 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.metatype.api.types.helpers;
+
+import java.util.Comparator;
+
+/**
+ * Long comparator.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class LongComparator implements Comparator<Long>
+{
+ public final static Comparator<Long> INSTANCE = new LongComparator();
+
+ public int compare(Long o1, Long o2)
+ {
+ return o1.compareTo(o2);
+ }
+}
\ No newline at end of file
Added: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/NamedComparator.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/NamedComparator.java (rev 0)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/NamedComparator.java 2008-11-17 11:04:36 UTC (rev 81164)
@@ -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.metatype.api.types.helpers;
+
+import java.util.Comparator;
+
+import org.jboss.metatype.api.types.Name;
+
+/**
+ * Named comparator.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class NamedComparator implements Comparator<Name>
+{
+ public final static Comparator<Name> INSTANCE = new NamedComparator();
+
+ public int compare(Name o1, Name o2)
+ {
+ return o1.compareTo(o2);
+ }
+}
\ No newline at end of file
Added: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/ShortComparator.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/ShortComparator.java (rev 0)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/ShortComparator.java 2008-11-17 11:04:36 UTC (rev 81164)
@@ -0,0 +1,39 @@
+/*
+* 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.metatype.api.types.helpers;
+
+import java.util.Comparator;
+
+/**
+ * Short comparator.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ShortComparator implements Comparator<Short>
+{
+ public final static Comparator<Short> INSTANCE = new ShortComparator();
+
+ public int compare(Short o1, Short o2)
+ {
+ return o1.compareTo(o2);
+ }
+}
\ No newline at end of file
Added: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/StringComparator.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/StringComparator.java (rev 0)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/helpers/StringComparator.java 2008-11-17 11:04:36 UTC (rev 81164)
@@ -0,0 +1,39 @@
+/*
+* 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.metatype.api.types.helpers;
+
+import java.util.Comparator;
+
+/**
+ * String comparator.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class StringComparator implements Comparator<String>
+{
+ public final static Comparator<String> INSTANCE = new StringComparator();
+
+ public int compare(String o1, String o2)
+ {
+ return o1.compareTo(o2);
+ }
+}
\ No newline at end of file
Modified: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/values/SimpleValueComparator.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/values/SimpleValueComparator.java 2008-11-17 10:35:33 UTC (rev 81163)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/values/SimpleValueComparator.java 2008-11-17 11:04:36 UTC (rev 81164)
@@ -21,109 +21,24 @@
*/
package org.jboss.metatype.api.values;
-import java.math.BigDecimal;
-import java.math.BigInteger;
import java.util.Comparator;
-import java.util.Date;
-import org.jboss.metatype.api.types.Name;
import org.jboss.metatype.api.types.SimpleMetaType;
/**
* A Comparator for SimpleValues.
*
* @author Scott.Stark at jboss.org
+ * @author Ales.Justin at jboss.org
* @version $Revision:$
*/
-public class SimpleValueComparator
- implements Comparator<SimpleValue>
+public class SimpleValueComparator implements Comparator<SimpleValue>
{
public int compare(SimpleValue o1, SimpleValue o2)
{
- int compare = -1;
- if(o1.getMetaType() == SimpleMetaType.BIGINTEGER && o2.getMetaType() == SimpleMetaType.BIGINTEGER)
- {
- BigInteger v1 = BigInteger.class.cast(o1.getValue());
- BigInteger v2 = BigInteger.class.cast(o2.getValue());
- compare = v1.compareTo(v2);
- }
- else if(o1.getMetaType() == SimpleMetaType.BIGDECIMAL && o2.getMetaType() == SimpleMetaType.BIGDECIMAL)
- {
- BigDecimal v1 = BigDecimal.class.cast(o1.getValue());
- BigDecimal v2 = BigDecimal.class.cast(o2.getValue());
- compare = v1.compareTo(v2);
- }
- else if(o1.getMetaType() == SimpleMetaType.BOOLEAN && o2.getMetaType() == SimpleMetaType.BOOLEAN)
- {
- Boolean v1 = Boolean.class.cast(o1.getValue());
- Boolean v2 = Boolean.class.cast(o2.getValue());
- compare = v1.compareTo(v2);
- }
- else if(o1.getMetaType() == SimpleMetaType.BYTE && o2.getMetaType() == SimpleMetaType.BYTE)
- {
- Byte v1 = Byte.class.cast(o1.getValue());
- Byte v2 = Byte.class.cast(o2.getValue());
- compare = v1.compareTo(v2);
- }
- else if(o1.getMetaType() == SimpleMetaType.CHARACTER && o2.getMetaType() == SimpleMetaType.CHARACTER)
- {
- Character v1 = Character.class.cast(o1.getValue());
- Character v2 = Character.class.cast(o2.getValue());
- compare = v1.compareTo(v2);
- }
- else if(o1.getMetaType() == SimpleMetaType.DATE && o2.getMetaType() == SimpleMetaType.DATE)
- {
- Date v1 = Date.class.cast(o1.getValue());
- Date v2 = Date.class.cast(o2.getValue());
- compare = v1.compareTo(v2);
- }
- else if(o1.getMetaType() == SimpleMetaType.DOUBLE && o2.getMetaType() == SimpleMetaType.DOUBLE)
- {
- Double v1 = Double.class.cast(o1.getValue());
- Double v2 = Double.class.cast(o2.getValue());
- compare = v1.compareTo(v2);
- }
- else if(o1.getMetaType() == SimpleMetaType.FLOAT && o2.getMetaType() == SimpleMetaType.FLOAT)
- {
- Float v1 = Float.class.cast(o1.getValue());
- Float v2 = Float.class.cast(o2.getValue());
- compare = v1.compareTo(v2);
- }
- else if(o1.getMetaType() == SimpleMetaType.INTEGER && o2.getMetaType() == SimpleMetaType.INTEGER)
- {
- Integer v1 = Integer.class.cast(o1.getValue());
- Integer v2 = Integer.class.cast(o2.getValue());
- compare = v1.compareTo(v2);
- }
- else if(o1.getMetaType() == SimpleMetaType.LONG && o2.getMetaType() == SimpleMetaType.LONG)
- {
- Long v1 = Long.class.cast(o1.getValue());
- Long v2 = Long.class.cast(o2.getValue());
- compare = v1.compareTo(v2);
- }
- else if(o1.getMetaType() == SimpleMetaType.SHORT && o2.getMetaType() == SimpleMetaType.SHORT)
- {
- Short v1 = Short.class.cast(o1.getValue());
- Short v2 = Short.class.cast(o2.getValue());
- compare = v1.compareTo(v2);
- }
- else if(o1.getMetaType() == SimpleMetaType.STRING && o2.getMetaType() == SimpleMetaType.STRING)
- {
- String v1 = String.class.cast(o1.getValue());
- String v2 = String.class.cast(o2.getValue());
- compare = v1.compareTo(v2);
- }
- else if(o1.getMetaType() == SimpleMetaType.NAMEDOBJECT && o2.getMetaType() == SimpleMetaType.NAMEDOBJECT)
- {
- Name v1 = Name.class.cast(o1.getValue());
- Name v2 = Name.class.cast(o2.getValue());
- compare = v1.compareTo(v2);
- }
- else if(o1.getMetaType() == SimpleMetaType.VOID && o2.getMetaType() == SimpleMetaType.VOID)
- {
- compare = 0;
- }
+ SimpleMetaType smt1 = o1.getMetaType();
+ SimpleMetaType smt2 = o2.getMetaType();
- return compare;
+ return (smt1 == smt2) ? smt1.compare(o1.getValue(), o2.getValue()) : -1;
}
}
More information about the jboss-cvs-commits
mailing list