001/**
002 * Copyright 2014 Tampere University of Technology, Pori Department
003 * 
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * 
008 *   http://www.apache.org/licenses/LICENSE-2.0
009 * 
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package service.tut.pori.facebookjazz;
017
018import javax.xml.bind.annotation.XmlAccessType;
019import javax.xml.bind.annotation.XmlAccessorType;
020import javax.xml.bind.annotation.XmlElement;
021import javax.xml.bind.annotation.XmlEnum;
022import javax.xml.bind.annotation.XmlRootElement;
023
024/**
025 * A user defined weight modifier.
026 * 
027 * <h3>XML Example</h3>
028 * 
029 * {@doc.restlet service="[service.tut.pori.facebookjazz.reference.Definitions#SERVICE_FBJ_REFERENCE_EXAMPLE]" method="[service.tut.pori.facebookjazz.Definitions#ELEMENT_WEIGHT_MODIFIER]" type="GET" query="" body_uri=""}
030 * 
031 */
032@XmlRootElement(name=Definitions.ELEMENT_WEIGHT_MODIFIER)
033@XmlAccessorType(XmlAccessType.NONE)
034public class WeightModifier {
035  @XmlElement(name=Definitions.ELEMENT_VALUE)
036  private Integer _value = null;
037  @XmlElement(name=Definitions.ELEMENT_WEIGHT_MODIFIER_TYPE)
038  private WeightModifierType _type = null;
039  
040  /**
041   * content weight type
042   * 
043   */
044  @XmlEnum
045  public enum WeightModifierType{
046    /** 
047     * Facebook group name 
048     * 
049     * @see service.tut.pori.facebookjazz.FacebookGroup#getWName()
050     */
051    GROUP__NAME(1),
052    /** 
053     * Facebook group description 
054     * 
055     * @see service.tut.pori.facebookjazz.FacebookGroup#getWDescription()
056     */
057    GROUP__DESCRIPTION(2),
058    /**
059     * Facebook status message
060     * 
061     * @see service.tut.pori.facebookjazz.FacebookStatusMessage#getWMessage()
062     */
063    STATUS_MESSAGE__MESSAGE(3),
064    /**
065     * Facebook status message comments
066     * 
067     * @see service.tut.pori.facebookjazz.FacebookStatusMessage#getMessageComments()
068     * @see service.tut.pori.facebookjazz.FacebookComment#getWMessage()
069     */
070    STATUS_MESSAGE__COMMENT_MESSAGE(4),
071    /**
072     * Facebook photo description
073     * 
074     * @see service.tut.pori.facebookjazz.FacebookPhotoDescription#getWDescription()
075     */
076    PHOTO_DESCRIPTION__DESCRIPTION(5),
077    /**
078     * Facebook photo description comments
079     * 
080     * @see service.tut.pori.facebookjazz.FacebookPhotoDescription#getDescriptionComments()
081     * @see service.tut.pori.facebookjazz.FacebookComment#getWMessage()
082     */
083    PHOTO_DESCRIPTION__COMMENT_MESSAGE(6),
084    /**
085     * Facebook video description
086     * 
087     * @see service.tut.pori.facebookjazz.FacebookVideoDescription#getWDescription()
088     */
089    VIDEO_DESCRIPTION__DESCRIPTION(7),
090    /**
091     * Facebook video description comments
092     * 
093     * @see service.tut.pori.facebookjazz.FacebookVideoDescription#getDescriptionComments()
094     * @see service.tut.pori.facebookjazz.FacebookComment#getWMessage()
095     */
096    VIDEO_DESCRIPTION__COMMENT_MESSAGE(8),
097    /**
098     * Facebook event name
099     * 
100     * @see service.tut.pori.facebookjazz.FacebookEvent#getWName()
101     */
102    EVENT__NAME(9),
103    /**
104     * Facebook event description
105     * 
106     * @see service.tut.pori.facebookjazz.FacebookEvent#getWDescription()
107     */
108    EVENT__DESCRIPTION(10);
109  
110    private int _value;
111    
112    /**
113     * 
114     * @param value
115     */
116    private WeightModifierType(int value){
117      _value = value;
118    }
119    
120    /**
121     * 
122     * @return the modifier as integer
123     */
124    public int toInt(){
125      return _value;
126    }
127    
128    /**
129     * 
130     * @param value
131     * @return the value converted to modifier type
132     * @throws IllegalArgumentException
133     */
134    public static WeightModifierType fromInt(int value) throws IllegalArgumentException{
135      for(WeightModifierType t : values()){
136        if(t._value == value){
137          return t;
138        }
139      }
140      throw new IllegalArgumentException("Bad "+WeightModifierType.class.toString()+" : "+value);
141    }
142  } //enum ContentWeightType
143
144  /**
145   * @return the value
146   * @see #setValue(Integer)
147   */
148  public Integer getValue() {
149    return _value;
150  }
151
152  /**
153   * @param value the value to set
154   * @see #getValue()
155   */
156  public void setValue(Integer value) {
157    _value = value;
158  }
159
160  /**
161   * @return the type
162   * @see #setType(WeightModifierType)
163   */
164  public WeightModifierType getType() {
165    return _type;
166  }
167
168  /**
169   * @param type the type to set
170   * @see #getType()
171   */
172  public void setType(WeightModifierType type) {
173    _type = type;
174  }
175  
176  /**
177   * for sub-classing, use the static
178   * 
179   * @return true if the modifier is valid
180   * @see #isValid(WeightModifier)
181   */
182  protected boolean isValid(){
183    if(_type == null || _value == null){
184      return false;
185    }else{
186      return true;
187    }
188  }
189  
190  /**
191   * 
192   * @param modifier
193   * @return false if modifier is null, contains invalid modifiers
194   */
195  public static boolean isValid(WeightModifier modifier){
196    return (modifier == null ? false : modifier.isValid());
197  }
198
199  @Override
200  public int hashCode() {
201    final int prime = 31;
202    int result = 1;
203    result = prime * result + ((_type == null) ? 0 : _type.hashCode());
204    result = prime * result + ((_value == null) ? 0 : _value.hashCode());
205    return result;
206  }
207
208  @Override
209  public boolean equals(Object obj) {
210    if (this == obj)
211      return true;
212    if (obj == null)
213      return false;
214    if (getClass() != obj.getClass())
215      return false;
216    WeightModifier other = (WeightModifier) obj;
217    if (_type != other._type)
218      return false;
219    if (_value == null) {
220      if (other._value != null)
221        return false;
222    } else if (!_value.equals(other._value))
223      return false;
224    return true;
225  }
226  
227  /**
228   * for serialization
229   */
230  @SuppressWarnings("unused")
231  private WeightModifier(){
232    // nothing needed
233  }
234  
235  /**
236   * 
237   * @param type
238   * @param value
239   */
240  public WeightModifier(WeightModifierType type, Integer value){
241    _type = type;
242    _value = value;
243  }
244}