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