Пример #1
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;
  }
Пример #2
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;
        }
Пример #3
0
 @Override
 public void visit(Relation r) {
   if (!r.isUsable() || r.hasIncompleteMembers()) return;
   List<RelationMember> rMembers = r.getMembers();
   Map<String, String> rkeys = r.getKeys();
   for (String key : ignoreKeys) rkeys.remove(key);
   RelationPair rKey = new RelationPair(rMembers, rkeys);
   relations.put(rKey, r);
   relations_nokeys.put(rMembers, r);
 }
Пример #4
0
 protected void loadIncompleteRelationMembers() throws OsmTransferException {
   // if incomplete relation members exist, download them too
   for (Relation r : ds.getRelations()) {
     if (canceled) return;
     // Relations may be incomplete in case of nested relations if child relations are accessed
     // before their parent
     // (it may happen because "relations" has no deterministic sort order, see #10388)
     if (r.isIncomplete() || r.hasIncompleteMembers()) {
       synchronized (this) {
         if (canceled) return;
         objectReader =
             new OsmServerObjectReader(r.getId(), OsmPrimitiveType.RELATION, fullRelation);
       }
       DataSet theirDataSet =
           objectReader.parseOsm(
               progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));
       synchronized (this) {
         objectReader = null;
       }
       new DataSetMerger(ds, theirDataSet).merge();
     }
   }
 }