src/test/java/org/apidesign/java4browser/StaticMethod.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 16 Sep 2012 07:28:57 +0200
changeset 9 0cab1e07e677
parent 7 5b135a2f2de3
permissions -rw-r--r--
Support for static integer fields
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@0
    18
package org.apidesign.java4browser;
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@9
    26
    
jaroslav@0
    27
    public static int sum(int x, int y) {
jaroslav@0
    28
        return x + y;
jaroslav@0
    29
    }
jaroslav@1
    30
    public static float power(float x) {
jaroslav@1
    31
        return x * x;
jaroslav@1
    32
    }
jaroslav@2
    33
    public static double minus(double x, long y) {
jaroslav@2
    34
        return x - y;
jaroslav@2
    35
    }
jaroslav@3
    36
    public static int div(byte c, double d) {
jaroslav@3
    37
        return (int)(d / c);
jaroslav@3
    38
    }
jaroslav@3
    39
    public static int mix(int a, long b, byte c, double d) {
jaroslav@3
    40
        return (int)((b / a + c) * d);
jaroslav@3
    41
    }
jaroslav@6
    42
    public static long xor(int a, long b) {
jaroslav@6
    43
        return a ^ b;
jaroslav@6
    44
    }
jaroslav@7
    45
    public static long orOrAnd(boolean doOr, int a, int b) {
jaroslav@7
    46
        return doOr ? a | b : a & b;
jaroslav@7
    47
    }
jaroslav@4
    48
    public static long factRec(int n) {
jaroslav@4
    49
        if (n <= 1) {
jaroslav@4
    50
            return 1;
jaroslav@4
    51
        } else {
jaroslav@4
    52
            return n * factRec(n - 1);
jaroslav@4
    53
        }
jaroslav@4
    54
    }
jaroslav@5
    55
    public static long factIter(int n) {
jaroslav@5
    56
        long res = 1;
jaroslav@5
    57
        for (int i = 2; i <= n; i++) {
jaroslav@5
    58
            res *= i;
jaroslav@5
    59
        }
jaroslav@5
    60
        return res;
jaroslav@5
    61
    }
jaroslav@9
    62
    public static int inc4() {
jaroslav@9
    63
        cnt++;
jaroslav@9
    64
        cnt+=2;
jaroslav@9
    65
        cnt++;
jaroslav@9
    66
        return cnt;
jaroslav@9
    67
    }
jaroslav@0
    68
}