net.sf.zekr.common.resource
Class QuranLocation

java.lang.Object
  extended by net.sf.zekr.common.resource.QuranLocation
All Implemented Interfaces:
java.lang.Comparable, IQuranLocation

public class QuranLocation
extends java.lang.Object
implements IQuranLocation

This data structure is the primitive structure of addressing somewhere in the Quran. Addressing is possible by just having aya number and sura number.
Note that this class does not provide any range checking or explicit exception handling for performance purposes.
Both sura and aya numbers are counted from 1.

Author:
Mohsen Saboorian

Constructor Summary
QuranLocation(int sura, int aya)
          No range check is performed.
QuranLocation(java.lang.String location)
          Loads a QuranLocation with the format sura#-aya#.
 
Method Summary
 int compareTo(java.lang.Object location)
           
 boolean equals(java.lang.Object obj)
           
 int getAbsoluteAya()
          Counts the aya number from the start of the Quran.
 int getAya()
           
 IQuranLocation getNext()
          Returns the next location (sura-aya pair).
 IQuranLocation getPrev()
          Returns the previous location (sura-aya pair).
 int getSura()
           
 java.lang.String getSuraName()
           
 java.lang.String getSuraName(boolean localize)
           
 boolean isValid()
           
static boolean isValidLocation(int suraNum, int ayaNum)
          Checks if the location (sura, aya) actually exists.
static boolean isValidLocation(java.lang.String loc)
          Checks if the given QuranLocation's compliant string is valid (is of the form of sura#-aya# and the location actually exists).
 void setAya(int aya)
           
 void setSura(int sura)
           
 java.lang.String toDetailedString()
          Makes a string representation of this class as: sura(sura#) - aya#
 java.lang.String toSortableString()
          Pads the sura/aya number so that all strings are of the same width and sortable.
 java.lang.String toString()
          Makes a string representation of this class as: sura#-aya#
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

QuranLocation

public QuranLocation(int sura,
                     int aya)
No range check is performed.

Parameters:
sura - counted from 1
aya - counted from 1

QuranLocation

public QuranLocation(java.lang.String location)
Loads a QuranLocation with the format sura#-aya#. Sura and Aya numbers are both counted from 1. If location is not of format sura#-aya#, an IllegalArgumentException is thrown.
Please note that no range check is performed for this method.

Parameters:
location - Quran location to be parsed
Throws:
java.lang.IllegalArgumentException - if location is not well-formed, ie. sura#-aya#
Method Detail

isValidLocation

public static boolean isValidLocation(java.lang.String loc)
Checks if the given QuranLocation's compliant string is valid (is of the form of sura#-aya# and the location actually exists).

Parameters:
loc - the location string to be verified
Returns:
true if this is a valid Quran location, false otherwise.

isValidLocation

public static boolean isValidLocation(int suraNum,
                                      int ayaNum)
Checks if the location (sura, aya) actually exists.

Returns:
true if this is a valid Quran location, false otherwise.

isValid

public boolean isValid()
Specified by:
isValid in interface IQuranLocation

getAya

public final int getAya()
Specified by:
getAya in interface IQuranLocation

setAya

public final void setAya(int aya)

getSura

public final int getSura()
Specified by:
getSura in interface IQuranLocation

setSura

public final void setSura(int sura)

getSuraName

public java.lang.String getSuraName()
Specified by:
getSuraName in interface IQuranLocation
Returns:
the sura name in the language and format specified in view.sura.name property.

getSuraName

public java.lang.String getSuraName(boolean localize)
Specified by:
getSuraName in interface IQuranLocation
Parameters:
localize - specifies whether or not to localize sura name
Returns:
the sura name either in Arabic or the language and format specified in view.sura.name property (if localize parameter is true).

getNext

public IQuranLocation getNext()
Description copied from interface: IQuranLocation
Returns the next location (sura-aya pair).

Specified by:
getNext in interface IQuranLocation
Returns:
the next Quran location, or null if there is nothing

getPrev

public IQuranLocation getPrev()
Description copied from interface: IQuranLocation
Returns the previous location (sura-aya pair).

Specified by:
getPrev in interface IQuranLocation
Returns:
the previous Quran location, or null if there is nothing

toString

public java.lang.String toString()
Description copied from interface: IQuranLocation
Makes a string representation of this class as: sura#-aya#

Specified by:
toString in interface IQuranLocation
Overrides:
toString in class java.lang.Object
Returns:
a string representation of the Quran location in the format sura#-aya#.

toDetailedString

public java.lang.String toDetailedString()
Makes a string representation of this class as: sura(sura#) - aya#


toSortableString

public java.lang.String toSortableString()
Description copied from interface: IQuranLocation
Pads the sura/aya number so that all strings are of the same width and sortable.

Specified by:
toSortableString in interface IQuranLocation
Returns:
a sortable representation of the quran location.

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(java.lang.Object location)
Specified by:
compareTo in interface java.lang.Comparable

getAbsoluteAya

public int getAbsoluteAya()
Description copied from interface: IQuranLocation
Counts the aya number from the start of the Quran. The value can be a number between 1 to 6236.

Specified by:
getAbsoluteAya in interface IQuranLocation
Returns:
the absolute aya number counted from the start of the Quran.