2
* @author : Paul Taylor
5
* Version @version:$Id: StringHashMap.java,v 1.16 2009/11/12 15:42:56 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.
63
* @throws IllegalArgumentException
65
public StringHashMap(String identifier, AbstractTagFrameBody frameBody, int size)
67
super(identifier, frameBody, size);
69
if (identifier.equals(DataTypes.OBJ_LANGUAGE))
71
valueToKey = Languages.getInstanceOf().getValueToIdMap();
72
keyToValue = Languages.getInstanceOf().getIdToValueMap();
76
throw new IllegalArgumentException("Hashmap identifier not defined in this class: " + identifier);
80
public StringHashMap(StringHashMap copyObject)
84
this.hasEmptyValue = copyObject.hasEmptyValue;
85
this.keyToValue = copyObject.keyToValue;
86
this.valueToKey = copyObject.valueToKey;
92
public Map<String, String> getKeyToValue()
100
public Map<String, String> getValueToKey()
108
public void setValue(Object value)
110
if (value instanceof String)
112
//Issue #273 temporary hack for MM
113
if(value.equals("XXX"))
115
this.value=value.toString();
119
this.value = ((String) value).toLowerCase();
132
public boolean equals(Object obj)
134
if (!(obj instanceof StringHashMap))
139
StringHashMap object = (StringHashMap) obj;
141
if (this.hasEmptyValue != object.hasEmptyValue)
146
if (this.keyToValue == null)
148
if (object.keyToValue != null)
155
if (!this.keyToValue.equals(object.keyToValue))
161
if (this.keyToValue == null)
163
if (object.keyToValue != null)
170
if (!this.valueToKey.equals(object.valueToKey))
176
return super.equals(obj);
182
public Iterator<String> iterator()
184
if (keyToValue == null)
190
// put them in a treeset first to sort them
191
TreeSet<String> treeSet = new TreeSet<String>(keyToValue.values());
198
return treeSet.iterator();
205
public String toString()
211
else if (keyToValue.get(value) == null)
217
return keyToValue.get(value);
222
* @return the ISO_8859 encoding for Datatypes of this type
224
protected String getTextEncodingCharSet()
226
return TextEncoding.CHARSET_ISO_8859_1;
2
* @author : Paul Taylor
5
* Version @version:$Id: StringHashMap.java 836 2009-11-12 15:44:07Z paultaylor $
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.
63
* @throws IllegalArgumentException
65
public StringHashMap(String identifier, AbstractTagFrameBody frameBody, int size)
67
super(identifier, frameBody, size);
69
if (identifier.equals(DataTypes.OBJ_LANGUAGE))
71
valueToKey = Languages.getInstanceOf().getValueToIdMap();
72
keyToValue = Languages.getInstanceOf().getIdToValueMap();
76
throw new IllegalArgumentException("Hashmap identifier not defined in this class: " + identifier);
80
public StringHashMap(StringHashMap copyObject)
84
this.hasEmptyValue = copyObject.hasEmptyValue;
85
this.keyToValue = copyObject.keyToValue;
86
this.valueToKey = copyObject.valueToKey;
92
public Map<String, String> getKeyToValue()
100
public Map<String, String> getValueToKey()
108
public void setValue(Object value)
110
if (value instanceof String)
112
//Issue #273 temporary hack for MM
113
if(value.equals("XXX"))
115
this.value=value.toString();
119
this.value = ((String) value).toLowerCase();
132
public boolean equals(Object obj)
134
if (!(obj instanceof StringHashMap))
139
StringHashMap object = (StringHashMap) obj;
141
if (this.hasEmptyValue != object.hasEmptyValue)
146
if (this.keyToValue == null)
148
if (object.keyToValue != null)
155
if (!this.keyToValue.equals(object.keyToValue))
161
if (this.keyToValue == null)
163
if (object.keyToValue != null)
170
if (!this.valueToKey.equals(object.valueToKey))
176
return super.equals(obj);
182
public Iterator<String> iterator()
184
if (keyToValue == null)
190
// put them in a treeset first to sort them
191
TreeSet<String> treeSet = new TreeSet<String>(keyToValue.values());
198
return treeSet.iterator();
205
public String toString()
211
else if (keyToValue.get(value) == null)
217
return keyToValue.get(value);
222
* @return the ISO_8859 encoding for Datatypes of this type
224
protected String getTextEncodingCharSet()
226
return TextEncoding.CHARSET_ISO_8859_1;