001 /* 002 * TIFFRational 003 * 004 * Copyright (c) 2001, 2002 Marco Schmidt. 005 * All rights reserved. 006 */ 007 008 package net.sourceforge.jiu.codecs.tiff; 009 010 /** 011 * Data class to store a TIFF rational number. 012 * A TIFF rational number is a fraction given by 32 bit integer numerator and denominator values. 013 * It is one of the data types used in TIFF tags ({@link TIFFTag}). 014 * For more information on TIFF's internals, see {@link TIFFCodec}, which lists a few links 015 * to TIFF specification documents. 016 * @author Marco Schmidt 017 */ 018 public class TIFFRational 019 { 020 private int numerator; 021 private int denominator; 022 023 /** 024 * Creates a TiffRational object from the arguments. 025 * @param numerator the numerator of the fraction stored in this object 026 * @param denominator the denominator of the fraction stored in this object 027 * @throws IllegalArgumentException if denominator is <code>0</code> (division by zero is not allowed) 028 */ 029 public TIFFRational(int numerator, int denominator) 030 { 031 if (denominator == 0) 032 { 033 throw new IllegalArgumentException("A zero denominator is not allowed."); 034 } 035 this.numerator = numerator; 036 this.denominator = denominator; 037 } 038 039 /** 040 * Returns the denominator value that was given to the constructor. 041 * @return denominator value 042 */ 043 public int getDenominator() 044 { 045 return denominator; 046 } 047 048 /** 049 * Returns the fraction as a <code>double</code> value. 050 * @return the fraction stored in this object 051 * @see #getAsFloat 052 */ 053 public double getAsDouble() 054 { 055 return (double)numerator / (double)denominator; 056 } 057 058 /** 059 * Returns the fraction as a <code>float</code> value. 060 * @return the fraction stored in this object 061 * @see #getAsDouble 062 */ 063 public float getAsFloat() 064 { 065 return (float)numerator / (float)denominator; 066 } 067 068 /** 069 * Returns the numerator value that was given to the constructor. 070 * @return numerator value 071 */ 072 public int getNumerator() 073 { 074 return numerator; 075 } 076 }