| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 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 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
public class StringHashMap extends StringFixedLength implements HashMapInterface<String, String> |
| 40 | |
{ |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | 300 | Map<String, String> keyToValue = null; |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | 300 | Map<String, String> valueToKey = null; |
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | 300 | boolean hasEmptyValue = false; |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
public StringHashMap(String identifier, AbstractTagFrameBody frameBody, int size) |
| 65 | |
{ |
| 66 | 185 | super(identifier, frameBody, size); |
| 67 | |
|
| 68 | 185 | if (identifier.equals(DataTypes.OBJ_LANGUAGE)) |
| 69 | |
{ |
| 70 | 185 | valueToKey = Languages.getInstanceOf().getValueToIdMap(); |
| 71 | 185 | keyToValue = Languages.getInstanceOf().getIdToValueMap(); |
| 72 | |
} |
| 73 | |
else |
| 74 | |
{ |
| 75 | 0 | throw new IllegalArgumentException("Hashmap identifier not defined in this class: " + identifier); |
| 76 | |
} |
| 77 | 185 | } |
| 78 | |
|
| 79 | |
public StringHashMap(StringHashMap copyObject) |
| 80 | |
{ |
| 81 | 115 | super(copyObject); |
| 82 | |
|
| 83 | 115 | this.hasEmptyValue = copyObject.hasEmptyValue; |
| 84 | 115 | this.keyToValue = copyObject.keyToValue; |
| 85 | 115 | this.valueToKey = copyObject.valueToKey; |
| 86 | 115 | } |
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
public Map<String, String> getKeyToValue() |
| 92 | |
{ |
| 93 | 0 | return keyToValue; |
| 94 | |
} |
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
public Map<String, String> getValueToKey() |
| 100 | |
{ |
| 101 | 0 | return valueToKey; |
| 102 | |
} |
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
public void setValue(Object value) |
| 108 | |
{ |
| 109 | 36 | if (value instanceof String) |
| 110 | |
{ |
| 111 | 35 | this.value = ((String) value).toLowerCase(); |
| 112 | |
} |
| 113 | |
else |
| 114 | |
{ |
| 115 | 1 | this.value = value; |
| 116 | |
} |
| 117 | 36 | } |
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
public boolean equals(Object obj) |
| 124 | |
{ |
| 125 | 1 | if ((obj instanceof StringHashMap) == false) |
| 126 | |
{ |
| 127 | 0 | return false; |
| 128 | |
} |
| 129 | |
|
| 130 | 1 | StringHashMap object = (StringHashMap) obj; |
| 131 | |
|
| 132 | 1 | if (this.hasEmptyValue != object.hasEmptyValue) |
| 133 | |
{ |
| 134 | 0 | return false; |
| 135 | |
} |
| 136 | |
|
| 137 | 1 | if (this.keyToValue == null) |
| 138 | |
{ |
| 139 | 0 | if (object.keyToValue != null) |
| 140 | |
{ |
| 141 | 0 | return false; |
| 142 | |
} |
| 143 | |
} |
| 144 | |
else |
| 145 | |
{ |
| 146 | 1 | if (this.keyToValue.equals(object.keyToValue) == false) |
| 147 | |
{ |
| 148 | 0 | return false; |
| 149 | |
} |
| 150 | |
} |
| 151 | |
|
| 152 | 1 | if (this.keyToValue == null) |
| 153 | |
{ |
| 154 | 0 | if (object.keyToValue != null) |
| 155 | |
{ |
| 156 | 0 | return false; |
| 157 | |
} |
| 158 | |
} |
| 159 | |
else |
| 160 | |
{ |
| 161 | 1 | if (this.valueToKey.equals(object.valueToKey) == false) |
| 162 | |
{ |
| 163 | 0 | return false; |
| 164 | |
} |
| 165 | |
} |
| 166 | |
|
| 167 | 1 | return super.equals(obj); |
| 168 | |
} |
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
public Iterator<String> iterator() |
| 174 | |
{ |
| 175 | 0 | if (keyToValue == null) |
| 176 | |
{ |
| 177 | 0 | return null; |
| 178 | |
} |
| 179 | |
else |
| 180 | |
{ |
| 181 | |
|
| 182 | 0 | TreeSet<String> treeSet = new TreeSet<String>(keyToValue.values()); |
| 183 | |
|
| 184 | 0 | if (hasEmptyValue) |
| 185 | |
{ |
| 186 | 0 | treeSet.add(""); |
| 187 | |
} |
| 188 | |
|
| 189 | 0 | return treeSet.iterator(); |
| 190 | |
} |
| 191 | |
} |
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
public String toString() |
| 197 | |
{ |
| 198 | 0 | if (value == null) |
| 199 | |
{ |
| 200 | 0 | return ""; |
| 201 | |
} |
| 202 | 0 | else if (keyToValue.get(value) == null) |
| 203 | |
{ |
| 204 | 0 | return ""; |
| 205 | |
} |
| 206 | |
else |
| 207 | |
{ |
| 208 | 0 | return keyToValue.get(value).toString(); |
| 209 | |
} |
| 210 | |
} |
| 211 | |
|
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
protected String getTextEncodingCharSet() |
| 216 | |
{ |
| 217 | 240 | return TextEncoding.CHARSET_ISO_8859_1; |
| 218 | |
} |
| 219 | |
} |