Coverage Report - org.jaudiotagger.tag.id3.framebody.FrameBodyPCNT
 
Classes in this File Line Coverage Branch Coverage Complexity
FrameBodyPCNT
88%
14/16
N/A
1
 
 1  
 /*
 2  
  *  MusicTag Copyright (C)2003,2004
 3  
  *
 4  
  *  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
 5  
  *  General Public  License as published by the Free Software Foundation; either version 2.1 of the License,
 6  
  *  or (at your option) any later version.
 7  
  *
 8  
  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 9  
  *  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 10  
  *  See the GNU Lesser General Public License for more details.
 11  
  *
 12  
  *  You should have received a copy of the GNU Lesser General Public License along with this library; if not,
 13  
  *  you can get a copy from http://www.opensource.org/licenses/lgpl-license.php or write to the Free Software
 14  
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 15  
  */
 16  
 package org.jaudiotagger.tag.id3.framebody;
 17  
 
 18  
 import org.jaudiotagger.tag.InvalidTagException;
 19  
 import org.jaudiotagger.tag.datatype.DataTypes;
 20  
 import org.jaudiotagger.tag.datatype.NumberVariableLength;
 21  
 import org.jaudiotagger.tag.id3.ID3v24Frames;
 22  
 
 23  
 import java.nio.ByteBuffer;
 24  
 
 25  
 /**
 26  
  * Play counter frame.
 27  
  * <p/>
 28  
  * <p/>
 29  
  * This is simply a counter of the number of times a file has been
 30  
  * played. The value is increased by one every time the file begins to
 31  
  * play. There may only be one "PCNT" frame in each tag. When the
 32  
  * counter reaches all one's, one byte is inserted in front of the
 33  
  * counter thus making the counter eight bits bigger. The counter must
 34  
  * be at least 32-bits long to begin with.
 35  
  * </p><p><table border=0 width="70%">
 36  
  * <tr><td colspan=2> &lt;Header for 'Play counter', ID: "PCNT"&gt;</td></tr>
 37  
  * <tr><td>Counter </td><td>$xx xx xx xx (xx ...)</td></tr>
 38  
  * </table></p>
 39  
  * <p/>
 40  
  * <p>For more details, please refer to the ID3 specifications:
 41  
  * <ul>
 42  
  * <li><a href="http://www.id3.org/id3v2.3.0.txt">ID3 v2.3.0 Spec</a>
 43  
  * </ul>
 44  
  *
 45  
  * @author : Paul Taylor
 46  
  * @author : Eric Farng
 47  
  * @version $Id: FrameBodyPCNT.java,v 1.14 2008/07/21 10:45:42 paultaylor Exp $
 48  
  */
 49  
 public class FrameBodyPCNT extends AbstractID3v2FrameBody implements ID3v24FrameBody, ID3v23FrameBody
 50  
 {
 51  
     private static final int COUNTER_MINIMUM_FIELD_SIZE = 4;
 52  
 
 53  
     /**
 54  
      * Creates a new FrameBodyPCNT datatype.
 55  
      */
 56  
     public FrameBodyPCNT()
 57  6
     {
 58  6
         this.setObjectValue(DataTypes.OBJ_NUMBER, 0L);
 59  6
     }
 60  
 
 61  
     public FrameBodyPCNT(FrameBodyPCNT body)
 62  
     {
 63  0
         super(body);
 64  0
     }
 65  
 
 66  
     /**
 67  
      * Creates a new FrameBodyPCNT datatype.
 68  
      *
 69  
      * @param counter
 70  
      */
 71  
     public FrameBodyPCNT(long counter)
 72  4
     {
 73  4
         this.setObjectValue(DataTypes.OBJ_NUMBER, counter);
 74  4
     }
 75  
 
 76  
     /**
 77  
      * Creates a new FrameBodyPCNT datatype.
 78  
      *
 79  
      * @throws InvalidTagException if unable to create framebody from buffer
 80  
      */
 81  
     public FrameBodyPCNT(ByteBuffer byteBuffer, int frameSize) throws InvalidTagException
 82  
     {
 83  2
         super(byteBuffer, frameSize);
 84  2
     }
 85  
 
 86  
     /**
 87  
      * @return the play count of this file
 88  
      */
 89  
     public long getCounter()
 90  
     {
 91  6
         return ((Number) getObjectValue(DataTypes.OBJ_NUMBER)).longValue();
 92  
     }
 93  
 
 94  
     /**
 95  
      * Set the play counter of this file
 96  
      *
 97  
      * @param counter
 98  
      */
 99  
     public void setCounter(long counter)
 100  
     {
 101  1
         setObjectValue(DataTypes.OBJ_NUMBER, counter);
 102  1
     }
 103  
 
 104  
     /**
 105  
      * The ID3v2 frame identifier
 106  
      *
 107  
      * @return the ID3v2 frame identifier  for this frame type
 108  
      */
 109  
     public String getIdentifier()
 110  
     {
 111  10
         return ID3v24Frames.FRAME_ID_PLAY_COUNTER;
 112  
     }
 113  
 
 114  
     /**
 115  
      *
 116  
      */
 117  
     protected void setupObjectList()
 118  
     {
 119  12
         objectList.add(new NumberVariableLength(DataTypes.OBJ_NUMBER, this, COUNTER_MINIMUM_FIELD_SIZE));
 120  12
     }
 121  
 }