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