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