Coverage Report - org.jaudiotagger.tag.id3.ID3v1Iterator
 
Classes in this File Line Coverage Branch Coverage Complexity
ID3v1Iterator
0%
0/35
0%
0/72
7.333
 
 1  
 /**
 2  
  *  @author : Paul Taylor
 3  
  *  @author : Eric Farng
 4  
  *
 5  
  *  Version @version:$Id: ID3v1Iterator.java,v 1.6 2008/01/01 15:14:22 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.id3;
 25  
 
 26  
 import java.util.Iterator;
 27  
 import java.util.NoSuchElementException;
 28  
 
 29  
 
 30  
 public class ID3v1Iterator implements Iterator
 31  
 {
 32  
     /**
 33  
      *
 34  
      */
 35  
     private static final int TITLE = 1;
 36  
 
 37  
     /**
 38  
      *
 39  
      */
 40  
     private static final int ARTIST = 2;
 41  
 
 42  
     /**
 43  
      *
 44  
      */
 45  
     private static final int ALBUM = 3;
 46  
 
 47  
     /**
 48  
      *
 49  
      */
 50  
     private static final int COMMENT = 4;
 51  
 
 52  
     /**
 53  
      *
 54  
      */
 55  
     private static final int YEAR = 5;
 56  
 
 57  
     /**
 58  
      *
 59  
      */
 60  
     private static final int GENRE = 6;
 61  
 
 62  
     /**
 63  
      *
 64  
      */
 65  
     private static final int TRACK = 7;
 66  
 
 67  
     /**
 68  
      *
 69  
      */
 70  
     private ID3v1Tag id3v1tag;
 71  
 
 72  
     /**
 73  
      *
 74  
      */
 75  0
     private int lastIndex = 0;
 76  
 
 77  
     /**
 78  
      * Creates a new ID3v1Iterator datatype.
 79  
      *
 80  
      * @param id3v1tag
 81  
      */
 82  
     public ID3v1Iterator(ID3v1Tag id3v1tag)
 83  0
     {
 84  0
         this.id3v1tag = id3v1tag;
 85  0
     }
 86  
 
 87  
     /**
 88  
      * @return
 89  
      */
 90  
     public boolean hasNext()
 91  
     {
 92  0
         return hasNext(lastIndex);
 93  
     }
 94  
 
 95  
     /**
 96  
      * @return
 97  
      */
 98  
     public Object next()
 99  
     {
 100  0
         return next(lastIndex);
 101  
     }
 102  
 
 103  
     /**
 104  
      *
 105  
      */
 106  
     public void remove()
 107  
     {
 108  0
         switch (lastIndex)
 109  
         {
 110  
             case TITLE:
 111  0
                 id3v1tag.title = "";
 112  
 
 113  
             case ARTIST:
 114  0
                 id3v1tag.artist = "";
 115  
 
 116  
             case ALBUM:
 117  0
                 id3v1tag.album = "";
 118  
 
 119  
             case COMMENT:
 120  0
                 id3v1tag.comment = "";
 121  
 
 122  
             case YEAR:
 123  0
                 id3v1tag.year = "";
 124  
 
 125  
             case GENRE:
 126  0
                 id3v1tag.genre = (byte) -1;
 127  
 
 128  
             case TRACK:
 129  
 
 130  0
                 if (id3v1tag instanceof ID3v11Tag)
 131  
                 {
 132  0
                     ((ID3v11Tag) id3v1tag).track = (byte) -1;
 133  
                 }
 134  
         }
 135  0
     }
 136  
 
 137  
     /**
 138  
      * @param index
 139  
      * @return
 140  
      */
 141  
     private boolean hasNext(int index)
 142  
     {
 143  0
         switch (index)
 144  
         {
 145  
             case TITLE:
 146  0
                 return (id3v1tag.title.length() > 0) || hasNext(index + 1);
 147  
 
 148  
             case ARTIST:
 149  0
                 return (id3v1tag.artist.length() > 0) || hasNext(index + 1);
 150  
 
 151  
             case ALBUM:
 152  0
                 return (id3v1tag.album.length() > 0) || hasNext(index + 1);
 153  
 
 154  
             case COMMENT:
 155  0
                 return (id3v1tag.comment.length() > 0) || hasNext(index + 1);
 156  
 
 157  
             case YEAR:
 158  0
                 return (id3v1tag.year.length() > 0) || hasNext(index + 1);
 159  
 
 160  
             case GENRE:
 161  0
                 return (id3v1tag.genre >= (byte) 0) || hasNext(index + 1);
 162  
 
 163  
             case TRACK:
 164  
 
 165  0
                 if (id3v1tag instanceof ID3v11Tag)
 166  
                 {
 167  0
                     return (((ID3v11Tag) id3v1tag).track >= (byte) 0) || hasNext(index + 1);
 168  
                 }
 169  
 
 170  
             default:
 171  0
                 return false;
 172  
         }
 173  
     }
 174  
 
 175  
     /**
 176  
      * @param index
 177  
      * @return
 178  
      * @throws NoSuchElementException
 179  
      */
 180  
     private Object next(int index)
 181  
     {
 182  0
         switch (lastIndex)
 183  
         {
 184  
             case 0:
 185  0
                 return (id3v1tag.title.length() > 0) ? id3v1tag.title : next(index + 1);
 186  
 
 187  
             case TITLE:
 188  0
                 return (id3v1tag.artist.length() > 0) ? id3v1tag.artist : next(index + 1);
 189  
 
 190  
             case ARTIST:
 191  0
                 return (id3v1tag.album.length() > 0) ? id3v1tag.album : next(index + 1);
 192  
 
 193  
             case ALBUM:
 194  0
                 return (id3v1tag.comment.length() > 0) ? id3v1tag.comment : next(index + 1);
 195  
 
 196  
             case COMMENT:
 197  0
                 return (id3v1tag.year.length() > 0) ? id3v1tag.year : next(index + 1);
 198  
 
 199  
             case YEAR:
 200  0
                 return (id3v1tag.genre >= (byte) 0) ? id3v1tag.genre : next(index + 1);
 201  
 
 202  
             case GENRE:
 203  0
                 return (id3v1tag instanceof ID3v11Tag && (((ID3v11Tag) id3v1tag).track >= (byte) 0)) ? ((ID3v11Tag) id3v1tag).track : null;
 204  
 
 205  
             default:
 206  0
                 throw new NoSuchElementException("Iteration has no more elements.");
 207  
         }
 208  
     }
 209  
 }