Class DefaultRepresentativeFraction
- All Implemented Interfaces:
- Serializable,- Cloneable,- Emptiable,- IdentifiedObject,- RepresentativeFraction
public class DefaultRepresentativeFraction
extends Number
implements RepresentativeFraction, IdentifiedObject, Emptiable, Cloneable
A scale defined as the inverse of a denominator.
 Scale is defined as a kind of 
 In addition to the standard properties, SIS provides the following methods:
 
Number.
 The following property is mandatory in a well-formed metadata according ISO 19115:
 MD_RepresentativeFraction
   └─denominator………………………… The number below the line in a vulgar fraction.- setScale(double)for computing the denominator from a scale value.
Limitations
- Instances of this class are not synchronized for multi-threading. Synchronization, if needed, is caller's responsibility.
- Serialized objects of this class are not guaranteed to be compatible with future Apache SIS releases.
       Serialization support is appropriate for short term storage or RMI between applications running the
       same version of Apache SIS. For long term storage, use XMLinstead.
- Since:
- 0.3
- See Also:
Defined in the sis-metadata module
- 
Constructor SummaryConstructorsConstructorDescriptionCreates a uninitialized representative fraction.DefaultRepresentativeFraction(long denominator) Creates a new representative fraction from the specified denominator.Constructs a new representative fraction initialized to the value of the given object.
- 
Method SummaryModifier and TypeMethodDescriptioncastOrCopy(RepresentativeFraction object) Returns a SIS metadata implementation with the same values than the given arbitrary implementation.clone()Returns a modifiable copy of this representative fraction.doubleReturns the scale value of this representative fraction.booleanCompares this object with the specified value for equality.floatReturns the scale as afloattype.voidfreeze()Makes this representative fraction unmodifiable.longReturns the denominator of this representative fraction.Returns a map view of the identifiers collection as (authority, code) entries.Returns all identifiers associated to this object, or an empty collection if none.intReturns a hash value for this representative fraction.intReturns 1 if the denominator is equal to 1, or 0 otherwise.booleanisEmpty()Returnstrueif no scale is defined.longReturns 1 if the denominator is equal to 1, or 0 otherwise.voidsetDenominator(long denominator) Sets the denominator value.voidsetScale(double scale) Sets the denominator from a scale in the (0 … 1] range.Returns a string representation of this scale, orNaNif undefined.Methods inherited from class NumberbyteValue, shortValue
- 
Constructor Details- 
DefaultRepresentativeFractionpublic DefaultRepresentativeFraction()Creates a uninitialized representative fraction. The denominator is initially zero and the double value is NaN.
- 
DefaultRepresentativeFractionpublic DefaultRepresentativeFraction(long denominator) Creates a new representative fraction from the specified denominator.- Parameters:
- denominator- the denominator as a positive number, or 0 if unspecified.
- Throws:
- IllegalArgumentException- if the given value is negative.
 
- 
DefaultRepresentativeFractionConstructs a new representative fraction initialized to the value of the given object.Note on properties validation: This constructor does not verify the property values of the given metadata (e.g. whether it contains unexpected negative values). This is because invalid metadata exist in practice, and verifying their validity in this copy constructor is often too late. Note that this is not the only hole, as invalid metadata instances can also be obtained by unmarshalling an invalid XML document.- Parameters:
- object- the metadata to copy values from, or- nullif none.
 
 
- 
- 
Method Details- 
castOrCopyReturns a SIS metadata implementation with the same values than the given arbitrary implementation. If the given object isnull, then this method returnsnull. Otherwise if the given object is already a SIS implementation, then the given object is returned unchanged. Otherwise a new SIS implementation is created and initialized to the property values of the given object, using a shallow copy operation (i.e. properties are not cloned).- Parameters:
- object- the object to get as a SIS implementation, or- nullif none.
- Returns:
- a SIS implementation containing the values of the given object (may be the
         given object itself), or nullif the argument was null.
 
- 
getDenominatorReturns the denominator of this representative fraction.- Specified by:
- getDenominatorin interface- RepresentativeFraction
- Returns:
- the denominator.
 
- 
setDenominatorpublic void setDenominator(long denominator) Sets the denominator value.- Parameters:
- denominator- the new denominator value, or 0 if none.
- Throws:
- IllegalArgumentException- if the given value is negative.
 
- 
setScalepublic void setScale(double scale) Sets the denominator from a scale in the (0 … 1] range. The denominator is computed byround(1 / scale).The equivalent of a getScale()method isdoubleValue().- Parameters:
- scale- the scale as a number between 0 exclusive and 1 inclusive, or NaN.
- Throws:
- IllegalArgumentException- if the given scale is our of range.
 
- 
doubleValuepublic double doubleValue()Returns the scale value of this representative fraction. This method is the converse ofsetScale(double).- Specified by:
- doubleValuein interface- RepresentativeFraction
- Specified by:
- doubleValuein class- Number
- Returns:
- the scale value of this representative fraction, or NaN if none.
 
- 
floatValuepublic float floatValue()Returns the scale as afloattype.- Specified by:
- floatValuein class- Number
- Returns:
- the scale.
 
- 
longValuepublic long longValue()Returns 1 if the denominator is equal to 1, or 0 otherwise.Rational: This method is defined that way because scales smaller than 1 can only be casted to 0, and NaN values are also represented by 0.- Specified by:
- longValuein class- Number
- Returns:
- 1 if the denominator is 1, or 0 otherwise.
 
- 
intValuepublic int intValue()Returns 1 if the denominator is equal to 1, or 0 otherwise.Rational: This method is defined that way because scales smaller than 1 can only be casted to 0, and NaN values are also represented by 0.
- 
isEmptypublic boolean isEmpty()Returnstrueif no scale is defined. The following relationship shall hold:assert isEmpty() == Double.isNaN(doubleValue()); 
- 
freezepublic void freeze()Makes this representative fraction unmodifiable. After invocation to this method, any call to a setter method will throw anUnmodifiableMetadataException.- Since:
- 0.7
- See Also:
 
- 
cloneReturns a modifiable copy of this representative fraction.
- 
equalsCompares this object with the specified value for equality.- Specified by:
- equalsin interface- RepresentativeFraction
- Overrides:
- equalsin class- Object
- Parameters:
- object- the object to compare with.
- Returns:
- trueif both objects are equal.
 
- 
hashCodepublic int hashCode()Returns a hash value for this representative fraction.- Specified by:
- hashCodein interface- RepresentativeFraction
- Overrides:
- hashCodein class- Object
 
- 
toStringReturns a string representation of this scale, orNaNif undefined. If defined, the string representation uses the colon as in "1:20000".
- 
getIdentifiersReturns all identifiers associated to this object, or an empty collection if none. Those identifiers are marshalled in XML asidoruuidattributes.- Specified by:
- getIdentifiersin interface- IdentifiedObject
- Returns:
- all identifiers associated to this object, or an empty collection if none.
- See Also:
 
- 
getIdentifierMapReturns a map view of the identifiers collection as (authority, code) entries. That map is live: changes in the identifiers list will be reflected in the map, and conversely.- Specified by:
- getIdentifierMapin interface- IdentifiedObject
- Returns:
- the identifiers as a map of (authority, code) entries, or an empty map if none.
 
 
-