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)
jaroslav@0
     1
/*
jaroslav@0
     2
Java 4 Browser Bytecode Translator
jaroslav@0
     3
Copyright (C) 2012-2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@0
     4
jaroslav@0
     5
This program is free software: you can redistribute it and/or modify
jaroslav@0
     6
it under the terms of the GNU General Public License as published by
jaroslav@0
     7
the Free Software Foundation, version 2 of the License.
jaroslav@0
     8
jaroslav@0
     9
This program is distributed in the hope that it will be useful,
jaroslav@0
    10
but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@0
    11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@0
    12
GNU General Public License for more details.
jaroslav@0
    13
jaroslav@0
    14
You should have received a copy of the GNU General Public License
jaroslav@0
    15
along with this program. Look for COPYING file in the top folder.
jaroslav@0
    16
If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@0
    17
*/
jaroslav@22
    18
package org.apidesign.vm4brwsr;
jaroslav@0
    19
jaroslav@0
    20
/**
jaroslav@0
    21
 *
jaroslav@0
    22
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@0
    23
 */
jaroslav@0
    24
public class StaticMethod {
jaroslav@9
    25
    private static int cnt;
jaroslav@48
    26
jaroslav@48
    27
    public static int minusOne() {
jaroslav@48
    28
        return -1;
jaroslav@48
    29
    }
jaroslav@9
    30
    
jaroslav@46
    31
    public static Object none(int x, int y) {
jaroslav@46
    32
        Object toRet = null;
jaroslav@46
    33
        for (int i = x; i < y; i++) {
jaroslav@46
    34
            if (i == 2) {
jaroslav@46
    35
                toRet = null;
jaroslav@46
    36
            } else {
jaroslav@46
    37
                toRet = new Object();
jaroslav@46
    38
            }
jaroslav@46
    39
        }
jaroslav@46
    40
        return toRet;
jaroslav@46
    41
    }
jaroslav@46
    42
    
jaroslav@0
    43
    public static int sum(int x, int y) {
jaroslav@0
    44
        return x + y;
jaroslav@0
    45
    }
jaroslav@1
    46
    public static float power(float x) {
jaroslav@1
    47
        return x * x;
jaroslav@1
    48
    }
jaroslav@2
    49
    public static double minus(double x, long y) {
jaroslav@2
    50
        return x - y;
jaroslav@2
    51
    }
jaroslav@3
    52
    public static int div(byte c, double d) {
jaroslav@3
    53
        return (int)(d / c);
jaroslav@3
    54
    }
jaroslav@3
    55
    public static int mix(int a, long b, byte c, double d) {
jaroslav@3
    56
        return (int)((b / a + c) * d);
jaroslav@3
    57
    }
jaroslav@6
    58
    public static long xor(int a, long b) {
jaroslav@6
    59
        return a ^ b;
jaroslav@6
    60
    }
jaroslav@7
    61
    public static long orOrAnd(boolean doOr, int a, int b) {
jaroslav@7
    62
        return doOr ? a | b : a & b;
jaroslav@7
    63
    }
jaroslav@93
    64
    public static int shiftLeft(int what, int much) {
jaroslav@93
    65
        return what << much;
jaroslav@93
    66
    }
jaroslav@93
    67
    public static int shiftArithmRight(int what, int much, boolean signed) {
jaroslav@93
    68
        if (signed) {
jaroslav@93
    69
            return what >> much;
jaroslav@93
    70
        } else {
jaroslav@93
    71
            return what >>> much;
jaroslav@93
    72
        }
jaroslav@93
    73
    }
jaroslav@4
    74
    public static long factRec(int n) {
jaroslav@4
    75
        if (n <= 1) {
jaroslav@4
    76
            return 1;
jaroslav@4
    77
        } else {
jaroslav@4
    78
            return n * factRec(n - 1);
jaroslav@4
    79
        }
jaroslav@4
    80
    }
jaroslav@5
    81
    public static long factIter(int n) {
jaroslav@5
    82
        long res = 1;
jaroslav@5
    83
        for (int i = 2; i <= n; i++) {
jaroslav@5
    84
            res *= i;
jaroslav@5
    85
        }
jaroslav@5
    86
        return res;
jaroslav@5
    87
    }
jaroslav@9
    88
    public static int inc4() {
jaroslav@9
    89
        cnt++;
jaroslav@9
    90
        cnt+=2;
jaroslav@9
    91
        cnt++;
jaroslav@9
    92
        return cnt;
jaroslav@9
    93
    }
jaroslav@0
    94
}