Changeset 6127 in josm for trunk/src/com/drew/lang


Ignore:
Timestamp:
2013-08-09T18:05:11+02:00 (11 years ago)
Author:
bastiK
Message:

applied #8895 - Upgrade metadata-extractor to v. 2.6.4 (patch by ebourg)

Location:
trunk/src/com/drew/lang
Files:
9 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/drew/lang/CompoundException.java

    r4231 r6127  
    11/*
    2  * This is public domain software - that is, you can do whatever you want
    3  * with it, and include it software that is licensed under the GNU or the
    4  * BSD license, or whatever other licence you choose, including proprietary
    5  * closed source licenses.  I do ask that you leave this header in tact.
     2 * Copyright 2002-2012 Drew Noakes
    63 *
    7  * If you make modifications to this code that you think would benefit the
    8  * wider community, please send me a copy and I'll post it on my site.
     4 *    Licensed under the Apache License, Version 2.0 (the "License");
     5 *    you may not use this file except in compliance with the License.
     6 *    You may obtain a copy of the License at
    97 *
    10  * If you make use of this code, I'd appreciate hearing about it.
    11  *   drew@drewnoakes.com
    12  * Latest version of this software kept at
    13  *   http://drewnoakes.com/
     8 *        http://www.apache.org/licenses/LICENSE-2.0
     9 *
     10 *    Unless required by applicable law or agreed to in writing, software
     11 *    distributed under the License is distributed on an "AS IS" BASIS,
     12 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 *    See the License for the specific language governing permissions and
     14 *    limitations under the License.
     15 *
     16 * More information about this project is available at:
     17 *
     18 *    http://drewnoakes.com/code/exif/
     19 *    http://code.google.com/p/metadata-extractor/
    1420 */
    1521package com.drew.lang;
     22
     23import com.drew.lang.annotations.NotNull;
     24import com.drew.lang.annotations.Nullable;
    1625
    1726import java.io.PrintStream;
     
    2231 * unavailable in previous versions.  This class allows support
    2332 * of these previous JDK versions.
     33 *
     34 * @author Drew Noakes http://drewnoakes.com
    2435 */
    2536public class CompoundException extends Exception
    2637{
    27     private final Throwable _innnerException;
     38    private static final long serialVersionUID = -9207883813472069925L;
    2839
    29     public CompoundException(String msg)
     40    @Nullable
     41    private final Throwable _innerException;
     42
     43    public CompoundException(@Nullable String msg)
    3044    {
    3145        this(msg, null);
    3246    }
    3347
    34     public CompoundException(Throwable exception)
     48    public CompoundException(@Nullable Throwable exception)
    3549    {
    3650        this(null, exception);
    3751    }
    3852
    39     public CompoundException(String msg, Throwable innerException)
     53    public CompoundException(@Nullable String msg, @Nullable Throwable innerException)
    4054    {
    4155        super(msg);
    42         _innnerException = innerException;
     56        _innerException = innerException;
    4357    }
    4458
     59    @Nullable
    4560    public Throwable getInnerException()
    4661    {
    47         return _innnerException;
     62        return _innerException;
    4863    }
    4964
     65    @NotNull
    5066    public String toString()
    5167    {
    52         StringBuffer sbuffer = new StringBuffer();
    53         sbuffer.append(super.toString());
    54         if (_innnerException != null) {
    55             sbuffer.append("\n");
    56             sbuffer.append("--- inner exception ---");
    57             sbuffer.append("\n");
    58             sbuffer.append(_innnerException.toString());
     68        StringBuilder string = new StringBuilder();
     69        string.append(super.toString());
     70        if (_innerException != null) {
     71            string.append("\n");
     72            string.append("--- inner exception ---");
     73            string.append("\n");
     74            string.append(_innerException.toString());
    5975        }
    60         return sbuffer.toString();
     76        return string.toString();
    6177    }
    6278
    63     public void printStackTrace(PrintStream s)
     79    public void printStackTrace(@NotNull PrintStream s)
    6480    {
    6581        super.printStackTrace(s);
    66         if (_innnerException != null) {
     82        if (_innerException != null) {
    6783            s.println("--- inner exception ---");
    68             _innnerException.printStackTrace(s);
     84            _innerException.printStackTrace(s);
    6985        }
    7086    }
    7187
    72     public void printStackTrace(PrintWriter s)
     88    public void printStackTrace(@NotNull PrintWriter s)
    7389    {
    7490        super.printStackTrace(s);
    75         if (_innnerException != null) {
     91        if (_innerException != null) {
    7692            s.println("--- inner exception ---");
    77             _innnerException.printStackTrace(s);
     93            _innerException.printStackTrace(s);
    7894        }
    7995    }
     
    8298    {
    8399        super.printStackTrace();
    84         if (_innnerException != null) {
     100        if (_innerException != null) {
    85101            System.err.println("--- inner exception ---");
    86             _innnerException.printStackTrace();
     102            _innerException.printStackTrace();
    87103        }
    88104    }
  • trunk/src/com/drew/lang/NullOutputStream.java

    r4231 r6127  
    1 /**
    2  * This is public domain software - that is, you can do whatever you want
    3  * with it, and include it software that is licensed under the GNU or the
    4  * BSD license, or whatever other licence you choose, including proprietary
    5  * closed source licenses.  I do ask that you leave this header in tact.
     1/*
     2 * Copyright 2002-2012 Drew Noakes
    63 *
    7  * If you make modifications to this code that you think would benefit the
    8  * wider community, please send me a copy and I'll post it on my site.
     4 *    Licensed under the Apache License, Version 2.0 (the "License");
     5 *    you may not use this file except in compliance with the License.
     6 *    You may obtain a copy of the License at
    97 *
    10  * If you make use of this code, I'd appreciate hearing about it.
    11  *   drew@drewnoakes.com
    12  * Latest version of this software kept at
    13  *   http://drewnoakes.com/
     8 *        http://www.apache.org/licenses/LICENSE-2.0
    149 *
    15  * Created by dnoakes on Dec 15, 2002 3:30:59 PM using IntelliJ IDEA.
     10 *    Unless required by applicable law or agreed to in writing, software
     11 *    distributed under the License is distributed on an "AS IS" BASIS,
     12 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 *    See the License for the specific language governing permissions and
     14 *    limitations under the License.
     15 *
     16 * More information about this project is available at:
     17 *
     18 *    http://drewnoakes.com/code/exif/
     19 *    http://code.google.com/p/metadata-extractor/
    1620 */
    1721package com.drew.lang;
     
    2024import java.io.OutputStream;
    2125
     26/**
     27 * An implementation of OutputSteam that ignores write requests by doing nothing.  This class may be useful in tests.
     28 *
     29 * @author Drew Noakes http://drewnoakes.com
     30 */
    2231public class NullOutputStream extends OutputStream
    2332{
  • trunk/src/com/drew/lang/Rational.java

    r4231 r6127  
    11/*
    2  * Rational.java
    3  *
    4  * This class is public domain software - that is, you can do whatever you want
    5  * with it, and include it software that is licensed under the GNU or the
    6  * BSD license, or whatever other licence you choose, including proprietary
    7  * closed source licenses.  Similarly, I release this Java version under the
    8  * same license, though I do ask that you leave this header in tact.
    9  *
    10  * If you make modifications to this code that you think would benefit the
    11  * wider community, please send me a copy and I'll post it on my site.
    12  *
    13  * If you make use of this code, I'd appreciate hearing about it.
    14  *   drew.noakes@drewnoakes.com
    15  * Latest version of this software kept at
    16  *   http://drewnoakes.com/
    17  *
    18  * Created on 6 May 2002, 18:06
    19  * Updated 26 Aug 2002 by Drew
    20  * - Added toSimpleString() method, which returns a simplified and hopefully more
    21  *   readable version of the Rational.  i.e. 2/10 -> 1/5, and 10/2 -> 5
    22  * Modified 29 Oct 2002 (v1.2)
    23  * - Improved toSimpleString() to factor more complex rational numbers into
    24  *   a simpler form
    25  *     i.e.
    26  *       10/15 -> 2/3
    27  * - toSimpleString() now accepts a boolean flag, 'allowDecimals' which will
    28  *   display the rational number in decimal form if it fits within 5 digits
    29  *     i.e.
    30  *       3/4 -> 0.75 when allowDecimal == true
     2 * Copyright 2002-2012 Drew Noakes
     3 *
     4 *    Licensed under the Apache License, Version 2.0 (the "License");
     5 *    you may not use this file except in compliance with the License.
     6 *    You may obtain a copy of the License at
     7 *
     8 *        http://www.apache.org/licenses/LICENSE-2.0
     9 *
     10 *    Unless required by applicable law or agreed to in writing, software
     11 *    distributed under the License is distributed on an "AS IS" BASIS,
     12 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 *    See the License for the specific language governing permissions and
     14 *    limitations under the License.
     15 *
     16 * More information about this project is available at:
     17 *
     18 *    http://drewnoakes.com/code/exif/
     19 *    http://code.google.com/p/metadata-extractor/
    3120 */
    3221
    3322package com.drew.lang;
     23
     24import com.drew.lang.annotations.NotNull;
     25import com.drew.lang.annotations.Nullable;
    3426
    3527import java.io.Serializable;
     
    3830 * Immutable class for holding a rational number without loss of precision.  Provides
    3931 * a familiar representation via toString() in form <code>numerator/denominator</code>.
    40  * <p>
    41  * @author  Drew Noakes http://drewnoakes.com
     32 *
     33 * @author Drew Noakes http://drewnoakes.com
    4234 */
    4335public class Rational extends java.lang.Number implements Serializable
    4436{
    45     /**
    46      * Holds the numerator.
    47      */
    48     private final int numerator;
    49 
    50     /**
    51      * Holds the denominator.
    52      */
    53     private final int denominator;
    54 
    55     private int maxSimplificationCalculations = 1000;
     37    private static final long serialVersionUID = 510688928138848770L;
     38
     39    /** Holds the numerator. */
     40    private final long _numerator;
     41
     42    /** Holds the denominator. */
     43    private final long _denominator;
    5644
    5745    /**
     
    6048     * with them!
    6149     */
    62     public Rational(int numerator, int denominator)
    63     {
    64         this.numerator = numerator;
    65         this.denominator = denominator;
     50    public Rational(long numerator, long denominator)
     51    {
     52        _numerator = numerator;
     53        _denominator = denominator;
    6654    }
    6755
     
    7058     * This may involve rounding.
    7159     *
    72      * @return  the numeric value represented by this object after conversion
    73      *          to type <code>double</code>.
     60     * @return the numeric value represented by this object after conversion
     61     *         to type <code>double</code>.
    7462     */
    7563    public double doubleValue()
    7664    {
    77         return (double)numerator / (double)denominator;
     65        return (double) _numerator / (double) _denominator;
    7866    }
    7967
     
    8270     * This may involve rounding.
    8371     *
    84      * @return  the numeric value represented by this object after conversion
    85      *          to type <code>float</code>.
     72     * @return the numeric value represented by this object after conversion
     73     *         to type <code>float</code>.
    8674     */
    8775    public float floatValue()
    8876    {
    89         return (float)numerator / (float)denominator;
     77        return (float) _numerator / (float) _denominator;
    9078    }
    9179
     
    9583     * casts the result of <code>doubleValue()</code> to <code>byte</code>.
    9684     *
    97      * @return  the numeric value represented by this object after conversion
    98      *          to type <code>byte</code>.
     85     * @return the numeric value represented by this object after conversion
     86     *         to type <code>byte</code>.
    9987     */
    10088    public final byte byteValue()
    10189    {
    102         return (byte)doubleValue();
     90        return (byte) doubleValue();
    10391    }
    10492
     
    10896     * casts the result of <code>doubleValue()</code> to <code>int</code>.
    10997     *
    110      * @return  the numeric value represented by this object after conversion
    111      *          to type <code>int</code>.
     98     * @return the numeric value represented by this object after conversion
     99     *         to type <code>int</code>.
    112100     */
    113101    public final int intValue()
    114102    {
    115         return (int)doubleValue();
     103        return (int) doubleValue();
    116104    }
    117105
     
    121109     * casts the result of <code>doubleValue()</code> to <code>long</code>.
    122110     *
    123      * @return  the numeric value represented by this object after conversion
    124      *          to type <code>long</code>.
     111     * @return the numeric value represented by this object after conversion
     112     *         to type <code>long</code>.
    125113     */
    126114    public final long longValue()
    127115    {
    128         return (long)doubleValue();
     116        return (long) doubleValue();
    129117    }
    130118
     
    134122     * casts the result of <code>doubleValue()</code> to <code>short</code>.
    135123     *
    136      * @return  the numeric value represented by this object after conversion
    137      *          to type <code>short</code>.
     124     * @return the numeric value represented by this object after conversion
     125     *         to type <code>short</code>.
    138126     */
    139127    public final short shortValue()
    140128    {
    141         return (short)doubleValue();
    142     }
    143 
    144 
    145     /**
    146      * Returns the denominator.
    147      */
    148     public final int getDenominator()
    149     {
    150         return this.denominator;
    151     }
    152 
    153     /**
    154      * Returns the numerator.
    155      */
    156     public final int getNumerator()
    157     {
    158         return this.numerator;
    159     }
    160 
    161     /**
    162      * Returns the reciprocal value of this obejct as a new Rational.
     129        return (short) doubleValue();
     130    }
     131
     132
     133    /** Returns the denominator. */
     134    public final long getDenominator()
     135    {
     136        return this._denominator;
     137    }
     138
     139    /** Returns the numerator. */
     140    public final long getNumerator()
     141    {
     142        return this._numerator;
     143    }
     144
     145    /**
     146     * Returns the reciprocal value of this object as a new Rational.
     147     *
    163148     * @return the reciprocal in a new object
    164149     */
     150    @NotNull
    165151    public Rational getReciprocal()
    166152    {
    167         return new Rational(this.denominator, this.numerator);
    168     }
    169 
    170     /**
    171      * Checks if this rational number is an Integer, either positive or negative.
    172      */
     153        return new Rational(this._denominator, this._numerator);
     154    }
     155
     156    /** Checks if this rational number is an Integer, either positive or negative. */
    173157    public boolean isInteger()
    174158    {
    175         if (denominator == 1 ||
    176                 (denominator != 0 && (numerator % denominator == 0)) ||
    177                 (denominator == 0 && numerator == 0)
    178         ) {
    179             return true;
    180         } else {
    181             return false;
    182         }
     159        return _denominator == 1 ||
     160                (_denominator != 0 && (_numerator % _denominator == 0)) ||
     161                (_denominator == 0 && _numerator == 0);
    183162    }
    184163
    185164    /**
    186165     * Returns a string representation of the object of form <code>numerator/denominator</code>.
    187      * @return  a string representation of the object.
    188      */
     166     *
     167     * @return a string representation of the object.
     168     */
     169    @NotNull
    189170    public String toString()
    190171    {
    191         return numerator + "/" + denominator;
    192     }
    193 
    194     /**
    195      * Returns the simplest represenation of this Rational's value possible.
    196      */
     172        return _numerator + "/" + _denominator;
     173    }
     174
     175    /** Returns the simplest representation of this Rational's value possible. */
     176    @NotNull
    197177    public String toSimpleString(boolean allowDecimal)
    198178    {
    199         if (denominator == 0 && numerator != 0) {
     179        if (_denominator == 0 && _numerator != 0) {
    200180            return toString();
    201181        } else if (isInteger()) {
    202182            return Integer.toString(intValue());
    203         } else if (numerator != 1 && denominator % numerator == 0) {
     183        } else if (_numerator != 1 && _denominator % _numerator == 0) {
    204184            // common factor between denominator and numerator
    205             int newDenominator = denominator / numerator;
     185            long newDenominator = _denominator / _numerator;
    206186            return new Rational(1, newDenominator).toSimpleString(allowDecimal);
    207187        } else {
     
    220200     * Decides whether a brute-force simplification calculation should be avoided
    221201     * by comparing the maximum number of possible calculations with some threshold.
     202     *
    222203     * @return true if the simplification should be performed, otherwise false
    223204     */
    224205    private boolean tooComplexForSimplification()
    225206    {
    226         double maxPossibleCalculations = (((double)(Math.min(denominator, numerator) - 1) / 5d) + 2);
     207        double maxPossibleCalculations = (((double) (Math.min(_denominator, _numerator) - 1) / 5d) + 2);
     208        final int maxSimplificationCalculations = 1000;
    227209        return maxPossibleCalculations > maxSimplificationCalculations;
    228210    }
     
    231213     * Compares two <code>Rational</code> instances, returning true if they are mathematically
    232214     * equivalent.
     215     *
    233216     * @param obj the Rational to compare this instance to.
    234217     * @return true if instances are mathematically equivalent, otherwise false.  Will also
    235218     *         return false if <code>obj</code> is not an instance of <code>Rational</code>.
    236219     */
    237     public boolean equals(Object obj)
    238     {
    239         if (!(obj instanceof Rational)) {
     220    @Override
     221    public boolean equals(@Nullable Object obj)
     222    {
     223        if (obj==null || !(obj instanceof Rational))
    240224            return false;
    241         }
    242         Rational that = (Rational)obj;
     225        Rational that = (Rational) obj;
    243226        return this.doubleValue() == that.doubleValue();
     227    }
     228
     229    @Override
     230    public int hashCode()
     231    {
     232        return (23 * (int)_denominator) + (int)_numerator;
    244233    }
    245234
     
    252241     * To reduce a rational, need to see if both numerator and denominator are divisible
    253242     * by a common factor.  Using the prime number series in ascending order guarantees
    254      * the minimun number of checks required.</p>
     243     * the minimum number of checks required.</p>
    255244     * <p>
    256245     * However, generating the prime number series seems to be a hefty task.  Perhaps
     
    265254     *   -- * ------------------------------------ + 2
    266255     *   10                    2
    267      *
     256     * <p/>
    268257     *   Math.min(denominator, numerator) - 1
    269258     * = ------------------------------------ + 2
    270259     *                  5
    271260     * </pre></code>
    272      * @return a simplified instance, or if the Rational could not be simpliffied,
     261     *
     262     * @return a simplified instance, or if the Rational could not be simplified,
    273263     *         returns itself (unchanged)
    274264     */
     265    @NotNull
    275266    public Rational getSimplifiedInstance()
    276267    {
     
    278269            return this;
    279270        }
    280         for (int factor = 2; factor <= Math.min(denominator, numerator); factor++) {
     271        for (int factor = 2; factor <= Math.min(_denominator, _numerator); factor++) {
    281272            if ((factor % 2 == 0 && factor > 2) || (factor % 5 == 0 && factor > 5)) {
    282273                continue;
    283274            }
    284             if (denominator % factor == 0 && numerator % factor == 0) {
     275            if (_denominator % factor == 0 && _numerator % factor == 0) {
    285276                // found a common factor
    286                 return new Rational(numerator / factor, denominator / factor);
     277                return new Rational(_numerator / factor, _denominator / factor);
    287278            }
    288279        }
Note: See TracChangeset for help on using the changeset viewer.