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