Search in sources :

Example 1 with TLongHashSet

use of com.slimjars.dist.gnu.trove.set.hash.TLongHashSet in project osm4j-geometry by topobyte.

the class ChainOfNodes method hasNodeIntersections.

/**
 * Return whether this ring has intersections in terms of node ids appearing
 * multiple times.
 */
public boolean hasNodeIntersections() {
    int size = nodeIds.size();
    // Keep a set of already encountered ids
    TLongSet before = new TLongHashSet();
    // The first id can't be there already because the set is empty
    before.add(nodeIds.get(0));
    // Check all nodes except the last one which gets special care
    for (int i = 1; i < size - 1; i++) {
        long id = nodeIds.get(i);
        // Is it already on the set -> there is an intersection
        if (before.contains(id)) {
            return true;
        }
        // Add to the set of encountered ids
        before.add(id);
    }
    // that is okay
    if (isClosed()) {
        return false;
    }
    // with one of the others
    return before.contains(nodeIds.get(size - 1));
}
Also used : TLongSet(com.slimjars.dist.gnu.trove.set.TLongSet) TLongHashSet(com.slimjars.dist.gnu.trove.set.hash.TLongHashSet)

Example 2 with TLongHashSet

use of com.slimjars.dist.gnu.trove.set.hash.TLongHashSet in project osm4j-core by topobyte.

the class EntityFinderIgnoreMissing method findMemberRelationsRecursively.

private void findMemberRelationsRecursively(Deque<OsmRelation> queue, Set<OsmRelation> outRelations) {
    TLongSet ids = new TLongHashSet();
    while (!queue.isEmpty()) {
        OsmRelation relation = queue.remove();
        for (OsmRelationMember member : OsmModelUtil.membersAsList(relation)) {
            if (member.getType() != EntityType.Relation) {
                continue;
            }
            long id = member.getId();
            if (ids.contains(id)) {
                continue;
            }
            ids.add(id);
            try {
                OsmRelation child = entityProvider.getRelation(id);
                outRelations.add(child);
                queue.add(child);
            } catch (EntityNotFoundException e) {
            // ignore silently
            }
        }
    }
}
Also used : TLongSet(com.slimjars.dist.gnu.trove.set.TLongSet) TLongHashSet(com.slimjars.dist.gnu.trove.set.hash.TLongHashSet) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) OsmRelationMember(de.topobyte.osm4j.core.model.iface.OsmRelationMember)

Example 3 with TLongHashSet

use of com.slimjars.dist.gnu.trove.set.hash.TLongHashSet in project osm4j-core by topobyte.

the class EntityFinderLogMissing method findMemberRelationsRecursively.

private void findMemberRelationsRecursively(Deque<OsmRelation> queue, Set<OsmRelation> outRelations) {
    TLongSet ids = new TLongHashSet();
    while (!queue.isEmpty()) {
        OsmRelation relation = queue.remove();
        for (OsmRelationMember member : OsmModelUtil.membersAsList(relation)) {
            if (member.getType() != EntityType.Relation) {
                continue;
            }
            long id = member.getId();
            if (ids.contains(id)) {
                continue;
            }
            ids.add(id);
            try {
                OsmRelation child = entityProvider.getRelation(id);
                outRelations.add(child);
                queue.add(child);
            } catch (EntityNotFoundException e) {
                logRelationNotFound(id);
            }
        }
    }
}
Also used : TLongSet(com.slimjars.dist.gnu.trove.set.TLongSet) TLongHashSet(com.slimjars.dist.gnu.trove.set.hash.TLongHashSet) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) OsmRelationMember(de.topobyte.osm4j.core.model.iface.OsmRelationMember)

Example 4 with TLongHashSet

use of com.slimjars.dist.gnu.trove.set.hash.TLongHashSet in project osm4j-core by topobyte.

the class EntityFinderThrowMissing method findMemberRelationsRecursively.

private void findMemberRelationsRecursively(Deque<OsmRelation> queue, Set<OsmRelation> outRelations) throws EntityNotFoundException {
    TLongSet ids = new TLongHashSet();
    while (!queue.isEmpty()) {
        OsmRelation relation = queue.remove();
        for (OsmRelationMember member : OsmModelUtil.membersAsList(relation)) {
            if (member.getType() != EntityType.Relation) {
                continue;
            }
            long id = member.getId();
            if (ids.contains(id)) {
                continue;
            }
            ids.add(id);
            OsmRelation child = entityProvider.getRelation(id);
            outRelations.add(child);
            queue.add(child);
        }
    }
}
Also used : TLongSet(com.slimjars.dist.gnu.trove.set.TLongSet) TLongHashSet(com.slimjars.dist.gnu.trove.set.hash.TLongHashSet) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) OsmRelationMember(de.topobyte.osm4j.core.model.iface.OsmRelationMember)

Aggregations

TLongSet (com.slimjars.dist.gnu.trove.set.TLongSet)4 TLongHashSet (com.slimjars.dist.gnu.trove.set.hash.TLongHashSet)4 OsmRelation (de.topobyte.osm4j.core.model.iface.OsmRelation)3 OsmRelationMember (de.topobyte.osm4j.core.model.iface.OsmRelationMember)3