vm/src/test/java/org/apidesign/vm4brwsr/Array.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 24 Sep 2012 11:07:38 +0200
changeset 22 b9318fe303cd
parent 21 src/test/java/org/apidesign/java4browser/Array.java@d8807b6a636a
child 32 82476405e1ad
permissions -rw-r--r--
Getting ready for multiple projects inside one Hg repository
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@21
    42
    int ints() {
jaroslav@21
    43
        return ints[2];
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@21
    56
    public static double sum() {
jaroslav@21
    57
        double sum = 0.0;
jaroslav@21
    58
        for (int i = 0; i < ARR.length; i++) {
jaroslav@21
    59
            sum += ARR[i].bytes();
jaroslav@21
    60
            sum += ARR[i].shorts();
jaroslav@21
    61
            sum += ARR[i].ints();
jaroslav@21
    62
            sum += ARR[i].floats();
jaroslav@21
    63
            sum += ARR[i].doubles();
jaroslav@21
    64
        }
jaroslav@21
    65
        return sum;
jaroslav@21
    66
    }
jaroslav@21
    67
    public static int simple() {
jaroslav@21
    68
        int[] arr = { 0, 1, 2, 3, 4, 5 };
jaroslav@21
    69
        
jaroslav@21
    70
        int sum = 0;
jaroslav@21
    71
        for (int i = 0; i < arr.length; i++) {
jaroslav@21
    72
            sum += arr[i];
jaroslav@21
    73
        }
jaroslav@21
    74
        return sum;
jaroslav@21
    75
    }
jaroslav@21
    76
}