source: josm/trunk/src/org/openstreetmap/josm/actions/upload/CyclicUploadDependencyException.java@ 12364

Last change on this file since 12364 was 12364, checked in by michael2402, 7 years ago

Javadoc: CyclicUploadDependencyException

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions.upload;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.ArrayList;
7import java.util.List;
8import java.util.Stack;
9
10import org.openstreetmap.josm.data.osm.Relation;
11
12/**
13 * This is an exception that is thrown if the user attempts to upload a list of relations with a cyclic dependency in them
14 */
15public class CyclicUploadDependencyException extends Exception {
16 private final Stack<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 = 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 new ArrayList<>(cycle);
59 }
60}
Note: See TracBrowser for help on using the repository browser.