- Timestamp:
- Jul 23, 2008, 5:03:28 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sample/hadoop-0.16/test.java
r31 r42 7 7 import java.io.IOException; 8 8 import java.io.RandomAccessFile; 9 import java.io.Writer; 9 10 import java.util.StringTokenizer; 11 import java.util.regex.Matcher; 12 import java.util.regex.Pattern; 10 13 11 14 import org.apache.hadoop.fs.FileStatus; … … 14 17 import org.apache.hadoop.mapred.JobConf; 15 18 16 17 19 // this example is testing for static valiable value 18 20 // it will show the value of static valiable is related to Class, not object … … 25 27 } 26 28 29 class Fu<T> { 30 T go; 31 32 void setFu(T go) { 33 this.go = go; 34 } 35 36 T getFu() { 37 return go; 38 } 39 } 40 41 class animal { 42 String head = "head"; 43 44 String feet = "feet"; 45 46 String body = "body"; 47 48 String hand = "head"; 49 50 String mind = "mind"; 51 52 int id = 1234567; 53 } 54 55 class bird extends animal { 56 String feather = "feather"; 57 58 bird() { 59 hand = "wing"; 60 id = 1234568; 61 System.out.println(head + hand + body + feet + "id=" + id); 62 System.out.println("super = " + super.hand + "this = " + this.hand); 63 } 64 } 65 66 class dog extends animal { 67 dog(animal a) { 68 System.out.println(a.head + hand + body + feet + "id=" + id); 69 } 70 71 void setbird(bird b) { 72 System.out.println(b.head + hand + body + feet + "id=" + id); 73 } 74 } 75 27 76 public class test { 28 77 int na; 78 29 79 static int sna; 80 30 81 static String str; 82 31 83 public test() { 32 84 } … … 113 165 } 114 166 167 void Inherbit() { 168 animal a = new animal(); 169 bird b = new bird(); 170 dog d = new dog(b); 171 animal aaa = new bird(); 172 // dog ddd = new animal(); -> error 173 174 animal aa = (animal) b; 175 System.out.println(aa.hand); 176 System.out.println(aa.mind); 177 // bird bb = (bird) a; -> error 178 // d.setbird(aa); -> error 179 // System.out.println(aa.feather); -> error 180 181 // Fu <T> 182 Fu<? extends String> ak; 183 ak = new Fu<String>(); 184 ak.getFu(); 185 Fu<?> in = ak; 186 // in.setFu("ss"); -> error 187 in.getFu(); 188 } 189 115 190 void ttt() throws IOException { 116 191 Path pi; … … 124 199 } 125 200 201 void parseN() throws IOException { 202 BufferedReader br = new BufferedReader(new FileReader(new File( 203 "/home/waue/Desktop/a"))); 204 // BufferedWriter bw = new BufferedWriter(new FileWriter(new 205 // File("/home/waue/Desktop/b"))); 206 String line = br.readLine(); 207 // char n = '\n'; 208 int Count = 0; 209 do { 210 if (line.isEmpty()) { 211 System.out.println("empty !"); 212 } else { 213 System.out.println(line); 214 } 215 line = br.readLine(); 216 Count++; 217 } while (line != null); 218 219 } 220 221 void regular() { 222 Pattern patten_line; 223 Matcher matcher; 224 String logData = new String(); 225 String line = "[**] [1:2003:8] MS-SQL Worm propagation attempt [**]"; 226 // String line = "[**] [1:2189:3] BAD-TRAFFIC IP Proto 103 PIM [**]"; 227 patten_line = Pattern 228 .compile("^\\[\\**\\] \\[([0-9]*):([0-9]*):([0-9]*)\\] ([^\\[]*)\\[\\**\\]$"); 229 matcher = patten_line.matcher(line); 230 System.out.println("go"); 231 if (matcher.matches()) { 232 int number = matcher.groupCount(); 233 String[] data = new String[number]; 234 for (int j = 0; j < number; j++) { 235 data[j] = matcher.group(j + 1); 236 logData += (data[j] + ";"); 237 } 238 239 System.out.println(logData); 240 } 241 System.out.println("end"); 242 } 243 126 244 public static void main(String[] args) throws IOException { 127 // test a = new test(); 128 // a.strToken(); 245 246 test t = new test(); 247 248 // 測試 strToken函數 249 // t.strToken(); 250 // 測試 檔案io 與 解析 129 251 // System.out.println(a.parseFirstLine("/home/waue/test.txt", 130 252 // "/home/waue/out.tmp.txt")); 131 // ttt(); 132 133 134 animal a = new animal(); 135 bird b = new bird(); 136 dog d = new dog(b); 137 animal aaa = new bird(); 138 // dog ddd = new animal(); -> error 139 140 animal aa = (animal) b; 141 System.out.println(aa.hand); 142 System.out.println(aa.mind); 143 // bird bb = (bird) a; -> error 144 // d.setbird(aa); -> error 145 // System.out.println(aa.feather); -> error 146 147 // Fu <T> 148 Fu<? extends String> ak; 149 ak = new Fu<String>(); 150 ak.getFu(); 151 Fu<?> in = ak; 152 // in.setFu("ss"); -> error 153 in.getFu(); 154 } 155 } 156 class Fu <T>{ 157 T go; 158 void setFu(T go){ 159 this.go = go; 160 } 161 T getFu(){ 162 return go; 163 } 164 } 165 166 class animal{ 167 String head = "head"; 168 String feet = "feet"; 169 String body = "body"; 170 String hand = "head"; 171 String mind = "mind"; 172 int id = 1234567; 173 } 174 class bird extends animal{ 175 String feather = "feather"; 176 bird(){ 177 hand = "wing"; 178 id = 1234568; 179 System.out.println(head + hand + body + feet + "id="+id); 180 System.out.println("super = " + super.hand +"this = " + this.hand); 181 } 182 } 183 class dog extends animal{ 184 dog(animal a){ 185 System.out.println(a.head + hand + body + feet + "id="+id); 186 } 187 void setbird(bird b){ 188 System.out.println(b.head + hand + body + feet + "id="+id); 189 } 190 } 253 // 測試 listStatus 254 // t.ttt(); 255 // 測試 繼承 與 汎型 256 // t.Inherbit() 257 // 測試 "換行" 是否為 "\n" 258 // t.parseN(); 259 // 測試 正規表示法 260 // t.regular(); 261 262 } 263 264 }
Note: See TracChangeset
for help on using the changeset viewer.