Ignore:
Timestamp:
2015-03-10T01:17:39+01:00 (11 years ago)
Author:
Don-vip
Message:

fix #11162 - update to metadata-extractor 2.7.2

File:
1 edited

Legend:

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

    r6127 r8132  
    11/*
    2  * Copyright 2002-2012 Drew Noakes
     2 * Copyright 2002-2015 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    1616 * More information about this project is available at:
    1717 *
    18  *    http://drewnoakes.com/code/exif/
    19  *    http://code.google.com/p/metadata-extractor/
     18 *    https://drewnoakes.com/code/exif/
     19 *    https://github.com/drewnoakes/metadata-extractor
    2020 */
    2121
     
    2929/**
    3030 * Immutable class for holding a rational number without loss of precision.  Provides
    31  * a familiar representation via toString() in form <code>numerator/denominator</code>.
    32  *
    33  * @author Drew Noakes http://drewnoakes.com
     31 * a familiar representation via {@link Rational#toString} in form <code>numerator/denominator</code>.
     32 *
     33 * Note that any value with a numerator of zero will be treated as zero, even if the
     34 * denominator is also zero.
     35 *
     36 * @author Drew Noakes https://drewnoakes.com
    3437 */
    3538public class Rational extends java.lang.Number implements Serializable
     
    6164     *         to type <code>double</code>.
    6265     */
     66    @Override
    6367    public double doubleValue()
    6468    {
    65         return (double) _numerator / (double) _denominator;
     69        return _numerator == 0
     70            ? 0.0
     71            : (double) _numerator / (double) _denominator;
    6672    }
    6773
     
    7379     *         to type <code>float</code>.
    7480     */
     81    @Override
    7582    public float floatValue()
    7683    {
    77         return (float) _numerator / (float) _denominator;
     84        return _numerator == 0
     85            ? 0.0f
     86            : (float) _numerator / (float) _denominator;
    7887    }
    7988
     
    8190     * Returns the value of the specified number as a <code>byte</code>.
    8291     * This may involve rounding or truncation.  This implementation simply
    83      * casts the result of <code>doubleValue()</code> to <code>byte</code>.
     92     * casts the result of {@link Rational#doubleValue} to <code>byte</code>.
    8493     *
    8594     * @return the numeric value represented by this object after conversion
    8695     *         to type <code>byte</code>.
    8796     */
     97    @Override
    8898    public final byte byteValue()
    8999    {
     
    94104     * Returns the value of the specified number as an <code>int</code>.
    95105     * This may involve rounding or truncation.  This implementation simply
    96      * casts the result of <code>doubleValue()</code> to <code>int</code>.
     106     * casts the result of {@link Rational#doubleValue} to <code>int</code>.
    97107     *
    98108     * @return the numeric value represented by this object after conversion
    99109     *         to type <code>int</code>.
    100110     */
     111    @Override
    101112    public final int intValue()
    102113    {
     
    107118     * Returns the value of the specified number as a <code>long</code>.
    108119     * This may involve rounding or truncation.  This implementation simply
    109      * casts the result of <code>doubleValue()</code> to <code>long</code>.
     120     * casts the result of {@link Rational#doubleValue} to <code>long</code>.
    110121     *
    111122     * @return the numeric value represented by this object after conversion
    112123     *         to type <code>long</code>.
    113124     */
     125    @Override
    114126    public final long longValue()
    115127    {
     
    120132     * Returns the value of the specified number as a <code>short</code>.
    121133     * This may involve rounding or truncation.  This implementation simply
    122      * casts the result of <code>doubleValue()</code> to <code>short</code>.
     134     * casts the result of {@link Rational#doubleValue} to <code>short</code>.
    123135     *
    124136     * @return the numeric value represented by this object after conversion
    125137     *         to type <code>short</code>.
    126138     */
     139    @Override
    127140    public final short shortValue()
    128141    {
     
    154167    }
    155168
    156     /** Checks if this rational number is an Integer, either positive or negative. */
     169    /** Checks if this {@link Rational} number is an Integer, either positive or negative. */
    157170    public boolean isInteger()
    158171    {
     
    167180     * @return a string representation of the object.
    168181     */
     182    @Override
    169183    @NotNull
    170184    public String toString()
     
    173187    }
    174188
    175     /** Returns the simplest representation of this Rational's value possible. */
     189    /** Returns the simplest representation of this {@link Rational}'s value possible. */
    176190    @NotNull
    177191    public String toSimpleString(boolean allowDecimal)
     
    211225
    212226    /**
    213      * Compares two <code>Rational</code> instances, returning true if they are mathematically
     227     * Compares two {@link Rational} instances, returning true if they are mathematically
    214228     * equivalent.
    215229     *
    216      * @param obj the Rational to compare this instance to.
     230     * @param obj the {@link Rational} to compare this instance to.
    217231     * @return true if instances are mathematically equivalent, otherwise false.  Will also
    218      *         return false if <code>obj</code> is not an instance of <code>Rational</code>.
     232     *         return false if <code>obj</code> is not an instance of {@link Rational}.
    219233     */
    220234    @Override
     
    235249    /**
    236250     * <p>
    237      * Simplifies the Rational number.</p>
     251     * Simplifies the {@link Rational} number.</p>
    238252     * <p>
    239253     * Prime number series: 1, 2, 3, 5, 7, 9, 11, 13, 17</p>
     
    244258     * <p>
    245259     * However, generating the prime number series seems to be a hefty task.  Perhaps
    246      * it's simpler to check if both d & n are divisible by all numbers from 2 ->
     260     * it's simpler to check if both d &amp; n are divisible by all numbers from 2 {@literal ->}
    247261     * (Math.min(denominator, numerator) / 2).  In doing this, one can check for 2
    248262     * and 5 once, then ignore all even numbers, and all numbers ending in 0 or 5.
     
    250264     * <p>
    251265     * Therefore, the max number of pairs of modulus divisions required will be:</p>
    252      * <code><pre>
     266     * <pre><code>
    253267     *    4   Math.min(denominator, numerator) - 1
    254268     *   -- * ------------------------------------ + 2
    255269     *   10                    2
    256      * <p/>
     270     *
    257271     *   Math.min(denominator, numerator) - 1
    258272     * = ------------------------------------ + 2
    259273     *                  5
    260      * </pre></code>
     274     * </code></pre>
    261275     *
    262276     * @return a simplified instance, or if the Rational could not be simplified,
Note: See TracChangeset for help on using the changeset viewer.