Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | class 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 Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 27 | 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 Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 36 | 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 Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 40 | public static int test2() { |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 41 | char[] cs = new char[20]; |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 42 | long t = System.currentTimeMillis(); |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 43 | StringBuilder sb = new StringBuilder(20); |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 44 | for (int i = 7; i >= 0; --i) { |
| 45 | int b = ((int) (t >> (i * 8))) & 0xff; |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 46 | sb.append(STRING_DIGITS[(b >> 4) & 0xf]); |
| 47 | sb.append(STRING_DIGITS[b & 0xf]); |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 48 | } |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 49 | String result = sb.toString(); |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 50 | System.logI(result); |
| 51 | return 123; |
| 52 | } |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 53 | |
| 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 Hughes | 1240dad | 2011-09-09 16:24:50 -0700 | [diff] [blame] | 90 | private static float f = 3.14f; |
| 91 | private static double d = Math.PI; |
| 92 | |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 93 | public static int test4() { |
| 94 | String s = "int=" + i + " long=" + j; |
| 95 | System.logI(s); |
| 96 | return 123; |
| 97 | } |
Elliott Hughes | 1240dad | 2011-09-09 16:24:50 -0700 | [diff] [blame] | 98 | |
Elliott Hughes | 29f2742 | 2011-09-18 16:02:18 -0700 | [diff] [blame^] | 99 | 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 Hughes | 1240dad | 2011-09-09 16:24:50 -0700 | [diff] [blame] | 119 | return 123; |
| 120 | } |
Elliott Hughes | 29f2742 | 2011-09-18 16:02:18 -0700 | [diff] [blame^] | 121 | |
| 122 | public static void main(String[] args) throws Exception { |
| 123 | test5(); |
| 124 | } |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 125 | } |