summaryrefslogtreecommitdiffstats
path: root/test/SystemMethods/SystemMethods.java
blob: 3d765487a9d8171828de32ce7596b27261ac93ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

class SystemMethods {
  public static int test0() {
    System.logI("hello world");
    return 123;
  }

  public static int test1() {
    String[] digits = new String[] {
      "0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f",
    };
    long t = System.currentTimeMillis();
    for (int i = 7; i >= 0; --i) {
      int b = ((int) (t >> (i * 8))) & 0xff;
      System.logI(digits[(b >> 4) & 0xf]);
      System.logI(digits[b & 0xf]);
    }
    return 123;
  }

  private static String[] STRING_DIGITS = new String[] {
    "0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f",
  };

  public static int test2() {
    char[] cs = new char[20];
    long t = System.currentTimeMillis();
    StringBuilder sb = new StringBuilder(20);
    for (int i = 7; i >= 0; --i) {
      int b = ((int) (t >> (i * 8))) & 0xff;
      sb.append(STRING_DIGITS[(b >> 4) & 0xf]);
      sb.append(STRING_DIGITS[b & 0xf]);
    }
    String result = sb.toString();
    System.logI(result);
    return 123;
  }

  private static char[] DIGITS = new char[] {
    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
    'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
    'u', 'v', 'w', 'x', 'y', 'z'
  };

  public static int test3() {
    long t = System.currentTimeMillis();

    long v = t;
    //        int i = (int) v;
    //        if (v >= 0 && i == v) {
    //            return intToHexString(i, false, 0);
    //        }

    int bufLen = 16;  // Max number of hex digits in a long
    char[] buf = new char[bufLen];
    int cursor = bufLen;

    do {
      buf[--cursor] = DIGITS[((int) v) & 0xF];
    } while ((v >>>= 4) != 0);

    String s = new String(buf, cursor, bufLen - cursor);
    System.logI(s);

    System.logI(IntegralToString.longToHexString(t));
    System.logI(Long.toHexString(t));
    System.logI(Long.toString(t));
    return 123;
  }

  private static int i = 4;
  private static long j = 0x0123456789abcdefL;

  public static int test4() {
    String s = "int=" + i + " long=" + j;
    System.logI(s);
    return 123;
  }
}