OSDN Git Service

timerIDを管理するクラスを作成.
authorspark_xp <spark_xp@d8c9ecd3-d47d-4367-8645-de82c00e513f>
Wed, 15 Sep 2010 07:10:49 +0000 (07:10 +0000)
committerspark_xp <spark_xp@d8c9ecd3-d47d-4367-8645-de82c00e513f>
Wed, 15 Sep 2010 07:10:49 +0000 (07:10 +0000)
git-svn-id: http://svn.sourceforge.jp/svnroot/nt-manager/NishioTweetManager/trunk@36 d8c9ecd3-d47d-4367-8645-de82c00e513f

nbproject/project.properties
src/twitter/task/ExistTimerIDException.java [new file with mode: 0644]
src/twitter/task/TimerID.java [new file with mode: 0644]
test/twitter/task/TimerIDTest.java [new file with mode: 0644]

index 09a685b..ec4efa4 100644 (file)
@@ -35,7 +35,6 @@ javac.target=1.6
 javac.test.classpath=\
     ${javac.classpath}:\
     ${build.classes.dir}:\
-    ${libs.junit.classpath}:\
     ${libs.junit_4.classpath}
 javadoc.additionalparam=
 javadoc.author=false
diff --git a/src/twitter/task/ExistTimerIDException.java b/src/twitter/task/ExistTimerIDException.java
new file mode 100644 (file)
index 0000000..43f6e80
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package twitter.task;
+
+/**
+ *
+ * @author nishio
+ */
+public class ExistTimerIDException extends Exception {
+
+    /**
+     * Creates a new instance of <code>ExistTimerIDException</code> without detail message.
+     */
+    public ExistTimerIDException() {
+    }
+
+
+    /**
+     * Constructs an instance of <code>ExistTimerIDException</code> with the specified detail message.
+     * @param msg the detail message.
+     */
+    public ExistTimerIDException(String msg) {
+        super(msg);
+    }
+}
diff --git a/src/twitter/task/TimerID.java b/src/twitter/task/TimerID.java
new file mode 100644 (file)
index 0000000..683e3cb
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package twitter.task;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ *
+ * @author nishio
+ */
+public class TimerID {
+    //singleton pattern
+    private static TimerID timerID;
+    //ID情報を管理するクラス
+    private Set<String> idList;
+
+    /**
+     * singleton コンストラクタ
+     */
+    private TimerID() {
+        idList = new HashSet<String>();
+    }
+
+    /**
+     * TimerIDインスタンスを取得
+     * @return
+     */
+    public static synchronized TimerID getInstance() {
+        if( timerID == null ) {
+            timerID = new TimerID();
+        }
+        return timerID;
+    }
+
+    /**
+     * 指定したIDがすでに存在するかどうか
+     * @param id
+     * @return
+     */
+    public boolean contains(String id) {
+        return idList.contains(id);
+    }
+
+    /**
+     * 利用したいIDを追加
+     * @param id
+     * @throws ExistTimerIDException 既に指定したタイマーIDが存在している
+     */
+    public void addID(String id) throws ExistTimerIDException {
+        if( contains(id) == true ) {
+            throw new ExistTimerIDException("既にそのIDは存在しています");
+        }
+        if( id == null ) {
+            throw new NullPointerException();
+        }
+        this.idList.add(id);
+    }
+
+    /**
+     * 利用していたIDを削除
+     * @param id
+     * @return idがそもそも存在していたかどうか 存在していた場合trueを返す
+     */
+    public boolean removeID(String id) {
+        return this.idList.remove(id);
+    }
+    
+    /**
+     * 情報検索の際に利用するタイマーのIDを生成
+     * @param searchWord
+     * @return
+     */
+    public static String createSearchTimerID(String searchWord) {
+        return "SEARCH:" + searchWord;
+    }
+
+    /**
+     * timelineのIDを生成
+     * @return
+     */
+    public static String createTimelineID() {
+        return "TIMELINE";
+    }
+
+    /**
+     * MentionのIDを生成
+     * @return
+     */
+    public static String createMentionID() {
+        return "MENTION";
+    }
+
+    /**
+     * DMのIDを生成
+     * @return
+     */
+    public static String createDirectMessageID() {
+        return "DIRECTMESSAGE";
+    }
+
+    /**
+     * 送信したDMのIDを生成
+     * @return
+     */
+    public static String createSendDirectMessageID() {
+        return "SENDDIRECTMESSAGE";
+    }
+}
diff --git a/test/twitter/task/TimerIDTest.java b/test/twitter/task/TimerIDTest.java
new file mode 100644 (file)
index 0000000..00e5fb1
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package twitter.task;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author nishio
+ */
+public class TimerIDTest {
+
+    public TimerIDTest() {
+    }
+
+    @BeforeClass
+    public static void setUpClass() throws Exception {
+    }
+
+    @AfterClass
+    public static void tearDownClass() throws Exception {
+    }
+
+    @Before
+    public void setUp() {
+    }
+
+    @After
+    public void tearDown() {
+    }
+
+    /**
+     * Test of contains method, of class TimerID.
+     */
+    @Test
+    public void testContains() {
+        System.out.println("contains");
+        String id = "TEST";
+        TimerID instance = TimerID.getInstance();
+        boolean expResult = false;
+        boolean result = instance.contains(id);
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of addID method, of class TimerID.
+     */
+    @Test
+    public void testAddID() throws Exception {
+        System.out.println("addID");
+        String id = "TEST";
+        TimerID instance = TimerID.getInstance();
+        instance.addID(id);
+        try {
+            //2回同じ物は追加できないはず
+            instance.addID(id);
+            fail();
+        }catch(Exception e) {
+
+        }
+    }
+
+    /**
+     * Test of removeID method, of class TimerID.
+     */
+    @Test
+    public void testRemoveID() {
+        System.out.println("removeID");
+        String id = "AIUEO";
+        TimerID instance = TimerID.getInstance();
+        boolean expResult = false;
+        boolean result = instance.removeID(id);
+        assertEquals(expResult, result);
+        try {
+            instance.addID(id);
+        } catch (ExistTimerIDException ex) {
+            Logger.getLogger(TimerIDTest.class.getName()).log(Level.SEVERE, null, ex);
+        }
+
+        result = instance.removeID(id);
+        assertEquals(true, result);
+    }
+
+    /**
+     * Test of createSearchTimerID method, of class TimerID.
+     */
+    @Test
+    public void testCreateSearchTimerID() {
+        System.out.println("createSearchTimerID");
+        String searchWord = "aiueo";
+        String expResult = "SEARCH:aiueo";
+        String result = TimerID.createSearchTimerID(searchWord);
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of createTimelineID method, of class TimerID.
+     */
+    @Test
+    public void testCreateTimelineID() {
+        System.out.println("createTimelineID");
+        String expResult = "TIMELINE";
+        String result = TimerID.createTimelineID();
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of createMentionID method, of class TimerID.
+     */
+    @Test
+    public void testCreateMentionID() {
+        System.out.println("createMentionID");
+        String expResult = "MENTION";
+        String result = TimerID.createMentionID();
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of createDirectMessageID method, of class TimerID.
+     */
+    @Test
+    public void testCreateDirectMessageID() {
+        System.out.println("createDirectMessageID");
+        String expResult = "DIRECTMESSAGE";
+        String result = TimerID.createDirectMessageID();
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of createSendDirectMessageID method, of class TimerID.
+     */
+    @Test
+    public void testCreateSendDirectMessageID() {
+        System.out.println("createSendDirectMessageID");
+        String expResult = "SENDDIRECTMESSAGE";
+        String result = TimerID.createSendDirectMessageID();
+        assertEquals(expResult, result);
+    }
+
+}
\ No newline at end of file