View Javadoc

1   package cz.cuni.amis.pogamut.emohawk.agent.module.sensomotoric;
2   
3   /**
4    * Represents bot emoticon. Bot emoticon consists from up to three emoticons and
5    * background bubble.
6    * 
7    * @author knight
8    */
9   public class Emoticon {
10      /** default bubble for emoticons */
11      private static EmoticonBubbleType DEFAULT_BUBBLE = EmoticonBubbleType.BUBBLE_THOUGHT_CENTER;
12      /** Left emoticon */
13      private EmoticonType leftEmoticon;
14      /** Center emoticon */
15      private EmoticonType centerEmoticon;
16      /** Right emoticon */
17      private EmoticonType rightEmoticon;
18      /** Bubble of the emoticon */
19      private EmoticonBubbleType bubble;
20      /**
21       * Through this we determine type of the emoticon - double emoticon has to have left and right
22       * emoticon type set - emoticonCount will be 2. Single emoticon has to have center emoticon set
23       * emoticonCount will be 1, triple emoticon has to have all emoticon types set - 
24       * emoticonCount will be 3. EmoticonCount 0 means that there is no emoticon set.
25       */
26      private int emoticonCount = 0;
27  
28      public EmoticonBubbleType getBubble() {
29          return bubble;
30      }
31  
32      public EmoticonType getCenterEmoticon() {
33          return centerEmoticon;
34      }
35  
36      public EmoticonType getLeftEmoticon() {
37          return leftEmoticon;
38      }
39  
40      public EmoticonType getRightEmoticon() {
41          return rightEmoticon;
42      }
43  
44      public int getEmoticonCount() {
45          return emoticonCount;
46      }
47      
48      /**
49       * Returns all 3 emoticons as currently displayed by you (displayed from LEFT-to-RIGHT).
50       * 
51       * 0 emoticons displayed: returns []
52       * 
53       * 1 emoticon displayed: returns [CENTER]
54       * 
55       * 2 emoticons displayed: returns [LEFT, RIGHT]
56       * 
57       * 3 emoticons displayed: returns [LEFT, CENTER, RIGHT]
58       * 
59       * @return array of [left, center, right] emoticon being displayed, NONE emoticons are omitted!
60       */
61      public EmoticonType[] getEmoticonTypes() {
62      	switch(getEmoticonCount()) {
63      	case 0:
64      		return new EmoticonType[0];
65      		
66      	case 1:
67      		return new EmoticonType[]{getCenterEmoticon()};
68      	
69      	case 2:
70      		return new EmoticonType[]{getLeftEmoticon(), getRightEmoticon()};
71      		
72      	case 3:
73      		return new EmoticonType[]{getLeftEmoticon(), getCenterEmoticon(), getRightEmoticon()};
74  
75      	default:
76      		throw new RuntimeException("Emoticon returned wrong emoticon count = " + getEmoticonCount() + " !!!");
77      	}
78  
79      }
80  
81      /**
82       * Triple emoticon constructor - has to have all three emoticons set.
83       * @param leftEmoticon
84       * @param centerEmoticon
85       * @param rightEmoticon
86       * @param bubble
87       */
88      public Emoticon(EmoticonType leftEmoticon, EmoticonType centerEmoticon, EmoticonType rightEmoticon, EmoticonBubbleType bubble) {
89          this.leftEmoticon = leftEmoticon;       
90          this.centerEmoticon = centerEmoticon;        
91          this.rightEmoticon = rightEmoticon;
92          if (leftEmoticon != null && rightEmoticon != null && centerEmoticon != null && leftEmoticon != EmoticonType.NONE && rightEmoticon != EmoticonType.NONE && centerEmoticon != EmoticonType.NONE)
93              emoticonCount = 3;
94          else if (leftEmoticon != null && rightEmoticon != null && leftEmoticon != EmoticonType.NONE && rightEmoticon != EmoticonType.NONE)
95              emoticonCount = 2;
96          else if (centerEmoticon != null && centerEmoticon != EmoticonType.NONE)
97              emoticonCount = 1;
98          this.bubble = bubble;
99          if (bubble == null || bubble == EmoticonBubbleType.NONE)
100             bubble = DEFAULT_BUBBLE;
101     }
102 
103     /**
104      * Single emoticon constructor - sets center emoticon type.
105      * @param centerEmoticon
106      * @param bubble
107      */
108     public Emoticon(EmoticonType centerEmoticon, EmoticonBubbleType bubble) {
109         this.centerEmoticon = centerEmoticon;
110         if (centerEmoticon != null && centerEmoticon != EmoticonType.NONE)
111             emoticonCount = 1;
112         this.bubble = bubble;  
113         if (bubble == null || bubble == EmoticonBubbleType.NONE)
114             bubble = DEFAULT_BUBBLE;
115     }
116 
117     /**
118      * Double emoticon constructor - sets left and right emoticon (only way to display
119      * double emoticon).
120      * @param leftEmoticon
121      * @param rightEmoticon
122      * @param bubble
123      */
124     public Emoticon(EmoticonType leftEmoticon, EmoticonType rightEmoticon, EmoticonBubbleType bubble) {
125         this.leftEmoticon = leftEmoticon;
126         this.rightEmoticon = rightEmoticon;
127         if (leftEmoticon != null && rightEmoticon != null && leftEmoticon != EmoticonType.NONE && rightEmoticon != EmoticonType.NONE)
128             emoticonCount = 2;
129         this.bubble = bubble;
130         if (bubble == null || bubble == EmoticonBubbleType.NONE)
131             bubble = DEFAULT_BUBBLE;
132     }
133 
134     @Override
135     public boolean equals(Object obj) {
136         if (obj == null) {
137             return false;
138         }
139         if (getClass() != obj.getClass()) {
140             return false;
141         }
142         final Emoticon other = (Emoticon) obj;
143         if (this.leftEmoticon != other.leftEmoticon) {
144             return false;
145         }
146         if (this.centerEmoticon != other.centerEmoticon) {
147             return false;
148         }
149         if (this.rightEmoticon != other.rightEmoticon) {
150             return false;
151         }
152         if (this.bubble != other.bubble) {
153             return false;
154         }
155         if (this.emoticonCount != other.emoticonCount) {
156             return false;
157         }
158         return true;
159     }
160 
161     @Override
162     public int hashCode() {
163         int hash = 5;
164         hash = 11 * hash + (this.leftEmoticon != null ? this.leftEmoticon.hashCode() : 0);
165         hash = 11 * hash + (this.centerEmoticon != null ? this.centerEmoticon.hashCode() : 0);
166         hash = 11 * hash + (this.rightEmoticon != null ? this.rightEmoticon.hashCode() : 0);
167         hash = 11 * hash + (this.bubble != null ? this.bubble.hashCode() : 0);
168         hash = 11 * hash + this.emoticonCount;
169         return hash;
170     }
171     
172     @Override
173     public String toString() {
174     	return "Emoticon[left=" + leftEmoticon + ", center=" + centerEmoticon + ", right=" + rightEmoticon + ", bubble=" + bubble + "]";
175     }
176 
177 }