- Timestamp:
- 2014-02-07T01:34:02+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/TagCollection.java
r6317 r6823 16 16 import java.util.Map.Entry; 17 17 import java.util.Set; 18 import java.util.regex.Pattern; 19 18 20 import org.openstreetmap.josm.tools.Utils; 19 21 20 22 /** 21 23 * TagCollection is a collection of tags which can be used to manipulate 22 * tags managed by {@link OsmPrimitive}s. 24 * tags managed by {@link org.openstreetmap.josm.data.osm.OsmPrimitive}s. 23 25 * 24 26 * A TagCollection can be created: 25 27 * <ul> 26 * <li>from the tags managed by a specific {@link OsmPrimitive} with {@link #from(Tagged)}</li> 27 * <li>from the union of all tags managed by a collection of {@link OsmPrimitive}s with {@link #unionOfAllPrimitives(Collection)}</li> 28 * <li>from the union of all tags managed by a {@link DataSet} with {@link #unionOfAllPrimitives(DataSet)}</li> 29 * <li>from the intersection of all tags managed by a collection of primitives with {@link #commonToAllPrimitives(Collection)}</li> 28 * <li>from the tags managed by a specific {@link org.openstreetmap.josm.data.osm.OsmPrimitive} with {@link #from(org.openstreetmap.josm.data.osm.Tagged)}</li> 29 * <li>from the union of all tags managed by a collection of {@link org.openstreetmap.josm.data.osm.OsmPrimitive}s with {@link #unionOfAllPrimitives(java.util.Collection)}</li> 30 * <li>from the union of all tags managed by a {@link org.openstreetmap.josm.data.osm.DataSet} with {@link #unionOfAllPrimitives(org.openstreetmap.josm.data.osm.DataSet)}</li> 31 * <li>from the intersection of all tags managed by a collection of primitives with {@link #commonToAllPrimitives(java.util.Collection)}</li> 30 32 * </ul> 31 33 * … … 33 35 * 34 36 * Basic set operations allow to create the union, the intersection and the difference 35 * of tag collections, see {@link #union(TagCollection)}, {@link #intersect(TagCollection)}, 36 * and {@link #minus(TagCollection)}. 37 * of tag collections, see {@link #union(org.openstreetmap.josm.data.osm.TagCollection)}, {@link #intersect(org.openstreetmap.josm.data.osm.TagCollection)}, 38 * and {@link #minus(org.openstreetmap.josm.data.osm.TagCollection)}. 37 39 * 38 40 * … … 42 44 /** 43 45 * Creates a tag collection from the tags managed by a specific 44 * {@link OsmPrimitive}. If <code>primitive</code> is null, replies 46 * {@link org.openstreetmap.josm.data.osm.OsmPrimitive}. If <code>primitive</code> is null, replies 45 47 * an empty tag collection. 46 48 * 47 49 * @param primitive the primitive 48 50 * @return a tag collection with the tags managed by a specific 49 * {@link OsmPrimitive} 51 * {@link org.openstreetmap.josm.data.osm.OsmPrimitive} 50 52 */ 51 53 public static TagCollection from(Tagged primitive) { … … 590 592 591 593 /** 592 * Applies this tag collection to an {@link OsmPrimitive}. Does nothing if 594 * Applies this tag collection to an {@link org.openstreetmap.josm.data.osm.OsmPrimitive}. Does nothing if 593 595 * primitive is null 594 596 * … … 611 613 612 614 /** 613 * Applies this tag collection to a collection of {@link OsmPrimitive}s. Does nothing if 615 * Applies this tag collection to a collection of {@link org.openstreetmap.josm.data.osm.OsmPrimitive}s. Does nothing if 614 616 * primitives is null 615 617 * … … 628 630 629 631 /** 630 * Replaces the tags of an {@link OsmPrimitive} by the tags in this collection . Does nothing if 632 * Replaces the tags of an {@link org.openstreetmap.josm.data.osm.OsmPrimitive} by the tags in this collection . Does nothing if 631 633 * primitive is null 632 634 * … … 646 648 647 649 /** 648 * Replaces the tags of a collection of{@link OsmPrimitive}s by the tags in this collection. 650 * Replaces the tags of a collection of{@link org.openstreetmap.josm.data.osm.OsmPrimitive}s by the tags in this collection. 649 651 * Does nothing if primitives is null 650 652 * … … 716 718 } 717 719 720 private static final Pattern SPLIT_VALUES_PATTERN = Pattern.compile(";\\s*"); 721 718 722 /** 719 723 * Replies the concatenation of all tag values (concatenated by a semicolon) … … 732 736 Map<String, Collection<String>> originalSplitValues = new LinkedHashMap<String, Collection<String>>(); 733 737 for (String v : originalValues) { 734 List<String> vs = Arrays.asList( v.split(";\\s*"));738 List<String> vs = Arrays.asList(SPLIT_VALUES_PATTERN.split(v)); 735 739 originalSplitValues.put(v, vs); 736 740 values.addAll(vs); -
trunk/src/org/openstreetmap/josm/data/projection/CustomProjection.java
r6798 r6823 157 157 private Map<String, String> parseParameterList(String pref) throws ProjectionConfigurationException { 158 158 Map<String, String> parameters = new HashMap<String, String>(); 159 String[] parts = pref.trim() .split("\\s+");159 String[] parts = Utils.WHITE_SPACES_PATTERN.split(pref.trim()); 160 160 if (pref.trim().isEmpty()) { 161 161 parts = new String[0]; -
trunk/src/org/openstreetmap/josm/data/validation/tests/NameMismatch.java
r6591 r6823 7 7 import java.util.HashSet; 8 8 import java.util.Map.Entry; 9 import java.util.regex.Pattern; 9 10 10 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 32 33 protected static final int NAME_MISSING = 1501; 33 34 protected static final int NAME_TRANSLATION_MISSING = 1502; 35 private static final Pattern NAME_SPLIT_PATTERN = Pattern.compile(" - "); 34 36 35 37 /** … … 86 88 Check if this is the case. */ 87 89 88 String[] splitNames = name.split(" - ");90 String[] splitNames = NAME_SPLIT_PATTERN.split(name); 89 91 if (splitNames.length == 1) { 90 92 /* The name is not composed of multiple parts. Complain. */ -
trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
r6783 r6823 669 669 } 670 670 671 public String getData(String str) { 672 Matcher m = Pattern.compile(" *# *([^#]+) *$").matcher(str); 673 str = m.replaceFirst("").trim(); 671 private static final Pattern CLEAN_STR_PATTERN = Pattern.compile(" *# *([^#]+) *$"); 672 private static final Pattern SPLIT_TRIMMED_PATTERN = Pattern.compile(" *: *"); 673 private static final Pattern SPLIT_ELEMENTS_PATTERN = Pattern.compile(" *&& *"); 674 675 public String getData(final String str) { 676 Matcher m = CLEAN_STR_PATTERN.matcher(str); 677 String trimmed = m.replaceFirst("").trim(); 674 678 try { 675 679 description = m.group(1); … … 680 684 description = null; 681 685 } 682 String[] n = str.split(" *: *", 3);686 String[] n = SPLIT_TRIMMED_PATTERN.split(trimmed, 3); 683 687 if (n[0].equals("way")) { 684 688 type = OsmPrimitiveType.WAY; … … 705 709 } else 706 710 return tr("Could not find warning level"); 707 for (String exp: n[2].split(" *&& *")) {711 for (String exp: SPLIT_ELEMENTS_PATTERN.split(n[2])) { 708 712 try { 709 713 data.add(new CheckerElement(exp)); -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r6806 r6823 41 41 import java.util.List; 42 42 import java.util.regex.Matcher; 43 import java.util.regex.Pattern; 43 44 import java.util.zip.GZIPInputStream; 44 45 import java.util.zip.ZipFile; … … 53 54 */ 54 55 public final class Utils { 56 57 public static final Pattern WHITE_SPACES_PATTERN = Pattern.compile("\\s+"); 55 58 56 59 private Utils() { … … 318 321 * @param in The source file 319 322 * @param out The destination file 320 * @throws IOException If any I/O error occurs 323 * @throws java.io.IOException If any I/O error occurs 321 324 */ 322 325 public static void copyFile(File in, File out) throws IOException { … … 365 368 366 369 /** 367 * <p>Utility method for closing a {@link Closeable} object.</p> 370 * <p>Utility method for closing a {@link java.io.Closeable} object.</p> 368 371 * 369 372 * @param c the closeable object. May be null. … … 379 382 380 383 /** 381 * <p>Utility method for closing a {@link ZipFile}.</p> 384 * <p>Utility method for closing a {@link java.util.zip.ZipFile}.</p> 382 385 * 383 386 * @param zip the zip file. May be null. … … 577 580 /** 578 581 * Transforms the collection {@code c} into an unmodifiable collection and 579 * applies the {@link Function} {@code f} on each element upon access. 582 * applies the {@link org.openstreetmap.josm.tools.Utils.Function} {@code f} on each element upon access. 580 583 * @param <A> class of input collection 581 584 * @param <B> class of transformed collection … … 619 622 /** 620 623 * Transforms the list {@code l} into an unmodifiable list and 621 * applies the {@link Function} {@code f} on each element upon access. 624 * applies the {@link org.openstreetmap.josm.tools.Utils.Function} {@code f} on each element upon access. 622 625 * @param <A> class of input collection 623 626 * @param <B> class of transformed collection … … 644 647 } 645 648 649 private static final Pattern HTTP_PREFFIX_PATTERN = Pattern.compile("https?"); 650 646 651 /** 647 652 * Opens a HTTP connection to the given URL and sets the User-Agent property to JOSM's one. 648 653 * @param httpURL The HTTP url to open (must use http:// or https://) 649 654 * @return An open HTTP connection to the given URL 650 * @throws IOException if an I/O exception occurs. 655 * @throws java.io.IOException if an I/O exception occurs. 651 656 * @since 5587 652 657 */ 653 658 public static HttpURLConnection openHttpConnection(URL httpURL) throws IOException { 654 if (httpURL == null || !httpURL.getProtocol().matches( "https?")) {659 if (httpURL == null || !HTTP_PREFFIX_PATTERN.matcher(httpURL.getProtocol()).matches()) { 655 660 throw new IllegalArgumentException("Invalid HTTP url"); 656 661 } … … 665 670 * @param url The url to open 666 671 * @return An stream for the given URL 667 * @throws IOException if an I/O exception occurs. 672 * @throws java.io.IOException if an I/O exception occurs. 668 673 * @since 5867 669 674 */ … … 711 716 * @param url The url to open 712 717 * @return An buffered stream reader for the given URL (using UTF-8) 713 * @throws IOException if an I/O exception occurs. 718 * @throws java.io.IOException if an I/O exception occurs. 714 719 * @since 5868 715 720 */ … … 736 741 * @param keepAlive whether not to set header {@code Connection=close} 737 742 * @return An open HTTP connection to the given URL 738 * @throws IOException if an I/O exception occurs. 743 * @throws java.io.IOException if an I/O exception occurs. 739 744 * @since 5587 740 745 */
Note:
See TracChangeset
for help on using the changeset viewer.