Coverage Report - org.jaudiotagger.tag.datatype.Lyrics3Line
 
Classes in this File Line Coverage Branch Coverage Complexity
Lyrics3Line
0%
0/67
0%
0/24
0
 
 1  
 /**
 2  
  *  @author : Paul Taylor
 3  
  *  @author : Eric Farng
 4  
  *
 5  
  *  Version @version:$Id: Lyrics3Line.java,v 1.10 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  
 import java.util.Iterator;
 31  
 import java.util.LinkedList;
 32  
 
 33  
 public class Lyrics3Line extends AbstractDataType
 34  
 {
 35  
     /**
 36  
      *
 37  
      */
 38  0
     private LinkedList<Lyrics3TimeStamp> timeStamp = new LinkedList<Lyrics3TimeStamp>();
 39  
 
 40  
     /**
 41  
      *
 42  
      */
 43  0
     private String lyric = "";
 44  
 
 45  
     /**
 46  
      * Creates a new ObjectLyrics3Line datatype.
 47  
      *
 48  
      * @param identifier
 49  
      */
 50  
     public Lyrics3Line(String identifier, AbstractTagFrameBody frameBody)
 51  
     {
 52  0
         super(identifier, frameBody);
 53  0
     }
 54  
 
 55  
     public Lyrics3Line(Lyrics3Line copy)
 56  
     {
 57  0
         super(copy);
 58  0
         this.lyric = new String(copy.lyric);
 59  
         Lyrics3TimeStamp newTimeStamp;
 60  0
         for (int i = 0; i < copy.timeStamp.size(); i++)
 61  
         {
 62  0
             newTimeStamp = new Lyrics3TimeStamp(copy.timeStamp.get(i));
 63  0
             this.timeStamp.add(newTimeStamp);
 64  
         }
 65  0
     }
 66  
 
 67  
     public void setLyric(String lyric)
 68  
     {
 69  0
         this.lyric = lyric;
 70  0
     }
 71  
 
 72  
     public void setLyric(ID3v2LyricLine line)
 73  
     {
 74  0
         this.lyric = line.getText();
 75  0
     }
 76  
 
 77  
     /**
 78  
      * @return
 79  
      */
 80  
     public String getLyric()
 81  
     {
 82  0
         return lyric;
 83  
     }
 84  
 
 85  
     /**
 86  
      * @return
 87  
      */
 88  
     public int getSize()
 89  
     {
 90  0
         int size = 0;
 91  0
         for (Object aTimeStamp : timeStamp)
 92  
         {
 93  0
             size += ((Lyrics3TimeStamp) aTimeStamp).getSize();
 94  
         }
 95  0
         return size + lyric.length();
 96  
     }
 97  
 
 98  
     /**
 99  
      * @param time
 100  
      */
 101  
     public void setTimeStamp(Lyrics3TimeStamp time)
 102  
     {
 103  0
         timeStamp.clear();
 104  0
         timeStamp.add(time);
 105  0
     }
 106  
 
 107  
     /**
 108  
      * @return
 109  
      */
 110  
     public Iterator<Lyrics3TimeStamp> getTimeStamp()
 111  
     {
 112  0
         return timeStamp.iterator();
 113  
     }
 114  
 
 115  
     public void addLyric(String newLyric)
 116  
     {
 117  0
         this.lyric += newLyric;
 118  0
     }
 119  
 
 120  
     public void addLyric(ID3v2LyricLine line)
 121  
     {
 122  0
         this.lyric += line.getText();
 123  0
     }
 124  
 
 125  
     /**
 126  
      * @param time
 127  
      */
 128  
     public void addTimeStamp(Lyrics3TimeStamp time)
 129  
     {
 130  0
         timeStamp.add(time);
 131  0
     }
 132  
 
 133  
     /**
 134  
      * @param obj
 135  
      * @return
 136  
      */
 137  
     public boolean equals(Object obj)
 138  
     {
 139  0
         if ((obj instanceof Lyrics3Line) == false)
 140  
         {
 141  0
             return false;
 142  
         }
 143  0
         Lyrics3Line object = (Lyrics3Line) obj;
 144  0
         if (this.lyric.equals(object.lyric) == false)
 145  
         {
 146  0
             return false;
 147  
         }
 148  0
         if (this.timeStamp.equals(object.timeStamp) == false)
 149  
         {
 150  0
             return false;
 151  
         }
 152  0
         return super.equals(obj);
 153  
     }
 154  
 
 155  
     /**
 156  
      * @return
 157  
      */
 158  
     public boolean hasTimeStamp()
 159  
     {
 160  0
         if (timeStamp.isEmpty())
 161  
         {
 162  0
             return false;
 163  
         }
 164  0
         return true;
 165  
     }
 166  
 
 167  
     /**
 168  
      * @param lineString
 169  
      * @param offset
 170  
      * @throws NullPointerException
 171  
      * @throws IndexOutOfBoundsException
 172  
      */
 173  
     public void readString(String lineString, int offset)
 174  
     {
 175  0
         if (lineString == null)
 176  
         {
 177  0
             throw new NullPointerException("Image is null");
 178  
         }
 179  0
         if ((offset < 0) || (offset >= lineString.length()))
 180  
         {
 181  0
             throw new IndexOutOfBoundsException("Offset to line is out of bounds: offset = " + offset + ", line.length()" + lineString.length());
 182  
         }
 183  0
         int delim = 0;
 184  
         Lyrics3TimeStamp time;
 185  0
         timeStamp = new LinkedList<Lyrics3TimeStamp>();
 186  0
         delim = lineString.indexOf("[", offset);
 187  0
         while (delim >= 0)
 188  
         {
 189  0
             offset = lineString.indexOf("]", delim) + 1;
 190  0
             time = new Lyrics3TimeStamp("Time Stamp");
 191  0
             time.readString(lineString.substring(delim, offset));
 192  0
             timeStamp.add(time);
 193  0
             delim = lineString.indexOf("[", offset);
 194  
         }
 195  0
         lyric = lineString.substring(offset);
 196  0
     }
 197  
 
 198  
     /**
 199  
      * @return
 200  
      */
 201  
     public String toString()
 202  
     {
 203  0
         String str = "";
 204  0
         for (Object aTimeStamp : timeStamp)
 205  
         {
 206  0
             str += aTimeStamp.toString();
 207  
         }
 208  0
         return "timeStamp = " + str + ", lyric = " + lyric + "\n";
 209  
     }
 210  
 
 211  
     /**
 212  
      * @return
 213  
      */
 214  
     public String writeString()
 215  
     {
 216  0
         String str = "";
 217  
         Lyrics3TimeStamp time;
 218  0
         for (Object aTimeStamp : timeStamp)
 219  
         {
 220  0
             time = (Lyrics3TimeStamp) aTimeStamp;
 221  0
             str += time.writeString();
 222  
         }
 223  0
         return str + lyric;
 224  
     }
 225  
 
 226  
     public void readByteArray(byte[] arr, int offset) throws InvalidDataTypeException
 227  
     {
 228  0
         readString(arr.toString(), offset);
 229  0
     }
 230  
 
 231  
     public byte[] writeByteArray()
 232  
     {
 233  0
         return Utils.getDefaultBytes(writeString(), "ISO8859-1");
 234  
     }
 235  
 }