vm/src/test/java/org/apidesign/vm4brwsr/Array.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 16 Oct 2012 11:55:56 +0200
changeset 104 1376481f15e7
parent 33 96e44a3f544d
child 106 346633cd13d6
permissions -rw-r--r--
Concatenation of strings works
jaroslav@21
     1
/*
jaroslav@21
     2
Java 4 Browser Bytecode Translator
jaroslav@21
     3
Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@21
     4
jaroslav@21
     5
This program is free software: you can redistribute it and/or modify
jaroslav@21
     6
it under the terms of the GNU General Public License as published by
jaroslav@21
     7
the Free Software Foundation, version 2 of the License.
jaroslav@21
     8
jaroslav@21
     9
This program is distributed in the hope that it will be useful,
jaroslav@21
    10
but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@21
    11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@21
    12
GNU General Public License for more details.
jaroslav@21
    13
jaroslav@21
    14
You should have received a copy of the GNU General Public License
jaroslav@21
    15
along with this program. Look for COPYING file in the top folder.
jaroslav@21
    16
If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@21
    17
*/
jaroslav@22
    18
package org.apidesign.vm4brwsr;
jaroslav@21
    19
jaroslav@21
    20
/**
jaroslav@21
    21
 *
jaroslav@21
    22
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@21
    23
 */
jaroslav@21
    24
public class Array {
jaroslav@21
    25
    byte[] bytes = { 1 };
jaroslav@21
    26
    short[] shorts = { 2, 3 };
jaroslav@21
    27
    int[] ints = { 4, 5, 6 };
jaroslav@21
    28
    float[] floats = { 7, 8, 9, 10 };
jaroslav@21
    29
    double[][] doubles = { {11}, {12}, {13}, {14}, {15} };
jaroslav@21
    30
    char[] chars = { 'a', 'b' };
jaroslav@21
    31
    
jaroslav@21
    32
    private Array() {
jaroslav@21
    33
    }
jaroslav@21
    34
    
jaroslav@21
    35
    byte bytes() {
jaroslav@21
    36
        return bytes[0];
jaroslav@21
    37
    }
jaroslav@21
    38
    short shorts() {
jaroslav@21
    39
        return shorts[1];
jaroslav@21
    40
    }
jaroslav@21
    41
    
jaroslav@32
    42
    int[] ints() {
jaroslav@32
    43
        return ints;
jaroslav@21
    44
    }
jaroslav@21
    45
    
jaroslav@21
    46
    float floats() {
jaroslav@21
    47
        return floats[3];
jaroslav@21
    48
    }
jaroslav@21
    49
    
jaroslav@21
    50
    double doubles() {
jaroslav@21
    51
        return doubles[4][0];
jaroslav@21
    52
    }
jaroslav@21
    53
    
jaroslav@21
    54
    private static final Array[] ARR = { new Array(), new Array(), new Array() };
jaroslav@21
    55
    
jaroslav@33
    56
    private static Array[] arr() {
jaroslav@33
    57
        return ARR;
jaroslav@33
    58
    }
jaroslav@33
    59
    private static <T> T[] filter(T[] in) {
jaroslav@33
    60
        return in;
jaroslav@33
    61
    }
jaroslav@33
    62
    
jaroslav@21
    63
    public static double sum() {
jaroslav@21
    64
        double sum = 0.0;
jaroslav@33
    65
        for (int i = 0; i < arr().length; i++) {
jaroslav@33
    66
            sum += arr()[i].bytes();
jaroslav@33
    67
            sum += arr()[i].shorts();
jaroslav@33
    68
            sum += arr()[i].ints()[2];
jaroslav@33
    69
            sum += arr()[i].floats();
jaroslav@33
    70
            sum += filter(arr())[i].doubles();
jaroslav@21
    71
        }
jaroslav@21
    72
        return sum;
jaroslav@21
    73
    }
jaroslav@21
    74
    public static int simple() {
jaroslav@21
    75
        int[] arr = { 0, 1, 2, 3, 4, 5 };
jaroslav@21
    76
        
jaroslav@21
    77
        int sum = 0;
jaroslav@21
    78
        for (int i = 0; i < arr.length; i++) {
jaroslav@21
    79
            sum += arr[i];
jaroslav@21
    80
        }
jaroslav@21
    81
        return sum;
jaroslav@21
    82
    }
jaroslav@104
    83
    
jaroslav@104
    84
    static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
jaroslav@104
    85
        while (count-- > 0) {
jaroslav@104
    86
            dst[dstBegin++] = value[srcBegin++];
jaroslav@104
    87
        }
jaroslav@104
    88
    }
jaroslav@104
    89
jaroslav@104
    90
    public static char copyArray() {
jaroslav@104
    91
        char[] arr = { '0' };
jaroslav@104
    92
        arraycopy(arr()[0].chars, 0, arr, 0, 1);
jaroslav@104
    93
        return arr[0];
jaroslav@104
    94
    }
jaroslav@21
    95
}