You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2011/04/25 11:19:32 UTC
svn commit: r1096439 [5/7] - in /incubator/isis/trunk/core/commons/src:
main/java/org/apache/isis/core/commons/authentication/
main/java/org/apache/isis/core/commons/components/
main/java/org/apache/isis/core/commons/config/ main/java/org/apache/isis/c...
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/ensure/Assert.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/ensure/Assert.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/ensure/Assert.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/ensure/Assert.java Mon Apr 25 09:19:29 2011
@@ -17,7 +17,6 @@
* under the License.
*/
-
package org.apache.isis.core.commons.ensure;
public final class Assert {
@@ -34,7 +33,7 @@ public final class Assert {
public static void assertEquals(final String message, final Object expected, final Object actual) {
assertTrue(message + ": expected " + expected + " but was " + actual, (expected == null && actual == null)
- || (expected != null && expected.equals(actual)));
+ || (expected != null && expected.equals(actual)));
}
public static void assertFalse(final boolean flag) {
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/ensure/Ensure.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/ensure/Ensure.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/ensure/Ensure.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/ensure/Ensure.java Mon Apr 25 09:19:29 2011
@@ -17,124 +17,126 @@
* under the License.
*/
+package org.apache.isis.core.commons.ensure;
-package org.apache.isis.core.commons.ensure;
-
-import org.hamcrest.Matcher;
-import org.hamcrest.StringDescription;
-
-
-/**
- * Uses the {@link Matcher Hamcrest API} as a means of verifying arguments and so on.
- */
-public final class Ensure {
-
- private Ensure() {}
-
- /**
- * To ensure that the provided argument is correct.
- *
- * @see #ensureThatArg(Object, Matcher,State)
- * @see #ensureThatState(Object, Matcher, String)
- * @see #ensureThatContext(Object, Matcher)
- *
- * @throws IllegalArgumentException if matcher does not {@link Matcher#matches(Object) match}.
- */
- public static <T> T ensureThatArg(final T object, final Matcher<T> matcher) {
- if (!matcher.matches(object)) {
- throw new IllegalArgumentException(
- "illegal argument, expected: " + descriptionOf(matcher));
- }
- return object;
- }
-
- /**
- * To ensure that the provided argument is correct.
- *
- * @see #ensureThatArg(Object, Matcher)
- * @see #ensureThatState(Object, Matcher, String)
- * @see #ensureThatContext(Object, Matcher)
- *
- * @throws IllegalArgumentException if matcher does not {@link Matcher#matches(Object) match}.
- */
- public static <T> T ensureThatArg(final T arg, final Matcher<T> matcher, final String message) {
- if (!matcher.matches(arg)) {
- throw new IllegalArgumentException(
- message);
- }
- return arg;
- }
-
- /**
- * To ensure that the current state of this object (instance fields) is correct.
- *
- * @see #ensureThatArg(Object, Matcher)
- * @see #ensureThatContext(Object, Matcher)
- * @see #ensureThatState(Object, Matcher, String)
- *
- * @throws IllegalStateException if matcher does not {@link Matcher#matches(Object) match}.
- */
- public static <T> T ensureThatState(final T field, final Matcher<T> matcher) {
- if (!matcher.matches(field)) {
- throw new IllegalStateException("illegal argument, expected: " + descriptionOf(matcher));
- }
- return field;
- }
-
- /**
- * To ensure that the current state of this object (instance fields) is correct.
- *
- * @see #ensureThatArg(Object, Matcher)
- * @see #ensureThatContext(Object, Matcher)
- * @see #ensureThatState(Object, Matcher)
- *
- * @throws IllegalStateException if matcher does not {@link Matcher#matches(Object) match}.
- */
- public static <T> T ensureThatState(final T field, final Matcher<T> matcher, final String message) {
- if (!matcher.matches(field)) {
- throw new IllegalStateException(message);
- }
- return field;
- }
-
-
- /**
- * To ensure that the current context (<tt>IsisContext</tt>) is correct.
- *
- * @see #ensureThatArg(Object, Matcher)
- * @see #ensureThatState(Object, Matcher)
- * @see #ensureThatContext(Object, Matcher, String)
- *
- * @throws IllegalThreadStateException if matcher does not {@link Matcher#matches(Object) match}.
- */
- public static <T> T ensureThatContext(final T contextProperty, final Matcher<T> matcher) {
- if (!matcher.matches(contextProperty)) {
- throw new IllegalThreadStateException("illegal argument, expected: " + descriptionOf(matcher));
- }
- return contextProperty;
- }
-
- /**
- * To ensure that the current context (<tt>IsisContext</tt>) is correct.
- *
- * @see #ensureThatArg(Object, Matcher)
- * @see #ensureThatState(Object, Matcher)
- * @see #ensureThatContext(Object, Matcher, String)
- *
- * @throws IllegalThreadStateException if matcher does not {@link Matcher#matches(Object) match}.
- */
- public static <T> T ensureThatContext(final T contextProperty, final Matcher<T> matcher, final String message) {
- if (!matcher.matches(contextProperty)) {
- throw new IllegalThreadStateException(message);
- }
- return contextProperty;
- }
-
- private static <T> String descriptionOf(final Matcher<T> matcher) {
- StringDescription stringDescription = new StringDescription();
- matcher.describeTo(stringDescription);
- String description = stringDescription.toString();
- return description;
- }
-
-}
+import org.hamcrest.Matcher;
+import org.hamcrest.StringDescription;
+
+/**
+ * Uses the {@link Matcher Hamcrest API} as a means of verifying arguments and so on.
+ */
+public final class Ensure {
+
+ private Ensure() {
+ }
+
+ /**
+ * To ensure that the provided argument is correct.
+ *
+ * @see #ensureThatArg(Object, Matcher,State)
+ * @see #ensureThatState(Object, Matcher, String)
+ * @see #ensureThatContext(Object, Matcher)
+ *
+ * @throws IllegalArgumentException
+ * if matcher does not {@link Matcher#matches(Object) match}.
+ */
+ public static <T> T ensureThatArg(final T object, final Matcher<T> matcher) {
+ if (!matcher.matches(object)) {
+ throw new IllegalArgumentException("illegal argument, expected: " + descriptionOf(matcher));
+ }
+ return object;
+ }
+
+ /**
+ * To ensure that the provided argument is correct.
+ *
+ * @see #ensureThatArg(Object, Matcher)
+ * @see #ensureThatState(Object, Matcher, String)
+ * @see #ensureThatContext(Object, Matcher)
+ *
+ * @throws IllegalArgumentException
+ * if matcher does not {@link Matcher#matches(Object) match}.
+ */
+ public static <T> T ensureThatArg(final T arg, final Matcher<T> matcher, final String message) {
+ if (!matcher.matches(arg)) {
+ throw new IllegalArgumentException(message);
+ }
+ return arg;
+ }
+
+ /**
+ * To ensure that the current state of this object (instance fields) is correct.
+ *
+ * @see #ensureThatArg(Object, Matcher)
+ * @see #ensureThatContext(Object, Matcher)
+ * @see #ensureThatState(Object, Matcher, String)
+ *
+ * @throws IllegalStateException
+ * if matcher does not {@link Matcher#matches(Object) match}.
+ */
+ public static <T> T ensureThatState(final T field, final Matcher<T> matcher) {
+ if (!matcher.matches(field)) {
+ throw new IllegalStateException("illegal argument, expected: " + descriptionOf(matcher));
+ }
+ return field;
+ }
+
+ /**
+ * To ensure that the current state of this object (instance fields) is correct.
+ *
+ * @see #ensureThatArg(Object, Matcher)
+ * @see #ensureThatContext(Object, Matcher)
+ * @see #ensureThatState(Object, Matcher)
+ *
+ * @throws IllegalStateException
+ * if matcher does not {@link Matcher#matches(Object) match}.
+ */
+ public static <T> T ensureThatState(final T field, final Matcher<T> matcher, final String message) {
+ if (!matcher.matches(field)) {
+ throw new IllegalStateException(message);
+ }
+ return field;
+ }
+
+ /**
+ * To ensure that the current context (<tt>IsisContext</tt>) is correct.
+ *
+ * @see #ensureThatArg(Object, Matcher)
+ * @see #ensureThatState(Object, Matcher)
+ * @see #ensureThatContext(Object, Matcher, String)
+ *
+ * @throws IllegalThreadStateException
+ * if matcher does not {@link Matcher#matches(Object) match}.
+ */
+ public static <T> T ensureThatContext(final T contextProperty, final Matcher<T> matcher) {
+ if (!matcher.matches(contextProperty)) {
+ throw new IllegalThreadStateException("illegal argument, expected: " + descriptionOf(matcher));
+ }
+ return contextProperty;
+ }
+
+ /**
+ * To ensure that the current context (<tt>IsisContext</tt>) is correct.
+ *
+ * @see #ensureThatArg(Object, Matcher)
+ * @see #ensureThatState(Object, Matcher)
+ * @see #ensureThatContext(Object, Matcher, String)
+ *
+ * @throws IllegalThreadStateException
+ * if matcher does not {@link Matcher#matches(Object) match}.
+ */
+ public static <T> T ensureThatContext(final T contextProperty, final Matcher<T> matcher, final String message) {
+ if (!matcher.matches(contextProperty)) {
+ throw new IllegalThreadStateException(message);
+ }
+ return contextProperty;
+ }
+
+ private static <T> String descriptionOf(final Matcher<T> matcher) {
+ final StringDescription stringDescription = new StringDescription();
+ matcher.describeTo(stringDescription);
+ final String description = stringDescription.toString();
+ return description;
+ }
+
+}
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/ensure/IsisAssertException.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/ensure/IsisAssertException.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/ensure/IsisAssertException.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/ensure/IsisAssertException.java Mon Apr 25 09:19:29 2011
@@ -17,12 +17,10 @@
* under the License.
*/
-
package org.apache.isis.core.commons.ensure;
import org.apache.isis.core.commons.exceptions.IsisException;
-
public class IsisAssertException extends IsisException {
private static final long serialVersionUID = 1L;
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/exceptions/IsisApplicationException.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/exceptions/IsisApplicationException.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/exceptions/IsisApplicationException.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/exceptions/IsisApplicationException.java Mon Apr 25 09:19:29 2011
@@ -17,19 +17,16 @@
* under the License.
*/
-
package org.apache.isis.core.commons.exceptions;
-
/**
* Indicates an error raised by the application code.
*
* <p>
- * The viewer is expected to render the message within the
- * application in a user-friendly fashion.
+ * The viewer is expected to render the message within the application in a user-friendly fashion.
*/
public class IsisApplicationException extends IsisException {
-
+
private static final long serialVersionUID = 1L;
public IsisApplicationException() {
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/exceptions/IsisException.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/exceptions/IsisException.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/exceptions/IsisException.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/exceptions/IsisException.java Mon Apr 25 09:19:29 2011
@@ -17,17 +17,14 @@
* under the License.
*/
-
package org.apache.isis.core.commons.exceptions;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.text.MessageFormat;
-
/**
- * General exception raised by the framework, typically
- * a system exception.
+ * General exception raised by the framework, typically a system exception.
*/
public class IsisException extends RuntimeException {
private static final long serialVersionUID = 1L;
@@ -57,7 +54,7 @@ public class IsisException extends Runti
cause = null;
}
- public IsisException(final String messageFormat, Object... args) {
+ public IsisException(final String messageFormat, final Object... args) {
super(MessageFormat.format(messageFormat, args));
cause = null;
}
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/exceptions/NotYetImplementedException.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/exceptions/NotYetImplementedException.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/exceptions/NotYetImplementedException.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/exceptions/NotYetImplementedException.java Mon Apr 25 09:19:29 2011
@@ -17,7 +17,6 @@
* under the License.
*/
-
package org.apache.isis.core.commons.exceptions;
/**
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/exceptions/UnexpectedCallException.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/exceptions/UnexpectedCallException.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/exceptions/UnexpectedCallException.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/exceptions/UnexpectedCallException.java Mon Apr 25 09:19:29 2011
@@ -17,15 +17,11 @@
* under the License.
*/
-
package org.apache.isis.core.commons.exceptions;
-
-
-
/**
- * Indicates that a call was made to a method (normally an overridden one) that was not expected, and hence
- * not coded for.
+ * Indicates that a call was made to a method (normally an overridden one) that was not expected, and hence not coded
+ * for.
*/
public class UnexpectedCallException extends IsisException {
private static final long serialVersionUID = 1L;
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/exceptions/UnknownTypeException.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/exceptions/UnknownTypeException.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/exceptions/UnknownTypeException.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/exceptions/UnknownTypeException.java Mon Apr 25 09:19:29 2011
@@ -17,33 +17,29 @@
* under the License.
*/
+package org.apache.isis.core.commons.exceptions;
-package org.apache.isis.core.commons.exceptions;
-
-
-
-
-public class UnknownTypeException extends IsisException {
- private static final long serialVersionUID = 1L;
-
- public UnknownTypeException() {
- super();
- }
-
- public UnknownTypeException(final String message) {
- super(message);
- }
-
- public UnknownTypeException(final Throwable cause) {
- super(cause);
- }
-
- public UnknownTypeException(final String message, final Throwable cause) {
- super(message, cause);
- }
-
- public UnknownTypeException(final Object object) {
- this(object == null ? "null" : object.toString());
- }
-
-}
+public class UnknownTypeException extends IsisException {
+ private static final long serialVersionUID = 1L;
+
+ public UnknownTypeException() {
+ super();
+ }
+
+ public UnknownTypeException(final String message) {
+ super(message);
+ }
+
+ public UnknownTypeException(final Throwable cause) {
+ super(cause);
+ }
+
+ public UnknownTypeException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+
+ public UnknownTypeException(final Object object) {
+ this(object == null ? "null" : object.toString());
+ }
+
+}
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/factory/InstanceCreationClassException.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/factory/InstanceCreationClassException.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/factory/InstanceCreationClassException.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/factory/InstanceCreationClassException.java Mon Apr 25 09:19:29 2011
@@ -17,12 +17,10 @@
* under the License.
*/
-
package org.apache.isis.core.commons.factory;
import org.apache.isis.core.commons.exceptions.IsisException;
-
public class InstanceCreationClassException extends IsisException {
private static final long serialVersionUID = 1L;
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/factory/InstanceCreationException.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/factory/InstanceCreationException.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/factory/InstanceCreationException.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/factory/InstanceCreationException.java Mon Apr 25 09:19:29 2011
@@ -17,12 +17,10 @@
* under the License.
*/
-
package org.apache.isis.core.commons.factory;
import org.apache.isis.core.commons.exceptions.IsisException;
-
public class InstanceCreationException extends IsisException {
private static final long serialVersionUID = 1L;
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/factory/InstanceUtil.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/factory/InstanceUtil.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/factory/InstanceUtil.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/factory/InstanceUtil.java Mon Apr 25 09:19:29 2011
@@ -17,46 +17,46 @@
* under the License.
*/
-
package org.apache.isis.core.commons.factory;
import org.apache.isis.core.commons.ensure.Assert;
import org.apache.isis.core.commons.lang.CastUtils;
-
public final class InstanceUtil {
-
- private InstanceUtil() {}
+
+ private InstanceUtil() {
+ }
public static Object createInstance(final String className) {
- return createInstance(className, (Class<?>)null, null);
+ return createInstance(className, (Class<?>) null, null);
}
public static Object createInstance(final Class<?> cls) {
- return createInstance(cls, (Class<?>)null, null);
+ return createInstance(cls, (Class<?>) null, null);
}
public static <T> T createInstance(final String className, final Class<T> requiredClass) {
- return createInstance(className, (Class<T>)null, requiredClass);
+ return createInstance(className, (Class<T>) null, requiredClass);
}
public static <T> T createInstance(final Class<?> cls, final Class<T> requiredClass) {
- return createInstance(cls, (Class<T>)null, requiredClass);
+ return createInstance(cls, (Class<T>) null, requiredClass);
}
public static <T> T createInstance(final String className, final String defaultTypeName, final Class<T> requiredType) {
Class<? extends T> defaultType = null;
if (defaultTypeName != null) {
- try {
- defaultType = CastUtils.cast(Thread.currentThread().getContextClassLoader().loadClass(defaultTypeName));
- if (defaultType == null) {
- throw new InstanceCreationClassException("Failed to load default type '" + defaultTypeName + "'");
- }
- } catch (final ClassNotFoundException e) {
- throw new UnavailableClassException("The default type '" + defaultTypeName + "' cannot be found");
- } catch (final NoClassDefFoundError e) {
- throw new InstanceCreationClassException("Default type '" + defaultTypeName + "' found, but is missing a dependent class: " + e.getMessage(), e);
- }
+ try {
+ defaultType = CastUtils.cast(Thread.currentThread().getContextClassLoader().loadClass(defaultTypeName));
+ if (defaultType == null) {
+ throw new InstanceCreationClassException("Failed to load default type '" + defaultTypeName + "'");
+ }
+ } catch (final ClassNotFoundException e) {
+ throw new UnavailableClassException("The default type '" + defaultTypeName + "' cannot be found");
+ } catch (final NoClassDefFoundError e) {
+ throw new InstanceCreationClassException("Default type '" + defaultTypeName
+ + "' found, but is missing a dependent class: " + e.getMessage(), e);
+ }
}
return createInstance(className, defaultType, requiredType);
}
@@ -64,22 +64,24 @@ public final class InstanceUtil {
public static <T> T createInstance(final Class<?> cls, final String defaultTypeName, final Class<T> requiredType) {
Class<? extends T> defaultType = null;
if (defaultTypeName != null) {
- defaultType = loadClass(defaultTypeName, requiredType);
- try {
- defaultType = CastUtils.cast(Thread.currentThread().getContextClassLoader().loadClass(defaultTypeName));
- if (defaultType == null) {
- throw new InstanceCreationClassException("Failed to load default type '" + defaultTypeName + "'");
- }
- } catch (final ClassNotFoundException e) {
- throw new UnavailableClassException("The default type '" + defaultTypeName + "' cannot be found");
- } catch (final NoClassDefFoundError e) {
- throw new InstanceCreationClassException("Default type '" + defaultTypeName + "' found, but is missing a dependent class: " + e.getMessage(), e);
- }
+ defaultType = loadClass(defaultTypeName, requiredType);
+ try {
+ defaultType = CastUtils.cast(Thread.currentThread().getContextClassLoader().loadClass(defaultTypeName));
+ if (defaultType == null) {
+ throw new InstanceCreationClassException("Failed to load default type '" + defaultTypeName + "'");
+ }
+ } catch (final ClassNotFoundException e) {
+ throw new UnavailableClassException("The default type '" + defaultTypeName + "' cannot be found");
+ } catch (final NoClassDefFoundError e) {
+ throw new InstanceCreationClassException("Default type '" + defaultTypeName
+ + "' found, but is missing a dependent class: " + e.getMessage(), e);
+ }
}
return createInstance(cls, defaultType, requiredType);
}
- public static <T> T createInstance(final String className, final Class<? extends T> defaultType, final Class<T> requiredType) {
+ public static <T> T createInstance(final String className, final Class<? extends T> defaultType,
+ final Class<T> requiredType) {
Assert.assertNotNull("Class to instantiate must be specified", className);
Class<?> cls = null;
try {
@@ -94,53 +96,58 @@ public final class InstanceUtil {
}
throw new UnavailableClassException("The class '" + className + "' cannot be found");
} catch (final NoClassDefFoundError e) {
- throw new InstanceCreationClassException("Class '" + className + "' found , but is missing a dependent class: " + e.getMessage(), e);
+ throw new InstanceCreationClassException("Class '" + className
+ + "' found , but is missing a dependent class: " + e.getMessage(), e);
}
}
- public static <T> T createInstance(final Class<?> cls, final Class<? extends T> defaultType, final Class<T> requiredType) {
+ public static <T> T createInstance(final Class<?> cls, final Class<? extends T> defaultType,
+ final Class<T> requiredType) {
Assert.assertNotNull("Class to instantiate must be specified", cls);
try {
if (requiredType == null || requiredType.isAssignableFrom(cls)) {
final Class<T> tClass = CastUtils.cast(cls);
return tClass.newInstance();
} else {
- throw new InstanceCreationClassException("Class '" + cls.getName() + "' is not of type '" + requiredType + "'");
+ throw new InstanceCreationClassException("Class '" + cls.getName() + "' is not of type '"
+ + requiredType + "'");
}
} catch (final NoClassDefFoundError e) {
- throw new InstanceCreationClassException("Class '" + cls + "'found , but is missing a dependent class: " + e.getMessage(), e);
+ throw new InstanceCreationClassException("Class '" + cls + "'found , but is missing a dependent class: "
+ + e.getMessage(), e);
} catch (final InstantiationException e) {
throw new InstanceCreationException("Could not instantiate an object of class '" + cls.getName() + "'; "
- + e.getMessage());
+ + e.getMessage());
} catch (final IllegalAccessException e) {
throw new InstanceCreationException("Could not access the class '" + cls.getName() + "'; " + e.getMessage());
}
}
- public static Class<?> loadClass(
- String className) {
+ public static Class<?> loadClass(final String className) {
Assert.assertNotNull("Class to instantiate must be specified", className);
- try {
- return Thread.currentThread().getContextClassLoader().loadClass(className);
- } catch (final ClassNotFoundException e) {
- throw new UnavailableClassException("The default type '" + className + "' cannot be found");
- } catch (final NoClassDefFoundError e) {
- throw new InstanceCreationClassException("Default type '" + className + "' found, but is missing a dependent class: " + e.getMessage(), e);
- }
- }
+ try {
+ return Thread.currentThread().getContextClassLoader().loadClass(className);
+ } catch (final ClassNotFoundException e) {
+ throw new UnavailableClassException("The default type '" + className + "' cannot be found");
+ } catch (final NoClassDefFoundError e) {
+ throw new InstanceCreationClassException("Default type '" + className
+ + "' found, but is missing a dependent class: " + e.getMessage(), e);
+ }
+ }
- public static <R, T extends R> Class<T> loadClass(
- String className, Class<R> requiredType) {
+ public static <R, T extends R> Class<T> loadClass(final String className, final Class<R> requiredType) {
Assert.assertNotNull("Class to instantiate must be specified", className);
- try {
- Class<?> loadedClass = loadClass(className);
- if (requiredType != null && !requiredType.isAssignableFrom(loadedClass)) {
- throw new InstanceCreationClassException("Class '" + className + "' is not of type '" + requiredType + "'");
- }
- return CastUtils.cast(loadedClass);
- } catch (final NoClassDefFoundError e) {
- throw new InstanceCreationClassException("Default type '" + className + "' found, but is missing a dependent class: " + e.getMessage(), e);
- }
- }
+ try {
+ final Class<?> loadedClass = loadClass(className);
+ if (requiredType != null && !requiredType.isAssignableFrom(loadedClass)) {
+ throw new InstanceCreationClassException("Class '" + className + "' is not of type '" + requiredType
+ + "'");
+ }
+ return CastUtils.cast(loadedClass);
+ } catch (final NoClassDefFoundError e) {
+ throw new InstanceCreationClassException("Default type '" + className
+ + "' found, but is missing a dependent class: " + e.getMessage(), e);
+ }
+ }
}
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/factory/UnavailableClassException.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/factory/UnavailableClassException.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/factory/UnavailableClassException.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/factory/UnavailableClassException.java Mon Apr 25 09:19:29 2011
@@ -17,12 +17,10 @@
* under the License.
*/
-
package org.apache.isis.core.commons.factory;
import org.apache.isis.core.commons.exceptions.IsisException;
-
public class UnavailableClassException extends IsisException {
private static final long serialVersionUID = 1L;
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/io/LazyInputStream.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/io/LazyInputStream.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/io/LazyInputStream.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/io/LazyInputStream.java Mon Apr 25 09:19:29 2011
@@ -17,167 +17,165 @@
* under the License.
*/
+package org.apache.isis.core.commons.io;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.nullValue;
+
+import java.io.IOException;
+import java.io.InputStream;
-package org.apache.isis.core.commons.io;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.CoreMatchers.nullValue;
-
-import java.io.IOException;
-import java.io.InputStream;
-
import org.apache.isis.core.commons.ensure.Ensure;
-
-/**
- * An input stream that reads from an underlying {@link InputStream}, deferring
- * the interactions until needed.
- *
- * <p>
- * This other stream is provided as needed by an {@link InputStreamProvider} so
- * that the underlying stream is not eagerly loaded.
- */
-public class LazyInputStream extends InputStream {
-
- /**
- * An interface to be implemented by clients that wish to utilize
- * {@link LazyInputStream}s. The implementation of this interface should
- * defer obtaining the desired input stream until absolutely necessary.
- */
- public static interface InputStreamProvider {
- InputStream getInputStream() throws IOException;
- }
-
- private InputStreamProvider provider;
-
- private InputStream underlying = null;
-
- // ///////////////////////////////////////////////////////
- // Constructor
- // ///////////////////////////////////////////////////////
-
- /**
- * Construct a new lazy stream based off the given provider.
- *
- * @param provider
- * the input stream provider. Must not be <code>null</code>.
- */
- public LazyInputStream(InputStreamProvider provider) {
- Ensure.ensureThatArg(provider, is(not(nullValue())));
- this.provider = provider;
- }
-
- // ///////////////////////////////////////////////////////
- // InputStream API
- // ///////////////////////////////////////////////////////
-
- @Override
- public void close() throws IOException {
- obtainUnderlyingIfRequired();
- underlying.close();
- }
-
- @Override
- public int available() throws IOException {
- obtainUnderlyingIfRequired();
- return underlying.available();
- }
-
- @Override
- public void mark(int readlimit) {
- try {
- obtainUnderlyingIfRequired();
- underlying.mark(readlimit);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public boolean markSupported() {
- try {
- obtainUnderlyingIfRequired();
- return underlying.markSupported();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public int read() throws IOException {
- obtainUnderlyingIfRequired();
- return underlying.read();
- }
-
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- obtainUnderlyingIfRequired();
- return underlying.read(b, off, len);
- }
-
- @Override
- public int read(byte[] b) throws IOException {
- obtainUnderlyingIfRequired();
- return underlying.read(b);
- }
-
- @Override
- public long skip(long n) throws IOException {
- obtainUnderlyingIfRequired();
- return underlying.skip(n);
- }
-
- @Override
- public void reset() throws IOException {
- obtainUnderlyingIfRequired();
- underlying.reset();
- }
-
- // ///////////////////////////////////////////////////////
- // helpers
- // ///////////////////////////////////////////////////////
-
- private void obtainUnderlyingIfRequired() throws IOException {
- if (underlying == null) {
- underlying = provider.getInputStream();
- }
- }
-
- // ///////////////////////////////////////////////////////
- // equals, hashCode
- // ///////////////////////////////////////////////////////
-
- @Override
- public boolean equals(Object obj) {
- try {
- obtainUnderlyingIfRequired();
- return underlying.equals(obj);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public int hashCode() {
- try {
- obtainUnderlyingIfRequired();
- return underlying.hashCode();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- // ///////////////////////////////////////////////////////
- // toString
- // ///////////////////////////////////////////////////////
-
- public String toString() {
- try {
- obtainUnderlyingIfRequired();
- return underlying.toString();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
-}
+
+/**
+ * An input stream that reads from an underlying {@link InputStream}, deferring the interactions until needed.
+ *
+ * <p>
+ * This other stream is provided as needed by an {@link InputStreamProvider} so that the underlying stream is not
+ * eagerly loaded.
+ */
+public class LazyInputStream extends InputStream {
+
+ /**
+ * An interface to be implemented by clients that wish to utilize {@link LazyInputStream}s. The implementation of
+ * this interface should defer obtaining the desired input stream until absolutely necessary.
+ */
+ public static interface InputStreamProvider {
+ InputStream getInputStream() throws IOException;
+ }
+
+ private final InputStreamProvider provider;
+
+ private InputStream underlying = null;
+
+ // ///////////////////////////////////////////////////////
+ // Constructor
+ // ///////////////////////////////////////////////////////
+
+ /**
+ * Construct a new lazy stream based off the given provider.
+ *
+ * @param provider
+ * the input stream provider. Must not be <code>null</code>.
+ */
+ public LazyInputStream(final InputStreamProvider provider) {
+ Ensure.ensureThatArg(provider, is(not(nullValue())));
+ this.provider = provider;
+ }
+
+ // ///////////////////////////////////////////////////////
+ // InputStream API
+ // ///////////////////////////////////////////////////////
+
+ @Override
+ public void close() throws IOException {
+ obtainUnderlyingIfRequired();
+ underlying.close();
+ }
+
+ @Override
+ public int available() throws IOException {
+ obtainUnderlyingIfRequired();
+ return underlying.available();
+ }
+
+ @Override
+ public void mark(final int readlimit) {
+ try {
+ obtainUnderlyingIfRequired();
+ underlying.mark(readlimit);
+ } catch (final IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public boolean markSupported() {
+ try {
+ obtainUnderlyingIfRequired();
+ return underlying.markSupported();
+ } catch (final IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public int read() throws IOException {
+ obtainUnderlyingIfRequired();
+ return underlying.read();
+ }
+
+ @Override
+ public int read(final byte[] b, final int off, final int len) throws IOException {
+ obtainUnderlyingIfRequired();
+ return underlying.read(b, off, len);
+ }
+
+ @Override
+ public int read(final byte[] b) throws IOException {
+ obtainUnderlyingIfRequired();
+ return underlying.read(b);
+ }
+
+ @Override
+ public long skip(final long n) throws IOException {
+ obtainUnderlyingIfRequired();
+ return underlying.skip(n);
+ }
+
+ @Override
+ public void reset() throws IOException {
+ obtainUnderlyingIfRequired();
+ underlying.reset();
+ }
+
+ // ///////////////////////////////////////////////////////
+ // helpers
+ // ///////////////////////////////////////////////////////
+
+ private void obtainUnderlyingIfRequired() throws IOException {
+ if (underlying == null) {
+ underlying = provider.getInputStream();
+ }
+ }
+
+ // ///////////////////////////////////////////////////////
+ // equals, hashCode
+ // ///////////////////////////////////////////////////////
+
+ @Override
+ public boolean equals(final Object obj) {
+ try {
+ obtainUnderlyingIfRequired();
+ return underlying.equals(obj);
+ } catch (final IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ try {
+ obtainUnderlyingIfRequired();
+ return underlying.hashCode();
+ } catch (final IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ // ///////////////////////////////////////////////////////
+ // toString
+ // ///////////////////////////////////////////////////////
+
+ @Override
+ public String toString() {
+ try {
+ obtainUnderlyingIfRequired();
+ return underlying.toString();
+ } catch (final IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/ArrayUtil.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/ArrayUtil.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/ArrayUtil.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/ArrayUtil.java Mon Apr 25 09:19:29 2011
@@ -17,20 +17,18 @@
* under the License.
*/
-
-package org.apache.isis.core.commons.lang;
+package org.apache.isis.core.commons.lang;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.apache.isis.core.commons.exceptions.IsisException;
-
-
-
-public final class ArrayUtil {
-
- private ArrayUtil() {}
+
+public final class ArrayUtil {
+
+ private ArrayUtil() {
+ }
public static Object[] getObjectAsObjectArray(final Object option) {
final Class<?> arrayType = option.getClass().getComponentType();
@@ -44,8 +42,7 @@ public final class ArrayUtil {
}
}
- private static Object[] convertPrimitiveToObjectArray(
- final Class<?> arrayType, final Object originalArray) {
+ private static Object[] convertPrimitiveToObjectArray(final Class<?> arrayType, final Object originalArray) {
Object[] convertedArray;
try {
final Class<?> wrapperClass = WrapperUtils.wrap(arrayType);
@@ -69,8 +66,6 @@ public final class ArrayUtil {
throw new IsisException(e);
}
return convertedArray;
- }
-
-
-}
-
+ }
+
+}
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/ArrayUtils.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/ArrayUtils.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/ArrayUtils.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/ArrayUtils.java Mon Apr 25 09:19:29 2011
@@ -17,9 +17,8 @@
* under the License.
*/
+package org.apache.isis.core.commons.lang;
-package org.apache.isis.core.commons.lang;
-
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
@@ -27,108 +26,105 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
-
-
-public final class ArrayUtils {
-
- private ArrayUtils() {}
-
- public static Object[] convertCharToCharacterArray(final Object originalArray) {
- final char[] original = (char[]) originalArray;
- final int len = original.length;
- final Character[] converted = new Character[len];
- for (int i = 0; i < converted.length; i++) {
- converted[i] = Character.valueOf(original[i]);
- }
- return converted;
- }
-
- public static <T> T[] combine(final T[]... arrays) {
- final List<T> combinedList = new ArrayList<T>();
- for (final T[] array : arrays) {
- for (final T t : array) {
- combinedList.add(t);
- }
- }
- return combinedList.toArray(arrays[0]); // using 1st element of arrays to specify the type
- }
-
- /**
- * Creates a mutable copy of the provided array.
- */
- public static <T> List<T> asList(final T[] items) {
- final List<T> list = new ArrayList<T>();
- for (final T item : items) {
- list.add(item);
- }
- return list;
- }
-
- /**
- * Creates a mutable copy of the provided array, eliminating duplicates.
- *
- * <p>
- * The order of the items will be preserved.
- */
- public static <T> Set<T> asOrderedSet(final T[] items) {
- final LinkedHashSet<T> list = new LinkedHashSet<T>();
- if (items != null) {
- for (final T item : items) {
- list.add(item);
- }
- }
- return list;
- }
-
- /**
- * Creates a mutable list of the provided array, also appending the additional element(s).
- */
- public static <T> List<T> concat(T[] elements, T... elementsToAppend) {
- List<T> result = new ArrayList<T>();
- for(T element: elements) {
- result.add(element);
- }
- for(T element: elementsToAppend) {
- if (element != null) {
- result.add(element);
- }
- }
- return result;
- }
-
- public static String[] append(String[] args, String... moreArgs) {
- ArrayList<String> argList = new ArrayList<String>();
- argList.addAll(Arrays.asList(args));
- argList.addAll(Arrays.asList(moreArgs));
- return argList.toArray(new String[]{});
- }
-
- /**
- * Creates a mutable list of the provided array, also appending the additional element(s).
- */
- public static <T> List<T> concat(T[] elements, List<T> elementsToAppend) {
- List<T> result = new ArrayList<T>();
- for(T element: elements) {
- result.add(element);
- }
- for(T element: elementsToAppend) {
- if (element != null) {
- result.add(element);
- }
- }
- return result;
- }
-
- @SuppressWarnings("unchecked")
- public static <D,S> D[] copy(S[] source, Class<D> cls) {
- if (source == null) {
- throw new IllegalArgumentException("Source array cannot be null");
- }
- D[] destination = (D[]) Array.newInstance(cls, source.length);
- System.arraycopy(source, 0, destination, 0, source.length);
- return destination;
- }
-
-
-}
-
+public final class ArrayUtils {
+
+ private ArrayUtils() {
+ }
+
+ public static Object[] convertCharToCharacterArray(final Object originalArray) {
+ final char[] original = (char[]) originalArray;
+ final int len = original.length;
+ final Character[] converted = new Character[len];
+ for (int i = 0; i < converted.length; i++) {
+ converted[i] = Character.valueOf(original[i]);
+ }
+ return converted;
+ }
+
+ public static <T> T[] combine(final T[]... arrays) {
+ final List<T> combinedList = new ArrayList<T>();
+ for (final T[] array : arrays) {
+ for (final T t : array) {
+ combinedList.add(t);
+ }
+ }
+ return combinedList.toArray(arrays[0]); // using 1st element of arrays to specify the type
+ }
+
+ /**
+ * Creates a mutable copy of the provided array.
+ */
+ public static <T> List<T> asList(final T[] items) {
+ final List<T> list = new ArrayList<T>();
+ for (final T item : items) {
+ list.add(item);
+ }
+ return list;
+ }
+
+ /**
+ * Creates a mutable copy of the provided array, eliminating duplicates.
+ *
+ * <p>
+ * The order of the items will be preserved.
+ */
+ public static <T> Set<T> asOrderedSet(final T[] items) {
+ final LinkedHashSet<T> list = new LinkedHashSet<T>();
+ if (items != null) {
+ for (final T item : items) {
+ list.add(item);
+ }
+ }
+ return list;
+ }
+
+ /**
+ * Creates a mutable list of the provided array, also appending the additional element(s).
+ */
+ public static <T> List<T> concat(final T[] elements, final T... elementsToAppend) {
+ final List<T> result = new ArrayList<T>();
+ for (final T element : elements) {
+ result.add(element);
+ }
+ for (final T element : elementsToAppend) {
+ if (element != null) {
+ result.add(element);
+ }
+ }
+ return result;
+ }
+
+ public static String[] append(final String[] args, final String... moreArgs) {
+ final ArrayList<String> argList = new ArrayList<String>();
+ argList.addAll(Arrays.asList(args));
+ argList.addAll(Arrays.asList(moreArgs));
+ return argList.toArray(new String[] {});
+ }
+
+ /**
+ * Creates a mutable list of the provided array, also appending the additional element(s).
+ */
+ public static <T> List<T> concat(final T[] elements, final List<T> elementsToAppend) {
+ final List<T> result = new ArrayList<T>();
+ for (final T element : elements) {
+ result.add(element);
+ }
+ for (final T element : elementsToAppend) {
+ if (element != null) {
+ result.add(element);
+ }
+ }
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <D, S> D[] copy(final S[] source, final Class<D> cls) {
+ if (source == null) {
+ throw new IllegalArgumentException("Source array cannot be null");
+ }
+ final D[] destination = (D[]) Array.newInstance(cls, source.length);
+ System.arraycopy(source, 0, destination, 0, source.length);
+ return destination;
+ }
+
+}
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/CastUtils.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/CastUtils.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/CastUtils.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/CastUtils.java Mon Apr 25 09:19:29 2011
@@ -17,77 +17,77 @@
* under the License.
*/
+package org.apache.isis.core.commons.lang;
-package org.apache.isis.core.commons.lang;
-
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.SortedSet;
-import java.util.Vector;
-
-
-/**
- * Helpers to co-erce existing (Java 1.1 code) into type-safe generics without having to suppress compiler
- * warnings all over the place.
- *
- */
-public final class CastUtils {
-
- private CastUtils() {}
-
- @SuppressWarnings("unchecked")
- public static <T> T cast(final Object obj) {
- return (T) obj;
- }
-
- @SuppressWarnings("unchecked")
- public static <T> Enumeration<T> enumerationOver(final Object obj, final Class<T> castTo) {
- return (Enumeration<T>) obj;
- }
-
- @SuppressWarnings("unchecked")
- public static <T> Iterator<T> iteratorOver(final Object obj, final Class<T> castTo) {
- return (Iterator<T>) obj;
- }
-
- @SuppressWarnings("unchecked")
- public static <T> Collection<T> collectionOf(final Object obj, final Class<T> castTo) {
- return (Collection<T>) obj;
- }
-
- @SuppressWarnings("unchecked")
- public static <T> List<T> listOf(final Object obj, final Class<T> castTo) {
- return (List<T>) obj;
- }
-
- @SuppressWarnings("unchecked")
- public static <T> Vector<T> vectorOf(final Object obj, final Class<T> castTo) {
- return (Vector<T>) obj;
- }
-
- @SuppressWarnings("unchecked")
- public static <T> Set<T> setOf(final Object obj, final Class<T> castTo) {
- return (Set<T>) obj;
- }
-
- @SuppressWarnings("unchecked")
- public static <T> SortedSet<T> sortedSetOf(final Object obj, final Class<T> castTo) {
- return (SortedSet<T>) obj;
- }
-
- @SuppressWarnings("unchecked")
- public static <K, V> Map<K, V> mapOf(final Object obj, final Class<K> keyCastTo, final Class<V> valueCastTo) {
- return (Map<K, V>) obj;
- }
-
- @SuppressWarnings("unchecked")
- public static <K, V> SortedMap<K, V> sortedMapOf(final Object obj, final Class<K> keyCastTo, final Class<V> valueCastTo) {
- return (SortedMap<K, V>) obj;
- }
-
-}
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.SortedSet;
+import java.util.Vector;
+
+/**
+ * Helpers to co-erce existing (Java 1.1 code) into type-safe generics without having to suppress compiler warnings all
+ * over the place.
+ *
+ */
+public final class CastUtils {
+
+ private CastUtils() {
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> T cast(final Object obj) {
+ return (T) obj;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> Enumeration<T> enumerationOver(final Object obj, final Class<T> castTo) {
+ return (Enumeration<T>) obj;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> Iterator<T> iteratorOver(final Object obj, final Class<T> castTo) {
+ return (Iterator<T>) obj;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> Collection<T> collectionOf(final Object obj, final Class<T> castTo) {
+ return (Collection<T>) obj;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> List<T> listOf(final Object obj, final Class<T> castTo) {
+ return (List<T>) obj;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> Vector<T> vectorOf(final Object obj, final Class<T> castTo) {
+ return (Vector<T>) obj;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> Set<T> setOf(final Object obj, final Class<T> castTo) {
+ return (Set<T>) obj;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> SortedSet<T> sortedSetOf(final Object obj, final Class<T> castTo) {
+ return (SortedSet<T>) obj;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <K, V> Map<K, V> mapOf(final Object obj, final Class<K> keyCastTo, final Class<V> valueCastTo) {
+ return (Map<K, V>) obj;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <K, V> SortedMap<K, V> sortedMapOf(final Object obj, final Class<K> keyCastTo,
+ final Class<V> valueCastTo) {
+ return (SortedMap<K, V>) obj;
+ }
+
+}
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/ClassUtil.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/ClassUtil.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/ClassUtil.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/ClassUtil.java Mon Apr 25 09:19:29 2011
@@ -17,43 +17,43 @@
* under the License.
*/
-
-package org.apache.isis.core.commons.lang;
+package org.apache.isis.core.commons.lang;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.apache.isis.core.commons.exceptions.IsisException;
-
-
-
-public final class ClassUtil {
-
- private ClassUtil() {}
- public static Object newInstance(final Class<?> type, final Class<?> constructorParamType, Object constructorArg) {
- return ClassUtil.newInstance(type, new Class[]{constructorParamType}, new Object[]{constructorArg});
+public final class ClassUtil {
+
+ private ClassUtil() {
+ }
+
+ public static Object newInstance(final Class<?> type, final Class<?> constructorParamType,
+ final Object constructorArg) {
+ return ClassUtil.newInstance(type, new Class[] { constructorParamType }, new Object[] { constructorArg });
}
/**
- * Tries to instantiate using a constructor accepting the supplied arguments; if no such
- * constructor then falls back to trying the no-arg constructor.
+ * Tries to instantiate using a constructor accepting the supplied arguments; if no such constructor then falls back
+ * to trying the no-arg constructor.
*/
- public static Object newInstance(final Class<?> type, final Class<?>[] constructorParamTypes, Object[] constructorArgs) {
+ public static Object newInstance(final Class<?> type, final Class<?>[] constructorParamTypes,
+ final Object[] constructorArgs) {
try {
Constructor<?> constructor;
try {
constructor = type.getConstructor(constructorParamTypes);
return constructor.newInstance(constructorArgs);
- } catch (NoSuchMethodException ex) {
+ } catch (final NoSuchMethodException ex) {
try {
constructor = type.getConstructor();
return constructor.newInstance();
- } catch (NoSuchMethodException e) {
+ } catch (final NoSuchMethodException e) {
throw new IsisException(e);
}
}
- } catch (SecurityException ex) {
+ } catch (final SecurityException ex) {
throw new IsisException(ex);
} catch (final IllegalArgumentException e) {
throw new IsisException(e);
@@ -64,7 +64,6 @@ public final class ClassUtil {
} catch (final InvocationTargetException e) {
throw new IsisException(e);
}
- }
-
-}
-
+ }
+
+}
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/HashCodeUtils.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/HashCodeUtils.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/HashCodeUtils.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/HashCodeUtils.java Mon Apr 25 09:19:29 2011
@@ -17,116 +17,114 @@
* under the License.
*/
+package org.apache.isis.core.commons.lang;
-package org.apache.isis.core.commons.lang;
-
-import java.lang.reflect.Array;
-
-
-/**
- * Collected methods which allow easy implementation of <code>hashCode</code>, based on Josh Bloch's Effective
- * Java.
- *
- * <p>
- * Example use case:
- *
- * <pre>
- * public int hashCode() {
- * int result = HashCodeUtil.SEED;
- * //collect the contributions of various fields
- * result = HashCodeUtil.hash(result, fPrimitive);
- * result = HashCodeUtil.hash(result, fObject);
- * result = HashCodeUtil.hash(result, fArray);
- * return result;
- * }
- * </pre>
- *
- * @see http://www.javapractices.com/Topic28.cjp
- */
-public final class HashCodeUtils {
-
- private HashCodeUtils() {}
-
- /**
- * An initial value for a <code>hashCode</code>, to which is added contributions from fields. Using a
- * non-zero value decreases collisons of <code>hashCode</code> values.
- */
- public static final int SEED = 23;
-
- /**
- * booleans.
- */
- public static int hash(final int aSeed, final boolean aBoolean) {
- return firstTerm(aSeed) + (aBoolean ? 1 : 0);
- }
-
- /**
- * chars.
- */
- public static int hash(final int aSeed, final char aChar) {
- return firstTerm(aSeed) + aChar;
- }
-
- /**
- * ints.
- *
- * <p>
- * Note that byte and short are handled by this method, through implicit conversion.
- */
- public static int hash(final int aSeed, final int aInt) {
- return firstTerm(aSeed) + aInt;
- }
-
- /**
- * longs.
- */
- public static int hash(final int aSeed, final long aLong) {
- return firstTerm(aSeed) + (int) (aLong ^ (aLong >>> 32));
- }
-
- /**
- * floats.
- */
- public static int hash(final int aSeed, final float aFloat) {
- return hash(aSeed, Float.floatToIntBits(aFloat));
- }
-
- /**
- * doubles.
- */
- public static int hash(final int aSeed, final double aDouble) {
- return hash(aSeed, Double.doubleToLongBits(aDouble));
- }
-
- /**
- * <code>aObject</code> is a possibly-null object field, and possibly an array.
- *
- * If <code>aObject</code> is an array, then each element may be a primitive or a possibly-null object.
- */
- public static int hash(final int aSeed, final Object aObject) {
- int result = aSeed;
- if (aObject == null) {
- result = hash(result, 0);
- } else if (!isArray(aObject)) {
- result = hash(result, aObject.hashCode());
- } else {
- final int length = Array.getLength(aObject);
- for (int idx = 0; idx < length; ++idx) {
- final Object item = Array.get(aObject, idx);
- // recursive call!
- result = hash(result, item);
- }
- }
- return result;
- }
-
- private static final int ODD_PRIME_NUMBER = 37;
-
- private static int firstTerm(final int aSeed) {
- return ODD_PRIME_NUMBER * aSeed;
- }
-
- private static boolean isArray(final Object aObject) {
- return aObject.getClass().isArray();
- }
-}
+import java.lang.reflect.Array;
+
+/**
+ * Collected methods which allow easy implementation of <code>hashCode</code>, based on Josh Bloch's Effective Java.
+ *
+ * <p>
+ * Example use case:
+ *
+ * <pre>
+ * public int hashCode() {
+ * int result = HashCodeUtil.SEED;
+ * // collect the contributions of various fields
+ * result = HashCodeUtil.hash(result, fPrimitive);
+ * result = HashCodeUtil.hash(result, fObject);
+ * result = HashCodeUtil.hash(result, fArray);
+ * return result;
+ * }
+ * </pre>
+ *
+ * @see http://www.javapractices.com/Topic28.cjp
+ */
+public final class HashCodeUtils {
+
+ private HashCodeUtils() {
+ }
+
+ /**
+ * An initial value for a <code>hashCode</code>, to which is added contributions from fields. Using a non-zero value
+ * decreases collisons of <code>hashCode</code> values.
+ */
+ public static final int SEED = 23;
+
+ /**
+ * booleans.
+ */
+ public static int hash(final int aSeed, final boolean aBoolean) {
+ return firstTerm(aSeed) + (aBoolean ? 1 : 0);
+ }
+
+ /**
+ * chars.
+ */
+ public static int hash(final int aSeed, final char aChar) {
+ return firstTerm(aSeed) + aChar;
+ }
+
+ /**
+ * ints.
+ *
+ * <p>
+ * Note that byte and short are handled by this method, through implicit conversion.
+ */
+ public static int hash(final int aSeed, final int aInt) {
+ return firstTerm(aSeed) + aInt;
+ }
+
+ /**
+ * longs.
+ */
+ public static int hash(final int aSeed, final long aLong) {
+ return firstTerm(aSeed) + (int) (aLong ^ (aLong >>> 32));
+ }
+
+ /**
+ * floats.
+ */
+ public static int hash(final int aSeed, final float aFloat) {
+ return hash(aSeed, Float.floatToIntBits(aFloat));
+ }
+
+ /**
+ * doubles.
+ */
+ public static int hash(final int aSeed, final double aDouble) {
+ return hash(aSeed, Double.doubleToLongBits(aDouble));
+ }
+
+ /**
+ * <code>aObject</code> is a possibly-null object field, and possibly an array.
+ *
+ * If <code>aObject</code> is an array, then each element may be a primitive or a possibly-null object.
+ */
+ public static int hash(final int aSeed, final Object aObject) {
+ int result = aSeed;
+ if (aObject == null) {
+ result = hash(result, 0);
+ } else if (!isArray(aObject)) {
+ result = hash(result, aObject.hashCode());
+ } else {
+ final int length = Array.getLength(aObject);
+ for (int idx = 0; idx < length; ++idx) {
+ final Object item = Array.get(aObject, idx);
+ // recursive call!
+ result = hash(result, item);
+ }
+ }
+ return result;
+ }
+
+ private static final int ODD_PRIME_NUMBER = 37;
+
+ private static int firstTerm(final int aSeed) {
+ return ODD_PRIME_NUMBER * aSeed;
+ }
+
+ private static boolean isArray(final Object aObject) {
+ return aObject.getClass().isArray();
+ }
+}
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/IoUtils.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/IoUtils.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/IoUtils.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/IoUtils.java Mon Apr 25 09:19:29 2011
@@ -17,70 +17,68 @@
* under the License.
*/
+package org.apache.isis.core.commons.lang;
-package org.apache.isis.core.commons.lang;
-
import java.io.ByteArrayInputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
-
-
-public final class IoUtils {
-
- private static final int DEFAULT_BUFFER_SIZE = 1024;
-
- private IoUtils() {}
-
- /**
- * Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>.
- * <p>
- * This method buffers the input internally, so there is no need to use a <code>BufferedInputStream</code>.
- *
- * @param input
- * the <code>InputStream</code> to read from
- * @param output
- * the <code>OutputStream</code> to write to
- * @return the number of bytes copied
- * @throws IllegalArgumentException
- * if the input or output is null
- * @throws IOException
- * if an I/O error occurs
- * @since Commons IO 1.1
- */
- public static int copy(final InputStream input, final OutputStream output) throws IOException {
- if (input == null) {
- throw new IllegalArgumentException("InputStream cannot be null");
- }
- if (output == null) {
- throw new IllegalArgumentException("OutputStream cannot be null");
- }
- final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
- int count = 0;
- int n = 0;
- while (-1 != (n = input.read(buffer))) {
- output.write(buffer, 0, n);
- count += n;
- }
- return count;
- }
-
- public static InputStream asUtf8ByteStream(String string) throws UnsupportedEncodingException {
- byte[] data = string.getBytes("utf-8");
- InputStream in = new ByteArrayInputStream(data);
+
+public final class IoUtils {
+
+ private static final int DEFAULT_BUFFER_SIZE = 1024;
+
+ private IoUtils() {
+ }
+
+ /**
+ * Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>.
+ * <p>
+ * This method buffers the input internally, so there is no need to use a <code>BufferedInputStream</code>.
+ *
+ * @param input
+ * the <code>InputStream</code> to read from
+ * @param output
+ * the <code>OutputStream</code> to write to
+ * @return the number of bytes copied
+ * @throws IllegalArgumentException
+ * if the input or output is null
+ * @throws IOException
+ * if an I/O error occurs
+ * @since Commons IO 1.1
+ */
+ public static int copy(final InputStream input, final OutputStream output) throws IOException {
+ if (input == null) {
+ throw new IllegalArgumentException("InputStream cannot be null");
+ }
+ if (output == null) {
+ throw new IllegalArgumentException("OutputStream cannot be null");
+ }
+ final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
+ int count = 0;
+ int n = 0;
+ while (-1 != (n = input.read(buffer))) {
+ output.write(buffer, 0, n);
+ count += n;
+ }
+ return count;
+ }
+
+ public static InputStream asUtf8ByteStream(final String string) throws UnsupportedEncodingException {
+ final byte[] data = string.getBytes("utf-8");
+ final InputStream in = new ByteArrayInputStream(data);
return in;
- }
+ }
- public static void closeSafely(Closeable reader) {
+ public static void closeSafely(final Closeable reader) {
if (reader != null) {
try {
reader.close();
- } catch (final IOException ignore) {}
+ } catch (final IOException ignore) {
+ }
}
}
-
-}
-
+}
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/JavaClassUtils.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/JavaClassUtils.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/JavaClassUtils.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/JavaClassUtils.java Mon Apr 25 09:19:29 2011
@@ -17,92 +17,87 @@
* under the License.
*/
+package org.apache.isis.core.commons.lang;
-package org.apache.isis.core.commons.lang;
-
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
-
-public final class JavaClassUtils {
-
- private static final String JAVA_CLASS_PREFIX = "java.";
-
- private static Map<String, Class<?>> builtInClasses = new HashMap<String, Class<?>>();
-
- static {
- put(void.class);
- put(boolean.class);
- put(char.class);
- put(byte.class);
- put(short.class);
- put(int.class);
- put(long.class);
- put(float.class);
- put(double.class);
- }
-
-
- private static void put(Class<?> cls) {
- builtInClasses.put(cls.getName(), cls);
- }
-
-
- private JavaClassUtils() {}
-
-
- public static Class<?> getBuiltIn(String name) {
- return builtInClasses.get(name);
- }
-
- public static String getSuperclass(final Class<?> type) {
- final Class<?> superType = type.getSuperclass();
-
- if (superType == null) {
- return null;
- }
- return superType.getName();
- }
-
- public static boolean isAbstract(final Class<?> type) {
- return Modifier.isAbstract(type.getModifiers());
- }
-
- public static boolean isFinal(final Class<?> type) {
- return Modifier.isFinal(type.getModifiers());
- }
-
- public static boolean isPublic(final Class<?> type) {
- return Modifier.isPublic(type.getModifiers());
- }
-
- public static boolean isJavaClass(final Class<?> type) {
- return type.getName().startsWith(JAVA_CLASS_PREFIX) || type.getName().startsWith("sun.");
- }
-
- public static boolean isPublic(final Method method) {
- return Modifier.isPublic(method.getModifiers());
- }
-
- public static List<Class<?>> toClasses(List<Object> objectList) {
- List<Class<?>> classList = new ArrayList<Class<?>>();
- for (Object service : objectList) {
- classList.add(service.getClass());
- }
- return classList;
+
+public final class JavaClassUtils {
+
+ private static final String JAVA_CLASS_PREFIX = "java.";
+
+ private static Map<String, Class<?>> builtInClasses = new HashMap<String, Class<?>>();
+
+ static {
+ put(void.class);
+ put(boolean.class);
+ put(char.class);
+ put(byte.class);
+ put(short.class);
+ put(int.class);
+ put(long.class);
+ put(float.class);
+ put(double.class);
}
+ private static void put(final Class<?> cls) {
+ builtInClasses.put(cls.getName(), cls);
+ }
+
+ private JavaClassUtils() {
+ }
+
+ public static Class<?> getBuiltIn(final String name) {
+ return builtInClasses.get(name);
+ }
+
+ public static String getSuperclass(final Class<?> type) {
+ final Class<?> superType = type.getSuperclass();
+
+ if (superType == null) {
+ return null;
+ }
+ return superType.getName();
+ }
+
+ public static boolean isAbstract(final Class<?> type) {
+ return Modifier.isAbstract(type.getModifiers());
+ }
+
+ public static boolean isFinal(final Class<?> type) {
+ return Modifier.isFinal(type.getModifiers());
+ }
+
+ public static boolean isPublic(final Class<?> type) {
+ return Modifier.isPublic(type.getModifiers());
+ }
+
+ public static boolean isJavaClass(final Class<?> type) {
+ return type.getName().startsWith(JAVA_CLASS_PREFIX) || type.getName().startsWith("sun.");
+ }
+
+ public static boolean isPublic(final Method method) {
+ return Modifier.isPublic(method.getModifiers());
+ }
+
+ public static List<Class<?>> toClasses(final List<Object> objectList) {
+ final List<Class<?>> classList = new ArrayList<Class<?>>();
+ for (final Object service : objectList) {
+ classList.add(service.getClass());
+ }
+ return classList;
+ }
/**
- * Returns the supplied Class so long as it implements (or is a subclass of) the
- * required class, and also has either a constructor accepting the specified param type,
- * or has a no-arg constructor.
+ * Returns the supplied Class so long as it implements (or is a subclass of) the required class, and also has either
+ * a constructor accepting the specified param type, or has a no-arg constructor.
*/
- public static Class<?> implementingClassOrNull(final Class<?> classCandidate, final Class<?> requiredClass, final Class<?> constructorParamType) {
+ public static Class<?> implementingClassOrNull(final Class<?> classCandidate, final Class<?> requiredClass,
+ final Class<?> constructorParamType) {
if (classCandidate == null) {
return null;
}
@@ -110,11 +105,11 @@ public final class JavaClassUtils {
return null;
}
try {
- classCandidate.getConstructor(new Class[] {constructorParamType});
+ classCandidate.getConstructor(new Class[] { constructorParamType });
} catch (final NoSuchMethodException ex) {
try {
- classCandidate.getConstructor(new Class[]{});
- } catch (NoSuchMethodException e) {
+ classCandidate.getConstructor(new Class[] {});
+ } catch (final NoSuchMethodException e) {
return null;
}
} catch (final SecurityException e) {
@@ -127,8 +122,8 @@ public final class JavaClassUtils {
return classCandidate;
}
-
- public static Class<?> implementingClassOrNull(final String classCandidateName, final Class<?> requiredClass, final Class<?> constructorParamType) {
+ public static Class<?> implementingClassOrNull(final String classCandidateName, final Class<?> requiredClass,
+ final Class<?> constructorParamType) {
if (classCandidateName == null) {
return null;
}
@@ -141,22 +136,17 @@ public final class JavaClassUtils {
}
}
-
public static boolean directlyImplements(final Class<?> cls, final Class<?> interfaceType) {
- for(Class<?> directlyImplementedInterface: cls.getInterfaces()) {
- if (directlyImplementedInterface == interfaceType) {
- return true;
- }
- }
- return false;
+ for (final Class<?> directlyImplementedInterface : cls.getInterfaces()) {
+ if (directlyImplementedInterface == interfaceType) {
+ return true;
+ }
+ }
+ return false;
}
-
public static boolean isStatic(final Method method) {
return Modifier.isStatic(method.getModifiers());
}
-
-
-
-
-}
+
+}
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/ListUtils.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/ListUtils.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/ListUtils.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/ListUtils.java Mon Apr 25 09:19:29 2011
@@ -17,135 +17,127 @@
* under the License.
*/
+package org.apache.isis.core.commons.lang;
-package org.apache.isis.core.commons.lang;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Iterator;
import java.util.List;
-
-
-public final class ListUtils {
- private static final String DEFAULT_DELIMITER = ",";
-
- private ListUtils() {}
-
- public static <T> List<T> combine(final List<T> list, final List<T> list2) {
- final List<T> combinedList = new ArrayList<T>();
- combinedList.addAll(list);
- combinedList.addAll(list2);
- return combinedList;
- }
-
- /**
- * Returns list1 with everything in list2, ignoring duplicates.
- */
- public static <T> List<T> merge(final List<T> list1, final List<T> list2) {
- for (final Iterator<T> iter = list2.iterator(); iter.hasNext();) {
- final T obj = iter.next();
- if (!(list1.contains(obj))) {
- list1.add(obj);
- }
- }
- return list1;
- }
-
-
- public static List<String> merge(final String[] array1, final String[] array2) {
- final List<String> prefixes = new ArrayList<String>();
- addNoDuplicates(array1, prefixes);
- addNoDuplicates(array2, prefixes);
- return prefixes;
- }
-
- private static void addNoDuplicates(final String[] array, final List<String> list) {
- for (int i = 0; i < array.length; i++) {
- if (!list.contains(array[i])) {
- list.add(array[i]);
- }
- }
- }
-
- public
- static List<Object> asList(final Object[] objectArray) {
- final List<Object> list = new ArrayList<Object>();
- for (int i = 0; i < objectArray.length; i++) {
- if (Collection.class.isAssignableFrom(objectArray[i].getClass())) {
+
+public final class ListUtils {
+ private static final String DEFAULT_DELIMITER = ",";
+
+ private ListUtils() {
+ }
+
+ public static <T> List<T> combine(final List<T> list, final List<T> list2) {
+ final List<T> combinedList = new ArrayList<T>();
+ combinedList.addAll(list);
+ combinedList.addAll(list2);
+ return combinedList;
+ }
+
+ /**
+ * Returns list1 with everything in list2, ignoring duplicates.
+ */
+ public static <T> List<T> merge(final List<T> list1, final List<T> list2) {
+ for (final T obj : list2) {
+ if (!(list1.contains(obj))) {
+ list1.add(obj);
+ }
+ }
+ return list1;
+ }
+
+ public static List<String> merge(final String[] array1, final String[] array2) {
+ final List<String> prefixes = new ArrayList<String>();
+ addNoDuplicates(array1, prefixes);
+ addNoDuplicates(array2, prefixes);
+ return prefixes;
+ }
+
+ private static void addNoDuplicates(final String[] array, final List<String> list) {
+ for (int i = 0; i < array.length; i++) {
+ if (!list.contains(array[i])) {
+ list.add(array[i]);
+ }
+ }
+ }
+
+ public static List<Object> asList(final Object[] objectArray) {
+ final List<Object> list = new ArrayList<Object>();
+ for (final Object element : objectArray) {
+ if (Collection.class.isAssignableFrom(element.getClass())) {
@SuppressWarnings("rawtypes")
- Collection collection = (Collection) objectArray[i];
- list.addAll(asList(collection.toArray()));
- } else {
- list.add(objectArray[i]);
- }
- }
- return list;
- }
-
- /**
- * @see #listToString(List, String)
- * @see #stringToList(String)
- */
- public static String listToString(List<String> list) {
- return listToString(list, DEFAULT_DELIMITER);
- }
-
- /**
- * @see #listToString(List, String)
- * @see #stringToList(String)
- */
- public static String listToString(List<String> list, String delimiter) {
- if (list.size() == 0) {
- return null;
- }
- StringBuilder buf = new StringBuilder();
- boolean first = true;
- for(String str: list) {
- if(first) {
- first = false;
- } else {
- buf.append(delimiter);
- }
- buf.append(str);
- }
- return buf.toString();
- }
-
- /**
- * @see #stringToList(String, String)
- * @see #listToString(List)
- */
- public static List<String> stringToList(String commaSeparated) {
- return appendDelimitedStringToList(commaSeparated, new ArrayList<String>());
- }
-
- /**
- * @see #stringToList(String)
- * @see #listToString(List, String)
- */
- public static List<String> stringToList(String delimited, String delimiter) {
- return appendDelimitedStringToList(delimited, delimiter, new ArrayList<String>());
- }
-
- /**
- * @see #appendDelimitedStringToList(String, String, List)
- */
- public static List<String> appendDelimitedStringToList(
- String commaSeparated, List<String> list) {
- return appendDelimitedStringToList(commaSeparated, DEFAULT_DELIMITER, list);
- }
-
- public static List<String> appendDelimitedStringToList(
- String delimited, String delimiter, List<String> list) {
- if (delimited == null) {
- return list;
- }
- String[] optionValues = delimited.split(delimiter);
- list.addAll(Arrays.asList(optionValues));
- return list;
- }
-
-
-}
-
+ final Collection collection = (Collection) element;
+ list.addAll(asList(collection.toArray()));
+ } else {
+ list.add(element);
+ }
+ }
+ return list;
+ }
+
+ /**
+ * @see #listToString(List, String)
+ * @see #stringToList(String)
+ */
+ public static String listToString(final List<String> list) {
+ return listToString(list, DEFAULT_DELIMITER);
+ }
+
+ /**
+ * @see #listToString(List, String)
+ * @see #stringToList(String)
+ */
+ public static String listToString(final List<String> list, final String delimiter) {
+ if (list.size() == 0) {
+ return null;
+ }
+ final StringBuilder buf = new StringBuilder();
+ boolean first = true;
+ for (final String str : list) {
+ if (first) {
+ first = false;
+ } else {
+ buf.append(delimiter);
+ }
+ buf.append(str);
+ }
+ return buf.toString();
+ }
+
+ /**
+ * @see #stringToList(String, String)
+ * @see #listToString(List)
+ */
+ public static List<String> stringToList(final String commaSeparated) {
+ return appendDelimitedStringToList(commaSeparated, new ArrayList<String>());
+ }
+
+ /**
+ * @see #stringToList(String)
+ * @see #listToString(List, String)
+ */
+ public static List<String> stringToList(final String delimited, final String delimiter) {
+ return appendDelimitedStringToList(delimited, delimiter, new ArrayList<String>());
+ }
+
+ /**
+ * @see #appendDelimitedStringToList(String, String, List)
+ */
+ public static List<String> appendDelimitedStringToList(final String commaSeparated, final List<String> list) {
+ return appendDelimitedStringToList(commaSeparated, DEFAULT_DELIMITER, list);
+ }
+
+ public static List<String> appendDelimitedStringToList(final String delimited, final String delimiter,
+ final List<String> list) {
+ if (delimited == null) {
+ return list;
+ }
+ final String[] optionValues = delimited.split(delimiter);
+ list.addAll(Arrays.asList(optionValues));
+ return list;
+ }
+
+}
Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/LocaleUtils.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/LocaleUtils.java?rev=1096439&r1=1096438&r2=1096439&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/LocaleUtils.java (original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/core/commons/lang/LocaleUtils.java Mon Apr 25 09:19:29 2011
@@ -17,23 +17,22 @@
* under the License.
*/
+package org.apache.isis.core.commons.lang;
-package org.apache.isis.core.commons.lang;
-
-import java.util.Locale;
-
-public class LocaleUtils {
-
- public static Locale findLocale(final String localeStr) {
- if (localeStr != null) {
- Locale[] availableLocales = Locale.getAvailableLocales();
- for(Locale locale: availableLocales) {
- if (locale.toString().equals(localeStr)) {
- return locale;
- }
- }
- }
- return null;
- }
-
-}
+import java.util.Locale;
+
+public class LocaleUtils {
+
+ public static Locale findLocale(final String localeStr) {
+ if (localeStr != null) {
+ final Locale[] availableLocales = Locale.getAvailableLocales();
+ for (final Locale locale : availableLocales) {
+ if (locale.toString().equals(localeStr)) {
+ return locale;
+ }
+ }
+ }
+ return null;
+ }
+
+}