add Tag constructor for intern() keys

This commit is contained in:
Hannes Janetzek 2014-06-09 00:45:04 +02:00
parent 2c6a85ee6d
commit 7c995534eb
2 changed files with 16 additions and 13 deletions

View File

@ -68,28 +68,31 @@ public class Tag {
* the value of the tag. * the value of the tag.
*/ */
public Tag(String key, String value) { public Tag(String key, String value) {
this.key = (key == null ? null : key.intern()); this.key = key == null ? null : key.intern();
this.value = (value == null ? null : value.intern()); this.value = value == null ? null : value.intern();
this.intern = true; this.intern = true;
} }
/** /**
* Create Tag with interned Key.
*
* @param key * @param key
* the key of the tag. * the key of the tag.
* @param value * @param value
* the value of the tag. * the value of the tag.
* @param intern * @param internValue
* true when value string should be intern()alized. * true when value string should be intern()alized.
*/ */
public Tag(String key, String value, boolean intern) { public Tag(String key, String value, boolean internValue) {
this.key = key.intern(); this.key = key;
this.value = (value == null || !internValue) ? value : value.intern();
this.intern = internValue;
}
if (intern) public Tag(String key, String value, boolean internKey, boolean internValue) {
this.value = (value == null ? null : value.intern()); this.key = (key == null || !internKey) ? key : key.intern();
else this.value = (value == null || !internValue) ? value : value.intern();
this.value = value; this.intern = internValue;
this.intern = intern;
} }
@Override @Override

View File

@ -121,7 +121,7 @@ public class TileDecoder extends PbfDecoder {
mTile, numKeys); mTile, numKeys);
return false; return false;
} }
keys[curKey++] = decodeString(); keys[curKey++] = decodeString().intern();
break; break;
case TAG_TILE_TAG_VALUES: case TAG_TILE_TAG_VALUES:
@ -222,7 +222,7 @@ public class TileDecoder extends PbfDecoder {
|| key == Tag.KEY_ELE) || key == Tag.KEY_ELE)
tag = new Tag(key, val, false); tag = new Tag(key, val, false);
else else
tag = new Tag(key, val, true); tag = new Tag(key, val, false, true);
mTileTags.add(tag); mTileTags.add(tag);
} }