2
* @author : Paul Taylor
5
* Version @version:$Id: StringHashMap.java,v 1.12 2008/07/21 10:45:41 paultaylor Exp $
7
* MusicTag Copyright (C)2003,2004
9
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
10
* General Public License as published by the Free Software Foundation; either version 2.1 of the License,
11
* or (at your option) any later version.
13
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
14
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
* See the GNU Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public License along with this library; if not,
18
* you can get a copy from http://www.opensource.org/licenses/lgpl-license.php or write to the Free Software
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
package org.jaudiotagger.tag.datatype;
26
import org.jaudiotagger.tag.id3.AbstractTagFrameBody;
27
import org.jaudiotagger.tag.id3.valuepair.TextEncoding;
28
import org.jaudiotagger.tag.reference.Languages;
30
import java.util.Iterator;
32
import java.util.TreeSet;
36
* Represents a String thats acts as a key into an enumeration of values. The String will be encoded
37
* using the default encoding regardless of what encoding may be specified in the framebody
39
public class StringHashMap extends StringFixedLength implements HashMapInterface<String, String>
45
Map<String, String> keyToValue = null;
50
Map<String, String> valueToKey = null;
55
boolean hasEmptyValue = false;
58
* Creates a new ObjectStringHashMap datatype.
62
* @throws IllegalArgumentException
64
public StringHashMap(String identifier, AbstractTagFrameBody frameBody, int size)
66
super(identifier, frameBody, size);
68
if (identifier.equals(DataTypes.OBJ_LANGUAGE))
70
valueToKey = Languages.getInstanceOf().getValueToIdMap();
71
keyToValue = Languages.getInstanceOf().getIdToValueMap();
75
throw new IllegalArgumentException("Hashmap identifier not defined in this class: " + identifier);
79
public StringHashMap(StringHashMap copyObject)
83
this.hasEmptyValue = copyObject.hasEmptyValue;
84
this.keyToValue = copyObject.keyToValue;
85
this.valueToKey = copyObject.valueToKey;
91
public Map<String, String> getKeyToValue()
99
public Map<String, String> getValueToKey()
107
public void setValue(Object value)
109
if (value instanceof String)
111
this.value = ((String) value).toLowerCase();
123
public boolean equals(Object obj)
125
if ((obj instanceof StringHashMap) == false)
130
StringHashMap object = (StringHashMap) obj;
132
if (this.hasEmptyValue != object.hasEmptyValue)
137
if (this.keyToValue == null)
139
if (object.keyToValue != null)
146
if (this.keyToValue.equals(object.keyToValue) == false)
152
if (this.keyToValue == null)
154
if (object.keyToValue != null)
161
if (this.valueToKey.equals(object.valueToKey) == false)
167
return super.equals(obj);
173
public Iterator<String> iterator()
175
if (keyToValue == null)
181
// put them in a treeset first to sort them
182
TreeSet<String> treeSet = new TreeSet<String>(keyToValue.values());
189
return treeSet.iterator();
196
public String toString()
202
else if (keyToValue.get(value) == null)
208
return keyToValue.get(value).toString();
213
* @return the ISO_8859 encoding for Datatypes of this type
215
protected String getTextEncodingCharSet()
217
return TextEncoding.CHARSET_ISO_8859_1;