void addRelationMembers(Relation r) {
   add(trn("{0} Member: ", "{0} Members: ", r.getMembersCount(), r.getMembersCount()));
   for (RelationMember m : r.getMembers()) {
     s.append(INDENT).append(INDENT);
     addHeadline(m.getMember());
     s.append(tr(" as \"{0}\"", m.getRole()));
     s.append(NL);
   }
 }
Exemplo n.º 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;
   }
 }
 /**
  * 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;
 }
Exemplo n.º 4
0
  /**
   * Formats a name for a relation
   *
   * @param relation the relation
   * @return the name
   */
  @Override
  public String format(Relation relation) {
    StringBuilder name = new StringBuilder();
    if (relation.isIncomplete()) {
      name.append(tr("incomplete"));
    } else {
      TaggingPreset preset =
          TaggingPresetNameTemplateList.getInstance().findPresetTemplate(relation);

      formatRelationNameAndType(relation, name, preset);

      int mbno = relation.getMembersCount();
      name.append(trn("{0} member", "{0} members", mbno, mbno));

      if (relation.hasIncompleteMembers()) {
        name.append(", ").append(tr("incomplete"));
      }

      name.append(")");
    }
    decorateNameWithId(name, relation);

    String result = name.toString();
    for (NameFormatterHook hook : formatHooks) {
      String hookResult = hook.checkFormat(relation, result);
      if (hookResult != null) return hookResult;
    }

    return result;
  }
 @Test
 public void testMultiGet10Relations() throws OsmTransferException {
   MultiFetchServerObjectReader reader = new MultiFetchServerObjectReader();
   ArrayList<Relation> relations = new ArrayList<>(ds.getRelations());
   for (int i = 0; i < 10; i++) {
     reader.append(relations.get(i));
   }
   DataSet out = reader.parseOsm(NullProgressMonitor.INSTANCE);
   assertEquals(10, out.getRelations().size());
   for (Relation r1 : out.getRelations()) {
     Relation r2 = (Relation) ds.getPrimitiveById(r1);
     assertNotNull(r2);
     assertEquals(r2.getMembersCount(), r1.getMembersCount());
     assertEquals(r2.get("name"), r2.get("name"));
   }
   assertTrue(reader.getMissingPrimitives().isEmpty());
 }
Exemplo n.º 6
0
        @Override
        public int compare(Relation r1, Relation r2) {
          // TODO This doesn't work correctly with formatHooks

          TaggingPreset preset1 =
              TaggingPresetNameTemplateList.getInstance().findPresetTemplate(r1);
          TaggingPreset preset2 =
              TaggingPresetNameTemplateList.getInstance().findPresetTemplate(r2);

          if (preset1 != null || preset2 != null) {
            StringBuilder name1 = new StringBuilder();
            formatRelationNameAndType(r1, name1, preset1);
            StringBuilder name2 = new StringBuilder();
            formatRelationNameAndType(r2, name2, preset2);

            int comp = name1.toString().compareTo(name2.toString());
            if (comp != 0) return comp;
          } else {

            String type1 = getRelationTypeName(r1);
            String type2 = getRelationTypeName(r2);

            int comp = ALPHANUM_COMPARATOR.compare(type1, type2);
            if (comp != 0) return comp;

            String name1 = getRelationName(r1);
            String name2 = getRelationName(r2);

            comp = ALPHANUM_COMPARATOR.compare(name1, name2);
            if (comp != 0) return comp;
          }

          if (r1.getMembersCount() != r2.getMembersCount())
            return (r1.getMembersCount() > r2.getMembersCount()) ? 1 : -1;

          int comp =
              Boolean.valueOf(r1.hasIncompleteMembers())
                  .compareTo(Boolean.valueOf(r2.hasIncompleteMembers()));
          if (comp != 0) return comp;

          if (r1.getUniqueId() > r2.getUniqueId()) return 1;
          else if (r1.getUniqueId() < r2.getUniqueId()) return -1;
          else return 0;
        }
Exemplo n.º 7
0
      @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;
            }
          }
        }
      }
 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;
 }