OSDN Git Service

timerIDを管理するクラスを作成.
[nt-manager/nt-manager.git] / src / twitter / task / TimerID.java
1 /*
2  * To change this template, choose Tools | Templates
3  * and open the template in the editor.
4  */
5
6 package twitter.task;
7
8 import java.util.HashSet;
9 import java.util.Set;
10
11 /**
12  *
13  * @author nishio
14  */
15 public class TimerID {
16     //singleton pattern
17     private static TimerID timerID;
18     //ID情報を管理するクラス
19     private Set<String> idList;
20
21     /**
22      * singleton コンストラクタ
23      */
24     private TimerID() {
25         idList = new HashSet<String>();
26     }
27
28     /**
29      * TimerIDインスタンスを取得
30      * @return
31      */
32     public static synchronized TimerID getInstance() {
33         if( timerID == null ) {
34             timerID = new TimerID();
35         }
36         return timerID;
37     }
38
39     /**
40      * 指定したIDがすでに存在するかどうか
41      * @param id
42      * @return
43      */
44     public boolean contains(String id) {
45         return idList.contains(id);
46     }
47
48     /**
49      * 利用したいIDを追加
50      * @param id
51      * @throws ExistTimerIDException 既に指定したタイマーIDが存在している
52      */
53     public void addID(String id) throws ExistTimerIDException {
54         if( contains(id) == true ) {
55             throw new ExistTimerIDException("既にそのIDは存在しています");
56         }
57         if( id == null ) {
58             throw new NullPointerException();
59         }
60         this.idList.add(id);
61     }
62
63     /**
64      * 利用していたIDを削除
65      * @param id
66      * @return idがそもそも存在していたかどうか 存在していた場合trueを返す
67      */
68     public boolean removeID(String id) {
69         return this.idList.remove(id);
70     }
71     
72     /**
73      * 情報検索の際に利用するタイマーのIDを生成
74      * @param searchWord
75      * @return
76      */
77     public static String createSearchTimerID(String searchWord) {
78         return "SEARCH:" + searchWord;
79     }
80
81     /**
82      * timelineのIDを生成
83      * @return
84      */
85     public static String createTimelineID() {
86         return "TIMELINE";
87     }
88
89     /**
90      * MentionのIDを生成
91      * @return
92      */
93     public static String createMentionID() {
94         return "MENTION";
95     }
96
97     /**
98      * DMのIDを生成
99      * @return
100      */
101     public static String createDirectMessageID() {
102         return "DIRECTMESSAGE";
103     }
104
105     /**
106      * 送信したDMのIDを生成
107      * @return
108      */
109     public static String createSendDirectMessageID() {
110         return "SENDDIRECTMESSAGE";
111     }
112 }