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

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

CyclicUploadDependencyException: Copy the collection passed to the constructor. Fix squid:S1149

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