vm/src/test/java/org/apidesign/vm4brwsr/StringSample.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 23 Oct 2012 16:50:27 +0200
changeset 116 033d51e026b0
parent 106 346633cd13d6
child 137 45184b2f9697
permissions -rw-r--r--
Some basic operations needed for a trivial calculator
jaroslav@106
     1
/**
jaroslav@106
     2
 * Back 2 Browser Bytecode Translator
jaroslav@106
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@106
     4
 *
jaroslav@106
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@106
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@106
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@106
     8
 *
jaroslav@106
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@106
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@106
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@106
    12
 * GNU General Public License for more details.
jaroslav@106
    13
 *
jaroslav@106
    14
 * You should have received a copy of the GNU General Public License
jaroslav@106
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@106
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@106
    17
 */
jaroslav@34
    18
package org.apidesign.vm4brwsr;
jaroslav@34
    19
jaroslav@34
    20
/**
jaroslav@34
    21
 *
jaroslav@34
    22
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@34
    23
 */
jaroslav@34
    24
public class StringSample {
jaroslav@34
    25
    public static final String HELLO = "Hello World!";
jaroslav@36
    26
    private static int counter;
jaroslav@36
    27
    
jaroslav@36
    28
    private final int cnt;
jaroslav@36
    29
    public StringSample() {
jaroslav@36
    30
        cnt = ++counter;
jaroslav@36
    31
    }
jaroslav@36
    32
    
jaroslav@34
    33
    
jaroslav@34
    34
    public static char sayHello(int indx) {
jaroslav@34
    35
        return HELLO.charAt(indx);
jaroslav@34
    36
    }
jaroslav@36
    37
    
jaroslav@116
    38
    public static boolean equalToHello(int from, int to) {
jaroslav@116
    39
        return "Hello".equals(HELLO.substring(from, to));
jaroslav@116
    40
    }
jaroslav@116
    41
    
jaroslav@45
    42
    public static String fromChars(char a, char b, char c) {
jaroslav@45
    43
        char[] arr = { a, b, c };
jaroslav@45
    44
        return new String(arr).toString();
jaroslav@45
    45
    }
jaroslav@45
    46
    
jaroslav@36
    47
    public static String toStringTest(int howMuch) {
jaroslav@104
    48
        counter = 0;
jaroslav@36
    49
        StringSample ss = null;
jaroslav@36
    50
        for (int i = 0; i < howMuch; i++) {
jaroslav@36
    51
            ss = new StringSample();
jaroslav@36
    52
        }
jaroslav@93
    53
        return ss.toString().toString();
jaroslav@36
    54
    }
jaroslav@104
    55
    
jaroslav@104
    56
    public static String concatStrings() {
jaroslav@104
    57
        return (toStringTest(1) + "Ahoj").toString();
jaroslav@104
    58
    }
jaroslav@36
    59
jaroslav@36
    60
    @Override
jaroslav@36
    61
    public String toString() {
jaroslav@36
    62
        return HELLO + cnt;
jaroslav@36
    63
    }
jaroslav@34
    64
}