Ignore:
Timestamp:
2014-02-07T01:34:02+01:00 (10 years ago)
Author:
bastiK
Message:

#8902 Small performance enhancements / coding style (patch by shinigami, parts)

patterns.diff: precompiled patterns
(only those parts applied, where performance may be relevant)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r6806 r6823  
    4141import java.util.List;
    4242import java.util.regex.Matcher;
     43import java.util.regex.Pattern;
    4344import java.util.zip.GZIPInputStream;
    4445import java.util.zip.ZipFile;
     
    5354 */
    5455public final class Utils {
     56
     57    public static final Pattern WHITE_SPACES_PATTERN = Pattern.compile("\\s+");
    5558
    5659    private Utils() {
     
    318321     * @param in The source file
    319322     * @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
    321324     */
    322325    public static void copyFile(File in, File out) throws IOException  {
     
    365368
    366369    /**
    367      * <p>Utility method for closing a {@link Closeable} object.</p>
     370     * <p>Utility method for closing a {@link java.io.Closeable} object.</p>
    368371     *
    369372     * @param c the closeable object. May be null.
     
    379382
    380383    /**
    381      * <p>Utility method for closing a {@link ZipFile}.</p>
     384     * <p>Utility method for closing a {@link java.util.zip.ZipFile}.</p>
    382385     *
    383386     * @param zip the zip file. May be null.
     
    577580    /**
    578581     * 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.
    580583     * @param <A> class of input collection
    581584     * @param <B> class of transformed collection
     
    619622    /**
    620623     * 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.
    622625     * @param <A> class of input collection
    623626     * @param <B> class of transformed collection
     
    644647    }
    645648
     649    private static final Pattern HTTP_PREFFIX_PATTERN = Pattern.compile("https?");
     650
    646651    /**
    647652     * Opens a HTTP connection to the given URL and sets the User-Agent property to JOSM's one.
    648653     * @param httpURL The HTTP url to open (must use http:// or https://)
    649654     * @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.
    651656     * @since 5587
    652657     */
    653658    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()) {
    655660            throw new IllegalArgumentException("Invalid HTTP url");
    656661        }
     
    665670     * @param url The url to open
    666671     * @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.
    668673     * @since 5867
    669674     */
     
    711716     * @param url The url to open
    712717     * @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.
    714719     * @since 5868
    715720     */
     
    736741     * @param keepAlive whether not to set header {@code Connection=close}
    737742     * @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.
    739744     * @since 5587
    740745     */
Note: See TracChangeset for help on using the changeset viewer.