File: TIFFRational.java

package info (click to toggle)
java-imaging-utilities 0.14.2%2B3-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,280 kB
  • ctags: 3,725
  • sloc: java: 31,190; sh: 238; makefile: 53; xml: 30
file content (76 lines) | stat: -rw-r--r-- 1,983 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * TIFFRational
 * 
 * Copyright (c) 2001, 2002 Marco Schmidt.
 * All rights reserved.
 */

package net.sourceforge.jiu.codecs.tiff;

/**
 * Data class to store a TIFF rational number.
 * A TIFF rational number is a fraction given by 32 bit integer numerator and denominator values.
 * It is one of the data types used in TIFF tags ({@link TIFFTag}).
 * For more information on TIFF's internals, see {@link TIFFCodec}, which lists a few links 
 * to TIFF specification documents.
 * @author Marco Schmidt
 */
public class TIFFRational
{
	private int numerator;
	private int denominator;

	/**
	 * Creates a TiffRational object from the arguments.
	 * @param numerator the numerator of the fraction stored in this object
	 * @param denominator the denominator of the fraction stored in this object
	 * @throws IllegalArgumentException if denominator is <code>0</code> (division by zero is not allowed)
	 */
	public TIFFRational(int numerator, int denominator)
	{
		if (denominator == 0)
		{
			throw new IllegalArgumentException("A zero denominator is not allowed.");
		}
		this.numerator = numerator;
		this.denominator = denominator;
	}

	/**
	 * Returns the denominator value that was given to the constructor.
	 * @return denominator value
	 */
	public int getDenominator()
	{
		return denominator;
	}

	/**
	 * Returns the fraction as a <code>double</code> value.
	 * @return the fraction stored in this object
	 * @see #getAsFloat
	 */
	public double getAsDouble()
	{
		return (double)numerator / (double)denominator;
	}

	/**
	 * Returns the fraction as a <code>float</code> value.
	 * @return the fraction stored in this object
	 * @see #getAsDouble
	 */
	public float getAsFloat()
	{
		return (float)numerator / (float)denominator;
	}

	/**
	 * Returns the numerator value that was given to the constructor.
	 * @return numerator value
	 */
	public int getNumerator()
	{
		return numerator;
	}
}