指令系统的发展经历

指令系统的发展经历了从简单到复杂的演变过程。早在20世纪50-60年代,计算机大多数采用分立元件的晶体管或电子管组成,其体积庞大,价格也很昂贵,因此计算机的硬件结构比较简单,所支持的指令系统也只有十几至几十条最基本的指令,而且寻址方式简单。

到60年代中期,随着集成电路的出现,计算机的功耗、体积、价格等不断下降,硬件功能不断增强,指令系统也越来越丰富。

 

  1 package Com.TableText;
  2 import java.util.ArrayList;  
  3 import java.util.LinkedHashSet;  
  4 import java.util.Set;  
  5 import java.util.regex.Matcher;  
  6 import java.util.regex.Pattern;  
  7 
  8 
  9 public class TableText_02 {  
 10       
 11     /** 
 12      * 功能描述:分割字符串 
 13      *  
 14      * @param str 
 15      *            String 原始字符串 
 16      * @param splitsign 
 17      *            String 分隔符 
 18      * @return String[] 分割后的字符串数组 
 19      */  
 20     @SuppressWarnings("unchecked")  
 21     public static String[] split(String str, String splitsign) {  
 22         int index;  
 23         if (str == null || splitsign == null) {  
 24             return null;  
 25         }  
 26         ArrayList al = new ArrayList();  
 27         while ((index = str.indexOf(splitsign)) != -1) {  
 28             al.add(str.substring(0, index));  
 29             str = str.substring(index + splitsign.length());  
 30         }  
 31         al.add(str);  
 32         return (String[]) al.toArray(new String[0]);  
 33     }  
 34   
 35     /** 
 36      * 功能描述:替换字符串 
 37      *  
 38      * @param from 
 39      *            String 原始字符串 
 40      * @param to 
 41      *            String 目标字符串 
 42      * @param source 
 43      *            String 母字符串 
 44      * @return String 替换后的字符串 
 45      */  
 46     public static String replace(String from, String to, String source) {  
 47         if (source == null || from == null || to == null)  
 48             return null;  
 49         StringBuffer str = new StringBuffer("");  
 50         int index = -1;  
 51         while ((index = source.indexOf(from)) != -1) {  
 52             str.append(source.substring(0, index) + to);  
 53             source = source.substring(index + from.length());  
 54             index = source.indexOf(from);  
 55         }  
 56         str.append(source);  
 57         return str.toString();  
 58     }  
 59   
 60     /** 
 61      * 替换字符串,能能够在HTML页面上直接显示(替换双引号和小于号) 
 62      *  
 63      * @param str 
 64      *            String 原始字符串 
 65      * @return String 替换后的字符串 
 66      */  
 67     public static String htmlencode(String str) {  
 68         if (str == null) {  
 69             return null;  
 70         }  
 71         return replace("\"", "&quot;", replace("<", "&lt;", str));  
 72     }  
 73   
 74     /** 
 75      * 替换字符串,将被编码的转换成原始码(替换成双引号和小于号) 
 76      *  
 77      * @param str 
 78      *            String 
 79      * @return String 
 80      */  
 81     public static String htmldecode(String str) {  
 82         if (str == null) {  
 83             return null;  
 84         }  
 85   
 86         return replace("&quot;", "\"", replace("&lt;", "<", str));  
 87     }  
 88   
 89     private static final String _BR = "<br/>";  
 90   
 91     /** 
 92      * 功能描述:在页面上直接显示文本内容,替换小于号,空格,回车,TAB 
 93      *  
 94      * @param str 
 95      *            String 原始字符串 
 96      * @return String 替换后的字符串 
 97      */  
 98     public static String htmlshow(String str) {  
 99         if (str == null) {  
100             return null;  
101         }  
102   
103         str = replace("<", "&lt;", str);  
104         str = replace(" ", "&nbsp;", str);  
105         str = replace("\r\n", _BR, str);  
106         str = replace("\n", _BR, str);  
107         str = replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;", str);  
108         return str;  
109     }  
110   
111     /** 
112      * 功能描述:返回指定字节长度的字符串 
113      *  
114      * @param str 
115      *            String 字符串 
116      * @param length 
117      *            int 指定长度 
118      * @return String 返回的字符串 
119      */  
120     public static String toLength(String str, int length) {  
121         if (str == null) {  
122             return null;  
123         }  
124         if (length <= 0) {  
125             return "";  
126         }  
127         try {  
128             if (str.getBytes("GBK").length <= length) {  
129                 return str;  
130             }  
131         } catch (Exception e) {  
132         }  
133         StringBuffer buff = new StringBuffer();  
134   
135         int index = 0;  
136         char c;  
137         length -= 3;  
138         while (length > 0) {  
139             c = str.charAt(index);  
140             if (c < 128) {  
141                 length--;  
142             } else {  
143                 length--;  
144                 length--;  
145             }  
146             buff.append(c);  
147             index++;  
148         }  
149         buff.append("...");  
150         return buff.toString();  
151     }  
152   
153     /** 
154      * 功能描述:判断是否为整数 
155      *  
156      * @param str 
157      *            传入的字符串 
158      * @return 是整数返回true,否则返回false 
159      */  
160     public static boolean isInteger(String str) {  
161         Pattern pattern = Pattern.compile("^[-\\+]?[\\d]+$");  
162         return pattern.matcher(str).matches();  
163     }  
164   
165     /** 
166      * 判断是否为浮点数,包括double和float 
167      *  
168      * @param str 
169      *            传入的字符串 
170      * @return 是浮点数返回true,否则返回false 
171      */  
172     public static boolean isDouble(String str) {  
173         Pattern pattern = Pattern.compile("^[-\\+]?\\d+\\.\\d+$");  
174         return pattern.matcher(str).matches();  
175     }  
176   
177     /** 
178      * 判断是不是合法字符 c 要判断的字符 
179      */  
180     public static boolean isLetter(String str) {  
181         if (str == null || str.length() < 0) {  
182             return false;  
183         }  
184         Pattern pattern = Pattern.compile("[\\w\\.-_]*");  
185         return pattern.matcher(str).matches();  
186     }  
187   
188     /** 
189      * 从指定的字符串中提取Email content 指定的字符串 
190      *  
191      * @param content 
192      * @return 
193      */  
194     public static String parse(String content) {  
195         String email = null;  
196         if (content == null || content.length() < 1) {  
197             return email;  
198         }  
199         // 找出含有@  
200         int beginPos;  
201         int i;  
202         String token = "@";  
203         String preHalf = "";  
204         String sufHalf = "";  
205   
206         beginPos = content.indexOf(token);  
207         if (beginPos > -1) {  
208             // 前项扫描  
209             String s = null;  
210             i = beginPos;  
211             while (i > 0) {  
212                 s = content.substring(i - 1, i);  
213                 if (isLetter(s))  
214                     preHalf = s + preHalf;  
215                 else  
216                     break;  
217                 i--;  
218             }  
219             // 后项扫描  
220             i = beginPos + 1;  
221             while (i < content.length()) {  
222                 s = content.substring(i, i + 1);  
223                 if (isLetter(s))  
224                     sufHalf = sufHalf + s;  
225                 else  
226                     break;  
227                 i++;  
228             }  
229             // 判断合法性  
230             email = preHalf + "@" + sufHalf;  
231             if (isEmail(email)) {  
232                 return email;  
233             }  
234         }  
235         return null;  
236     }  
237   
238     /** 
239      * 功能描述:判断输入的字符串是否符合Email样式. 
240      *  
241      * @param str 
242      *            传入的字符串 
243      * @return 是Email样式返回true,否则返回false 
244      */  
245     public static boolean isEmail(String email) {  
246         if (email == null || email.length() < 1 || email.length() > 256) {  
247             return false;  
248         }  
249         Pattern pattern = Pattern  
250                 .compile("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");  
251         return pattern.matcher(email).matches();  
252     }  
253   
254     /** 
255      * 功能描述:判断输入的字符串是否为纯汉字 
256      *  
257      * @param str 
258      *            传入的字符窜 
259      * @return 如果是纯汉字返回true,否则返回false 
260      */  
261     public static boolean isChinese(String str) {  
262         Pattern pattern = Pattern.compile("[\u0391-\uFFE5]+$");  
263         return pattern.matcher(str).matches();  
264     }  
265   
266     /** 
267      * 功能描述:是否为空白,包括null和"" 
268      *  
269      * @param str 
270      * @return 
271      */  
272     public static boolean isBlank(String str) {  
273         return str == null || str.trim().length() == 0;  
274     }  
275   
276     /** 
277      * 功能描述:判断是否为质数 
278      *  
279      * @param x 
280      * @return 
281      */  
282     public static boolean isPrime(int x) {  
283         if (x <= 7) {  
284             if (x == 2 || x == 3 || x == 5 || x == 7)  
285                 return true;  
286         }  
287         int c = 7;  
288         if (x % 2 == 0)  
289             return false;  
290         if (x % 3 == 0)  
291             return false;  
292         if (x % 5 == 0)  
293             return false;  
294         int end = (int) Math.sqrt(x);  
295         while (c <= end) {  
296             if (x % c == 0) {  
297                 return false;  
298             }  
299             c += 4;  
300             if (x % c == 0) {  
301                 return false;  
302             }  
303             c += 2;  
304             if (x % c == 0) {  
305                 return false;  
306             }  
307             c += 4;  
308             if (x % c == 0) {  
309                 return false;  
310             }  
311             c += 2;  
312             if (x % c == 0) {  
313                 return false;  
314             }  
315             c += 4;  
316             if (x % c == 0) {  
317                 return false;  
318             }  
319             c += 6;  
320             if (x % c == 0) {  
321                 return false;  
322             }  
323             c += 2;  
324             if (x % c == 0) {  
325                 return false;  
326             }  
327             c += 6;  
328         }  
329         return true;  
330     }  
331   
332     /** 
333      * 功能描述:人民币转成大写 
334      *  
335      * @param str 
336      *            数字字符串 
337      * @return String 人民币转换成大写后的字符串 
338      */  
339     public static String hangeToBig(String str) {  
340         double value;  
341         try {  
342             value = Double.parseDouble(str.trim());  
343         } catch (Exception e) {  
344             return null;  
345         }  
346         char[] hunit = { '拾', '佰', '仟' }; // 段内位置表示  
347         char[] vunit = { '万', '亿' }; // 段名表示  
348         char[] digit = { '零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖' }; // 数字表示  
349         long midVal = (long) (value * 100); // 转化成整形  
350         String valStr = String.valueOf(midVal); // 转化成字符串  
351   
352         String head = valStr.substring(0, valStr.length() - 2); // 取整数部分  
353         String rail = valStr.substring(valStr.length() - 2); // 取小数部分  
354   
355         String prefix = ""; // 整数部分转化的结果  
356         String suffix = ""; // 小数部分转化的结果  
357         // 处理小数点后面的数  
358         if (rail.equals("00")) { // 如果小数部分为0  
359             suffix = "整";  
360         } else {  
361             suffix = digit[rail.charAt(0) - '0'] + "角"  
362                     + digit[rail.charAt(1) - '0'] + "分"; // 否则把角分转化出来  
363         }  
364         // 处理小数点前面的数  
365         char[] chDig = head.toCharArray(); // 把整数部分转化成字符数组  
366         char zero = '0'; // 标志'0'表示出现过0  
367         byte zeroSerNum = 0; // 连续出现0的次数  
368         for (int i = 0; i < chDig.length; i++) { // 循环处理每个数字  
369             int idx = (chDig.length - i - 1) % 4; // 取段内位置  
370             int vidx = (chDig.length - i - 1) / 4; // 取段位置  
371             if (chDig[i] == '0') { // 如果当前字符是0  
372                 zeroSerNum++; // 连续0次数递增  
373                 if (zero == '0') { // 标志  
374                     zero = digit[0];  
375                 } else if (idx == 0 && vidx > 0 && zeroSerNum < 4) {  
376                     prefix += vunit[vidx - 1];  
377                     zero = '0';  
378                 }  
379                 continue;  
380             }  
381             zeroSerNum = 0; // 连续0次数清零  
382             if (zero != '0') { // 如果标志不为0,则加上,例如万,亿什么的  
383                 prefix += zero;  
384                 zero = '0';  
385             }  
386             prefix += digit[chDig[i] - '0']; // 转化该数字表示  
387             if (idx > 0)  
388                 prefix += hunit[idx - 1];  
389             if (idx == 0 && vidx > 0) {  
390                 prefix += vunit[vidx - 1]; // 段结束位置应该加上段名如万,亿  
391             }  
392         }  
393   
394         if (prefix.length() > 0)  
395             prefix += '圆'; // 如果整数部分存在,则有圆的字样  
396         return prefix + suffix; // 返回正确表示  
397     }  
398   
399     /** 
400      * 功能描述:去掉字符串中重复的子字符串 
401      *  
402      * @param str 
403      *            原字符串,如果有子字符串则用空格隔开以表示子字符串 
404      * @return String 返回去掉重复子字符串后的字符串 
405      */  
406    
407     private static String removeSameString(String str) {  
408         Set<String> mLinkedSet = new LinkedHashSet<String>();// set集合的特征:其子集不可以重复  
409         String[] strArray = str.split(" ");// 根据空格(正则表达式)分割字符串  
410         StringBuffer sb = new StringBuffer();  
411   
412         for (int i = 0; i < strArray.length; i++) {  
413             if (!mLinkedSet.contains(strArray[i])) {  
414                 mLinkedSet.add(strArray[i]);  
415                 sb.append(strArray[i] + " ");  
416             }  
417         }  
418         System.out.println(mLinkedSet);  
419         return sb.toString();  
420     }  
421   
422     /** 
423      * 功能描述:过滤特殊字符 
424      *  
425      * @param src 
426      * @return 
427      */  
428     public static String encoding(String src) {  
429         if (src == null)  
430             return "";  
431         StringBuilder result = new StringBuilder();  
432         if (src != null) {  
433             src = src.trim();  
434             for (int pos = 0; pos < src.length(); pos++) {  
435                 switch (src.charAt(pos)) {  
436                 case '\"':  
437                     result.append("&quot;");  
438                     break;  
439                 case '<':  
440                     result.append("&lt;");  
441                     break;  
442                 case '>':  
443                     result.append("&gt;");  
444                     break;  
445                 case '\'':  
446                     result.append("&apos;");  
447                     break;  
448                 case '&':  
449                     result.append("&amp;");  
450                     break;  
451                 case '%':  
452                     result.append("&pc;");  
453                     break;  
454                 case '_':  
455                     result.append("&ul;");  
456                     break;  
457                 case '#':  
458                     result.append("&shap;");  
459                     break;  
460                 case '?':  
461                     result.append("&ques;");  
462                     break;  
463                 default:  
464                     result.append(src.charAt(pos));  
465                     break;  
466                 }  
467             }  
468         }  
469         return result.toString();  
470     }  
471   
472     /** 
473      * 功能描述:判断是不是合法的手机号码 
474      *  
475      * @param handset 
476      * @return boolean 
477      */  
478     public static boolean isHandset(String handset) {  
479         try {  
480             String regex = "^1[\\d]{10}$";  
481             Pattern pattern = Pattern.compile(regex);  
482             Matcher matcher = pattern.matcher(handset);  
483             return matcher.matches();  
484   
485         } catch (RuntimeException e) {  
486             return false;  
487         }  
488     }  
489   
490     /** 
491      * 功能描述:反过滤特殊字符 
492      *  
493      * @param src 
494      * @return 
495      */  
496     public static String decoding(String src) {  
497         if (src == null)  
498             return "";  
499         String result = src;  
500         result = result.replace("&quot;", "\"").replace("&apos;", "\'");  
501         result = result.replace("&lt;", "<").replace("&gt;", ">");  
502         result = result.replace("&amp;", "&");  
503         result = result.replace("&pc;", "%").replace("&ul", "_");  
504         result = result.replace("&shap;", "#").replace("&ques", "?");  
505         return result;  
506     }  
507   
508     /** 
509      * @param args 
510      */  
511     public static void main(String[] args) {  
512          String source = "asdfghjklmnbvcxz";  
513          String from = "efg";  
514          String to = "china";  
515          System.out.println("在字符串source中,用to替换from,替换结果为:"  
516          + replace(from, to, source));  
517          System.out.println("返回指定字节长度的字符串:"  
518          + toLength("qwertyuioplkjhgfdsa", 9));  
519          System.out.println("判断是否为整数:" + isInteger("+0"));  
520          System.out.println("判断是否为浮点数,包括double和float:" + isDouble("+0.36"));  
521          System.out.println("判断输入的字符串是否符合Email样式:" +  
522          isEmail("[email protected]"));  
523          System.out.println("判断输入的字符串是否为纯汉字:" + isChinese("你好!"));  
524          System.out.println("判断输入的数据是否是质数:" + isPrime(12));  
525          System.out.println("人民币转换成大写:" + hangeToBig("10019658"));  
526          System.out.println("去掉字符串中重复的子字符串:" + removeSameString("100 100 9658"));  
527          System.out.println("过滤特殊字符:" + encoding("100\"s<>fdsd100 9658"));  
528          System.out.println("判断是不是合法的手机号码:" + isHandset("15981807340"));  
529          System.out.println("从字符串中取值Email:" + parse("159818 [email protected]"));  
530     }  
531 }

猜你喜欢

转载自www.cnblogs.com/borter/p/9387568.html