Package com.lightcrafts.utils

Examples of com.lightcrafts.utils.Rational


     *
     * @param numerator The numerator.
     * @param denominator The denominator.  It must not be zero.
     */
    public RationalMetaValue( int numerator, int denominator ) {
        this( new Rational( numerator, denominator ) );
    }
View Full Code Here


     * as a {@link Rational}, returns 1.
     * @see #compareTo(Object)
     */
    public final int compareTo( String s ) {
        try {
            final Rational rightRational = Rational.parseRational( s );
            final Rational leftRational = getRationalValue();
            return leftRational.compareTo( rightRational );
        }
        catch ( NumberFormatException e ) {
            return 1;
        }
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public void setLongValue( long newValue ) {
        setRationalValueAt( new Rational( (int)newValue, 1 ), 0 );
    }
View Full Code Here

     */
    public final void readExternal( ObjectInput in ) throws IOException {
        final int length = readHeader( in );
        m_value = new Rational[ length ];
        for ( int i = 0; i < length; ++i )
            m_value[i] = new Rational( in.readInt(), in.readInt() );
    }
View Full Code Here

     * Parse and append a new value.
     *
     * @param newValue The new value.
     */
    protected final void appendValueImpl( String newValue ) {
        final Rational newRational = Rational.parseRational( newValue );
        if ( m_value == null )
            m_value = new Rational[] { newRational };
        else {
            m_value = (Rational[])LCArrays.resize( m_value, m_value.length + 1 );
            m_value[ m_value.length - 1 ] = newRational;
View Full Code Here

            case META_SRATIONAL:
            case META_URATIONAL:
                //
                // Print rational numbers better.
                //
                final Rational r =
                    ((RationalMetaValue)value).getRationalValue();
                if ( r.isInteger() )
                    return Integer.toString( r.intValue() );
                if ( r.numerator() > r.denominator() )
                    return TextUtil.tenths( r );
            default:
                return null;
        }
    }
View Full Code Here

                    EXIF_FIELD_SIZE[ EXIF_FIELD_TYPE_SRATIONAL ];
                final int longSize = EXIF_FIELD_SIZE[ EXIF_FIELD_TYPE_SLONG ];
                for ( int i = 0; i < numValues; ++i )
                    try {
                        final int pos = offset + i * valueSize;
                        values[i] = new Rational(
                            m_buf.getInt( pos ), m_buf.getInt( pos + longSize )
                        );
                    }
                    catch ( IllegalArgumentException e ) {
                        m_handler.gotBadMetadata( e );
                        return null;
                    }
                return new RationalMetaValue( values );
            }

            case EXIF_FIELD_TYPE_URATIONAL: {
                final Rational[] values = new Rational[ numValues ];
                final int valueSize =
                    EXIF_FIELD_SIZE[ EXIF_FIELD_TYPE_URATIONAL ];
                final int longSize = EXIF_FIELD_SIZE[ EXIF_FIELD_TYPE_ULONG ];
                for ( int i = 0; i < numValues; ++i )
                    try {
                        final int pos = offset + i * valueSize;
                        values[i] = new Rational(
                            m_buf.getInt( pos ), m_buf.getInt( pos + longSize )
                        );
                    }
                    catch ( IllegalArgumentException e ) {
                        m_handler.gotBadMetadata( e );
View Full Code Here

    public float getShutterSpeed() {
        final ImageMetaValue value = getValue( CIFF_SI_SHUTTER_SPEED );
        if ( value == null )
            return 0;
        final int apex = value.getIntValue();
        final Rational speed = MetadataUtil.convertShutterSpeedFromAPEX( apex );
        return speed.floatValue();
    }
View Full Code Here

                    MetadataUtil.convertISOFromAPEX( apex )
                );
            }
            case CIFF_SI_SHUTTER_SPEED: {
                final int apex = value.getIntValue();
                final Rational speed =
                    MetadataUtil.convertShutterSpeedFromAPEX( apex );
                return MetadataUtil.shutterSpeedString( speed.doubleValue() );
            }
            default:
                return super.valueToString( value );
        }
    }
View Full Code Here

                    TIFF_FIELD_SIZE[ TIFF_FIELD_TYPE_SRATIONAL ];
                final int longSize = TIFF_FIELD_SIZE[ TIFF_FIELD_TYPE_SLONG ];
                for ( int i = 0; i < numValues; ++i )
                    try {
                        final int pos = offset + i * valueSize;
                        values[i] = new Rational(
                            m_buf.getInt( pos ), m_buf.getInt( pos + longSize )
                        );
                    }
                    catch ( IllegalArgumentException e ) {
                        logBadImageMetadata();
                        return null;
                    }
                return new RationalMetaValue( values );
            }

            case TIFF_FIELD_TYPE_URATIONAL: {
                final Rational[] values = new Rational[ numValues ];
                final int valueSize =
                    TIFF_FIELD_SIZE[ TIFF_FIELD_TYPE_URATIONAL ];
                final int longSize = TIFF_FIELD_SIZE[ TIFF_FIELD_TYPE_ULONG ];
                for ( int i = 0; i < numValues; ++i )
                    try {
                        final int pos = offset + i * valueSize;
                        values[i] = new Rational(
                            m_buf.getInt( pos ), m_buf.getInt( pos + longSize )
                        );
                    }
                    catch ( IllegalArgumentException e ) {
                        logBadImageMetadata();
View Full Code Here

TOP

Related Classes of com.lightcrafts.utils.Rational

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.