Coverage Report - org.jaudiotagger.audio.asf.data.LanguageList
 
Classes in this File Line Coverage Branch Coverage Complexity
LanguageList
50%
12/24
33%
2/6
1.5
 
 1  
 package org.jaudiotagger.audio.asf.data;
 2  
 
 3  
 import org.jaudiotagger.audio.asf.util.Utils;
 4  
 import org.jaudiotagger.logging.ErrorMessage;
 5  
 
 6  
 import java.math.BigInteger;
 7  
 import java.util.ArrayList;
 8  
 import java.util.List;
 9  
 
 10  
 /**
 11  
  * This structure represents the data of the ASF language object.<br>
 12  
  * The language list is simply a listing of language codes which should comply
 13  
  * to RFC-1766.<br>
 14  
  * <b>Consider:</b> the index of a language is used by other entries in the ASF
 15  
  * metadata. 
 16  
  * 
 17  
  * @author Christian Laireiter
 18  
  */
 19  
 public class LanguageList extends Chunk {
 20  
 
 21  
     /**
 22  
      * List of language codes, complying RFC-1766
 23  
      */
 24  24
     private final List<String> languages = new ArrayList<String>();
 25  
 
 26  
     /**
 27  
      * Creates a new instance.<br>
 28  
      */
 29  
     public LanguageList() {
 30  0
         super(GUID.GUID_LANGUAGE_LIST, 0, BigInteger.ZERO);
 31  0
     }
 32  
 
 33  
     /**
 34  
      * Creates an instance.
 35  
      * 
 36  
      * @param pos
 37  
      *            position within the ASF file.
 38  
      * @param size
 39  
      *            size of the chunk
 40  
      */
 41  
     public LanguageList(final long pos, final BigInteger size) {
 42  40
         super(GUID.GUID_LANGUAGE_LIST, pos, size);
 43  24
     }
 44  
 
 45  
     /**
 46  
      * This method adds a language.<br>
 47  
      * 
 48  
      * @param language
 49  
      *            language code
 50  
      */
 51  
     public void addLanguage(final String language) {
 52  516
         if (language.length() < MetadataDescriptor.MAX_LANG_INDEX) {
 53  516
             if (!this.languages.contains(language)) {
 54  516
                 this.languages.add(language);
 55  
             }
 56  
         } else {
 57  0
             throw new IllegalArgumentException(
 58  
                     ErrorMessage.WMA_LENGTH_OF_LANGUAGE_IS_TOO_LARGE
 59  
                             .getMsg(language.length() * 2 + 2));
 60  
         }
 61  516
     }
 62  
 
 63  
     /**
 64  
      * Returns the language code at the specified index.
 65  
      * 
 66  
      * @param index
 67  
      *            the index of the language code to get.
 68  
      * @return the language code at given index.
 69  
      */
 70  
     public String getLanguage(final int index) {
 71  512
         return this.languages.get(index);
 72  
     }
 73  
 
 74  
     /**
 75  
      * Returns the amount of stored language codes.
 76  
      * 
 77  
      * @return number of stored language codes.
 78  
      */
 79  
     public int getLanguageCount() {
 80  516
         return this.languages.size();
 81  
     }
 82  
 
 83  
     /**
 84  
      * Returns all language codes in list.
 85  
      * 
 86  
      * @return list of language codes.
 87  
      */
 88  
     public List<String> getLanguages() {
 89  1016
         return new ArrayList<String>(this.languages);
 90  
     }
 91  
 
 92  
     /**
 93  
      * {@inheritDoc}
 94  
      */
 95  
     @Override
 96  
     public String prettyPrint(final String prefix) {
 97  0
         final StringBuilder result = new StringBuilder(super.prettyPrint(prefix));
 98  0
         for (int i = 0; i < getLanguageCount(); i++) {
 99  0
             result.append(prefix);
 100  0
             result.append("  |-> ");
 101  0
             result.append(i);
 102  0
             result.append(" : ");
 103  0
             result.append(getLanguage(i));
 104  0
             result.append(Utils.LINE_SEPARATOR);
 105  
         }
 106  0
         return result.toString();
 107  
     }
 108  
 
 109  
     /**
 110  
      * Removes the language entry at specified index.
 111  
      * 
 112  
      * @param index
 113  
      *            index of language to remove.
 114  
      */
 115  
     public void removeLanguage(final int index) {
 116  4
         this.languages.remove(index);
 117  4
     }
 118  
 }