blob: 429755fb215ff03217b45aee3f2ece4f93e575a8 [file] [log] [blame]
Elliott Hughes0f4c41d2011-09-04 14:58:03 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17class SystemMethods {
18 public static int test0() {
19 System.logI("hello world");
20 return 123;
21 }
22
23 public static int test1() {
24 String[] digits = new String[] {
25 "0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f",
26 };
Elliott Hughes0f4c41d2011-09-04 14:58:03 -070027 long t = System.currentTimeMillis();
28 for (int i = 7; i >= 0; --i) {
29 int b = ((int) (t >> (i * 8))) & 0xff;
30 System.logI(digits[(b >> 4) & 0xf]);
31 System.logI(digits[b & 0xf]);
32 }
33 return 123;
34 }
35
Elliott Hughesf5ecf062011-09-06 17:37:59 -070036 private static String[] STRING_DIGITS = new String[] {
37 "0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f",
38 };
39
Elliott Hughes0f4c41d2011-09-04 14:58:03 -070040 public static int test2() {
Elliott Hughes0f4c41d2011-09-04 14:58:03 -070041 char[] cs = new char[20];
Elliott Hughes0f4c41d2011-09-04 14:58:03 -070042 long t = System.currentTimeMillis();
Elliott Hughes0f4c41d2011-09-04 14:58:03 -070043 StringBuilder sb = new StringBuilder(20);
Elliott Hughes0f4c41d2011-09-04 14:58:03 -070044 for (int i = 7; i >= 0; --i) {
45 int b = ((int) (t >> (i * 8))) & 0xff;
Elliott Hughesf5ecf062011-09-06 17:37:59 -070046 sb.append(STRING_DIGITS[(b >> 4) & 0xf]);
47 sb.append(STRING_DIGITS[b & 0xf]);
Elliott Hughes0f4c41d2011-09-04 14:58:03 -070048 }
Elliott Hughes0f4c41d2011-09-04 14:58:03 -070049 String result = sb.toString();
Elliott Hughes0f4c41d2011-09-04 14:58:03 -070050 System.logI(result);
51 return 123;
52 }
Elliott Hughesf5ecf062011-09-06 17:37:59 -070053
54 private static char[] DIGITS = new char[] {
55 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
56 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
57 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
58 'u', 'v', 'w', 'x', 'y', 'z'
59 };
60
61 public static int test3() {
62 long t = System.currentTimeMillis();
63
64 long v = t;
65 // int i = (int) v;
66 // if (v >= 0 && i == v) {
67 // return intToHexString(i, false, 0);
68 // }
69
70 int bufLen = 16; // Max number of hex digits in a long
71 char[] buf = new char[bufLen];
72 int cursor = bufLen;
73
74 do {
75 buf[--cursor] = DIGITS[((int) v) & 0xF];
76 } while ((v >>>= 4) != 0);
77
78 String s = new String(buf, cursor, bufLen - cursor);
79 System.logI(s);
80
81 System.logI(IntegralToString.longToHexString(t));
82 System.logI(Long.toHexString(t));
83 System.logI(Long.toString(t));
84 return 123;
85 }
86
87 private static int i = 4;
88 private static long j = 0x0123456789abcdefL;
89
Elliott Hughes1240dad2011-09-09 16:24:50 -070090 private static float f = 3.14f;
91 private static double d = Math.PI;
92
Elliott Hughesf5ecf062011-09-06 17:37:59 -070093 public static int test4() {
94 String s = "int=" + i + " long=" + j;
95 System.logI(s);
96 return 123;
97 }
Elliott Hughes1240dad2011-09-09 16:24:50 -070098
Elliott Hughes29f27422011-09-18 16:02:18 -070099 public static int test5() throws Exception {
100 System.logI("new Thread...");
101 Thread t = new Thread(new Runnable() {
102 public void run() {
103 System.logI("hello from a new thread!");
104 System.logI(Thread.currentThread().toString());
105 try {
106 System.logI("sleeping for 2s");
107 Thread.sleep(2*1000);
108 } catch (Exception ex) { ex.printStackTrace(); }
109 System.logI("finished sleeping");
110 throw new RuntimeException("uncaught exception");
111 }
112 });
113 System.logI("calling Thread.toString...");
114 System.logI(t.toString());
115 System.logI("calling Thread.start...");
116 t.start();
117 //t.join();
118 System.logI("...done!");
Elliott Hughes1240dad2011-09-09 16:24:50 -0700119 return 123;
120 }
Elliott Hughes29f27422011-09-18 16:02:18 -0700121
122 public static void main(String[] args) throws Exception {
123 test5();
124 }
Elliott Hughes0f4c41d2011-09-04 14:58:03 -0700125}