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;
86 default: assert false; return null;
96 public Period getPeriod(){
97 return this.homePeriod;
104 public TalkType getTalkType(){
105 return this.talkType;
112 public boolean isGrave(){
113 return this.talkType == TalkType.GRAVE;
117 * 発言種別ごとにその日(Period)の累積発言回数を返す。
121 public int getTalkCount(){
130 public int getTotalChars(){
138 public Avatar getAvatar(){
144 * 公開発言番号が割り振られてなければ0以下の値を返す。
147 public int getTalkNo(){
153 * @return 公開発言番号が割り当てられているならtrueを返す。
155 public boolean hasTalkNo(){
156 if(0 < this.talkNo) return true;
164 public String getMessageID(){
165 return this.messageID;
169 * メッセージIDからエポック秒(ms)に変換する。
170 * @return GMT 1970-01-01 00:00:00 からのエポック秒(ms)
172 public long getTimeFromID(){
173 String epoch = this.messageID.replace("mes", "");
174 long result = Long.parseLong(epoch) * 1000;
182 public int getHour(){
190 public int getMinute(){
198 public CharSequence getDialog(){
206 public void setCount(int count){
212 * この会話を識別するためのアンカー文字列を生成する。
216 public String getAnchorNotation(){
217 int day = this.homePeriod.getDay();
219 String hstr = "0"+this.hour;
220 hstr = hstr.substring(hstr.length() - 2);
221 String mstr = "0"+this.minute;
222 mstr = mstr.substring(mstr.length() - 2);
224 return day + "d" + hstr + ":" + mstr;
228 * この会話を識別するためのG国用アンカー文字列を発言番号から生成する。
229 * 例えば「{@literal >>172}」など。
230 * @return アンカー文字列。発言番号がなければ空文字列。
232 public String getAnchorNotation_G(){
233 if( ! hasTalkNo() ) return "";
234 return ">>" + this.talkNo;
241 * @return 会話のString表現
244 public String toString(){
245 StringBuilder result = new StringBuilder();
247 result.append(this.avatar.getFullName());
249 if (this.talkType == TalkType.PUBLIC) result.append(" says ");
250 else if(this.talkType == TalkType.PRIVATE) result.append(" think ");
251 else if(this.talkType == TalkType.WOLFONLY) result.append(" howl ");
252 else if(this.talkType == TalkType.GRAVE) result.append(" groan ");
254 result.append(this.dialog);
256 return result.toString();