Coverage Report - org.jaudiotagger.tag.asf.AsfTagField
 
Classes in this File Line Coverage Branch Coverage Complexity
AsfTagField
76%
20/26
33%
6/18
1.308
 
 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.tag.asf;
 20  
 
 21  
 import org.jaudiotagger.audio.asf.data.MetadataDescriptor;
 22  
 import org.jaudiotagger.tag.TagField;
 23  
 import org.jaudiotagger.tag.asf.AsfFieldKey;
 24  
 import org.jaudiotagger.tag.asf.AsfTag;
 25  
 
 26  
 /**
 27  
  * This class encapsulates a
 28  
  * {@link org.jaudiotagger.audio.asf.data.MetadataDescriptor}and provides access
 29  
  * to it. <br>
 30  
  * The metadata descriptor used for construction is copied.
 31  
  * 
 32  
  * @author Christian Laireiter (liree)
 33  
  */
 34  4
 public class AsfTagField implements TagField, Cloneable {
 35  
 
 36  
     /**
 37  
      * This descriptor is wrapped.
 38  
      */
 39  
     protected MetadataDescriptor toWrap;
 40  
 
 41  
     /**
 42  
      * Creates a tag field.
 43  
      * 
 44  
      * @param field
 45  
      *            the ASF field that should be represented.
 46  
      */
 47  40
     public AsfTagField(final AsfFieldKey field) {
 48  40
         assert field != null;
 49  40
         this.toWrap = new MetadataDescriptor(field.getHighestContainer(), field
 50  
                 .getFieldName(), MetadataDescriptor.TYPE_STRING);
 51  40
     }
 52  
 
 53  
     /**
 54  
      * Creates an instance.
 55  
      * 
 56  
      * @param source
 57  
      *            The descriptor which should be represented as a
 58  
      *            {@link TagField}.
 59  
      */
 60  5529
     public AsfTagField(final MetadataDescriptor source) {
 61  5529
         assert source != null;
 62  
         // XXX Copy ? maybe not really.
 63  5529
         this.toWrap = source.createCopy();
 64  5529
     }
 65  
 
 66  
     /**
 67  
      * Creates a tag field.
 68  
      * 
 69  
      * @param fieldKey
 70  
      *            The field identifier to use.
 71  
      */
 72  773
     public AsfTagField(final String fieldKey) {
 73  773
         assert fieldKey != null;
 74  773
         this.toWrap = new MetadataDescriptor(AsfFieldKey.getAsfFieldKey(
 75  
                 fieldKey).getHighestContainer(), fieldKey,
 76  
                 MetadataDescriptor.TYPE_STRING);
 77  773
     }
 78  
 
 79  
     /**
 80  
      * {@inheritDoc}
 81  
      */
 82  
     @Override
 83  
     public Object clone() throws CloneNotSupportedException {
 84  8393
         return super.clone();
 85  
     }
 86  
 
 87  
     /**
 88  
      * {@inheritDoc}
 89  
      */
 90  
     public void copyContent(final TagField field) {
 91  0
         throw new UnsupportedOperationException("Not implemented yet.");
 92  
     }
 93  
 
 94  
     /**
 95  
      * Returns the wrapped metadata descriptor (which actually stores the
 96  
      * values).
 97  
      * 
 98  
      * @return the wrapped metadata descriptor
 99  
      */
 100  
     public MetadataDescriptor getDescriptor() {
 101  16879
         return this.toWrap;
 102  
     }
 103  
 
 104  
     /**
 105  
      * {@inheritDoc}
 106  
      */
 107  
     public String getId() {
 108  37710
         return this.toWrap.getName();
 109  
     }
 110  
 
 111  
     /**
 112  
      * {@inheritDoc}
 113  
      */
 114  
     public byte[] getRawContent() {
 115  4288
         return this.toWrap.getRawData();
 116  
     }
 117  
 
 118  
     /**
 119  
      * {@inheritDoc}
 120  
      */
 121  
     public boolean isBinary() {
 122  0
         return this.toWrap.getType() == MetadataDescriptor.TYPE_BINARY;
 123  
     }
 124  
 
 125  
     /**
 126  
      * {@inheritDoc}
 127  
      */
 128  
     public void isBinary(final boolean value) {
 129  0
         if (!value && isBinary()) {
 130  0
             throw new UnsupportedOperationException("No conversion supported.");
 131  
         }
 132  0
         this.toWrap.setBinaryValue(this.toWrap.getRawData());
 133  0
     }
 134  
 
 135  
     /**
 136  
      * {@inheritDoc}
 137  
      */
 138  
     public boolean isCommon() {
 139  
         // HashSet is safe against null comparison
 140  7966
         return AsfTag.COMMON_FIELDS.contains(AsfFieldKey
 141  
                 .getAsfFieldKey(getId()));
 142  
     }
 143  
 
 144  
     /**
 145  
      * {@inheritDoc}
 146  
      */
 147  
     public boolean isEmpty() {
 148  96
         return this.toWrap.isEmpty();
 149  
     }
 150  
 
 151  
     /**
 152  
      * {@inheritDoc}
 153  
      */
 154  
     @Override
 155  
     public String toString() {
 156  1341
         return this.toWrap.getString();
 157  
     }
 158  
 
 159  
 }