~ubuntu-branches/ubuntu/utopic/libjaudiotagger-java/utopic

« back to all changes in this revision

Viewing changes to src/org/jaudiotagger/tag/datatype/StringHashMap.java

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath, Damien Raude-Morvan, Varun Hiremath
  • Date: 2009-04-01 19:17:56 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090401191756-bygniim270guy7o1
Tags: 1.0.9-1
[ Damien Raude-Morvan ]
* New upstream release
* debian/watch: Use java.net repository (which contains new releases!)
* debian/control:
  - Build-Depends on default-jdk-builddep
  - Bump Standards-Version to 3.8.1 (no changes needed)
  - Change section to "java"
* debian/rules: use default-java as JAVA_HOME
* debina/orig-tar.{sh|excludes}: strip audio and others binary files from ZIP
* debian/build.xml:
  - compile with "nowarn" to keep build log readable
  - exclude LogFormatter from build (use com.sun classes)
* debian/ant.properties: new source directory is "src" in orig.tar.gz
* Add myself as Uploaders

[ Varun Hiremath ]
* Accept changes made by Damien Raude-Morvan (Closes: #522130)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 *  @author : Paul Taylor
 
3
 *  @author : Eric Farng
 
4
 *
 
5
 *  Version @version:$Id: StringHashMap.java,v 1.12 2008/07/21 10:45:41 paultaylor Exp $
 
6
 *
 
7
 *  MusicTag Copyright (C)2003,2004
 
8
 *
 
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.
 
12
 *
 
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.
 
16
 *
 
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
 
20
 *
 
21
 * Description:
 
22
 *
 
23
 */
 
24
package org.jaudiotagger.tag.datatype;
 
25
 
 
26
import org.jaudiotagger.tag.id3.AbstractTagFrameBody;
 
27
import org.jaudiotagger.tag.id3.valuepair.TextEncoding;
 
28
import org.jaudiotagger.tag.reference.Languages;
 
29
 
 
30
import java.util.Iterator;
 
31
import java.util.Map;
 
32
import java.util.TreeSet;
 
33
 
 
34
 
 
35
/**
 
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
 
38
 */
 
39
public class StringHashMap extends StringFixedLength implements HashMapInterface<String, String>
 
40
{
 
41
 
 
42
    /**
 
43
     *
 
44
     */
 
45
    Map<String, String> keyToValue = null;
 
46
 
 
47
    /**
 
48
     *
 
49
     */
 
50
    Map<String, String> valueToKey = null;
 
51
 
 
52
    /**
 
53
     *
 
54
     */
 
55
    boolean hasEmptyValue = false;
 
56
 
 
57
    /**
 
58
     * Creates a new ObjectStringHashMap datatype.
 
59
     *
 
60
     * @param identifier
 
61
     * @param size
 
62
     * @throws IllegalArgumentException
 
63
     */
 
64
    public StringHashMap(String identifier, AbstractTagFrameBody frameBody, int size)
 
65
    {
 
66
        super(identifier, frameBody, size);
 
67
 
 
68
        if (identifier.equals(DataTypes.OBJ_LANGUAGE))
 
69
        {
 
70
            valueToKey = Languages.getInstanceOf().getValueToIdMap();
 
71
            keyToValue = Languages.getInstanceOf().getIdToValueMap();
 
72
        }
 
73
        else
 
74
        {
 
75
            throw new IllegalArgumentException("Hashmap identifier not defined in this class: " + identifier);
 
76
        }
 
77
    }
 
78
 
 
79
    public StringHashMap(StringHashMap copyObject)
 
80
    {
 
81
        super(copyObject);
 
82
 
 
83
        this.hasEmptyValue = copyObject.hasEmptyValue;
 
84
        this.keyToValue = copyObject.keyToValue;
 
85
        this.valueToKey = copyObject.valueToKey;
 
86
    }
 
87
 
 
88
    /**
 
89
     * @return
 
90
     */
 
91
    public Map<String, String> getKeyToValue()
 
92
    {
 
93
        return keyToValue;
 
94
    }
 
95
 
 
96
    /**
 
97
     * @return
 
98
     */
 
99
    public Map<String, String> getValueToKey()
 
100
    {
 
101
        return valueToKey;
 
102
    }
 
103
 
 
104
    /**
 
105
     * @param value
 
106
     */
 
107
    public void setValue(Object value)
 
108
    {
 
109
        if (value instanceof String)
 
110
        {
 
111
            this.value = ((String) value).toLowerCase();
 
112
        }
 
113
        else
 
114
        {
 
115
            this.value = value;
 
116
        }
 
117
    }
 
118
 
 
119
    /**
 
120
     * @param obj
 
121
     * @return
 
122
     */
 
123
    public boolean equals(Object obj)
 
124
    {
 
125
        if ((obj instanceof StringHashMap) == false)
 
126
        {
 
127
            return false;
 
128
        }
 
129
 
 
130
        StringHashMap object = (StringHashMap) obj;
 
131
 
 
132
        if (this.hasEmptyValue != object.hasEmptyValue)
 
133
        {
 
134
            return false;
 
135
        }
 
136
 
 
137
        if (this.keyToValue == null)
 
138
        {
 
139
            if (object.keyToValue != null)
 
140
            {
 
141
                return false;
 
142
            }
 
143
        }
 
144
        else
 
145
        {
 
146
            if (this.keyToValue.equals(object.keyToValue) == false)
 
147
            {
 
148
                return false;
 
149
            }
 
150
        }
 
151
 
 
152
        if (this.keyToValue == null)
 
153
        {
 
154
            if (object.keyToValue != null)
 
155
            {
 
156
                return false;
 
157
            }
 
158
        }
 
159
        else
 
160
        {
 
161
            if (this.valueToKey.equals(object.valueToKey) == false)
 
162
            {
 
163
                return false;
 
164
            }
 
165
        }
 
166
 
 
167
        return super.equals(obj);
 
168
    }
 
169
 
 
170
    /**
 
171
     * @return
 
172
     */
 
173
    public Iterator<String> iterator()
 
174
    {
 
175
        if (keyToValue == null)
 
176
        {
 
177
            return null;
 
178
        }
 
179
        else
 
180
        {
 
181
            // put them in a treeset first to sort them
 
182
            TreeSet<String> treeSet = new TreeSet<String>(keyToValue.values());
 
183
 
 
184
            if (hasEmptyValue)
 
185
            {
 
186
                treeSet.add("");
 
187
            }
 
188
 
 
189
            return treeSet.iterator();
 
190
        }
 
191
    }
 
192
 
 
193
    /**
 
194
     * @return
 
195
     */
 
196
    public String toString()
 
197
    {
 
198
        if (value == null)
 
199
        {
 
200
            return "";
 
201
        }
 
202
        else if (keyToValue.get(value) == null)
 
203
        {
 
204
            return "";
 
205
        }
 
206
        else
 
207
        {
 
208
            return keyToValue.get(value).toString();
 
209
        }
 
210
    }
 
211
 
 
212
    /**
 
213
     * @return the ISO_8859 encoding for Datatypes of this type
 
214
     */
 
215
    protected String getTextEncodingCharSet()
 
216
    {
 
217
        return TextEncoding.CHARSET_ISO_8859_1;
 
218
    }
 
219
}