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