Exemple #1
0
  public String formatAsHtmlUnorderedList(Collection<? extends OsmPrimitive> primitives) {
    return Utils.joinAsHtmlUnorderedList(
        Utils.transform(
            primitives,
            new Function<OsmPrimitive, String>() {

              @Override
              public String apply(OsmPrimitive x) {
                return x.getDisplayName(DefaultNameFormatter.this);
              }
            }));
  }
  /**
   * Inform a non-expert user about what tag conflict resolution means.
   *
   * @param primitives The primitives to be combined
   * @param normalizedTags The normalized tag collection of the primitives to be combined
   * @throws UserCancelException If the user cancels the dialog.
   */
  protected static void informAboutTagConflicts(
      final Collection<? extends OsmPrimitive> primitives, final TagCollection normalizedTags)
      throws UserCancelException {
    String conflicts =
        Utils.joinAsHtmlUnorderedList(
            Utils.transform(
                normalizedTags.getKeysWithMultipleValues(),
                new Function<String, String>() {
                  @Override
                  public String apply(String key) {
                    return tr(
                        "{0} ({1})",
                        key,
                        Utils.join(
                            tr(", "),
                            Utils.transform(
                                normalizedTags.getValues(key),
                                new Function<String, String>() {
                                  @Override
                                  public String apply(String x) {
                                    return x == null || x.isEmpty() ? tr("<i>missing</i>") : x;
                                  }
                                })));
                  }
                }));
    String msg = /* for correct i18n of plural forms - see #9110 */
        trn(
            "You are about to combine {0} objects, "
                + "but the following tags are used conflictingly:<br/>{1}"
                + "If these objects are combined, the resulting object may have unwanted tags.<br/>"
                + "If you want to continue, you are shown a dialog to fix the conflicting tags.<br/><br/>"
                + "Do you want to continue?",
            "You are about to combine {0} objects, "
                + "but the following tags are used conflictingly:<br/>{1}"
                + "If these objects are combined, the resulting object may have unwanted tags.<br/>"
                + "If you want to continue, you are shown a dialog to fix the conflicting tags.<br/><br/>"
                + "Do you want to continue?",
            primitives.size(),
            primitives.size(),
            conflicts);

    if (!ConditionalOptionPaneUtil.showConfirmationDialog(
        "combine_tags",
        Main.parent,
        "<html>" + msg + "</html>",
        tr("Combine confirmation"),
        JOptionPane.YES_NO_OPTION,
        JOptionPane.QUESTION_MESSAGE,
        JOptionPane.YES_OPTION)) {
      throw new UserCancelException();
    }
  }
 @Override
 protected String buildRequestString(final OsmPrimitiveType type, Set<Long> idPackage) {
   final Utils.Function<Long, Object> toOverpassExpression =
       new Utils.Function<Long, Object>() {
         @Override
         public Object apply(Long x) {
           return type.getAPIName() + "(" + x + ");>;";
         }
       };
   final String query =
       "(" + Utils.join("", Utils.transform(idPackage, toOverpassExpression)) + ");out meta;";
   return "interpreter?data=" + Utils.encodeUrl(query);
 }
Exemple #4
0
 protected void checkNumberOfLanesByKey(final OsmPrimitive p, String lanesKey, String message) {
   final Collection<String> keysForPattern =
       Utils.filter(
           p.keySet(), Predicates.stringContainsPattern(Pattern.compile(":" + lanesKey + "$")));
   if (keysForPattern.size() < 1) {
     // nothing to check
     return;
   }
   final Set<Integer> lanesCount =
       new HashSet<Integer>(
           Utils.transform(
               keysForPattern,
               new Utils.Function<String, Integer>() {
                 @Override
                 public Integer apply(String key) {
                   return getLanesCount(p.get(key));
                 }
               }));
   if (lanesCount.size() > 1) {
     // if not all numbers are the same
     errors.add(new TestError(this, Severity.WARNING, message, 3100, p));
   } else if (lanesCount.size() == 1 && p.hasKey(lanesKey)) {
     // ensure that lanes <= *:lanes
     try {
       if (Integer.parseInt(p.get(lanesKey)) > lanesCount.iterator().next()) {
         errors.add(
             new TestError(
                 this,
                 Severity.WARNING,
                 tr("Number of {0} greater than {1}", lanesKey, "*:" + lanesKey),
                 3100,
                 p));
       }
     } catch (NumberFormatException ignore) {
       Main.debug(ignore.getMessage());
     }
   }
 }