|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.bristle.javalib.util.StringWrapper
public class StringWrapper
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 |
|---|
public StringWrapper(String strValue)
strValue - Value of the String| Method Detail |
|---|
public void setString(String strNew)
strNew - The new String.public String getString()
public static String castToString(StringWrapper wrapper)
wrapper - StringWrapper to cast to String.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||