4 * License : The MIT License
5 * Copyright(c) 2008 olyutorskii
8 package jp.sfjp.jindolf.data;
10 import jp.sourceforge.jindolf.corelib.TalkType;
15 public class Talk implements Topic{
17 private final Period homePeriod;
18 private final TalkType talkType;
19 private final Avatar avatar;
20 private final int talkNo;
21 private final String messageID;
22 private final int hour;
23 private final int minute;
24 private final CharSequence dialog;
25 private final int charNum;
26 private int count = -1;
31 * @param homePeriod 発言元Period
32 * @param talkType 発言種別
33 * @param avatar Avatar
34 * @param talkNo 公開発言番号。公開発言でないなら0以下の値を指定。
35 * @param messageID メッセージID
40 public Talk(Period homePeriod,
46 CharSequence dialog ){
47 if( homePeriod == null
51 || dialog == null ) throw new NullPointerException();
52 if(hour < 0 || 23 < hour ) throw new IllegalArgumentException();
53 if(minute < 0 || 59 < minute) throw new IllegalArgumentException();
54 if(talkType != TalkType.PUBLIC){
55 if(0 < talkNo) throw new IllegalArgumentException();
58 this.homePeriod = homePeriod;
59 this.talkType = talkType;
62 this.messageID = messageID;
67 this.charNum = this.dialog.length();
78 public static String encodeColorName(TalkType type){
82 case PUBLIC: result = "白"; break;
83 case PRIVATE: result = "灰"; break;
84 case WOLFONLY: result = "赤"; break;
85 case GRAVE: result = "青"; break;
98 public Period getPeriod(){
99 return this.homePeriod;
106 public TalkType getTalkType(){
107 return this.talkType;
114 public boolean isGrave(){
115 return this.talkType == TalkType.GRAVE;
119 * 発言種別ごとにその日(Period)の累積発言回数を返す。
123 public int getTalkCount(){
132 public int getTotalChars(){
140 public Avatar getAvatar(){
146 * 公開発言番号が割り振られてなければ0以下の値を返す。
149 public int getTalkNo(){
155 * @return 公開発言番号が割り当てられているならtrueを返す。
157 public boolean hasTalkNo(){
158 if(0 < this.talkNo) return true;
166 public String getMessageID(){
167 return this.messageID;
171 * メッセージIDからエポック秒(ms)に変換する。
172 * @return GMT 1970-01-01 00:00:00 からのエポック秒(ms)
174 public long getTimeFromID(){
175 String epoch = this.messageID.replace("mes", "");
176 long result = Long.parseLong(epoch) * 1000;
184 public int getHour(){
192 public int getMinute(){
200 public CharSequence getDialog(){
208 public void setCount(int count){
214 * この会話を識別するためのアンカー文字列を生成する。
218 public String getAnchorNotation(){
219 int day = this.homePeriod.getDay();
221 String hstr = "0"+this.hour;
222 hstr = hstr.substring(hstr.length() - 2);
223 String mstr = "0"+this.minute;
224 mstr = mstr.substring(mstr.length() - 2);
226 return day + "d" + hstr + ":" + mstr;
230 * この会話を識別するためのG国用アンカー文字列を発言番号から生成する。
231 * 例えば「{@literal >>172}」など。
232 * @return アンカー文字列。発言番号がなければ空文字列。
234 public String getAnchorNotation_G(){
235 if( ! hasTalkNo() ) return "";
236 return ">>" + this.talkNo;
243 * @return 会話のString表現
246 public String toString(){
247 StringBuilder result = new StringBuilder();
249 result.append(this.avatar.getFullName());
251 if (this.talkType == TalkType.PUBLIC) result.append(" says ");
252 else if(this.talkType == TalkType.PRIVATE) result.append(" think ");
253 else if(this.talkType == TalkType.WOLFONLY) result.append(" howl ");
254 else if(this.talkType == TalkType.GRAVE) result.append(" groan ");
256 result.append(this.dialog);
258 return result.toString();