コード例 #1
0
 /**
  * Replies true if {@code tp1} and {@code tp2} have the same tags and the same members
  *
  * @param tp1 a turn restriction. Must not be null.
  * @param tp2 a turn restriction . Must not be null.
  * @return true if {@code tp1} and {@code tp2} have the same tags and the same members
  * @throws IllegalArgumentException thrown if {@code tp1} is null
  * @throws IllegalArgumentException thrown if {@code tp2} is null
  */
 public static boolean hasSameMembersAndTags(Relation tp1, Relation tp2)
     throws IllegalArgumentException {
   CheckParameterUtil.ensureParameterNotNull(tp1, "tp1");
   CheckParameterUtil.ensureParameterNotNull(tp2, "tp2");
   if (!TagCollection.from(tp1).asSet().equals(TagCollection.from(tp2).asSet())) return false;
   if (tp1.getMembersCount() != tp2.getMembersCount()) return false;
   for (int i = 0; i < tp1.getMembersCount(); i++) {
     if (!tp1.getMember(i).equals(tp2.getMember(i))) return false;
   }
   return true;
 }
コード例 #2
0
 private static final boolean addStopToRoute(Relation route, OsmPrimitive stop) {
   if (route.getMembersCount() == 0
       || !route.getMember(route.getMembersCount() - 1).getMember().equals(stop)) {
     route.addMember(new RelationMember(stop.get(OSM_PUBLIC_TRANSPORT), stop));
     return true;
   } else {
     return false;
   }
 }
コード例 #3
0
 public RelationMemberConflictDecision(Relation relation, int pos) {
   CheckParameterUtil.ensureParameterNotNull(relation, "relation");
   RelationMember member = relation.getMember(pos);
   if (member == null)
     throw new IndexOutOfBoundsException(
         tr(
             "Position {0} is out of range. Current number of members is {1}.",
             pos, relation.getMembersCount()));
   this.relation = relation;
   this.pos = pos;
   this.originalPrimitive = member.getMember();
   this.role = member.hasRole() ? member.getRole() : "";
   this.decision = UNDECIDED;
 }
コード例 #4
0
ファイル: Selector.java プロジェクト: josefadamcik/josm
      @Override
      public void visit(Relation r) {
        /*
         * If e.parent is already set to the first matching referrer. We skip any following
         * referrer injected into the visitor.
         */
        if (e.parent != null) return;

        if (!left.matches(e.withPrimitive(r))) return;
        for (int i = 0; i < r.getMembersCount(); i++) {
          RelationMember m = r.getMember(i);
          if (m.getMember().equals(e.osm)) {
            if (link.matches(e.withParentAndIndexAndLinkContext(r, i, r.getMembersCount()))) {
              e.parent = r;
              e.index = i;
              e.count = r.getMembersCount();
              return;
            }
          }
        }
      }
コード例 #5
0
ファイル: DuplicateWay.java プロジェクト: olejorgenb/josm
  /** Fix the error by removing all but one instance of duplicate ways */
  @Override
  public Command fixError(TestError testError) {
    Collection<? extends OsmPrimitive> sel = testError.getPrimitives();
    HashSet<Way> ways = new HashSet<Way>();

    for (OsmPrimitive osm : sel) {
      if (osm instanceof Way) {
        ways.add((Way) osm);
      }
    }

    if (ways.size() < 2) return null;

    long idToKeep = 0;
    Way wayToKeep = ways.iterator().next();
    // Only one way will be kept - the one with lowest positive ID, if such exist
    // or one "at random" if no such exists. Rest of the ways will be deleted
    for (Way w : ways) {
      if (!w.isNew()) {
        if (idToKeep == 0 || w.getId() < idToKeep) {
          idToKeep = w.getId();
          wayToKeep = w;
        }
      }
    }

    // Find the way that is member of one or more relations. (If any)
    Way wayWithRelations = null;
    List<Relation> relations = null;
    for (Way w : ways) {
      List<Relation> rel = OsmPrimitive.getFilteredList(w.getReferrers(), Relation.class);
      if (!rel.isEmpty()) {
        if (wayWithRelations != null)
          throw new AssertionError(
              "Cannot fix duplicate Ways: More than one way is relation member.");
        wayWithRelations = w;
        relations = rel;
      }
    }

    Collection<Command> commands = new LinkedList<Command>();

    // Fix relations.
    if (wayWithRelations != null && wayToKeep != wayWithRelations) {
      for (Relation rel : relations) {
        Relation newRel = new Relation(rel);
        for (int i = 0; i < newRel.getMembers().size(); ++i) {
          RelationMember m = newRel.getMember(i);
          if (wayWithRelations.equals(m.getMember())) {
            newRel.setMember(i, new RelationMember(m.getRole(), wayToKeep));
          }
        }
        commands.add(new ChangeCommand(rel, newRel));
      }
    }

    // Delete all ways in the list
    // Note: nodes are not deleted, these can be detected and deleted at next pass
    ways.remove(wayToKeep);
    commands.add(new DeleteCommand(ways));
    return new SequenceCommand(tr("Delete duplicate ways"), commands);
  }
コード例 #6
0
ファイル: DuplicateRelation.java プロジェクト: windu2b/josm
  /**
   * Fix the error by removing all but one instance of duplicate relations
   *
   * @param testError The error to fix, must be of type {@link #DUPLICATE_RELATION}
   */
  @Override
  public Command fixError(TestError testError) {
    if (testError.getCode() == SAME_RELATION) return null;
    Collection<? extends OsmPrimitive> sel = testError.getPrimitives();
    HashSet<Relation> rel_fix = new HashSet<Relation>();

    for (OsmPrimitive osm : sel)
      if (osm instanceof Relation && !osm.isDeleted()) {
        rel_fix.add((Relation) osm);
      }

    if (rel_fix.size() < 2) return null;

    long idToKeep = 0;
    Relation relationToKeep = rel_fix.iterator().next();
    // Only one relation will be kept - the one with lowest positive ID, if such exist
    // or one "at random" if no such exists. Rest of the relations will be deleted
    for (Relation w : rel_fix) {
      if (!w.isNew()) {
        if (idToKeep == 0 || w.getId() < idToKeep) {
          idToKeep = w.getId();
          relationToKeep = w;
        }
      }
    }

    // Find the relation that is member of one or more relations. (If any)
    Relation relationWithRelations = null;
    List<Relation> rel_ref = null;
    for (Relation w : rel_fix) {
      List<Relation> rel = OsmPrimitive.getFilteredList(w.getReferrers(), Relation.class);
      if (!rel.isEmpty()) {
        if (relationWithRelations != null)
          throw new AssertionError(
              "Cannot fix duplicate relations: More than one relation is member of another relation.");
        relationWithRelations = w;
        rel_ref = rel;
      }
    }

    Collection<Command> commands = new LinkedList<Command>();

    // Fix relations.
    if (relationWithRelations != null && relationToKeep != relationWithRelations) {
      for (Relation rel : rel_ref) {
        Relation newRel = new Relation(rel);
        for (int i = 0; i < newRel.getMembers().size(); ++i) {
          RelationMember m = newRel.getMember(i);
          if (relationWithRelations.equals(m.getMember())) {
            newRel.setMember(i, new RelationMember(m.getRole(), relationToKeep));
          }
        }
        commands.add(new ChangeCommand(rel, newRel));
      }
    }

    // Delete all relations in the list
    rel_fix.remove(relationToKeep);
    commands.add(new DeleteCommand(rel_fix));
    return new SequenceCommand(tr("Delete duplicate relations"), commands);
  }