jaroslav@106: /** jaroslav@106: * Back 2 Browser Bytecode Translator jaroslav@106: * Copyright (C) 2012 Jaroslav Tulach jaroslav@106: * jaroslav@106: * This program is free software: you can redistribute it and/or modify jaroslav@106: * it under the terms of the GNU General Public License as published by jaroslav@106: * the Free Software Foundation, version 2 of the License. jaroslav@106: * jaroslav@106: * This program is distributed in the hope that it will be useful, jaroslav@106: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@106: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@106: * GNU General Public License for more details. jaroslav@106: * jaroslav@106: * You should have received a copy of the GNU General Public License jaroslav@106: * along with this program. Look for COPYING file in the top folder. jaroslav@106: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@106: */ jaroslav@22: package org.apidesign.vm4brwsr; jaroslav@21: jaroslav@21: /** jaroslav@21: * jaroslav@21: * @author Jaroslav Tulach jaroslav@21: */ jaroslav@21: public class Array { jaroslav@21: byte[] bytes = { 1 }; jaroslav@21: short[] shorts = { 2, 3 }; jaroslav@21: int[] ints = { 4, 5, 6 }; jaroslav@21: float[] floats = { 7, 8, 9, 10 }; jaroslav@21: double[][] doubles = { {11}, {12}, {13}, {14}, {15} }; jaroslav@21: char[] chars = { 'a', 'b' }; jaroslav@21: jaroslav@21: private Array() { jaroslav@21: } jaroslav@21: jaroslav@21: byte bytes() { jaroslav@21: return bytes[0]; jaroslav@21: } jaroslav@21: short shorts() { jaroslav@21: return shorts[1]; jaroslav@21: } jaroslav@21: jaroslav@32: int[] ints() { jaroslav@32: return ints; jaroslav@21: } jaroslav@21: jaroslav@21: float floats() { jaroslav@21: return floats[3]; jaroslav@21: } jaroslav@21: jaroslav@21: double doubles() { jaroslav@21: return doubles[4][0]; jaroslav@21: } jaroslav@21: jaroslav@21: private static final Array[] ARR = { new Array(), new Array(), new Array() }; jaroslav@21: jaroslav@33: private static Array[] arr() { jaroslav@33: return ARR; jaroslav@33: } jaroslav@33: private static T[] filter(T[] in) { jaroslav@33: return in; jaroslav@33: } jaroslav@33: jaroslav@21: public static double sum() { jaroslav@21: double sum = 0.0; jaroslav@33: for (int i = 0; i < arr().length; i++) { jaroslav@33: sum += arr()[i].bytes(); jaroslav@33: sum += arr()[i].shorts(); jaroslav@33: sum += arr()[i].ints()[2]; jaroslav@33: sum += arr()[i].floats(); jaroslav@33: sum += filter(arr())[i].doubles(); jaroslav@21: } jaroslav@21: return sum; jaroslav@21: } jaroslav@21: public static int simple() { jaroslav@21: int[] arr = { 0, 1, 2, 3, 4, 5 }; jaroslav@21: jaroslav@21: int sum = 0; jaroslav@21: for (int i = 0; i < arr.length; i++) { jaroslav@21: sum += arr[i]; jaroslav@21: } jaroslav@21: return sum; jaroslav@21: } jaroslav@104: jaroslav@104: static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) { jaroslav@104: while (count-- > 0) { jaroslav@104: dst[dstBegin++] = value[srcBegin++]; jaroslav@104: } jaroslav@104: } jaroslav@104: jaroslav@104: public static char copyArray() { jaroslav@104: char[] arr = { '0' }; jaroslav@104: arraycopy(arr()[0].chars, 0, arr, 0, 1); jaroslav@104: return arr[0]; jaroslav@104: } jaroslav@21: }