Author: rhauch
Date: 2008-07-11 16:33:53 -0400 (Fri, 11 Jul 2008)
New Revision: 351
Modified:
trunk/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java
trunk/dna-common/src/main/java/org/jboss/dna/common/util/ArgCheck.java
trunk/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties
trunk/dna-common/src/test/java/org/jboss/dna/common/util/ArgCheckTest.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicEmptyProperty.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicMultiValueProperty.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicSingleValueProperty.java
Log:
DNA-163 - Most, if not all, of the assertions in BasicMultiValueProperty are incorrect.
http://jira.jboss.com/jira/browse/DNA-163
The assertions were indeed correct, but they were misplaced and should instead be in the
constructors. The BasicEmptyProperty class should be used for properties that have no
values; the BasicSingleValueProperty should be used for properties that have just a single
value (which may be null); and the BasicMultiValueProperty should be used for properties
that contain 2+ values. This is done to minimize the memory footprint: if a single
Property implementation were used, it would have to support multiple values, but in
reality most properties will be properties with one a single value and therefore the extra
collection is simply wasted memory. By having different implementations for the different
situations, we're able to hold onto the values with the most efficiency. Also, since
the objects are intended to be immutable, there is no need to support changing the values.
This description was added to the JavaDoc.
This relies upon a new ArgCheck method, which was added with tests (along with several
other similar methods).
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java 2008-07-09
21:20:54 UTC (rev 350)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java 2008-07-11
20:33:53 UTC (rev 351)
@@ -58,6 +58,10 @@
// Core-related fields
public static I18n argumentMayNotBeLessThan;
public static I18n argumentMayNotBeGreaterThan;
+ public static I18n argumentMustBeGreaterThan;
+ public static I18n argumentMustBeLessThan;
+ public static I18n argumentMustBeGreaterThanOrEqualTo;
+ public static I18n argumentMustBeLessThanOrEqualTo;
public static I18n argumentMayNotBeNegative;
public static I18n argumentMayNotBePositive;
public static I18n argumentMustBeNegative;
@@ -76,6 +80,8 @@
public static I18n argumentDidNotContainObject;
public static I18n argumentDidNotContainKey;
public static I18n argumentMayNotContainNullValue;
+ public static I18n argumentMustBeOfMinimumSize;
+ public static I18n argumentMustBeOfMaximumSize;
public static I18n componentClassnameNotValid;
public static I18n componentNotConfigured;
public static I18n dateParsingFailure;
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/util/ArgCheck.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/util/ArgCheck.java 2008-07-09
21:20:54 UTC (rev 350)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/util/ArgCheck.java 2008-07-11
20:33:53 UTC (rev 351)
@@ -40,7 +40,7 @@
* @param argument The argument
* @param notLessThanValue the value that is to be used to check the value
* @param name The name of the argument
- * @throws IllegalArgumentException If argument is negative (<0)
+ * @throws IllegalArgumentException If argument greater than or equal to the supplied
vlaue
*/
public static void isNotLessThan( int argument,
int notLessThanValue,
@@ -56,17 +56,85 @@
* @param argument The argument
* @param notGreaterThanValue the value that is to be used to check the value
* @param name The name of the argument
- * @throws IllegalArgumentException If argument is negative (<0)
+ * @throws IllegalArgumentException If argument is less than or equal to the supplied
value
*/
public static void isNotGreaterThan( int argument,
int notGreaterThanValue,
String name ) {
- if (argument < notGreaterThanValue) {
+ if (argument > notGreaterThanValue) {
throw new
IllegalArgumentException(CommonI18n.argumentMayNotBeGreaterThan.text(name, argument,
notGreaterThanValue));
}
}
/**
+ * Check that the argument is greater than the supplied value
+ *
+ * @param argument The argument
+ * @param greaterThanValue the value that is to be used to check the value
+ * @param name The name of the argument
+ * @throws IllegalArgumentException If argument is not greater than the supplied
value
+ */
+ public static void isGreaterThan( int argument,
+ int greaterThanValue,
+ String name ) {
+ if (argument <= greaterThanValue) {
+ throw new
IllegalArgumentException(CommonI18n.argumentMustBeGreaterThan.text(name, argument,
greaterThanValue));
+ }
+ }
+
+ /**
+ * Check that the argument is less than the supplied value
+ *
+ * @param argument The argument
+ * @param lessThanValue the value that is to be used to check the value
+ * @param name The name of the argument
+ * @throws IllegalArgumentException If argument is not less than the supplied value
+ */
+ public static void isLessThan( int argument,
+ int lessThanValue,
+ String name ) {
+ if (argument >= lessThanValue) {
+ throw new
IllegalArgumentException(CommonI18n.argumentMustBeLessThan.text(name, argument,
lessThanValue));
+ }
+ }
+
+ /**
+ * Check that the argument is greater than or equal to the supplied value
+ *
+ * @param argument The argument
+ * @param greaterThanOrEqualToValue the value that is to be used to check the value
+ * @param name The name of the argument
+ * @throws IllegalArgumentException If argument is not greater than or equal to the
supplied value
+ */
+ public static void isGreaterThanOrEqualTo( int argument,
+ int greaterThanOrEqualToValue,
+ String name ) {
+ if (argument < greaterThanOrEqualToValue) {
+ throw new
IllegalArgumentException(CommonI18n.argumentMustBeGreaterThanOrEqualTo.text(name,
+
argument,
+
greaterThanOrEqualToValue));
+ }
+ }
+
+ /**
+ * Check that the argument is less than or equal to the supplied value
+ *
+ * @param argument The argument
+ * @param lessThanOrEqualToValue the value that is to be used to check the value
+ * @param name The name of the argument
+ * @throws IllegalArgumentException If argument is not less than or equal to the
supplied value
+ */
+ public static void isLessThanOrEqualTo( int argument,
+ int lessThanOrEqualToValue,
+ String name ) {
+ if (argument > lessThanOrEqualToValue) {
+ throw new
IllegalArgumentException(CommonI18n.argumentMustBeLessThanOrEqualTo.text(name,
+
argument,
+
lessThanOrEqualToValue));
+ }
+ }
+
+ /**
* Check that the argument is non-negative (>=0).
*
* @param argument The argument
@@ -374,8 +442,8 @@
* @param argumentName The name that will be used within the exception message for
the argument should an exception be thrown
* @param object The object to assert as the same as
<code>argument</code>.
* @param objectName The name that will be used within the exception message for
<code>object</code> should an exception be
- * thrown; if <code>null</code> and
<code>object</code> is not <code>null</code>,
<code>object.toString()</code>
- * will be used.
+ * thrown; if <code>null</code> and
<code>object</code> is not <code>null</code>,
<code>object.toString()</code> will
+ * be used.
* @throws IllegalArgumentException If the specified objects are not the same.
*/
public static <T> void isSame( final T argument,
@@ -396,8 +464,8 @@
* @param argumentName The name that will be used within the exception message for
the argument should an exception be thrown
* @param object The object to assert as not the same as
<code>argument</code>.
* @param objectName The name that will be used within the exception message for
<code>object</code> should an exception be
- * thrown; if <code>null</code> and
<code>object</code> is not <code>null</code>,
<code>object.toString()</code>
- * will be used.
+ * thrown; if <code>null</code> and
<code>object</code> is not <code>null</code>,
<code>object.toString()</code> will
+ * be used.
* @throws IllegalArgumentException If the specified objects are the same.
*/
public static <T> void isNotSame( final T argument,
@@ -418,8 +486,8 @@
* @param argumentName The name that will be used within the exception message for
the argument should an exception be thrown
* @param object The object to assert as equal to <code>argument</code>.
* @param objectName The name that will be used within the exception message for
<code>object</code> should an exception be
- * thrown; if <code>null</code> and
<code>object</code> is not <code>null</code>,
<code>object.toString()</code>
- * will be used.
+ * thrown; if <code>null</code> and
<code>object</code> is not <code>null</code>,
<code>object.toString()</code> will
+ * be used.
* @throws IllegalArgumentException If the specified objects are not equal.
*/
public static <T> void isEquals( final T argument,
@@ -440,8 +508,8 @@
* @param argumentName The name that will be used within the exception message for
the argument should an exception be thrown
* @param object The object to assert as equal to <code>argument</code>.
* @param objectName The name that will be used within the exception message for
<code>object</code> should an exception be
- * thrown; if <code>null</code> and
<code>object</code> is not <code>null</code>,
<code>object.toString()</code>
- * will be used.
+ * thrown; if <code>null</code> and
<code>object</code> is not <code>null</code>,
<code>object.toString()</code> will
+ * be used.
* @throws IllegalArgumentException If the specified objects are equals.
*/
public static <T> void isNotEquals( final T argument,
@@ -594,6 +662,126 @@
}
}
+ /**
+ * Check that the collection contains at least the supplied number of elements
+ *
+ * @param argument Collection
+ * @param minimumSize the minimum size
+ * @param name The name of the argument
+ * @throws IllegalArgumentException If collection has a size smaller than the
supplied value
+ */
+ public static void hasSizeOfAtLeast( Collection<?> argument,
+ int minimumSize,
+ String name ) {
+ isNotNull(argument, name);
+ if (argument.size() < minimumSize) {
+ throw new
IllegalArgumentException(CommonI18n.argumentMustBeOfMinimumSize.text(name,
+
Collection.class.getSimpleName(),
+
argument.size(),
+
minimumSize));
+ }
+ }
+
+ /**
+ * Check that the collection contains no more than the supplied number of elements
+ *
+ * @param argument Collection
+ * @param maximumSize the maximum size
+ * @param name The name of the argument
+ * @throws IllegalArgumentException If collection has a size smaller than the
supplied value
+ */
+ public static void hasSizeOfAtMost( Collection<?> argument,
+ int maximumSize,
+ String name ) {
+ isNotNull(argument, name);
+ if (argument.size() > maximumSize) {
+ throw new
IllegalArgumentException(CommonI18n.argumentMustBeOfMinimumSize.text(name,
+
Collection.class.getSimpleName(),
+
argument.size(),
+
maximumSize));
+ }
+ }
+
+ /**
+ * Check that the map contains at least the supplied number of entries
+ *
+ * @param argument the map
+ * @param minimumSize the minimum size
+ * @param name The name of the argument
+ * @throws IllegalArgumentException If the map has a size smaller than the supplied
value
+ */
+ public static void hasSizeOfAtLeast( Map<?, ?> argument,
+ int minimumSize,
+ String name ) {
+ isNotNull(argument, name);
+ if (argument.size() < minimumSize) {
+ throw new
IllegalArgumentException(CommonI18n.argumentMustBeOfMinimumSize.text(name,
+
Map.class.getSimpleName(),
+
argument.size(),
+
minimumSize));
+ }
+ }
+
+ /**
+ * Check that the map contains no more than the supplied number of entries
+ *
+ * @param argument the map
+ * @param maximumSize the maximum size
+ * @param name The name of the argument
+ * @throws IllegalArgumentException If the map has a size smaller than the supplied
value
+ */
+ public static void hasSizeOfAtMost( Map<?, ?> argument,
+ int maximumSize,
+ String name ) {
+ isNotNull(argument, name);
+ if (argument.size() > maximumSize) {
+ throw new
IllegalArgumentException(CommonI18n.argumentMustBeOfMinimumSize.text(name,
+
Map.class.getSimpleName(),
+
argument.size(),
+
maximumSize));
+ }
+ }
+
+ /**
+ * Check that the array contains at least the supplied number of elements
+ *
+ * @param argument the array
+ * @param minimumSize the minimum size
+ * @param name The name of the argument
+ * @throws IllegalArgumentException If the array has a size smaller than the supplied
value
+ */
+ public static void hasSizeOfAtLeast( Object[] argument,
+ int minimumSize,
+ String name ) {
+ isNotNull(argument, name);
+ if (argument.length < minimumSize) {
+ throw new
IllegalArgumentException(CommonI18n.argumentMustBeOfMinimumSize.text(name,
+
Object[].class.getSimpleName(),
+
argument.length,
+
minimumSize));
+ }
+ }
+
+ /**
+ * Check that the array contains no more than the supplied number of elements
+ *
+ * @param argument the array
+ * @param maximumSize the maximum size
+ * @param name The name of the argument
+ * @throws IllegalArgumentException If the array has a size smaller than the supplied
value
+ */
+ public static void hasSizeOfAtMost( Object[] argument,
+ int maximumSize,
+ String name ) {
+ isNotNull(argument, name);
+ if (argument.length > maximumSize) {
+ throw new
IllegalArgumentException(CommonI18n.argumentMustBeOfMinimumSize.text(name,
+
Object[].class.getSimpleName(),
+
argument.length,
+
maximumSize));
+ }
+ }
+
private ArgCheck() {
// prevent construction
}
Modified: trunk/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties
===================================================================
---
trunk/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties 2008-07-09
21:20:54 UTC (rev 350)
+++
trunk/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties 2008-07-11
20:33:53 UTC (rev 351)
@@ -39,6 +39,10 @@
# Core-related fields
argumentMayNotBeGreaterThan = The {0} argument value, {1}, may not be greater than {2}
argumentMayNotBeLessThan = The {0} argument value, {1}, may not be less than {2}
+argumentMustBeGreaterThan = The {0} argument value, {1}, must be greater than {2}
+argumentMustBeLessThan = The {0} argument value, {1}, must be less than {2}
+argumentMustBeGreaterThanOrEqualTo = The {0} argument value, {1}, must be greater than or
equal to {2}
+argumentMustBeLessThanOrEqualTo = The {0} argument value, {1}, must be less than or equal
to {2}
argumentMayNotBeNegative = The {0} argument value, {1}, may not be negative
argumentMayNotBePositive = The {0} argument value, {1}, may not be positive
argumentMustBeNegative = The {0} argument value, {1}, must be negative
@@ -57,6 +61,8 @@
argumentDidNotContainObject = "The {0} argument did not contain the expected object
{1}
argumentDidNotContainKey = "The {0} argument did not contain the expected key {1}
argumentMayNotContainNullValue = The {0} argument may not contain a null value (first
null found at position {1})
+argumentMustBeOfMinimumSize = The {0} argument is a {1} with {2} elements but must have
at least {3}
+argumentMustBeOfMaximumSize = The {0} argument is a {1} with {2} elements but must have
no more than {3}
componentClassnameNotValid = The class name {0} specified for {1} is not a valid Java
class name
componentNotConfigured = The component {0} was not configured and will not be used
dateParsingFailure = Unable to parse the date "{0}" using the standard ISO 8601
format
Modified: trunk/dna-common/src/test/java/org/jboss/dna/common/util/ArgCheckTest.java
===================================================================
--- trunk/dna-common/src/test/java/org/jboss/dna/common/util/ArgCheckTest.java 2008-07-09
21:20:54 UTC (rev 350)
+++ trunk/dna-common/src/test/java/org/jboss/dna/common/util/ArgCheckTest.java 2008-07-11
20:33:53 UTC (rev 351)
@@ -414,4 +414,185 @@
public void containsNoNullsArrayShouldThrowExceptionIfGivenArrayWithNullEntry() {
ArgCheck.containsNoNulls(new Object[] {"some", null, "thing",
null}, "test");
}
+
+ @Test( expected = IllegalArgumentException.class )
+ public void isNotLessThanShouldThrowExceptionIfValueIsLessThanSuppliedValue() {
+ ArgCheck.isNotLessThan(0, 1, "value");
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void isNotGreaterThanShouldThrowExceptionIfValueIsGreaterThanSuppliedValue()
{
+ ArgCheck.isNotGreaterThan(1, 0, "value");
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void isNotLessThanShouldThrowExceptionIfValueIsEqualToSuppliedValue() {
+ ArgCheck.isNotLessThan(1, 2, "value");
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void isNotGreaterThanShouldThrowExceptionIfValueIsEqualToSuppliedValue() {
+ ArgCheck.isNotGreaterThan(2, 1, "value");
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void isLessThanShouldThrowExceptionIfValueIsGreaterThanSuppliedValue() {
+ ArgCheck.isLessThan(1, 0, "value");
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void isGreaterThanShouldThrowExceptionIfValueIsLessThanSuppliedValue() {
+ ArgCheck.isGreaterThan(0, 1, "value");
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void isLessThanShouldThrowExceptionIfValueIsEqualToSuppliedValue() {
+ ArgCheck.isLessThan(1, 1, "value");
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void isGreaterThanShouldThrowExceptionIfValueIsEqualToSuppliedValue() {
+ ArgCheck.isGreaterThan(1, 1, "value");
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void
isLessThanOrEqualToShouldThrowExceptionIfValueIsNotLessThanOrEqualToSuppliedValue() {
+ ArgCheck.isLessThanOrEqualTo(1, 0, "value");
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void
isGreaterThanOrEqualToShouldThrowExceptionIfValueIsNotGreaterThanOrEqualToSuppliedValue()
{
+ ArgCheck.isGreaterThanOrEqualTo(0, 1, "value");
+ }
+
+ @Test
+ public void isNotLessThanShouldNotThrowExceptionIfValueIsNotLessThanSuppliedValue()
{
+ ArgCheck.isNotLessThan(1, 1, "value");
+ ArgCheck.isNotLessThan(2, 1, "value");
+ ArgCheck.isNotLessThan(100, 1, "value");
+ }
+
+ @Test
+ public void
isNotGreaterThanShouldNotThrowExceptionIfValueIsNotGreaterThanSuppliedValue() {
+ ArgCheck.isNotGreaterThan(1, 1, "value");
+ ArgCheck.isNotGreaterThan(1, 2, "value");
+ ArgCheck.isNotGreaterThan(1, 100, "value");
+ }
+
+ @Test
+ public void isLessThanShouldNotThrowExceptionIfValueIsLessThanSuppliedValue() {
+ ArgCheck.isLessThanOrEqualTo(1, 2, "value");
+ ArgCheck.isLessThanOrEqualTo(1, 100, "value");
+ }
+
+ @Test
+ public void isGreaterThanShouldNotThrowExceptionIfValueIsGreaterThanSuppliedValue()
{
+ ArgCheck.isGreaterThan(2, 1, "value");
+ ArgCheck.isGreaterThan(100, 1, "value");
+ }
+
+ @Test
+ public void
isLessThanOrEqualToShouldNotThrowExceptionIfValueIsLessThanOrEqualToSuppliedValue() {
+ ArgCheck.isLessThanOrEqualTo(1, 1, "value");
+ ArgCheck.isLessThanOrEqualTo(1, 2, "value");
+ ArgCheck.isLessThanOrEqualTo(1, 100, "value");
+ }
+
+ @Test
+ public void
isGreaterThanOrEqualToShouldNotThrowExceptionIfValueIsGreaterThanOrEqualToSuppliedValue()
{
+ ArgCheck.isGreaterThanOrEqualTo(1, 1, "value");
+ ArgCheck.isGreaterThanOrEqualTo(2, 1, "value");
+ ArgCheck.isGreaterThanOrEqualTo(100, 1, "value");
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void
hasSizeOfAtLeastShouldThrowExceptionIfCollectionSizeIsSmallerThanSuppliedValue() {
+ ArgCheck.hasSizeOfAtLeast(Collections.singletonList(" "), 2,
"value");
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void
hasSizeOfAtMostShouldThrowExceptionIfCollectionSizeIsLargerThanSuppliedValue() {
+ ArgCheck.hasSizeOfAtMost(Collections.singletonList(" "), 0,
"value");
+ }
+
+ @Test
+ public void
hasSizeOfAtLeastShouldNotThrowExceptionIfCollectionSizeIsEqualToSuppliedValue() {
+ ArgCheck.hasSizeOfAtLeast(Collections.singletonList(" "), 1,
"value");
+ }
+
+ @Test
+ public void
hasSizeOfAtMostShouldNotThrowExceptionIfCollectionSizeIsEqualToSuppliedValue() {
+ ArgCheck.hasSizeOfAtMost(Collections.singletonList(" "), 1,
"value");
+ }
+
+ @Test
+ public void
hasSizeOfAtLeastShouldNotThrowExceptionIfCollectionSizeIsGreaterThanSuppliedValue() {
+ ArgCheck.hasSizeOfAtLeast(Collections.singletonList(" "), 0,
"value");
+ }
+
+ @Test
+ public void
hasSizeOfAtMostShouldNotThrowExceptionIfCollectionSizeIsGreaterThanSuppliedValue() {
+ ArgCheck.hasSizeOfAtMost(Collections.singletonList(" "), 2,
"value");
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void hasSizeOfAtLeastShouldThrowExceptionIfMapSizeIsSmallerThanSuppliedValue()
{
+ ArgCheck.hasSizeOfAtLeast(Collections.singletonMap("key",
"value"), 2, "value");
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void hasSizeOfAtMostShouldThrowExceptionIfMapSizeIsLargerThanSuppliedValue()
{
+ ArgCheck.hasSizeOfAtMost(Collections.singletonMap("key",
"value"), 0, "value");
+ }
+
+ @Test
+ public void hasSizeOfAtLeastShouldNotThrowExceptionIfMapSizeIsEqualToSuppliedValue()
{
+ ArgCheck.hasSizeOfAtLeast(Collections.singletonMap("key",
"value"), 1, "value");
+ }
+
+ @Test
+ public void hasSizeOfAtMostShouldNotThrowExceptionIfMapSizeIsEqualToSuppliedValue()
{
+ ArgCheck.hasSizeOfAtMost(Collections.singletonMap("key",
"value"), 1, "value");
+ }
+
+ @Test
+ public void
hasSizeOfAtLeastShouldNotThrowExceptionIfMapSizeIsGreaterThanSuppliedValue() {
+ ArgCheck.hasSizeOfAtLeast(Collections.singletonMap("key",
"value"), 0, "value");
+ }
+
+ @Test
+ public void
hasSizeOfAtMostShouldNotThrowExceptionIfMapSizeIsGreaterThanSuppliedValue() {
+ ArgCheck.hasSizeOfAtMost(Collections.singletonMap("key",
"value"), 2, "value");
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void
hasSizeOfAtLeastShouldThrowExceptionIfArraySizeIsSmallerThanSuppliedValue() {
+ ArgCheck.hasSizeOfAtLeast(new Object[] {"key", "value"}, 3,
"value");
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void hasSizeOfAtMostShouldThrowExceptionIfArraySizeIsLargerThanSuppliedValue()
{
+ ArgCheck.hasSizeOfAtMost(new Object[] {"key", "value"}, 1,
"value");
+ }
+
+ @Test
+ public void
hasSizeOfAtLeastShouldNotThrowExceptionIfArraySizeIsEqualToSuppliedValue() {
+ ArgCheck.hasSizeOfAtLeast(new Object[] {"key", "value"}, 2,
"value");
+ }
+
+ @Test
+ public void hasSizeOfAtMostShouldNotThrowExceptionIfArraySizeIsEqualToSuppliedValue()
{
+ ArgCheck.hasSizeOfAtMost(new Object[] {"key", "value"}, 2,
"value");
+ }
+
+ @Test
+ public void
hasSizeOfAtLeastShouldNotThrowExceptionIfArraySizeIsGreaterThanSuppliedValue() {
+ ArgCheck.hasSizeOfAtLeast(new Object[] {"key", "value"}, 1,
"value");
+ }
+
+ @Test
+ public void
hasSizeOfAtMostShouldNotThrowExceptionIfArraySizeIsGreaterThanSuppliedValue() {
+ ArgCheck.hasSizeOfAtMost(new Object[] {"key", "value"}, 3,
"value");
+ }
+
}
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicEmptyProperty.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicEmptyProperty.java 2008-07-09
21:20:54 UTC (rev 350)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicEmptyProperty.java 2008-07-11
20:33:53 UTC (rev 351)
@@ -27,13 +27,20 @@
import org.jboss.dna.spi.graph.Name;
/**
+ * An immutable version of a property that has no values. This is done for efficiency of
the in-memory representation, since many
+ * properties will have just a single value, while others will have multiple values.
+ *
* @author Randall Hauch
*/
@Immutable
public class BasicEmptyProperty extends BasicProperty {
+ private static final Iterator<Object> SHARED_ITERATOR = new
EmptyIterator<Object>();
+
/**
- * @param name
+ * Create a property with no values.
+ *
+ * @param name the property name
*/
public BasicEmptyProperty( Name name ) {
super(name);
@@ -71,10 +78,10 @@
* {@inheritDoc}
*/
public Iterator<Object> iterator() {
- return new EmptyIterator<Object>();
+ return SHARED_ITERATOR;
}
- protected class EmptyIterator<T> implements Iterator<T> {
+ protected static class EmptyIterator<T> implements Iterator<T> {
protected EmptyIterator() {
}
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicMultiValueProperty.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicMultiValueProperty.java 2008-07-09
21:20:54 UTC (rev 350)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicMultiValueProperty.java 2008-07-11
20:33:53 UTC (rev 351)
@@ -21,12 +21,17 @@
*/
package org.jboss.dna.spi.graph.impl;
+import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.graph.Name;
/**
+ * An immutable version of a property that has 2 or more values. This is done for
efficiency of the in-memory representation,
+ * since many properties will have just a single value, while others will have multiple
values.
+ *
* @author Randall Hauch
*/
@Immutable
@@ -35,20 +40,40 @@
private final List<Object> values;
/**
- * @param name
- * @param values
+ * Create a property with 2 or more values. Note that the supplied list may be
modifiable, as this object does not expose any
+ * means for modifying the contents.
+ *
+ * @param name the property name
+ * @param values the property values
+ * @throws IllegalArgumentException if the values is null or does not have at least 2
values
*/
public BasicMultiValueProperty( Name name,
List<Object> values ) {
super(name);
+ ArgCheck.isNotNull(values, "values");
+ ArgCheck.hasSizeOfAtLeast(values, 2, "values");
this.values = values;
}
/**
+ * Create a property with 2 or more values.
+ *
+ * @param name the property name
+ * @param values the property values
+ * @throws IllegalArgumentException if the values is null or does not have at least 2
values
+ */
+ public BasicMultiValueProperty( Name name,
+ Object... values ) {
+ super(name);
+ ArgCheck.isNotNull(values, "values");
+ ArgCheck.hasSizeOfAtLeast(values, 2, "values");
+ this.values = Arrays.asList(values);
+ }
+
+ /**
* {@inheritDoc}
*/
public boolean isEmpty() {
- assert values.isEmpty() == false;
return false;
}
@@ -56,7 +81,6 @@
* {@inheritDoc}
*/
public boolean isMultiple() {
- assert values.size() > 1;
return true;
}
@@ -64,7 +88,6 @@
* {@inheritDoc}
*/
public boolean isSingle() {
- assert values.size() == 1;
return false;
}
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicSingleValueProperty.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicSingleValueProperty.java 2008-07-09
21:20:54 UTC (rev 350)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicSingleValueProperty.java 2008-07-11
20:33:53 UTC (rev 351)
@@ -27,6 +27,9 @@
import org.jboss.dna.spi.graph.Name;
/**
+ * An immutable version of a property that has exactly 1 value. This is done for
efficiency of the in-memory representation, since
+ * many properties will have just a single value, while others will have multiple
values.
+ *
* @author Randall Hauch
*/
@Immutable
@@ -35,8 +38,10 @@
protected final Object value;
/**
- * @param name
- * @param value
+ * Create a property with a single value
+ *
+ * @param name the property name
+ * @param value the property value (which may be null)
*/
public BasicSingleValueProperty( Name name,
Object value ) {