com.bristle.javalib.util
Class StringWrapper

java.lang.Object
  extended by com.bristle.javalib.util.StringWrapper
Direct Known Subclasses:
GetOpt.DefaultString

public class StringWrapper
extends Object

This class wraps a String. It is useful to subclass when you want an object that is essentially a String, but can be distinguished from other String types. For example, when you write a method with multiple parameters that are all Strings, but serve different purposes, and you want to be sure they were passed in the correct order on the method call, you can define each parameter to be a different subclass of this class. Note: This class would not be necessary if java.lang.String was not declared as "final".

Usage:
   - The typical scenario for using this class is:
     - Declare subclasses of this class:
        public static class PromptString extends StringWrapper
        { public PromptString(String strValue) { super(strValue); } }
        public static class ErrorString extends StringWrapper
        { public ErrorString(String strValue) { super(strValue); } }
     - Declare a method that takes the subclasses as parameters:
        public String getValue(PromptString strPrompt, ErrorString strError);
     - Call the method, with order of arguments enforced:
        strValue = getValue
                      (new PromptString("prompt: "), 
                       new ErrorString("Error occurred"));

   - See the source code of the inner Tester class for more examples.
  
Assumptions:
Effects:
       - None.
Anticipated Changes:
Notes:
Implementation Notes:
Portability Issues:
Revision History:
   $Log$


Nested Class Summary
static class StringWrapper.Tester
          Each class contains a Tester inner class with a main() for easier unit testing.
 
Constructor Summary
StringWrapper(String strValue)
          Constructor.
 
Method Summary
static String castToString(StringWrapper wrapper)
          Return the StringWrapper cast to a String, or null if the specified StringWrapper is null.
 String getString()
          Get the wrapped String.
 void setString(String strNew)
          Set the wrapped String.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringWrapper

public StringWrapper(String strValue)
Constructor.

Parameters:
strValue - Value of the String
Method Detail

setString

public void setString(String strNew)
Set the wrapped String.

Parameters:
strNew - The new String.

getString

public String getString()
Get the wrapped String.

Returns:
The log level.

castToString

public static String castToString(StringWrapper wrapper)
Return the StringWrapper cast to a String, or null if the specified StringWrapper is null.

Parameters:
wrapper - StringWrapper to cast to String.
Returns:
String version of the object.