Coverage Report - org.jaudiotagger.audio.asf.data.StreamBitratePropertiesChunk
 
Classes in this File Line Coverage Branch Coverage Complexity
StreamBitratePropertiesChunk
41%
7/17
0%
0/4
1.5
 
 1  
 /*
 2  
  * Entagged Audio Tag library
 3  
  * Copyright (c) 2004-2005 Christian Laireiter <liree@web.de>
 4  
  * 
 5  
  * This library is free software; you can redistribute it and/or
 6  
  * modify it under the terms of the GNU Lesser General Public
 7  
  * License as published by the Free Software Foundation; either
 8  
  * version 2.1 of the License, or (at your option) any later version.
 9  
  *  
 10  
  * This library is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
  * Lesser General Public License for more details.
 14  
  * 
 15  
  * You should have received a copy of the GNU Lesser General Public
 16  
  * License along with this library; if not, write to the Free Software
 17  
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 18  
  */
 19  
 package org.jaudiotagger.audio.asf.data;
 20  
 
 21  
 import org.jaudiotagger.audio.asf.util.Utils;
 22  
 
 23  
 import java.math.BigInteger;
 24  
 import java.util.ArrayList;
 25  
 import java.util.List;
 26  
 
 27  
 /**
 28  
  * This class represents the "Stream Bitrate Properties" chunk of an ASF media
 29  
  * file. <br>
 30  
  * It is optional, but contains useful information about the streams bitrate.<br>
 31  
  * 
 32  
  * @author Christian Laireiter
 33  
  */
 34  
 public class StreamBitratePropertiesChunk extends Chunk {
 35  
 
 36  
     /**
 37  
      * For each call of {@link #addBitrateRecord(int,long)} an {@link Long}
 38  
      * object is appended, which represents the average bitrate.
 39  
      */
 40  
     private final List<Long> bitRates;
 41  
 
 42  
     /**
 43  
      * For each call of {@link #addBitrateRecord(int,long)} an {@link Integer}
 44  
      * object is appended, which represents the stream-number.
 45  
      */
 46  
     private final List<Integer> streamNumbers;
 47  
 
 48  
     /**
 49  
      * Creates an instance.
 50  
      * 
 51  
      * @param chunkLen
 52  
      *            Length of current chunk.
 53  
      */
 54  
     public StreamBitratePropertiesChunk(final BigInteger chunkLen) {
 55  80
         super(GUID.GUID_STREAM_BITRATE_PROPERTIES, chunkLen);
 56  80
         this.bitRates = new ArrayList<Long>();
 57  80
         this.streamNumbers = new ArrayList<Integer>();
 58  80
     }
 59  
 
 60  
     /**
 61  
      * Adds the public values of a stream-record.
 62  
      * 
 63  
      * @param streamNum
 64  
      *            The number of the referred stream.
 65  
      * @param averageBitrate
 66  
      *            Its average bitrate.
 67  
      */
 68  
     public void addBitrateRecord(final int streamNum, final long averageBitrate) {
 69  80
         this.streamNumbers.add(streamNum);
 70  80
         this.bitRates.add(averageBitrate);
 71  80
     }
 72  
 
 73  
     /**
 74  
      * Returns the average bitrate of the given stream.<br>
 75  
      * 
 76  
      * @param streamNumber
 77  
      *            Number of the stream whose bitrate to determine.
 78  
      * @return The average bitrate of the numbered stream. <code>-1</code> if no
 79  
      *         information was given.
 80  
      */
 81  
     public long getAvgBitrate(final int streamNumber) {
 82  0
         final Integer seach = streamNumber;
 83  0
         final int index = this.streamNumbers.indexOf(seach);
 84  
         long result;
 85  0
         if (index == -1) {
 86  0
             result = -1;
 87  
         } else {
 88  0
             result = this.bitRates.get(index);
 89  
         }
 90  0
         return result;
 91  
     }
 92  
 
 93  
     /**
 94  
      * (overridden)
 95  
      * 
 96  
      * @see org.jaudiotagger.audio.asf.data.Chunk#prettyPrint(String)
 97  
      */
 98  
     @Override
 99  
     public String prettyPrint(final String prefix) {
 100  0
         final StringBuilder result = new StringBuilder(super.prettyPrint(prefix));
 101  0
         for (int i = 0; i < this.bitRates.size(); i++) {
 102  0
             result.append(prefix).append("  |-> Stream no. \"").append(
 103  
                     this.streamNumbers.get(i)).append(
 104  
                     "\" has an average bitrate of \"").append(
 105  
                     this.bitRates.get(i)).append('"').append(
 106  
                     Utils.LINE_SEPARATOR);
 107  
         }
 108  0
         return result.toString();
 109  
     }
 110  
 
 111  
 }