vm/src/test/java/org/apidesign/vm4brwsr/StaticMethod.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 08 Oct 2012 17:10:27 -0700
branchemul
changeset 93 a236a9f137ac
parent 48 4fca8ddf46de
child 94 19497b4312bb
permissions -rw-r--r--
Concatanation of strings sort of works (but produces wrong result)
     1 /*
     2 Java 4 Browser Bytecode Translator
     3 Copyright (C) 2012-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 package org.apidesign.vm4brwsr;
    19 
    20 /**
    21  *
    22  * @author Jaroslav Tulach <jtulach@netbeans.org>
    23  */
    24 public class StaticMethod {
    25     private static int cnt;
    26 
    27     public static int minusOne() {
    28         return -1;
    29     }
    30     
    31     public static Object none(int x, int y) {
    32         Object toRet = null;
    33         for (int i = x; i < y; i++) {
    34             if (i == 2) {
    35                 toRet = null;
    36             } else {
    37                 toRet = new Object();
    38             }
    39         }
    40         return toRet;
    41     }
    42     
    43     public static int sum(int x, int y) {
    44         return x + y;
    45     }
    46     public static float power(float x) {
    47         return x * x;
    48     }
    49     public static double minus(double x, long y) {
    50         return x - y;
    51     }
    52     public static int div(byte c, double d) {
    53         return (int)(d / c);
    54     }
    55     public static int mix(int a, long b, byte c, double d) {
    56         return (int)((b / a + c) * d);
    57     }
    58     public static long xor(int a, long b) {
    59         return a ^ b;
    60     }
    61     public static long orOrAnd(boolean doOr, int a, int b) {
    62         return doOr ? a | b : a & b;
    63     }
    64     public static int shiftLeft(int what, int much) {
    65         return what << much;
    66     }
    67     public static int shiftArithmRight(int what, int much, boolean signed) {
    68         if (signed) {
    69             return what >> much;
    70         } else {
    71             return what >>> much;
    72         }
    73     }
    74     public static long factRec(int n) {
    75         if (n <= 1) {
    76             return 1;
    77         } else {
    78             return n * factRec(n - 1);
    79         }
    80     }
    81     public static long factIter(int n) {
    82         long res = 1;
    83         for (int i = 2; i <= n; i++) {
    84             res *= i;
    85         }
    86         return res;
    87     }
    88     public static int inc4() {
    89         cnt++;
    90         cnt+=2;
    91         cnt++;
    92         return cnt;
    93     }
    94 }