|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.opensha.commons.eq.cat.DefaultCatalog
public class DefaultCatalog
Default catalog implementation. This class validates all data added to this
catalog and provides accessors for basic extents values (min and max lat,
lon, depth, mag, and date). The extents values are calculated automatically
as these data types are added to the catalog.
Note that implementation assumes that input data is sorted ascending
by date.
A DefaultCatalog only allows access to copies of source data via
getData(); internal arrays are unmodifiable. To avoid
performance loss, especially with larger catalogs, users should use a
MutableCatalog instead.
This class provides a static method to read catalog bounds data from an XML
metadata element created when saving as a binary file. The bounds data is
provided so that a catalog does not have to be loaded to retrieve min/max
data. However, this data is not used to reset internal min/max fields; they
are set each time a catalog is initialized/loaded.
| Field Summary |
|---|
| Fields inherited from interface org.opensha.commons.eq.cat.Catalog |
|---|
MAX_SIZE |
| Constructor Summary | |
|---|---|
DefaultCatalog()
Constructs a new empty catalog. |
|
DefaultCatalog(File file,
CatalogReader reader)
Constructs a new catalog from the given file using the specified reader. |
|
| Method Summary | |
|---|---|
void |
addData(DataType type,
Object data)
Adds an array of data of the specified type to this catalog. |
Object |
clone()
Returns a deep copy of this catalog. |
boolean |
contains(DataType type)
Returns whether this catalog contains a particular DataType. |
Object |
copyData(DataType type)
Returns a deep copy of the requested data type or null if
the type does not esist in this catalog. |
Catalog |
deriveCatalog(int[] indices,
Catalog catalog)
Derives a new catalog from this one using the events at the given indices. |
Object |
deriveData(DataType type,
int[] indices)
Returns an indices.length sized array of the requested data
type from the indices specified or null if the data type
does not exist in this catalog. |
static Map<String,String> |
getBoundsData(Element data)
Deprecated. |
Object |
getData(DataType type)
Returns a copy of the requested data type or null if the
DataType is not present in this catalog. |
Set<DataType> |
getDataTypes()
Returns an immutable set of the data types in this catalog. |
Date |
getDate(int index)
Returns the Date of the event at index. |
int |
getEventID(int index)
Returns the eventID of the event at index. |
String |
getEventString(int index)
Returns a string representation of the event at a given index. |
String |
getEventStringWithID(int index)
Returns a string representation of the event at a given index. |
long |
getTime(int index)
Returns the time of the event at index (in milliseconds). |
double |
getValue(DataType type,
int index)
Returns the value of a the requested DataType for the event
at the specified index. |
Date |
maxDate()
Returns end date of this catalog or null if it is not set. |
double |
maxForType(DataType type)
Returns the maximum value of the requested DataType. |
Date |
minDate()
Returns start date of this catalog or null if it is not set. |
double |
minForType(DataType type)
Returns the minimum value of the requested DataType. |
boolean |
readable()
Returns whether copies of or references to internal data are provided by getData(). |
void |
readCatalog(File file,
Element meta)
Reads this catalog from serialized data arrays. |
protected void |
setReadable(boolean readable)
Sets whether getData() returns references to internal data
arrays or copies. |
int |
size()
Returns the number of events in this catalog or -1 if the catalog is empty. |
Element |
writeCatalog(File file)
Writes this catalog as a binary file and returns XML metadata that can be referenced for data type order when deserializing. |
void |
writeCatalog(File file,
CatalogWriter writer)
Writes this catalog to a given file using a specified CatalogWriter. |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DefaultCatalog()
public DefaultCatalog(File file,
CatalogReader reader)
throws IOException
file - to readreader - to process file
IOException - if unable to initialize catalog using supplied
File and CatalogReader| Method Detail |
|---|
public int size()
Catalog
size in interface Catalogpublic boolean contains(DataType type)
CatalogDataType.
contains in interface Catalogtype - to look for
public Object clone()
clone in class ObjectCatalogObject.clone()protected void setReadable(boolean readable)
getData() returns references to internal data
arrays or copies. Open access can significantly reduce memory overhead
but increases risks of catalog data manipulation if the catalog is re-
written to disk.
readable - whether references to (true) or copies of (false) data
are returnedpublic boolean readable()
CataloggetData().
readable in interface Catalog
public void addData(DataType type,
Object data)
Catalog
addData in interface Catalogtype - of data to be addeddata - array to be addedpublic Object getData(DataType type)
Catalognull if the
DataType is not present in this catalog. Implementations may
return a reference or a deep copy of the requested data array.
getData in interface Catalogtype - requested
public Object copyData(DataType type)
null if
the type does not esist in this catalog.
type - requested
public Set<DataType> getDataTypes()
public Object deriveData(DataType type,
int[] indices)
indices.length sized array of the requested data
type from the indices specified or null if the data type
does not exist in this catalog. This is a deep copy.
type - requestedindices - to return for type
NullPointerException - if index array is null
IndexOutOfBoundsException - if any indices are out of range
TODO better argument checking
public Catalog deriveCatalog(int[] indices,
Catalog catalog)
indices - of events to extractcatalog - the output catalog
NullPointerException - if index array is null
IndexOutOfBoundsException - if any indices are out of range
TODO better argument checking
public void writeCatalog(File file,
CatalogWriter writer)
throws IOException
CatalogWriter.
file - to write towriter - file formatter to use
IOException - if unable to write catalog to file
public Element writeCatalog(File file)
throws IOException
file - to write to
NullPointerException - if supplied file is null
IOException - if there is a problem writing the file
public void readCatalog(File file,
Element meta)
throws IOException,
ClassNotFoundException
file - to readmeta - data to read; XML format list of data types to load
NullPointerException - if supplied file or XML metadata is
null
IllegalArgumentException - if a DataType read from
metadata is not a valid type
IOException - if there is an IO problem reading the file
ClassNotFoundException - if there is a problem reading objects from
the filepublic String getEventString(int index)
Catalog
getEventString in interface Catalogindex - of event
public String getEventStringWithID(int index)
Catalog
getEventStringWithID in interface Catalogindex - of event
public int getEventID(int index)
Catalog
getEventID in interface Catalogindex - of event
public long getTime(int index)
Catalog
getTime in interface Catalogindex - of event
public Date getDate(int index)
CatalogDate of the event at index.
getDate in interface Catalogindex - of event
Date of the eventpublic Date minDate()
Catalognull if it is not set.
minDate in interface CatalogDatepublic Date maxDate()
Catalognull if it is not set.
maxDate in interface CatalogDate
public double getValue(DataType type,
int index)
CatalogDataType for the event
at the specified index. Method is only valid for the following
double-valued DataTypes: [LONGITUDE, LATITUDE, DEPTH,
MAGNITUDE]
getValue in interface Catalogtype - requestedindex - of event
type value at event indexpublic double minForType(DataType type)
CatalogDataType. Method
is only valid for the following double-valued DataTypes:
[LONGITUDE, LATITUDE, DEPTH, MAGNITUDE]
minForType in interface Catalogtype - requested
DatTypepublic double maxForType(DataType type)
CatalogDataType. Method
is only valid for the following double-valued DataTypes:
[LONGITUDE, LATITUDE, DEPTH, MAGNITUDE]
maxForType in interface Catalogtype - requested
DatType@Deprecated public static Map<String,String> getBoundsData(Element data)
Map for easy access. Input
metadata should have been created when saving catalog in binary format.
If inappropriate XML is encountered, method returns null.
TODO delete?
data - element to parse
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||