TagSet: numTags and tag array as private (#439)

This commit is contained in:
Gustl22 2017-11-13 11:24:54 +01:00 committed by Emux
parent 9c3488e107
commit fe2c067272
10 changed files with 57 additions and 37 deletions

View File

@ -135,7 +135,7 @@ public class GeoJsonTileDecoder implements ITileDecoder {
//add tag information //add tag information
mTileSource.decodeTags(mMapElement, mTagMap); mTileSource.decodeTags(mMapElement, mTagMap);
if (mMapElement.tags.numTags == 0) if (mMapElement.tags.size() == 0)
return; return;
mTileSource.postGeomHook(mMapElement); mTileSource.postGeomHook(mMapElement);

View File

@ -143,7 +143,7 @@ public class OSciMap2TileSource extends UrlTileSource {
private boolean decodeTileTags() throws IOException { private boolean decodeTileTags() throws IOException {
String tagString = decodeString(); String tagString = decodeString();
int curTag = mTileTags.numTags; int curTag = mTileTags.size();
String key = Tags.keys[mSArray[curTag]]; String key = Tags.keys[mSArray[curTag]];
Tag tag; Tag tag;
@ -261,7 +261,7 @@ public class OSciMap2TileSource extends UrlTileSource {
if (fail || indexCnt == 0) { if (fail || indexCnt == 0) {
log.debug(mTile + " failed reading way: bytes:" + bytes + " index:" log.debug(mTile + " failed reading way: bytes:" + bytes + " index:"
+ (Arrays.toString(index)) + " tag:" + (Arrays.toString(index)) + " tag:"
+ (mElem.tags.numTags > 0 ? Arrays.deepToString(mElem.tags.tags) : "null") + (mElem.tags.size() > 0 ? Arrays.deepToString(mElem.tags.getTags()) : "null")
+ " " + indexCnt + " " + coordCnt); + " " + indexCnt + " " + coordCnt);
return false; return false;
} }
@ -290,7 +290,7 @@ public class OSciMap2TileSource extends UrlTileSource {
int cnt = 0; int cnt = 0;
int end = position() + bytes; int end = position() + bytes;
int max = mTileTags.numTags - 1; int max = mTileTags.size() - 1;
for (; position() < end; cnt++) { for (; position() < end; cnt++) {
int tagNum = decodeVarint32(); int tagNum = decodeVarint32();
@ -315,7 +315,7 @@ public class OSciMap2TileSource extends UrlTileSource {
return false; return false;
} }
mElem.tags.add(mTileTags.tags[tagNum]); mElem.tags.add(mTileTags.get(tagNum));
} }
if (cnt == 0) { if (cnt == 0) {

View File

@ -137,7 +137,7 @@ public class TileDecoder implements ITileDecoder {
//add tag information //add tag information
mTileSource.decodeTags(mMapElement, mTagMap); mTileSource.decodeTags(mMapElement, mTagMap);
if (mMapElement.tags.numTags == 0) if (mMapElement.tags.size() == 0)
return; return;
mTileSource.postGeomHook(mMapElement); mTileSource.postGeomHook(mMapElement);

View File

@ -67,7 +67,7 @@ public class GeoJsonTileDecoder implements ITileDecoder {
/* add tag information */ /* add tag information */
mTileSource.decodeTags(mapElement, f.getProperties(mProperties)); mTileSource.decodeTags(mapElement, f.getProperties(mProperties));
if (mapElement.tags.numTags == 0) if (mapElement.tags.size() == 0)
continue; continue;
/* add geometry information */ /* add geometry information */

View File

@ -2,6 +2,7 @@
* Copyright 2013 Hannes Janetzek * Copyright 2013 Hannes Janetzek
* Copyright 2016 Andrey Novikov * Copyright 2016 Andrey Novikov
* Copyright 2016 devemux86 * Copyright 2016 devemux86
* Copyright 2017 Gustl22
* *
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
* *
@ -30,12 +31,12 @@ public class TagSet {
/** /**
* The Tags. * The Tags.
*/ */
public Tag[] tags; private Tag[] tags;
/** /**
* The number of current Tags in set. * The number of current Tags in set.
*/ */
public int numTags; private int numTags;
/** /**
* Instantiates a new TagSet with initial size of 10. * Instantiates a new TagSet with initial size of 10.
@ -60,6 +61,13 @@ public class TagSet {
numTags = 0; numTags = 0;
} }
/**
* @return Size of TagSet
*/
public int size() {
return numTags;
}
/** /**
* Clear. Reset the TagSet to contain 0 tags and null out tags. * Clear. Reset the TagSet to contain 0 tags and null out tags.
*/ */
@ -79,6 +87,19 @@ public class TagSet {
return result; return result;
} }
/**
* Find Tag by given index.
*
* @param index the index of tag.
* @return the tag if found, null otherwise.
*/
public Tag get(int index) {
if (index >= numTags) {
return null;
}
return tags[index];
}
/** /**
* Find Tag by given key. * Find Tag by given key.
* *
@ -93,11 +114,20 @@ public class TagSet {
return null; return null;
} }
/**
* Return Tags array contained in TagSet.
*
* @return the tags array.
*/
public Tag[] getTags() {
return tags;
}
/** /**
* Checks if any tag has the key 'key'. * Checks if any tag has the key 'key'.
* *
* @param key the key as intern String. * @param key the key as intern String.
* @return true, iff any tag has the given key * @return true, if 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++) {

View File

@ -65,12 +65,12 @@ public class OsmTileLayer extends VectorTileLayer {
}; };
protected TagSet filterTags(TagSet tagSet) { protected TagSet filterTags(TagSet tagSet) {
Tag[] tags = tagSet.tags; Tag[] tags = tagSet.getTags();
mFilteredTags.clear(); mFilteredTags.clear();
O: O:
for (int i = 0, n = tagSet.numTags; i < n; i++) { for (int i = 0, n = tagSet.size(); i < n; i++) {
Tag t = tags[i]; Tag t = tags[i];
for (TagReplacement replacement : mTagReplacement) { for (TagReplacement replacement : mTagReplacement) {

View File

@ -37,13 +37,13 @@ class MatchingCacheKey {
* set temporary values for comparison * set temporary values for comparison
*/ */
boolean set(TagSet tags, MatchingCacheKey compare) { boolean set(TagSet tags, MatchingCacheKey compare) {
int numTags = tags.numTags; int numTags = tags.size();
/* Test if tags are equal to previous query */ /* Test if tags are equal to previous query */
if (compare != null && numTags == compare.mTags.length) { if (compare != null && numTags == compare.mTags.length) {
int i = 0; int i = 0;
for (; i < numTags; i++) { for (; i < numTags; i++) {
Tag t1 = tags.tags[i]; Tag t1 = tags.get(i);
Tag t2 = compare.mTags[i]; Tag t2 = compare.mTags[i];
if (!(t1 == t2 || (Utils.equals(t1.key, t2.key) && Utils.equals(t1.value, t2.value)))) if (!(t1 == t2 || (Utils.equals(t1.key, t2.key) && Utils.equals(t1.value, t2.value))))
@ -60,7 +60,7 @@ class MatchingCacheKey {
int result = 7; int result = 7;
for (int i = 0; i < numTags; i++) { for (int i = 0; i < numTags; i++) {
Tag t = tags.tags[i]; Tag t = tags.get(i);
result = 31 * result + t.hashCode(); result = 31 * result + t.hashCode();
mTags[i] = t; mTags[i] = t;
} }

View File

@ -602,7 +602,8 @@ public class MapDatabase implements ITileDataSource {
MapElement e = mElem; MapElement e = mElem;
for (int elementCounter = numberOfPois; elementCounter != 0; --elementCounter) { for (int elementCounter = numberOfPois; elementCounter != 0; --elementCounter) {
int numTags = 0; /* reset to common tag position */
e.tags.clear();
if (mDebugFile) { if (mDebugFile) {
/* get and check the POI signature */ /* get and check the POI signature */
@ -631,13 +632,8 @@ public class MapDatabase implements ITileDataSource {
if (numberOfTags != 0) { if (numberOfTags != 0) {
if (!mReadBuffer.readTags(e.tags, poiTags, numberOfTags)) if (!mReadBuffer.readTags(e.tags, poiTags, numberOfTags))
return false; return false;
numTags = numberOfTags;
} }
/* reset to common tag position */
e.tags.numTags = numTags;
/* get the feature bitmask (1 byte) */ /* get the feature bitmask (1 byte) */
byte featureByte = mReadBuffer.readByte(); byte featureByte = mReadBuffer.readByte();
@ -665,8 +661,8 @@ public class MapDatabase implements ITileDataSource {
if (pois != null) { if (pois != null) {
List<Tag> tags = new ArrayList<>(); List<Tag> tags = new ArrayList<>();
for (int i = 0; i < e.tags.numTags; i++) for (int i = 0; i < e.tags.size(); i++)
tags.add(e.tags.tags[i]); tags.add(e.tags.get(i));
GeoPoint position = new GeoPoint(latitude, longitude); GeoPoint position = new GeoPoint(latitude, longitude);
// depending on the zoom level configuration the poi can lie outside // depending on the zoom level configuration the poi can lie outside
// the tile requested, we filter them out here // the tile requested, we filter them out here
@ -813,7 +809,8 @@ public class MapDatabase implements ITileDataSource {
//setTileClipping(queryParameters); //setTileClipping(queryParameters);
for (int elementCounter = numberOfWays; elementCounter != 0; --elementCounter) { for (int elementCounter = numberOfWays; elementCounter != 0; --elementCounter) {
int numTags = 0; /* reset to common tag position */
e.tags.clear();
if (mDebugFile) { if (mDebugFile) {
// get and check the way signature // get and check the way signature
@ -844,8 +841,6 @@ public class MapDatabase implements ITileDataSource {
if (!mReadBuffer.readTags(e.tags, wayTags, numberOfTags)) if (!mReadBuffer.readTags(e.tags, wayTags, numberOfTags))
return false; return false;
numTags = numberOfTags;
mReadBuffer.setBufferPosition(pos); mReadBuffer.setBufferPosition(pos);
} }
} else { } else {
@ -872,11 +867,8 @@ public class MapDatabase implements ITileDataSource {
byte numberOfTags = (byte) (specialByte & WAY_NUMBER_OF_TAGS_BITMASK); byte numberOfTags = (byte) (specialByte & WAY_NUMBER_OF_TAGS_BITMASK);
if (numberOfTags != 0) { if (numberOfTags != 0) {
if (!mReadBuffer.readTags(e.tags, wayTags, numberOfTags)) if (!mReadBuffer.readTags(e.tags, wayTags, numberOfTags))
return false; return false;
numTags = numberOfTags;
} }
/* get the feature bitmask (1 byte) */ /* get the feature bitmask (1 byte) */
@ -890,8 +882,6 @@ public class MapDatabase implements ITileDataSource {
boolean hasHouseNr = (featureByte & WAY_FEATURE_HOUSE_NUMBER) != 0; boolean hasHouseNr = (featureByte & WAY_FEATURE_HOUSE_NUMBER) != 0;
boolean hasRef = (featureByte & WAY_FEATURE_REF) != 0; boolean hasRef = (featureByte & WAY_FEATURE_REF) != 0;
e.tags.numTags = numTags;
if (mTileSource.experimental) { if (mTileSource.experimental) {
if (hasName) { if (hasName) {
int textPos = mReadBuffer.readUnsignedInt(); int textPos = mReadBuffer.readUnsignedInt();
@ -978,8 +968,8 @@ public class MapDatabase implements ITileDataSource {
GeoPoint[][] wayNodesArray = wayNodes.toArray(new GeoPoint[wayNodes.size()][]); GeoPoint[][] wayNodesArray = wayNodes.toArray(new GeoPoint[wayNodes.size()][]);
if (!filterRequired || !wayFilterEnabled || wayFilterBbox.intersectsArea(wayNodesArray)) { if (!filterRequired || !wayFilterEnabled || wayFilterBbox.intersectsArea(wayNodesArray)) {
List<Tag> tags = new ArrayList<>(); List<Tag> tags = new ArrayList<>();
for (int i = 0; i < e.tags.numTags; i++) for (int i = 0; i < e.tags.size(); i++)
tags.add(e.tags.tags[i]); tags.add(e.tags.get(i));
if (Selector.ALL == selector || hasName || hasHouseNr || hasRef || wayAsLabelTagFilter(tags)) { if (Selector.ALL == selector || hasName || hasHouseNr || hasRef || wayAsLabelTagFilter(tags)) {
GeoPoint labelPos = e.labelPosition != null ? new GeoPoint(e.labelPosition.y / 1E6, e.labelPosition.x / 1E6) : null; GeoPoint labelPos = e.labelPosition != null ? new GeoPoint(e.labelPosition.y / 1E6, e.labelPosition.x / 1E6) : null;
ways.add(new Way(layer, tags, wayNodesArray, labelPos, e.type)); ways.add(new Way(layer, tags, wayNodesArray, labelPos, e.type));

View File

@ -38,8 +38,8 @@ public final class OSMUtils {
*/ */
public static boolean isArea(MapElement mapElement) { public static boolean isArea(MapElement mapElement) {
boolean result = true; boolean result = true;
for (int i = 0; i < mapElement.tags.numTags; i++) { for (int i = 0; i < mapElement.tags.size(); i++) {
Tag tag = mapElement.tags.tags[i]; Tag tag = mapElement.tags.get(i);
String key = tag.key.toLowerCase(Locale.ENGLISH); String key = tag.key.toLowerCase(Locale.ENGLISH);
String value = tag.value.toLowerCase(Locale.ENGLISH); String value = tag.value.toLowerCase(Locale.ENGLISH);
if ("area".equals(key)) { if ("area".equals(key)) {

View File

@ -389,7 +389,7 @@ public class TileDecoder extends PbfDecoder {
mElem.tags.clear(); mElem.tags.clear();
int max = mTileTags.numTags - 1; int max = mTileTags.size() - 1;
for (int i = 0; i < numTags; i++) { for (int i = 0; i < numTags; i++) {
int idx = tagIds[i]; int idx = tagIds[i];
@ -400,7 +400,7 @@ public class TileDecoder extends PbfDecoder {
Integer.valueOf(i)); Integer.valueOf(i));
return false; return false;
} }
mElem.tags.add(mTileTags.tags[idx]); mElem.tags.add(mTileTags.get(idx));
} }
return true; return true;