Coverage Report - org.jaudiotagger.audio.asf.tag.AsfTagTextField
 
Classes in this File Line Coverage Branch Coverage Complexity
AsfTagTextField
73%
11/15
25%
1/4
1.571
 
 1  
 package org.jaudiotagger.audio.asf.tag;
 2  
 
 3  
 import org.jaudiotagger.audio.asf.data.AsfHeader;
 4  
 import org.jaudiotagger.audio.asf.data.ContentDescriptor;
 5  
 import org.jaudiotagger.audio.asf.util.Utils;
 6  
 import org.jaudiotagger.tag.TagTextField;
 7  
 
 8  
 /**
 9  
  * Represents a tag text field for ASF fields.<br> 
 10  
  * 
 11  
  * @author Christian Laireiter
 12  
  */
 13  
 public class AsfTagTextField extends AsfTagField implements TagTextField
 14  
 {
 15  
 
 16  
     /**
 17  
      * Creates an instance.
 18  
      * 
 19  
      * @param source The content descriptor, whose content is published.<br> Must not be of type {@link ContentDescriptor#TYPE_BINARY}.
 20  
      */
 21  
     public AsfTagTextField(ContentDescriptor source)
 22  
     {
 23  800
         super(source);
 24  800
         if (source.getType() == ContentDescriptor.TYPE_BINARY)
 25  
         {
 26  0
             throw new IllegalArgumentException("Cannot interpret binary as string.");
 27  
         }
 28  800
     }
 29  
 
 30  
     /**
 31  
      * Creates a tag text field and assigns the string value.
 32  
      * @param fieldKey The fields identifier.
 33  
      * @param value the value to assign.
 34  
      */
 35  
     public AsfTagTextField(String fieldKey, String value)
 36  
     {
 37  1779
         super(new ContentDescriptor(fieldKey, ContentDescriptor.TYPE_STRING));
 38  1779
         setContent(value);
 39  1779
     }
 40  
 
 41  
     /**
 42  
      * {@inheritDoc}
 43  
      */
 44  
     public String getContent()
 45  
     {
 46  2915
         return getDescriptor().getString();
 47  
     }
 48  
 
 49  
     /**
 50  
      * {@inheritDoc}
 51  
      */
 52  
     public String getEncoding()
 53  
     {
 54  4
         return AsfHeader.ASF_CHARSET.name();
 55  
     }
 56  
 
 57  
     /**
 58  
      * {@inheritDoc}
 59  
      */
 60  
     public void setContent(String content)
 61  
     {
 62  1779
         getDescriptor().setStringValue(content);
 63  1779
     }
 64  
 
 65  
     /**
 66  
      * {@inheritDoc}
 67  
      */
 68  
     public void setEncoding(String encoding)
 69  
     {
 70  0
         if (!AsfHeader.ASF_CHARSET.name().equals(encoding))
 71  
         {
 72  0
             throw new IllegalArgumentException("Only UTF-16LE is possible with ASF.");
 73  
         }
 74  0
     }
 75  
 
 76  
      /**
 77  
      * @return true if blank or only contains whitespoace
 78  
      */
 79  
     public boolean isEmpty()
 80  
     {
 81  1152
         return Utils.isBlank(getContent());
 82  
     }
 83  
 }