source: josm/trunk/src/org/openstreetmap/josm/data/osm/CyclicUploadDependencyException.java@ 13437

Last change on this file since 13437 was 12673, checked in by Don-vip, 7 years ago

see #15182 - move CyclicUploadDependencyException from actions.upload to data.osm (used in data.APIDataSet)

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.ArrayList;
7import java.util.Collections;
8import java.util.List;
9import java.util.Stack;
10
11/**
12 * This is an exception that is thrown if the user attempts to upload a list of relations with a cyclic dependency in them
13 * @since 12673 (moved from {@code action.upload} package)
14 */
15public class CyclicUploadDependencyException extends Exception {
16 private final List<Relation> cycle;
17
18 /**
19 * Creates a new {@link CyclicUploadDependencyException}
20 * @param cycle The cycle that was found
21 */
22 public CyclicUploadDependencyException(Stack<Relation> cycle) {
23 this.cycle = new ArrayList<>(cycle);
24 }
25
26 protected String formatRelation(Relation r) {
27 StringBuilder sb = new StringBuilder();
28 if (r.getName() != null) {
29 sb.append('\'').append(r.getName()).append('\'');
30 } else if (!r.isNew()) {
31 sb.append(r.getId());
32 } else {
33 sb.append("relation@").append(r.hashCode());
34 }
35 return sb.toString();
36 }
37
38 @Override
39 public String getMessage() {
40 StringBuilder sb = new StringBuilder();
41 sb.append(tr("Cyclic dependency between relations:"))
42 .append('[');
43 for (int i = 0; i < cycle.size(); i++) {
44 if (i > 0) {
45 sb.append(',');
46 }
47 sb.append(formatRelation(cycle.get(i)));
48 }
49 sb.append(']');
50 return sb.toString();
51 }
52
53 /**
54 * Gets the cycle
55 * @return The cycle that was detected
56 */
57 public List<Relation> getCyclicUploadDependency() {
58 return Collections.unmodifiableList(cycle);
59 }
60}
Note: See TracBrowser for help on using the repository browser.