com.sun.slamd.example
Class ValuePattern

java.lang.Object
  extended by com.sun.slamd.example.ValuePattern

public class ValuePattern
extends java.lang.Object

This class defines a utility that can be used to construct values from static strings and numeric ranges. The values constructed can have multiple numeric ranges, and each range can either iterate through the values sequentially or move through them in random order. The numeric ranges should be enclosed in square brackets, with the upper and lower bounds separated by a dash for random order or a colon for sequential order. For sequential ranges, the upper bound can be followed by an 'x' character and a positive or negative integer to indicate that the increment or decrement should be in steps of that amount. Both sequential and random ranges may be followed by a percent sign and a format string (as used by an instance of java.util.DecimalFormat to define the format that should be used for the values.

Author:
Neil A. Wilson

Constructor Summary
ValuePattern(java.lang.String pattern)
          Creates the value pattern based on the provided pattern string.
ValuePattern(java.lang.String pattern, java.util.Random random)
          Creates the value pattern based on the provided pattern string.
 
Method Summary
 NumericRange[] getComponents()
          Retrieves the components that make up this value pattern.
 java.lang.String getPattern()
          Retrieves the pattern used to construct the values for this value pattern.
 java.lang.String nextValue()
          Retrieves the next value that should be used for this value pattern.
 void nextValue(java.lang.StringBuffer buffer)
          Appends the next value for this value pattern to the provided buffer.
 void setDefaultNumberFormat(java.text.NumberFormat format)
          Specifies the number format that should be used for numeric ranges in which no other format has been specified.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ValuePattern

public ValuePattern(java.lang.String pattern)
Creates the value pattern based on the provided pattern string.

Parameters:
pattern - The pattern string to use to create this value pattern.

ValuePattern

public ValuePattern(java.lang.String pattern,
                    java.util.Random random)
Creates the value pattern based on the provided pattern string.

Parameters:
pattern - The pattern string to use to create this value pattern.
random - The random number generator to use for this value pattern.
Method Detail

setDefaultNumberFormat

public void setDefaultNumberFormat(java.text.NumberFormat format)
Specifies the number format that should be used for numeric ranges in which no other format has been specified.

Parameters:
format - The number format that should be used for numeric ranges in which no other format has been specified.

nextValue

public java.lang.String nextValue()
Retrieves the next value that should be used for this value pattern.

Returns:
The next value that should be used for this value pattern.

nextValue

public void nextValue(java.lang.StringBuffer buffer)
Appends the next value for this value pattern to the provided buffer.

Parameters:
buffer - The buffer to which the value should be appended.

getPattern

public java.lang.String getPattern()
Retrieves the pattern used to construct the values for this value pattern.

Returns:
The pattern to use to construct the values for this value pattern.

getComponents

public NumericRange[] getComponents()
Retrieves the components that make up this value pattern. The components returned may include a mixture of numeric and string elements.

Returns:
The components that make up this value pattern.