Coverage Report - org.jaudiotagger.tag.datatype.BooleanByte
 
Classes in this File Line Coverage Branch Coverage Complexity
BooleanByte
0%
0/32
0%
0/20
2.375
 
 1  
 /**
 2  
  *  @author : Paul Taylor
 3  
  *  @author : Eric Farng
 4  
  *
 5  
  *  Version @version:$Id: BooleanByte.java,v 1.9 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.tag.InvalidDataTypeException;
 27  
 import org.jaudiotagger.tag.id3.AbstractTagFrameBody;
 28  
 
 29  
 /**
 30  
  * Represents a bit flag within a byte
 31  
  */
 32  
 public class BooleanByte extends AbstractDataType
 33  
 {
 34  
     /**
 35  
      *
 36  
      */
 37  0
     int bitPosition = -1;
 38  
 
 39  
     /**
 40  
      * Creates a new ObjectBooleanByte datatype.
 41  
      *
 42  
      * @param identifier
 43  
      * @param bitPosition
 44  
      * @throws IndexOutOfBoundsException
 45  
      */
 46  
     public BooleanByte(String identifier, AbstractTagFrameBody frameBody, int bitPosition)
 47  
     {
 48  0
         super(identifier, frameBody);
 49  0
         if ((bitPosition < 0) || (bitPosition > 7))
 50  
         {
 51  0
             throw new IndexOutOfBoundsException("Bit position needs to be from 0 - 7 : " + bitPosition);
 52  
         }
 53  
 
 54  0
         this.bitPosition = bitPosition;
 55  0
     }
 56  
 
 57  
     public BooleanByte(BooleanByte copy)
 58  
     {
 59  0
         super(copy);
 60  0
         this.bitPosition = copy.bitPosition;
 61  0
     }
 62  
 
 63  
     /**
 64  
      * @return
 65  
      */
 66  
     public int getBitPosition()
 67  
     {
 68  0
         return bitPosition;
 69  
     }
 70  
 
 71  
     /**
 72  
      * @return
 73  
      */
 74  
     public int getSize()
 75  
     {
 76  0
         return 1;
 77  
     }
 78  
 
 79  
     /**
 80  
      * @param obj
 81  
      * @return
 82  
      */
 83  
     public boolean equals(Object obj)
 84  
     {
 85  0
         if ((obj instanceof BooleanByte) == false)
 86  
         {
 87  0
             return false;
 88  
         }
 89  
 
 90  0
         BooleanByte object = (BooleanByte) obj;
 91  
 
 92  0
         if (this.bitPosition != object.bitPosition)
 93  
         {
 94  0
             return false;
 95  
         }
 96  
 
 97  0
         return super.equals(obj);
 98  
     }
 99  
 
 100  
     /**
 101  
      * @param arr
 102  
      * @param offset
 103  
      * @throws NullPointerException
 104  
      * @throws IndexOutOfBoundsException
 105  
      */
 106  
     public void readByteArray(byte[] arr, int offset) throws InvalidDataTypeException
 107  
     {
 108  0
         if (arr == null)
 109  
         {
 110  0
             throw new NullPointerException("Byte array is null");
 111  
         }
 112  
 
 113  0
         if ((offset < 0) || (offset >= arr.length))
 114  
         {
 115  0
             throw new IndexOutOfBoundsException("Offset to byte array is out of bounds: offset = " + offset + ", array.length = " + arr.length);
 116  
         }
 117  
 
 118  0
         byte newValue = arr[offset];
 119  
 
 120  0
         newValue >>= bitPosition;
 121  0
         newValue &= 0x1;
 122  0
         this.value = newValue == 1;
 123  0
     }
 124  
 
 125  
     /**
 126  
      * @return
 127  
      */
 128  
     public String toString()
 129  
     {
 130  0
         return "" + value;
 131  
     }
 132  
 
 133  
     /**
 134  
      * @return
 135  
      */
 136  
     public byte[] writeByteArray()
 137  
     {
 138  
         byte[] retValue;
 139  
 
 140  0
         retValue = new byte[1];
 141  
 
 142  0
         if (value != null)
 143  
         {
 144  0
             retValue[0] = (byte) (((Boolean) value).booleanValue() ? 1 : 0);
 145  0
             retValue[0] <<= bitPosition;
 146  
         }
 147  
 
 148  0
         return retValue;
 149  
     }
 150  
 }