add TagSet class
This commit is contained in:
99
src/org/oscim/core/TagSet.java
Normal file
99
src/org/oscim/core/TagSet.java
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.core;
|
||||
|
||||
public class TagSet {
|
||||
public static TagSet EMPTY_TAG_SET = new TagSet();
|
||||
|
||||
public Tag[] tags;
|
||||
public int numTags;
|
||||
|
||||
private TagSet() {
|
||||
|
||||
}
|
||||
|
||||
public TagSet(int count) {
|
||||
tags = new Tag[count];
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
numTags = 0;
|
||||
}
|
||||
|
||||
/** find Tag by key - NOTE: key must be internal() */
|
||||
public Tag get(String key) {
|
||||
for (int i = 0; i < numTags; i++) {
|
||||
if (tags[i].key == key)
|
||||
return tags[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void add(Tag tag) {
|
||||
if (numTags >= tags.length) {
|
||||
Tag[] tmp = tags;
|
||||
tags = new Tag[numTags + 4];
|
||||
System.arraycopy(tmp, 0, tags, 0, numTags);
|
||||
}
|
||||
tags[numTags++] = tag;
|
||||
}
|
||||
|
||||
public boolean contains(Tag tag) {
|
||||
for (int i = 0; i < numTags; i++) {
|
||||
Tag t = tags[i];
|
||||
if (t == tag || (t.key == tag.key && (t.value == t.value)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasKey(String[] keys) {
|
||||
for (int i = 0; i < numTags; i++) {
|
||||
Tag t = tags[i];
|
||||
for (String key : keys)
|
||||
if (key == t.key)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasKey(String key) {
|
||||
for (int i = 0; i < numTags; i++) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -14,12 +14,14 @@
|
||||
*/
|
||||
package org.oscim.core.osm;
|
||||
|
||||
import org.oscim.core.TagSet;
|
||||
|
||||
public abstract class OSMElement {
|
||||
|
||||
public final TagGroup tags;
|
||||
public final TagSet tags;
|
||||
public final long id;
|
||||
|
||||
public OSMElement(TagGroup tags, long id) {
|
||||
public OSMElement(TagSet tags, long id) {
|
||||
assert tags != null;
|
||||
this.tags = tags;
|
||||
this.id = id;
|
||||
|
||||
@@ -15,7 +15,11 @@
|
||||
package org.oscim.core.osm;
|
||||
|
||||
public class OSMMember {
|
||||
|
||||
public enum MemberType{
|
||||
NODE,
|
||||
WAY,
|
||||
RELATIOM
|
||||
}
|
||||
static final boolean useDebugLabels = true;
|
||||
|
||||
public final String role;
|
||||
|
||||
@@ -14,11 +14,15 @@
|
||||
*/
|
||||
package org.oscim.core.osm;
|
||||
|
||||
import org.oscim.core.TagSet;
|
||||
|
||||
public class OSMNode extends OSMElement {
|
||||
//public static EMPTY_NODE = new OSMNode()
|
||||
|
||||
public final double lat;
|
||||
public final double lon;
|
||||
|
||||
public OSMNode(double lat, double lon, TagGroup tags, long id) {
|
||||
public OSMNode(double lat, double lon, TagSet tags, long id) {
|
||||
super(tags, id);
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
|
||||
@@ -17,13 +17,15 @@ package org.oscim.core.osm;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.oscim.core.TagSet;
|
||||
|
||||
public class OSMRelation extends OSMElement {
|
||||
|
||||
public final List<OSMMember> relationMembers;
|
||||
|
||||
// content added after constructor call
|
||||
|
||||
public OSMRelation(TagGroup tags, long id, int initialMemberSize) {
|
||||
public OSMRelation(TagSet tags, long id, int initialMemberSize) {
|
||||
super(tags, id);
|
||||
this.relationMembers =
|
||||
new ArrayList<OSMMember>(initialMemberSize);
|
||||
|
||||
@@ -16,14 +16,14 @@ package org.oscim.core.osm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.oscim.core.TagSet;
|
||||
|
||||
public class OSMWay extends OSMElement {
|
||||
|
||||
public final List<OSMNode> nodes;
|
||||
|
||||
public OSMWay(TagGroup tags, long id, List<OSMNode> nodes) {
|
||||
public OSMWay(TagSet tags, long id, List<OSMNode> nodes) {
|
||||
super(tags, id);
|
||||
for (OSMNode node : nodes)
|
||||
assert node != null;
|
||||
this.nodes = nodes;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.core.osm;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class TagGroup {
|
||||
public final static TagGroup EMPTY_TAG_GROUP = new TagGroup();
|
||||
|
||||
public final Map<String, String> tags;
|
||||
|
||||
public TagGroup(Map<String,String> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
private TagGroup(){
|
||||
this.tags = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user