com.blackperl.Perl
Class Ucfirst

java.lang.Object
  |
  +--com.blackperl.Perl.Ucfirst

public final class Ucfirst
extends java.lang.Object

Static-method implementation of the Perl ucfirst keyword. The class provides several static methods to emulate Perl's ucfirst. In keeping with the philosophy of not directly replicating Java functionality, there is no implementation of lc. Rather, the developer should use the toUpperCase method of the String class. The methods actually use the toUpperCase method to do the needed conversions. Thus, each version of ucfirst also has a form that takes a Locale object as an additional parameter, to dictate the rules for converting the characters to upper-case.

Some simple examples:

     import com.blackperl.Perl.Ucfirst;
 
     String name = "rObErT";
     String bettername = Ucfirst.ucfirst(name.toLowerCase());
     // bettername == "Robert"
 
     name = "Fred";
     name = Ucfirst.ucfirst(name); // name is unchanged in this case
 
This implementation departs slightly from the Perl model in the following way: if the argument passed to the function is a StringBuffer rather than a String, the argument itself is modified in-place. The return value is still a stringified representation of the final value, but unlike the previous example, the value passed in has been altered:
     import com.blackperl.Perl.Lcfirst;
 
     StringBuffer name = new StringBuffer("barney");
     String bettername = Ucfirst.ucfirst(name);
     // bettername == name.toString() == "Barney"
 
All components in this package provide an instance method to retrieve a singleton object which may be used to call the static methods, if the programmer prefers using an object to static invocation.

If this is the JDK 1.5 ("Tiger") edition of the package, this class is suitable for use via static import:

     import com.blackperl.Perl.Ucfirst.ucfirst;
 
     String name = "rObErT";
     String bettername = ucfirst(name.toLowerCase());
     // bettername is now "Robert".
 


Method Summary
static com.blackperl.Perl.Ucfirst instance()
          The instance method is used to retrieve the Ucfirst singleton that applications can use in lieu of invoking the methods statically.
static java.lang.String ucfirst(java.lang.String string)
          Take the String parameter and return a new String whose first character has been made upper-case, if the character is in fact alphabetic.
static java.lang.String ucfirst(java.lang.StringBuffer buffer)
          This form is a slight departure from the Perl equivalent, in that it actually modifies the argument in-place.
static java.lang.String ucfirst(java.lang.StringBuffer buffer, java.util.Locale locale)
          This form is a slight departure from the Perl equivalent, in that it actually modifies the argument in-place.
static java.lang.String ucfirst(java.lang.String string, java.util.Locale locale)
          Take the String parameter and return a new String whose first character has been made upper-case, if the character is in fact alphabetic.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

instance

public static com.blackperl.Perl.Ucfirst instance()
The instance method is used to retrieve the Ucfirst singleton that applications can use in lieu of invoking the methods statically.

Returns:
Singleton instance of the Ucfirst class

ucfirst

public static java.lang.String ucfirst(java.lang.String string)
Take the String parameter and return a new String whose first character has been made upper-case, if the character is in fact alphabetic. This uses the default locale to determine the correct way to convert to upper-case. Since the argument is immutable, it itself is not changed.

Parameters:
string - The String to convert (not changed)
Returns:
The converted value

ucfirst

public static java.lang.String ucfirst(java.lang.StringBuffer buffer)
This form is a slight departure from the Perl equivalent, in that it actually modifies the argument in-place. The first character is converted to upper-case using the default locale rules (if the character is not alphabetic, it is unchanged). Returns a String copy of the converted value.

Parameters:
buffer - The StringBuffer to operate on
Returns:
A String copy of the converted value

ucfirst

public static java.lang.String ucfirst(java.lang.StringBuffer buffer,
                                       java.util.Locale locale)
This form is a slight departure from the Perl equivalent, in that it actually modifies the argument in-place. The first character is converted to upper-case using the locale rules defined in the Locale parameter (if the character is not alphabetic, it is unchanged). Returns a String copy of the converted value.

Parameters:
buffer - The StringBuffer to operate on
locale - A Locale object for upper-case rules
Returns:
A String copy of the converted value

ucfirst

public static java.lang.String ucfirst(java.lang.String string,
                                       java.util.Locale locale)
Take the String parameter and return a new String whose first character has been made upper-case, if the character is in fact alphabetic. The Locale parameter determines the correct way to convert to upper-case. Since the argument is immutable, it itself is not changed.

Parameters:
string - The String to convert (not changed)
locale - A Locale object for upper-case rules
Returns:
The converted value