Author: chris.laprun(a)jboss.com
Date: 2010-04-29 19:05:07 -0400 (Thu, 29 Apr 2010)
New Revision: 2905
Modified:
components/common/trunk/common/src/main/java/org/gatein/common/util/ParameterValidation.java
components/common/trunk/common/src/test/java/org/gatein/common/util/ParameterValidationTestCase.java
Log:
- Added isOldAndNewDifferent method.
Modified:
components/common/trunk/common/src/main/java/org/gatein/common/util/ParameterValidation.java
===================================================================
---
components/common/trunk/common/src/main/java/org/gatein/common/util/ParameterValidation.java 2010-04-29
18:40:30 UTC (rev 2904)
+++
components/common/trunk/common/src/main/java/org/gatein/common/util/ParameterValidation.java 2010-04-29
23:05:07 UTC (rev 2905)
@@ -1,36 +1,36 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2009, Red Hat Middleware, LLC, 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. *
- ******************************************************************************/
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, 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.gatein.common.util;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
+
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
-import org.gatein.common.logging.Logger;
-import org.gatein.common.logging.LoggerFactory;
-
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision: 5757 $
@@ -184,6 +184,11 @@
return array != null && array.length > 0;
}
+ public static boolean isOldAndNewDifferent(Object oldValue, Object newValue)
+ {
+ return (oldValue != null && !oldValue.equals(newValue)) || (oldValue ==
null && newValue != null);
+ }
+
/**
* Checks if a given value matches the given format (as a regular expression). If yes,
returns it as is. Otherwise,
* returns the default value.
Modified:
components/common/trunk/common/src/test/java/org/gatein/common/util/ParameterValidationTestCase.java
===================================================================
---
components/common/trunk/common/src/test/java/org/gatein/common/util/ParameterValidationTestCase.java 2010-04-29
18:40:30 UTC (rev 2904)
+++
components/common/trunk/common/src/test/java/org/gatein/common/util/ParameterValidationTestCase.java 2010-04-29
23:05:07 UTC (rev 2905)
@@ -1,29 +1,29 @@
/*
-* JBoss, a division of Red Hat
-* Copyright 2009, Red Hat Middleware, LLC, 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.
-*/
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, 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.gatein.common.util;
import junit.framework.TestCase;
-import org.gatein.common.util.ParameterValidation;
import java.util.regex.Pattern;
@@ -41,6 +41,16 @@
appender = "";
}
+ public void testIsOldAndNewDifferent()
+ {
+ assertFalse(ParameterValidation.isOldAndNewDifferent(null, null));
+ assertTrue(ParameterValidation.isOldAndNewDifferent("foo", null));
+ assertTrue(ParameterValidation.isOldAndNewDifferent(null, "foo"));
+ assertFalse(ParameterValidation.isOldAndNewDifferent("foo",
"foo"));
+ assertTrue(ParameterValidation.isOldAndNewDifferent("bar",
"foo"));
+ assertTrue(ParameterValidation.isOldAndNewDifferent(new Object(), new Object()));
+ }
+
public void testIsNullOrEmpty()
{
assertTrue(ParameterValidation.isNullOrEmpty(null));