FileDocCategorySizeDatePackage
NumberHashMap.javaAPI DocJaudiotagger 2.0.48388Wed Mar 30 16:12:12 BST 2011org.jaudiotagger.tag.datatype

NumberHashMap

public class NumberHashMap extends NumberFixedLength implements HashMapInterface
Represents a number thats acts as a key into an enumeration of values

Fields Summary
private Map
keyToValue
key to value map
private Map
valueToKey
value to key map
private boolean
hasEmptyValue
Constructors Summary
public NumberHashMap(String identifier, org.jaudiotagger.tag.id3.AbstractTagFrameBody frameBody, int size)
Creates a new ObjectNumberHashMap datatype.

param
identifier
param
frameBody
param
size
throws
IllegalArgumentException



                      
          
    
        super(identifier, frameBody, size);

        if (identifier.equals(DataTypes.OBJ_GENRE))
        {
            valueToKey = GenreTypes.getInstanceOf().getValueToIdMap();
            keyToValue = GenreTypes.getInstanceOf().getIdToValueMap();

            //genres can be an id or literal value
            hasEmptyValue = true;
        }
        else if (identifier.equals(DataTypes.OBJ_TEXT_ENCODING))
        {
            valueToKey = TextEncoding.getInstanceOf().getValueToIdMap();
            keyToValue = TextEncoding.getInstanceOf().getIdToValueMap();
        }
        else if (identifier.equals(DataTypes.OBJ_INTERPOLATION_METHOD))
        {
            valueToKey = InterpolationTypes.getInstanceOf().getValueToIdMap();
            keyToValue = InterpolationTypes.getInstanceOf().getIdToValueMap();
        }
        else if (identifier.equals(DataTypes.OBJ_PICTURE_TYPE))
        {
            valueToKey = PictureTypes.getInstanceOf().getValueToIdMap();
            keyToValue = PictureTypes.getInstanceOf().getIdToValueMap();

            //Issue #224 Values should map, but have examples where they dont, this is a workaround
            hasEmptyValue = true;
        }
        else if (identifier.equals(DataTypes.OBJ_TYPE_OF_EVENT))
        {
            valueToKey = EventTimingTypes.getInstanceOf().getValueToIdMap();
            keyToValue = EventTimingTypes.getInstanceOf().getIdToValueMap();
        }
        else if (identifier.equals(DataTypes.OBJ_TIME_STAMP_FORMAT))
        {
            valueToKey = EventTimingTimestampTypes.getInstanceOf().getValueToIdMap();
            keyToValue = EventTimingTimestampTypes.getInstanceOf().getIdToValueMap();
        }
        else if (identifier.equals(DataTypes.OBJ_TYPE_OF_CHANNEL))
        {
            valueToKey = ChannelTypes.getInstanceOf().getValueToIdMap();
            keyToValue = ChannelTypes.getInstanceOf().getIdToValueMap();
        }
        else if (identifier.equals(DataTypes.OBJ_RECIEVED_AS))
        {
            valueToKey = ReceivedAsTypes.getInstanceOf().getValueToIdMap();
            keyToValue = ReceivedAsTypes.getInstanceOf().getIdToValueMap();
        }
        else if (identifier.equals(DataTypes.OBJ_CONTENT_TYPE))
        {
            valueToKey = SynchronisedLyricsContentType.getInstanceOf().getValueToIdMap();
            keyToValue = SynchronisedLyricsContentType.getInstanceOf().getIdToValueMap();
        }
        else
        {
            throw new IllegalArgumentException("Hashmap identifier not defined in this class: " + identifier);
        }
    
public NumberHashMap(NumberHashMap copyObject)

        super(copyObject);

        this.hasEmptyValue = copyObject.hasEmptyValue;

        // we don't need to clone/copy the maps here because they are static
        this.keyToValue = copyObject.keyToValue;
        this.valueToKey = copyObject.valueToKey;
    
Methods Summary
public booleanequals(java.lang.Object obj)

param
obj
return

        if(obj==this)
        {
            return true;
        }
        
        if (!(obj instanceof NumberHashMap))
        {
            return false;
        }

        NumberHashMap that = (NumberHashMap) obj;

        return
              EqualsUtil.areEqual(hasEmptyValue, that.hasEmptyValue) &&
              EqualsUtil.areEqual(keyToValue, that.keyToValue) &&
              EqualsUtil.areEqual(valueToKey, that.valueToKey) &&
              super.equals(that);
    
public java.util.MapgetKeyToValue()

return
the key to value map

        return keyToValue;
    
public java.util.MapgetValueToKey()

return
the value to key map

        return valueToKey;
    
public java.util.Iteratoriterator()

return

        if (keyToValue == null)
        {
            return null;
        }
        else
        {
            // put them in a treeset first to sort them
            TreeSet<String> treeSet = new TreeSet<String>(keyToValue.values());

            if (hasEmptyValue)
            {
                treeSet.add("");
            }

            return treeSet.iterator();
        }
    
public voidreadByteArray(byte[] arr, int offset)
Read the key from the buffer.

param
arr
param
offset
throws
InvalidDataTypeException if emptyValues are not allowed and the eky was invalid.

        super.readByteArray(arr, offset);

        //Mismatch:Superclass uses Long, but maps expect Integer
        Integer intValue = ((Long) value).intValue();
        if (!keyToValue.containsKey(intValue))
        {
            if (!hasEmptyValue)
            {
                throw new InvalidDataTypeException(ErrorMessage.MP3_REFERENCE_KEY_INVALID.getMsg(identifier, intValue));
            }
            else if (identifier.equals(DataTypes.OBJ_PICTURE_TYPE))
            {
                logger.warning(ErrorMessage.MP3_PICTURE_TYPE_INVALID.getMsg(value));
            }
        }
    
public voidsetValue(java.lang.Object value)

param
value

        if (value instanceof Byte)
        {
            this.value = (long) ((Byte) value).byteValue();
        }
        else if (value instanceof Short)
        {
            this.value = (long) ((Short) value).shortValue();
        }
        else if (value instanceof Integer)
        {
            this.value = (long) ((Integer) value).intValue();
        }
        else
        {
            this.value = value;
        }
    
public java.lang.StringtoString()

return

        if (value == null)
        {
            return "";
        }
        else if (keyToValue.get(value) == null)
        {
            return "";
        }
        else
        {
            return keyToValue.get(value);
        }