Coverage Report - org.jaudiotagger.tag.datatype.Lyrics3TimeStamp
 
Classes in this File Line Coverage Branch Coverage Complexity
Lyrics3TimeStamp
0%
0/59
0%
0/22
1.938
 
 1  
 /**
 2  
  *  @author : Paul Taylor
 3  
  *  @author : Eric Farng
 4  
  *
 5  
  *  Version @version:$Id: Lyrics3TimeStamp.java,v 1.8 2008/07/21 10:45:41 paultaylor Exp $
 6  
  *
 7  
  *  MusicTag Copyright (C)2003,2004
 8  
  *
 9  
  *  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
 10  
  *  General Public  License as published by the Free Software Foundation; either version 2.1 of the License,
 11  
  *  or (at your option) any later version.
 12  
  *
 13  
  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 14  
  *  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 15  
  *  See the GNU Lesser General Public License for more details.
 16  
  *
 17  
  *  You should have received a copy of the GNU Lesser General Public License along with this library; if not,
 18  
  *  you can get a copy from http://www.opensource.org/licenses/lgpl-license.php or write to the Free Software
 19  
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 20  
  *
 21  
  * Description:
 22  
  *
 23  
  */
 24  
 package org.jaudiotagger.tag.datatype;
 25  
 
 26  
 import org.jaudiotagger.audio.generic.Utils;
 27  
 import org.jaudiotagger.tag.InvalidDataTypeException;
 28  
 import org.jaudiotagger.tag.id3.AbstractTagFrameBody;
 29  
 
 30  
 public class Lyrics3TimeStamp extends AbstractDataType
 31  
 {
 32  
     /**
 33  
      *
 34  
      */
 35  0
     private long minute = 0;
 36  
 
 37  
     /**
 38  
      *
 39  
      */
 40  0
     private long second = 0;
 41  
 
 42  
     /**
 43  
      * Todo this is wrong
 44  
      */
 45  
     public void readString(String s)
 46  
     {
 47  0
     }
 48  
 
 49  
     /**
 50  
      * Creates a new ObjectLyrics3TimeStamp datatype.
 51  
      *
 52  
      * @param identifier
 53  
      */
 54  
     public Lyrics3TimeStamp(String identifier, AbstractTagFrameBody frameBody)
 55  
     {
 56  0
         super(identifier, frameBody);
 57  0
     }
 58  
 
 59  
     public Lyrics3TimeStamp(String identifier)
 60  
     {
 61  0
         super(identifier, null);
 62  0
     }
 63  
 
 64  
     public Lyrics3TimeStamp(Lyrics3TimeStamp copy)
 65  
     {
 66  0
         super(copy);
 67  0
         this.minute = copy.minute;
 68  0
         this.second = copy.second;
 69  0
     }
 70  
 
 71  
     public void setMinute(long minute)
 72  
     {
 73  0
         this.minute = minute;
 74  0
     }
 75  
 
 76  
     /**
 77  
      * @return
 78  
      */
 79  
     public long getMinute()
 80  
     {
 81  0
         return minute;
 82  
     }
 83  
 
 84  
     public void setSecond(long second)
 85  
     {
 86  0
         this.second = second;
 87  0
     }
 88  
 
 89  
     /**
 90  
      * @return
 91  
      */
 92  
     public long getSecond()
 93  
     {
 94  0
         return second;
 95  
     }
 96  
 
 97  
     /**
 98  
      * @return
 99  
      */
 100  
     public int getSize()
 101  
     {
 102  0
         return 7;
 103  
     }
 104  
 
 105  
     /**
 106  
      * Creates a new ObjectLyrics3TimeStamp datatype.
 107  
      *
 108  
      * @param timeStamp
 109  
      * @param timeStampFormat
 110  
      */
 111  
     public void setTimeStamp(long timeStamp, byte timeStampFormat)
 112  
     {
 113  
         /**
 114  
          * @todo convert both types of formats
 115  
          */
 116  0
         timeStamp = timeStamp / 1000;
 117  0
         minute = timeStamp / 60;
 118  0
         second = timeStamp % 60;
 119  0
     }
 120  
 
 121  
     /**
 122  
      * @param obj
 123  
      * @return
 124  
      */
 125  
     public boolean equals(Object obj)
 126  
     {
 127  0
         if ((obj instanceof Lyrics3TimeStamp) == false)
 128  
         {
 129  0
             return false;
 130  
         }
 131  
 
 132  0
         Lyrics3TimeStamp object = (Lyrics3TimeStamp) obj;
 133  
 
 134  0
         if (this.minute != object.minute)
 135  
         {
 136  0
             return false;
 137  
         }
 138  
 
 139  0
         if (this.second != object.second)
 140  
         {
 141  0
             return false;
 142  
         }
 143  
 
 144  0
         return super.equals(obj);
 145  
     }
 146  
 
 147  
     /**
 148  
      * @param timeStamp
 149  
      * @param offset
 150  
      * @throws NullPointerException
 151  
      * @throws IndexOutOfBoundsException
 152  
      */
 153  
     public void readString(String timeStamp, int offset)
 154  
     {
 155  0
         if (timeStamp == null)
 156  
         {
 157  0
             throw new NullPointerException("Image is null");
 158  
         }
 159  
 
 160  0
         if ((offset < 0) || (offset >= timeStamp.length()))
 161  
         {
 162  0
             throw new IndexOutOfBoundsException("Offset to timeStamp is out of bounds: offset = " + offset + ", timeStamp.length()" + timeStamp.length());
 163  
         }
 164  
 
 165  0
         timeStamp = timeStamp.substring(offset);
 166  
 
 167  0
         if (timeStamp.length() == 7)
 168  
         {
 169  0
             minute = Integer.parseInt(timeStamp.substring(1, 3));
 170  0
             second = Integer.parseInt(timeStamp.substring(4, 6));
 171  
         }
 172  
         else
 173  
         {
 174  0
             minute = 0;
 175  0
             second = 0;
 176  
         }
 177  0
     }
 178  
 
 179  
     /**
 180  
      * @return
 181  
      */
 182  
     public String toString()
 183  
     {
 184  0
         return writeString();
 185  
     }
 186  
 
 187  
     /**
 188  
      * @return
 189  
      */
 190  
     public String writeString()
 191  
     {
 192  
         String str;
 193  0
         str = "[";
 194  
 
 195  0
         if (minute < 0)
 196  
         {
 197  0
             str += "00";
 198  
         }
 199  
         else
 200  
         {
 201  0
             if (minute < 10)
 202  
             {
 203  0
                 str += '0';
 204  
             }
 205  
 
 206  0
             str += Long.toString(minute);
 207  
         }
 208  
 
 209  0
         str += ':';
 210  
 
 211  0
         if (second < 0)
 212  
         {
 213  0
             str += "00";
 214  
         }
 215  
         else
 216  
         {
 217  0
             if (second < 10)
 218  
             {
 219  0
                 str += '0';
 220  
             }
 221  
 
 222  0
             str += Long.toString(second);
 223  
         }
 224  
 
 225  0
         str += ']';
 226  
 
 227  0
         return str;
 228  
     }
 229  
 
 230  
     public void readByteArray(byte[] arr, int offset) throws InvalidDataTypeException
 231  
     {
 232  0
         readString(arr.toString(), offset);
 233  0
     }
 234  
 
 235  
     public byte[] writeByteArray()
 236  
     {
 237  0
         return Utils.getDefaultBytes(writeString(), "ISO8859-1");
 238  
     }
 239  
 
 240  
 }