001/**
002 * Copyright 2015 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.contentanalysis.video;
017
018import javax.xml.bind.annotation.XmlAccessType;
019import javax.xml.bind.annotation.XmlAccessorType;
020import javax.xml.bind.annotation.XmlElement;
021import javax.xml.bind.annotation.XmlRootElement;
022
023/**
024 * A media object time code. If start is null and end is not null, end is used for start, and vice versa.
025 * 
026 * <h3>XML Example</h3>
027 * 
028 * {@doc.restlet service="[service.tut.pori.contentanalysis.video.reference.Definitions#SERVICE_VCA_REFERENCE_EXAMPLE]" method="[service.tut.pori.contentanalysis.video.Definitions#ELEMENT_TIMECODE]" type="GET" query="" body_uri=""}
029 * 
030 */
031@XmlRootElement(name=Definitions.ELEMENT_TIMECODE)
032@XmlAccessorType(value=XmlAccessType.NONE)
033public class Timecode {
034  private Double _start = null;
035  private Double _end = null;
036
037  /**
038   * only for sub-classing, use the static.
039   * 
040   * @return true if the timecode is valid
041   * @see #isValid(Timecode)
042   */
043  protected boolean isValid(){
044    return (_start != null || _end != null);
045  }
046  
047  /**
048   * 
049   * @param timecode
050   * @return true if the time code is valid and not null
051   */
052  public static boolean isValid(Timecode timecode){
053    return (timecode == null ? false : timecode.isValid());
054  }
055
056  /**
057   * @return the start
058   * @see #setStart(Double)
059   */
060  @XmlElement(name = Definitions.ELEMENT_TIMECODE_START)
061  public Double getStart() {
062    return (_start == null ? _end : _start);
063  }
064
065  /**
066   * @param start the start to set
067   * @see #getStart()
068   */
069  public void setStart(Double start) {
070    _start = start;
071  }
072
073  /**
074   * @return the end
075   * @see #setEnd(Double)
076   */
077  @XmlElement(name = Definitions.ELEMENT_TIMECODE_END)
078  public Double getEnd() {
079    return (_end == null ? _start : _end);
080  }
081
082  /**
083   * @param end the end to set
084   * @see #getEnd()
085   */
086  public void setEnd(Double end) {
087    _end = end;
088  }
089  
090  /**
091   * 
092   */
093  public Timecode(){
094    // nothing needed
095  }
096  
097  /**
098   * 
099   * @param start
100   * @param end
101   */
102  public Timecode(Double start, Double end){
103    _start = start;
104    _end = end;
105  }
106}