org.geotools.metadata.iso.identification
Class RepresentativeFractionImpl

Object
  extended by Number
      extended by RepresentativeFractionImpl
All Implemented Interfaces:
Serializable, RepresentativeFraction

public class RepresentativeFractionImpl
extends Number
implements RepresentativeFraction

A scale where denominator = 1 / scale. This implementation is set up as a number - because it is.

Since:
2.4
Author:
Jody Garnett
See Also:
Serialized Form
Module:
modules/library/metadata (gt-metadata.jar)

Constructor Summary
RepresentativeFractionImpl()
          Default empty constructor.
RepresentativeFractionImpl(long denominator)
          Creates a new representative fraction from the specified denominator.
 
Method Summary
 double doubleValue()
          Returns the scale in a form usable for computation.
 boolean equals(Object object)
          Compares this object with the specified value for equality.
 float floatValue()
          Returns the scale as a float type.
static RepresentativeFraction fromScale(double scale)
          Creates a representative fraction from a scale as a double value.
 long getDenominator()
          Returns the number below the line in a vulgar fraction.
 int hashCode()
          Returns a hash value for this representative fraction.
 int intValue()
          Returns the scale as an integer.
 long longValue()
          Returns the scale as an integer.
 void setDenominator(long denominator)
          Sets the denominator value.
 double toScale()
          Deprecated. This is equivalent to doubleValue().
 
Methods inherited from class Number
byteValue, shortValue
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RepresentativeFractionImpl

public RepresentativeFractionImpl()
Default empty constructor.


RepresentativeFractionImpl

public RepresentativeFractionImpl(long denominator)
Creates a new representative fraction from the specified denominator.

Parameters:
denominator - The denominator.
Method Detail

fromScale

public static RepresentativeFraction fromScale(double scale)
                                        throws IllegalArgumentException
Creates a representative fraction from a scale as a double value. The denominator will be set to 1/scale.

Parameters:
scale - The scale as a number between 0 and 1.
Returns:
The representative fraction created from the given scale.
Throws:
IllegalArgumentException - if the condition abs(scale) <= 1 is not meet.

toScale

@Deprecated
public double toScale()
Deprecated. This is equivalent to doubleValue().

Specified by:
toScale in interface RepresentativeFraction

doubleValue

public double doubleValue()
Returns the scale in a form usable for computation.

Specified by:
doubleValue in interface RepresentativeFraction
Specified by:
doubleValue in class Number
Returns:
1.0 / denominator

floatValue

public float floatValue()
Returns the scale as a float type.

Specified by:
floatValue in class Number

longValue

public long longValue()
               throws ArithmeticException
Returns the scale as an integer. This method returns 0, 1 or throws an exception as specified in intValue().

Specified by:
longValue in class Number
Throws:
ArithmeticException - if the denominator is 0.

intValue

public int intValue()
             throws ArithmeticException
Returns the scale as an integer. If the denominator is 0, then this method throws an ArithmeticException since infinities can not be represented by an integer. Otherwise if the denominator is 1, then this method returns 1. Otherwise returns 0 0 since the scale is a fraction between 0 and 1, and such value can not be represented as an integer.

Specified by:
intValue in class Number
Throws:
ArithmeticException - if the denominator is 0.

getDenominator

public long getDenominator()
Returns the number below the line in a vulgar fraction.

Specified by:
getDenominator in interface RepresentativeFraction

setDenominator

public void setDenominator(long denominator)
Sets the denominator value.

Parameters:
denominator - The new denominator value.

equals

public boolean equals(Object object)
Compares this object with the specified value for equality.

Specified by:
equals in interface RepresentativeFraction
Overrides:
equals in class Object
Parameters:
object - The object to compare with.
Returns:
true if both objects are equal.

hashCode

public int hashCode()
Returns a hash value for this representative fraction.

Specified by:
hashCode in interface RepresentativeFraction
Overrides:
hashCode in class Object


Copyright © 1996-2009 Geotools. All Rights Reserved.