TagSet: refactor + add docs
- removed duplicate hasKey/hasValue functions - renamed asString -> toString
This commit is contained in:
parent
a6c2ac1d41
commit
82f169f2d5
@ -396,7 +396,7 @@ public class VectorTileLoader extends TileLoader implements IRenderTheme.Callbac
|
|||||||
@Override
|
@Override
|
||||||
public void renderPointSymbol(Symbol symbol) {
|
public void renderPointSymbol(Symbol symbol) {
|
||||||
if (symbol.texture == null) {
|
if (symbol.texture == null) {
|
||||||
Log.d(TAG, "missing symbol for " + mElement.tags.asString());
|
Log.d(TAG, "missing symbol for " + mElement.tags.toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int i = 0, n = mElement.getNumPoints(); i < n; i++) {
|
for (int i = 0, n = mElement.getNumPoints(); i < n; i++) {
|
||||||
|
@ -16,40 +16,65 @@ package org.oscim.core;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class TagSet holds a set of Tags.
|
||||||
|
*/
|
||||||
public class TagSet {
|
public class TagSet {
|
||||||
|
|
||||||
|
/** The Tags. */
|
||||||
public Tag[] tags;
|
public Tag[] tags;
|
||||||
|
|
||||||
|
/** The number of current Tags in set. */
|
||||||
public int numTags;
|
public int numTags;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new TagSet with initial size of 10.
|
||||||
|
*/
|
||||||
public TagSet() {
|
public TagSet() {
|
||||||
tags = new Tag[10];
|
tags = new Tag[10];
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagSet(int count) {
|
/**
|
||||||
tags = new Tag[count];
|
* Instantiates a new tag set initialized with the given size.
|
||||||
|
*
|
||||||
|
* @param size the initial size.
|
||||||
|
*/
|
||||||
|
public TagSet(int size) {
|
||||||
|
tags = new Tag[size];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the TagSet to contain 0 tags.
|
||||||
|
*/
|
||||||
public void clear() {
|
public void clear() {
|
||||||
numTags = 0;
|
numTags = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* null out current tags
|
* Clear. Reset the TagSet to contain 0 tags and null out tags.
|
||||||
*
|
|
||||||
* @param nulltags ...
|
|
||||||
*/
|
*/
|
||||||
public void clear(boolean nulltags) {
|
public void clearAndNullTags() {
|
||||||
Arrays.fill(tags, null);
|
Arrays.fill(tags, null);
|
||||||
numTags = 0;
|
numTags = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return Tags contained in TagSet as new array.
|
||||||
|
*
|
||||||
|
* @return the tag[]
|
||||||
|
*/
|
||||||
public Tag[] asArray() {
|
public Tag[] asArray() {
|
||||||
Tag[] result = new Tag[numTags];
|
Tag[] result = new Tag[numTags];
|
||||||
System.arraycopy(tags, 0, result, 0, numTags);
|
System.arraycopy(tags, 0, result, 0, numTags);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** find Tag by key - NOTE: key must be internal() */
|
/**
|
||||||
|
* Find Tag by given key.
|
||||||
|
*
|
||||||
|
* @param key the key as intern String.
|
||||||
|
* @return the tag if found, null otherwise.
|
||||||
|
*/
|
||||||
public Tag get(String key) {
|
public Tag get(String key) {
|
||||||
for (int i = 0; i < numTags; i++) {
|
for (int i = 0; i < numTags; i++) {
|
||||||
if (tags[i].key == key)
|
if (tags[i].key == key)
|
||||||
@ -58,6 +83,12 @@ public class TagSet {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if any tag has the key 'key'.
|
||||||
|
*
|
||||||
|
* @param key the key as intern String.
|
||||||
|
* @return true, iff any tag has the given key
|
||||||
|
*/
|
||||||
public boolean containsKey(String key) {
|
public boolean containsKey(String key) {
|
||||||
for (int i = 0; i < numTags; i++) {
|
for (int i = 0; i < numTags; i++) {
|
||||||
if (tags[i].key == key)
|
if (tags[i].key == key)
|
||||||
@ -66,6 +97,12 @@ public class TagSet {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value for a given key.
|
||||||
|
*
|
||||||
|
* @param key the key as intern String
|
||||||
|
* @return the value when found, null otherwise
|
||||||
|
*/
|
||||||
public String getValue(String key) {
|
public String getValue(String key) {
|
||||||
for (int i = 0; i < numTags; i++) {
|
for (int i = 0; i < numTags; i++) {
|
||||||
if (tags[i].key == key)
|
if (tags[i].key == key)
|
||||||
@ -74,14 +111,11 @@ public class TagSet {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains(String key, String value) {
|
/**
|
||||||
for (int i = 0; i < numTags; i++) {
|
* Adds the Tag tag to TagSet.
|
||||||
if (tags[i].key == key)
|
*
|
||||||
return value.equals(tags[i].value);
|
* @param tag the Tag to be added
|
||||||
}
|
*/
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Tag tag) {
|
public void add(Tag tag) {
|
||||||
if (numTags >= tags.length) {
|
if (numTags >= tags.length) {
|
||||||
Tag[] tmp = tags;
|
Tag[] tmp = tags;
|
||||||
@ -91,6 +125,11 @@ public class TagSet {
|
|||||||
tags[numTags++] = tag;
|
tags[numTags++] = tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the tags from 'tagArray'.
|
||||||
|
*
|
||||||
|
* @param tagArray the tag array
|
||||||
|
*/
|
||||||
public void set(Tag[] tagArray) {
|
public void set(Tag[] tagArray) {
|
||||||
int newTags = tagArray.length;
|
int newTags = tagArray.length;
|
||||||
if (newTags > tags.length)
|
if (newTags > tags.length)
|
||||||
@ -100,6 +139,12 @@ public class TagSet {
|
|||||||
numTags = newTags;
|
numTags = newTags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if 'tag' is contained in TagSet.
|
||||||
|
*
|
||||||
|
* @param tag the tag
|
||||||
|
* @return true, iff tag is in TagSet
|
||||||
|
*/
|
||||||
public boolean contains(Tag tag) {
|
public boolean contains(Tag tag) {
|
||||||
for (int i = 0; i < numTags; i++) {
|
for (int i = 0; i < numTags; i++) {
|
||||||
Tag t = tags[i];
|
Tag t = tags[i];
|
||||||
@ -109,45 +154,23 @@ public class TagSet {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasKey(String[] keys) {
|
/**
|
||||||
|
* Checks if a Tag with given key and value is contained in TagSet.
|
||||||
|
*
|
||||||
|
* @param key the key as intern String
|
||||||
|
* @param value the value as intern String
|
||||||
|
* @return true, iff any tag has the given key and value
|
||||||
|
*/
|
||||||
|
public boolean contains(String key, String value) {
|
||||||
for (int i = 0; i < numTags; i++) {
|
for (int i = 0; i < numTags; i++) {
|
||||||
Tag t = tags[i];
|
if (tags[i].key == key)
|
||||||
for (String key : keys)
|
return value.equals(tags[i].value);
|
||||||
if (key == t.key)
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasKey(String key) {
|
@Override
|
||||||
for (int i = 0; i < numTags; i++) {
|
public String toString() {
|
||||||
Tag t = tags[i];
|
|
||||||
if (key == t.key)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasValue(String[] vals) {
|
|
||||||
for (int i = 0; i < numTags; i++) {
|
|
||||||
Tag t = tags[i];
|
|
||||||
for (String value : vals)
|
|
||||||
if (value == t.value)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasValue(String value) {
|
|
||||||
for (int i = 0; i < numTags; i++) {
|
|
||||||
Tag t = tags[i];
|
|
||||||
if (value == t.value)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String asString() {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < numTags; i++)
|
for (int i = 0; i < numTags; i++)
|
||||||
sb.append(tags[i]);
|
sb.append(tags[i]);
|
||||||
|
@ -371,7 +371,7 @@ public class VectorTileLoader extends TileLoader implements IRenderTheme.Callbac
|
|||||||
@Override
|
@Override
|
||||||
public void renderPointSymbol(Symbol symbol) {
|
public void renderPointSymbol(Symbol symbol) {
|
||||||
if (symbol.texture == null) {
|
if (symbol.texture == null) {
|
||||||
Log.d(TAG, "missing symbol for " + mElement.tags.asString());
|
Log.d(TAG, "missing symbol for " + mElement.tags.toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int i = 0, n = mElement.getNumPoints(); i < n; i++) {
|
for (int i = 0, n = mElement.getNumPoints(); i < n; i++) {
|
||||||
|
@ -88,7 +88,7 @@ public class TileDecoder extends PbfDecoder {
|
|||||||
mTile = tile;
|
mTile = tile;
|
||||||
mMapDataSink = sink;
|
mMapDataSink = sink;
|
||||||
|
|
||||||
mTileTags.clear(true);
|
mTileTags.clearAndNullTags();
|
||||||
int version = -1;
|
int version = -1;
|
||||||
|
|
||||||
int val;
|
int val;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user