Changeset 32725 in osm for applications/editors/josm
- Timestamp:
- 2016-07-27T03:10:06+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin2
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/build.xml
r32680 r32725 5 5 <property name="commit.message" value="[josm_utilsplugin2]: select boundary by double-click; multitagger table highlights"/> 6 6 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 7 <property name="plugin.main.version" value="10 580"/>7 <property name="plugin.main.version" value="10658"/> 8 8 9 9 <property name="plugin.author" value="Kalle Lampila, Upliner, Zverik, akks, joshdoe and others"/> -
applications/editors/josm/plugins/utilsplugin2/src/edu/princeton/cs/algs4/Bag.java
r28116 r32725 14 14 15 15 /** 16 * The <tt>Bag</tt> class represents a bag (or multiset) of 17 * generic items. It supports insertion and iterating over the 16 * The <tt>Bag</tt> class represents a bag (or multiset) of 17 * generic items. It supports insertion and iterating over the 18 18 * items in arbitrary order. 19 19 * <p> 20 * The <em>add</em>, <em>isEmpty</em>, and <em>size</em> operation 20 * The <em>add</em>, <em>isEmpty</em>, and <em>size</em> operation 21 21 * take constant time. Iteration takes time proportional to the number of items. 22 22 * <p> … … 34 34 } 35 35 36 /**36 /** 37 37 * Create an empty stack. 38 38 */ … … 43 43 } 44 44 45 /**45 /** 46 46 * Is the BAG empty? 47 47 */ … … 50 50 } 51 51 52 /**52 /** 53 53 * Return the number of items in the bag. 54 54 */ … … 57 57 } 58 58 59 /**59 /** 60 60 * Add the item to the bag. 61 61 */ … … 90 90 91 91 return true; 92 } 92 } 93 93 94 95 /** 94 /** 96 95 * Return an iterator that iterates over the items in the bag. 97 96 */ 97 @Override 98 98 public Iterator<Item> iterator() { 99 return new ListIterator(); 99 return new ListIterator(); 100 100 } 101 101 … … 104 104 private Node current = first; 105 105 106 @Override 106 107 public boolean hasNext() { return current != null; } 108 @Override 107 109 public void remove() { throw new UnsupportedOperationException(); } 108 110 111 @Override 109 112 public Item next() { 110 113 if (!hasNext()) throw new NoSuchElementException(); 111 114 Item item = current.item; 112 current = current.next; 115 current = current.next; 113 116 return item; 114 117 } 115 118 } 116 117 119 } -
applications/editors/josm/plugins/utilsplugin2/src/edu/princeton/cs/algs4/DirectedEdge.java
r28116 r32725 17 17 */ 18 18 19 public class DirectedEdge { 19 public class DirectedEdge { 20 20 private final int v; 21 21 private final int w; 22 22 private final double weight; 23 23 24 /**24 /** 25 25 * Create a directed edge from v to w with given weight. 26 26 */ … … 31 31 } 32 32 33 /**33 /** 34 34 * Return the vertex where this edge begins. 35 35 */ … … 38 38 } 39 39 40 /**40 /** 41 41 * Return the vertex where this edge ends. 42 42 */ … … 45 45 } 46 46 47 /**47 /** 48 48 * Return the weight of this edge. 49 49 */ 50 50 public double weight() { return weight; } 51 51 52 /**52 /** 53 53 * Return a string representation of this edge. 54 54 */ 55 @Override 55 56 public String toString() { 56 57 return v + "->" + w + " " + String.format("%5.2f", weight); 57 58 } 58 59 /**60 * Test client.61 */62 // public static void main(String[] args) {63 // DirectedEdge e = new DirectedEdge(12, 23, 3.14);64 // StdOut.println(e);65 // }66 59 } -
applications/editors/josm/plugins/utilsplugin2/src/edu/princeton/cs/algs4/EdgeWeightedDigraph.java
r30737 r32725 25 25 private int E; 26 26 private Bag<DirectedEdge>[] adj; 27 27 28 28 /** 29 29 * Create an empty edge-weighted digraph with V vertices. … … 34 34 this.V = V; 35 35 this.E = 0; 36 adj = (Bag<DirectedEdge>[])new Bag[V];36 adj = new Bag[V]; 37 37 for (int v = 0; v < V; v++) 38 38 adj[v] = new Bag<>(); 39 39 } 40 40 41 /**41 /** 42 42 * Create a edge-weighted digraph with V vertices and E edges. 43 43 */ … … 57 57 * Create an edge-weighted digraph from input stream. 58 58 */ 59 // public EdgeWeightedDigraph(In in) {60 // this(in.readInt());61 // int E = in.readInt();62 // for (int i = 0; i < E; i++) {63 // int v = in.readInt();64 // int w = in.readInt();65 // double weight = in.readDouble();66 // addEdge(new DirectedEdge(v, w, weight));67 // }68 // }59 // public EdgeWeightedDigraph(In in) { 60 // this(in.readInt()); 61 // int E = in.readInt(); 62 // for (int i = 0; i < E; i++) { 63 // int v = in.readInt(); 64 // int w = in.readInt(); 65 // double weight = in.readDouble(); 66 // addEdge(new DirectedEdge(v, w, weight)); 67 // } 68 // } 69 69 70 /**70 /** 71 71 * Copy constructor. 72 72 */ … … 86 86 } 87 87 88 /**88 /** 89 89 * Return the number of vertices in this digraph. 90 90 */ … … 93 93 } 94 94 95 /**95 /** 96 96 * Return the number of edges in this digraph. 97 97 */ … … 100 100 } 101 101 102 /**102 /** 103 103 * Add the edge e to this digraph. 104 104 */ … … 109 109 } 110 110 111 /**111 /** 112 112 * Return the edges leaving vertex v as an Iterable. 113 113 * To iterate over the edges leaving vertex v, use foreach notation: … … 118 118 } 119 119 120 /**120 /** 121 121 * Return all edges in this graph as an Iterable. 122 122 * To iterate over the edges, use foreach notation: … … 131 131 } 132 132 return list; 133 } 133 } 134 134 135 /**135 /** 136 136 * Return number of edges leaving v. 137 137 */ … … 140 140 } 141 141 142 /**142 /** 143 143 * Return a string representation of this graph. 144 144 */ 145 @Override 145 146 public String toString() { 146 147 String NEWLINE = System.getProperty("line.separator"); -
applications/editors/josm/plugins/utilsplugin2/src/edu/princeton/cs/algs4/IndexMinPQ.java
r30737 r32725 51 51 52 52 // return the index associated with a minimal key 53 public int minIndex() { 53 public int minIndex() { 54 54 if (N == 0) throw new NoSuchElementException("Priority queue underflow"); 55 return pq[1]; 55 return pq[1]; 56 56 } 57 57 58 58 // return a minimal key 59 public Key minKey() { 59 public Key minKey() { 60 60 if (N == 0) throw new NoSuchElementException("Priority queue underflow"); 61 return keys[pq[1]]; 61 return keys[pq[1]]; 62 62 } 63 63 64 64 // delete a minimal key and returns its associated index 65 public int delMin() { 65 public int delMin() { 66 66 if (N == 0) throw new NoSuchElementException("Priority queue underflow"); 67 int min = pq[1]; 68 exch(1, N--); 67 int min = pq[1]; 68 exch(1, N--); 69 69 sink(1); 70 70 qp[min] = -1; // delete 71 71 keys[pq[N+1]] = null; // to help with garbage collection 72 72 pq[N+1] = -1; // not needed 73 return min; 73 return min; 74 74 } 75 75 … … 121 121 122 122 123 /**************************************************************124 * General helper functions125 **************************************************************/123 /************************************************************** 124 * General helper functions 125 **************************************************************/ 126 126 private boolean greater(int i, int j) { 127 127 return keys[pq[i]].compareTo(keys[pq[j]]) > 0; … … 134 134 135 135 136 /**************************************************************137 * Heap helper functions138 **************************************************************/136 /************************************************************** 137 * Heap helper functions 138 **************************************************************/ 139 139 private void swim(int k) { 140 140 while (k > 1 && greater(k/2, k)) { … … 155 155 156 156 157 /***********************************************************************158 * Iterators159 **********************************************************************/157 /*********************************************************************** 158 * Iterators 159 **********************************************************************/ 160 160 161 /**161 /** 162 162 * Return an iterator that iterates over all of the elements on the 163 163 * priority queue in ascending order. … … 165 165 * The iterator doesn't implement <tt>remove()</tt> since it's optional. 166 166 */ 167 @Override 167 168 public Iterator<Integer> iterator() { return new HeapIterator(); } 168 169 … … 179 180 } 180 181 182 @Override 181 183 public boolean hasNext() { return !copy.isEmpty(); } 184 @Override 182 185 public void remove() { throw new UnsupportedOperationException(); } 183 186 187 @Override 184 188 public Integer next() { 185 189 if (!hasNext()) throw new NoSuchElementException(); -
applications/editors/josm/plugins/utilsplugin2/src/edu/princeton/cs/algs4/Stack.java
r28116 r32725 8 8 * A generic stack, implemented using a linked list. Each stack 9 9 * element is of type Item. 10 * 11 * % more tobe.txt 10 * 11 * % more tobe.txt 12 12 * to be or not to - be - - that - - - is 13 13 * … … 42 42 } 43 43 44 /**44 /** 45 45 * Create an empty stack. 46 46 */ … … 51 51 } 52 52 53 /**53 /** 54 54 * Is the stack empty? 55 55 */ … … 58 58 } 59 59 60 /**60 /** 61 61 * Return the number of items in the stack. 62 62 */ … … 65 65 } 66 66 67 /**67 /** 68 68 * Add the item to the stack. 69 69 */ … … 77 77 } 78 78 79 /**79 /** 80 80 * Delete and return the item most recently added to the stack. 81 81 * Throw an exception if no such item exists because the stack is empty. … … 91 91 92 92 93 /**93 /** 94 94 * Return the item most recently added to the stack. 95 95 * Throw an exception if no such item exists because the stack is empty. … … 100 100 } 101 101 102 /**102 /** 103 103 * Return string representation. 104 104 */ 105 @Override 105 106 public String toString() { 106 107 StringBuilder s = new StringBuilder(); … … 109 110 return s.toString(); 110 111 } 111 112 112 113 113 114 // check internal invariants … … 132 133 133 134 return true; 134 } 135 } 135 136 136 137 137 /**138 /** 138 139 * Return an iterator to the stack that iterates through the items in LIFO order. 139 140 */ 141 @Override 140 142 public Iterator<Item> iterator() { return new ListIterator(); } 141 143 … … 143 145 private class ListIterator implements Iterator<Item> { 144 146 private Node current = first; 147 @Override 145 148 public boolean hasNext() { return current != null; } 149 @Override 146 150 public void remove() { throw new UnsupportedOperationException(); } 147 151 152 @Override 148 153 public Item next() { 149 154 if (!hasNext()) throw new NoSuchElementException(); 150 155 Item item = current.item; 151 current = current.next; 156 current = current.next; 152 157 return item; 153 158 } … … 155 160 156 161 157 /**162 /** 158 163 * A test client. 159 164 */ 160 // public static void main(String[] args) {161 // Stack<String> s = new Stack<String>();162 // while (!StdIn.isEmpty()) {163 // String item = StdIn.readString();164 // if (!item.equals("-")) s.push(item);165 // else if (!s.isEmpty()) StdOut.print(s.pop() + " ");166 // }167 // StdOut.println("(" + s.size() + " left on stack)");168 // }165 // public static void main(String[] args) { 166 // Stack<String> s = new Stack<String>(); 167 // while (!StdIn.isEmpty()) { 168 // String item = StdIn.readString(); 169 // if (!item.equals("-")) s.push(item); 170 // else if (!s.isEmpty()) StdOut.print(s.pop() + " "); 171 // } 172 // StdOut.println("(" + s.size() + " left on stack)"); 173 // } 169 174 } 170 175 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/CopyTagsAction.java
r32333 r32725 18 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 19 import org.openstreetmap.josm.data.osm.Tag; 20 import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils; 20 21 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 21 22 import org.openstreetmap.josm.tools.Shortcut; … … 62 63 } 63 64 } 64 if (!values.isEmpty()) Utils.copyToClipboard(Utils.join("\n", values)); 65 if (!values.isEmpty()) 66 ClipboardUtils.copyString(Utils.join("\n", values)); 65 67 } 66 68 … … 83 85 tr("Information"), 84 86 JOptionPane.INFORMATION_MESSAGE 85 );87 ); 86 88 return true; 87 89 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/PasteRelationsAction.java
r32410 r32725 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.datatransfer.UnsupportedFlavorException; 6 7 import java.awt.event.ActionEvent; 7 8 import java.awt.event.KeyEvent; 9 import java.io.IOException; 8 10 import java.util.ArrayList; 9 11 import java.util.Collection; 12 import java.util.Collections; 10 13 import java.util.HashMap; 11 14 import java.util.List; … … 21 24 import org.openstreetmap.josm.data.osm.Relation; 22 25 import org.openstreetmap.josm.data.osm.RelationMember; 26 import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils; 27 import org.openstreetmap.josm.gui.datatransfer.data.PrimitiveTransferData; 23 28 import org.openstreetmap.josm.tools.Shortcut; 24 29 … … 44 49 45 50 Map<Relation, String> relations = new HashMap<>(); 46 for (PrimitiveData pdata : Main.pasteBuffer.getDirectlyAdded()) { 51 Collection<PrimitiveData> data = Collections.emptySet(); 52 try { 53 data = ((PrimitiveTransferData) ClipboardUtils.getClipboard().getData(PrimitiveTransferData.DATA_FLAVOR)).getDirectlyAdded(); 54 } catch (UnsupportedFlavorException | IOException ex) { 55 Main.warn(ex); 56 } 57 for (PrimitiveData pdata : data) { 47 58 OsmPrimitive p = getLayerManager().getEditDataSet().getPrimitiveById(pdata.getUniqueId(), pdata.getType()); 48 59 if (p != null) { … … 98 109 @Override 99 110 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 100 setEnabled(selection != null && !selection.isEmpty() && !Main.pasteBuffer.isEmpty()); 111 setEnabled(selection != null && !selection.isEmpty() 112 && ClipboardUtils.getClipboard().isDataFlavorAvailable(PrimitiveTransferData.DATA_FLAVOR)); 101 113 } 102 114 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/TagBufferAction.java
r32410 r32725 13 13 import java.util.Map; 14 14 import java.util.Set; 15 import java.util.function.Predicate; 15 16 16 17 import org.openstreetmap.josm.Main; … … 20 21 import org.openstreetmap.josm.command.SequenceCommand; 21 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 import org.openstreetmap.josm.tools.Predicate;23 23 import org.openstreetmap.josm.tools.Shortcut; 24 import org.openstreetmap.josm.tools. Utils;24 import org.openstreetmap.josm.tools.SubclassFilteredCollection; 25 25 26 26 /** … … 31 31 public class TagBufferAction extends JosmAction { 32 32 private static final String TITLE = tr("Copy tags from previous selection"); 33 private static final Predicate<OsmPrimitive> IS_TAGGED_PREDICATE = new Predicate<OsmPrimitive>() { 34 @Override 35 public boolean evaluate(OsmPrimitive object) { 36 return object.isTagged(); 37 } 38 }; 33 private static final Predicate<OsmPrimitive> IS_TAGGED_PREDICATE = object -> object.isTagged(); 39 34 private Map<String, String> tags = new HashMap<>(); 40 35 private Map<String, String> currentTags = new HashMap<>(); … … 117 112 private void rememberSelectionTags() { 118 113 // Fix #8350 - only care about tagged objects 119 final Collection<OsmPrimitive> selectedTaggedObjects = Utils.filter(114 final Collection<OsmPrimitive> selectedTaggedObjects = SubclassFilteredCollection.filter( 120 115 getLayerManager().getEditDataSet().getSelected(), IS_TAGGED_PREDICATE); 121 116 if (!selectedTaggedObjects.isEmpty()) { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/command/ChangeRelationMemberCommand.java
r32410 r32725 6 6 import java.util.Collection; 7 7 import java.util.LinkedList; 8 import java.util.Objects; 8 9 9 10 import org.openstreetmap.josm.command.Command; … … 36 37 LinkedList<RelationMember> newrms = new LinkedList<>(); 37 38 for (RelationMember rm : relation.getMembers()) { 38 if ( rm.getMember() == oldP) {39 if (Objects.equals(rm.getMember(), oldP)) { 39 40 newrms.add(new RelationMember(rm.getRole(), newP)); 40 41 } else { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/curves/CircleArcMaker.java
r32410 r32725 11 11 import java.util.LinkedList; 12 12 import java.util.List; 13 import java.util.Objects; 13 14 import java.util.Set; 14 15 … … 178 179 // We look for the first anchor node. The next should be directly to the left or right. 179 180 // Exception when the way is closed 180 if ( n == anchorNodes[a]) {181 if (Objects.equals(n, anchorNodes[a])) { 181 182 bi = i; 182 183 Node otherAnchor = anchorNodes[a + 1]; 183 if (i > 0 && tw.getNode(i - 1) == otherAnchor) {184 if (i > 0 && Objects.equals(tw.getNode(i - 1), otherAnchor)) { 184 185 ei = i - 1; 185 } else if (i < (tw.getNodesCount() - 1) && tw.getNode(i + 1) == otherAnchor) {186 } else if (i < (tw.getNodesCount() - 1) && Objects.equals(tw.getNode(i + 1), otherAnchor)) { 186 187 ei = i + 1; 187 188 } else { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/customurl/URLList.java
r32410 r32725 4 4 import java.io.BufferedReader; 5 5 import java.io.File; 6 import java.io.FileReader;7 6 import java.io.IOException; 8 7 import java.io.PrintWriter; 8 import java.nio.charset.StandardCharsets; 9 import java.nio.file.Files; 9 10 import java.util.ArrayList; 10 11 import java.util.List; … … 70 71 public static List<String> loadURLList() { 71 72 ArrayList<String> items = new ArrayList<>(); 72 BufferedReader fr = null; 73 try { 74 File f = new File(UtilsPlugin2.getInstance().getPluginDir(), "customurl.txt"); 75 fr = new BufferedReader(new FileReader(f)); 73 File f = new File(UtilsPlugin2.getInstance().getPluginDir(), "customurl.txt"); 74 try (BufferedReader fr = Files.newBufferedReader(f.toPath(), StandardCharsets.UTF_8)) { 76 75 String s; 77 while ((s = fr.readLine()) != null) items.add(s); 76 while ((s = fr.readLine()) != null) { 77 items.add(s); 78 } 78 79 } catch (IOException e) { 79 e.printStackTrace(); 80 } finally { 81 try { 82 if (fr != null) 83 fr.close(); 84 } catch (Exception e) { 85 Main.warn(e); 86 } 80 Main.error(e); 87 81 } 88 82 return items; -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/latlon/LatLonAction.java
r32410 r32725 68 68 } 69 69 70 if ( type == "nodes") {70 if ("nodes".equals(type)) { 71 71 //we dont need to do anything, we already have all the nodes 72 } 73 if (type == "way") { 72 } else if ("way".equals(type)) { 74 73 Way wnew = new Way(); 75 74 wnew.setNodes(nodes); 76 75 cmds.add(new AddCommand(wnew)); 77 } 78 if (type == "area") { 76 } else if ("area".equals(type)) { 79 77 nodes.add(nodes.get(0)); // this is needed to close the way. 80 78 Way wnew = new Way(); -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/ParentsMatch.java
r32410 r32725 22 22 @Override 23 23 protected Long getNumber(OsmPrimitive osm) { 24 return new Long(osm.getReferrers().size());24 return Long.valueOf(osm.getReferrers().size()); 25 25 } 26 26 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/UsedInRelationsMatch.java
r32410 r32725 25 25 } 26 26 27 private class RelationCounter implements Visitor {27 private static class RelationCounter implements Visitor { 28 28 int count; 29 29 @Override … … 54 54 counter.count = 0; 55 55 osm.visitReferrers(counter); 56 return new Long(counter.count);56 return Long.valueOf(counter.count); 57 57 } 58 58 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/UsedInWaysMatch.java
r32410 r32725 25 25 } 26 26 27 private class WayCounter implements Visitor {27 private static class WayCounter implements Visitor { 28 28 int count; 29 29 @Override … … 54 54 counter.count = 0; 55 55 osm.visitReferrers(counter); 56 return new Long(counter.count);56 return Long.valueOf(counter.count); 57 57 } else return null; 58 58 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/NodeWayUtils.java
r32410 r32725 9 9 import java.util.Iterator; 10 10 import java.util.List; 11 import java.util.Objects; 11 12 import java.util.Set; 12 13 … … 107 108 int count = 0; 108 109 for (Way anyway: ways) { 109 if ( anyway == w) continue;110 if (Objects.equals(anyway, w)) continue; 110 111 if (newWays.contains(anyway) || excludeWays.contains(anyway)) continue; 111 112 … … 130 131 int count = 0; 131 132 for (Way anyway: ways) { 132 if ( anyway == w) continue;133 if (Objects.equals(anyway, w)) continue; 133 134 if (newWays.contains(anyway)) continue; 134 135 List<Pair<Node, Node>> nodePairs2 = anyway.getNodePairs(false); … … 291 292 292 293 for (OsmPrimitive ref : curNode.getReferrers()) { 293 if (ref instanceof Way && ref != w&& ref.isSelectable()) {294 if (ref instanceof Way && !Objects.equals(ref, w) && ref.isSelectable()) { 294 295 // 295 296 Way w2 = (Way) ref; … … 298 299 if (w2.getNodesCount() < 2 || w2.isClosed()) continue; 299 300 300 if ( curNode == w2.firstNode()) {301 if (Objects.equals(curNode, w2.firstNode())) { 301 302 nextNode = w2.getNode(1); 302 303 preLast = w2.getNode(w2.getNodesCount()-2); 303 304 endNode = w2.lastNode(); // forward direction 304 } else if ( curNode == w2.lastNode()) {305 } else if (Objects.equals(curNode, w2.lastNode())) { 305 306 nextNode = w2.getNode(w2.getNodesCount()-2); 306 307 preLast = w2.getNode(1); … … 321 322 } 322 323 } 323 if ( firstWay == nextWay) {324 if (Objects.equals(firstWay, nextWay)) { 324 325 //we came to starting way, but not not the right end 325 if ( otherEnd == firstWay.firstNode()) return false;326 if (Objects.equals(otherEnd, firstWay.firstNode())) return false; 326 327 newWays.addAll(newestWays); 327 328 return true; // correct loop found
Note:
See TracChangeset
for help on using the changeset viewer.