samples/conditionaluseofapi/src/conditionaluseofapi/StringBuilderAdd15.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:50:50 +0200
changeset 6 b577ee7fcf67
permissions -rw-r--r--
example with conditional usage of an API
jtulach@6
     1
package conditionaluseofapi;
jtulach@6
     2
jtulach@6
     3
/** Implementation for string concatention using Java 5 only.
jtulach@6
     4
 * 
jtulach@6
     5
 * StringBuilder is supposed to be faster than StringBuffer as it
jtulach@6
     6
 * is not synchronized and as such it is does not waste time with
jtulach@6
     7
 * synchronization when its methods are called. 
jtulach@6
     8
 *
jtulach@6
     9
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jtulach@6
    10
 */
jtulach@6
    11
final class StringBuilderAdd15 implements AddString {
jtulach@6
    12
    
jtulach@6
    13
    private StringBuilder sb = new StringBuilder();
jtulach@6
    14
jtulach@6
    15
    public void addString(String msg) {
jtulach@6
    16
        sb.append(msg);
jtulach@6
    17
    }
jtulach@6
    18
jtulach@6
    19
    public String getMessage() {
jtulach@6
    20
        return sb.toString();
jtulach@6
    21
    }
jtulach@6
    22
jtulach@6
    23
    public String toString() {
jtulach@6
    24
        return "New Shiny and Fast Java 5 Implementation";
jtulach@6
    25
    }
jtulach@6
    26
}