欢迎进入Java社区论坛,与200万技术人员互动交流 >>进入
/IrregularVerbs/src/com/b510/irregularverbs/utils/CommonUtil.java
1 /**
2 *
3 */
4 package com.b510.irregularverbs.utils;
5
6 /**
7 * @author Hongten
8 * @created Feb 27, 2014
9 */
10 public class CommonUtil {
11
12 //Commands
13 public static final String EXIT = “exit”;
14 public static final String PRONUNCIATION = “pronunciation”;
15 public static final String ALL = “all”;
16 //Description
17 public static final String DESCRIPTION = “Please input a Irregular Verb or Command:\n[e.g: ‘came’, ‘all’, ‘pronunciation’, ‘exit’]”;
18 public static final String EXIT_SYSTEM = “exited system.”;
19 public static final String LOADIGN_VERBS = “After loading vocabulary!”;
20
21 public static final String NO_MATCHED = “No matched!”;
22 public static final String ADVICE = “You may want to search the follow word(s):”;
23 public static final String SPEND = “Spend >> [“;
24 public static final String SPEND_END = “]ms”;
25
26 public static final int STR_SIZE = 25;
27 public static final String COMMA = “,”;
28 public static final String EMPTY = “”;
29 public static final String BLANK = ” “;
30
31 public static final String LINE_ONE = “=====================”;
32 public static final String LINE_TWO = LINE_ONE + LINE_ONE;
33 public static final String LINE_THREE = LINE_TWO+ “\n”;
34 }
/IrregularVerbs/src/com/b510/irregularverbs/utils/IrregularVerbUtil.java
1 /**
2 *
3 */
4 package com.b510.irregularverbs.utils;
5
6 import java.util.ArrayList;
7 import java.util.List;
8
9 import com.b510.irregularverbs.lib.VocabularyLib;
10 import com.b510.irregularverbs.vo.IrregularVerbsVO;
11
12 /**
13 * The tool for the Irregular Verbs. Providing load and reload methods to get all irregular verbs.
14 * it also provide the match method to handle the content, which user input in the console.
15 * and display the result of matching.
16 * @author Hongten
17 * @created Feb 27, 2014
18 */
19 public class IrregularVerbUtil {
20
21 private static IrregularVerbUtil irregularVerbs = new IrregularVerbUtil();
22 public static List verbs = new ArrayList();
23 // The switch of the pronunciation
24 public static boolean proFlag = false;
25
26 /**
27 * Load all of the irregular verbs.
28 * @return all of the irregular verbs.
29 */
30 public static List loadIrregularVerbsVOs() {
31 return VocabularyLib.getVocabularyLib();
32 }
33
34 private IrregularVerbUtil() {
35 }
36
37 public static IrregularVerbUtil getInstance() {
38 if (verbs.size() <= 0) {
39 loadIrregularVerbsVOs();
40 }
41 return irregularVerbs;
42 }
43
44 /**
45 * Reload all of the irregular verbs.
46 */
47 public static void reLoadVerbs() {
48 verbs = null;
49 verbs = new ArrayList();
50 loadIrregularVerbsVOs();
51 PrintUtil.printInfo(CommonUtil.LOADIGN_VERBS);
52 PrintUtil.printInfo(CommonUtil.LINE_THREE);
53 }
54
55 /**
56 * Processing the input content,and display the result for matching.
57 * @param input input content.
58 */
59 public void match(String input) {
60 long startTime = System.currentTimeMillis();
61 List temp = new ArrayList();
62 List mayBeVOs = new ArrayList();
63 for (IrregularVerbsVO vo : verbs) {
64 handleMatchWord(input, temp, vo);
65 // match same word(s)
66 input = input.toLowerCase();
67 if (vo.getPrototype().startsWith(input) || vo.getPostTense().startsWith(input) || vo.getPostParticiple().startsWith(input)) {
68 mayBeVOs.add(vo);
[1][2][3][4][5][6][7]
天再高又怎样,踮起脚尖就更接近阳光。