📄 solution.java
字号:
public AmpList getAmpList() {
return ampList;
}
/**
* Given a Collection of Amps, add any that are associated with this
* Solution to its ampList. Note that references are used, the amps are
* not copied. Returns a count of the number that were added. Sets
* staleMagnitude 'true' if any are added */
public int addAmps(Collection list) {
Amplitude amp[] = new Amplitude[list.size()];
list.toArray(amp);
int knt = 0;
for (int i = 0; i<amp.length; i++) {
if (addAmp(amp[i])) knt++ ; // only adds if its for this Sol
}
return knt;
}
/**
* Add one amp to the solution's list ONLY if it is associated with
* this Solution. Sets staleMagnitude 'true' and returns 'true' if the amp
* was added. */
public boolean addAmp(Amplitude amp) {
if (amp.sol == this) {
if (ampList.add(amp)) {
magnitude.setStale(true);
return true;
}
}
return false;
}
/**
* Remove this amp from the ampList. Returns 'true' if the amp was in the
* list to start with. NOTE: this should NOT be confused with Amp.delete()
* which marks a amp for deletion from the data source. Sets staleLocation
* 'true' if amps are removed. */
public boolean removeAmp(Amplitude amp) {
if (ampList.remove(amp) ) {
magnitude.setStale(true);
return true;
}
return false;
}
/**
* Given a Collection of Waveforms, add any that are associated with this
* Solution to its waveformList. Note that references are used, the waveforms are
* not copied. Returns a count of the number of waveforms that were added.
* Note that not all schemas make a connection between solutions and waveforms.
* This method is provided to accommodate those that do. */
public int addWaveforms(Collection newWfList) {
if (newWfList == null) return 0;
Waveform wf[] = new Waveform[newWfList.size()];
newWfList.toArray(wf);
int knt = 0;
for (int i = 0; i<wf.length; i++)
{
if (waveformList.add(wf[i])) knt++ ; // only adds if its for this Channel
}
return knt;
}
/**
* Add one Waveform to the waveformList. Note that references are used, the
* waveforms are not copied. Returns true it the waveform is added. * Note
* that not all schemas make a connection between solutions and waveforms. *
* This method is provided to accommodate those that do. */
public boolean addWaveform(Waveform wf)
{
return waveformList.add(wf); // only adds if its for this Channel
}
/**
* Delete a Solution. This is a "virtual delete".
* It is not actually removed from memory or the dbase.
* Other classes must decide how they want to handle deleted phases.
* Override this method to add additional behavior.
*/
public boolean delete()
{
deleteFlag = true;
return true;
}
/** Returns true if this Solution has been virtually deleted */
public boolean isDeleted() {
return deleteFlag;
}
// ABSTRACT methods -------------------------------------------------------
/**
* Set this solution's ID to a unique number that is valid in the local
* context. Returns the unique value. Returns 0 if there is an error. */
abstract public long setUniqueId();
/**
* Returns the Solution with this ID number from the data source.
* No other criteria or flags are checked.
*/
abstract public Solution getById(Connection conn, long id);
/**
* Returns the Solution with this ID number from the default data source.
* No other criteria or flags are checked.
*/
abstract public Solution getById(long id);
/**
* Returns the Solution with this ID number from the data source only if the
* event is "valid". This means the 'validFlag' is true and the 'dummyFlag'
* is false.
*
* @see: EventSelectionProperties
*/
abstract public Solution getValidById(Connection conn, long id);
/**
* Returns the Solution with this ID number from the default data source only if the
* event is marked "valid". This means the 'validFlag' is true and the 'dummyFlag'
* is false.
*
* @see: EventSelectionProperties
*/
abstract public Solution getValidById(long id);
/**
* Returns array of Solutions within this time window. Times are seconds in
* UNIX epoch time. Returns null if no event is found.
* No other criteria or flags are checked.
*/
abstract public Solution[] getByTime(double start, double stop);
/**
* Returns array of Solutions within this time window. Times are seconds in
* UNIX epoch time. Returns null if no event is found.
* No other criteria or flags are checked.
*/
abstract public Solution[]
getByTime(Connection conn, double start, double stop);
/**
* Returns array of "valid" Solutions within this time window.
* Some data sets contain solutions that have duplicates, interim, or bogus
* entries. This method filters those out and returns only VALID solutions.
* This means the 'validFlag' is true and the 'dummyFlag' is false.
*
* @see: EventSelectionProperties
*/
abstract public Solution[] getValidByTime (double start, double stop);
/**
* Returns array of "valid" Solutions within this time window.
* Some data sets contain solutions that have duplicates, interim, or bogus
* entries. This method filters those out and returns only VALID solutions.
* This means the 'validFlag' is true and the 'dummyFlag' is false.
*
* @see: EventSelectionProperties
*/
abstract public Solution[] getValidByTime (Connection conn,
double start, double stop);
/**
* Returns array of Solutions that meet the properties defined in
* EventSelectionProperties.
*/
abstract public Solution[] getByProperties (EventSelectionProperties properties);
/**
* Returns array of Solutions that meet the properties defined in
* EventSelectionProperties.
*/
abstract public Solution[] getByProperties (Connection conn,
EventSelectionProperties properties);
/** Commit any additions, changes or deletions to the data source.
* Returns 'true' if commit was successful. What constitutes "success" will
* be left to the site implementation. For example, the commit of the event
* summary info may succeed but the magnitude info may not. Or there may be
* a problem committing the the phase list. The getCommitStatus() method is
* intended to give you feedback about what went wrong.
* The general idea is that the commit
* is successful if no further action is required to fix exceptions. */
abstract public boolean commit() throws JasiCommitException;
/** Commit any additions, changes or deletions to the data source plus
* take any site-specific actions for a final solution. */
abstract public boolean finalCommit() throws JasiCommitException;
/**
* Set the isUpdate() flag for all data dbase members the given boolean value. */
abstract public void setUpdate(boolean tf);
/** Return the local implentation's Origin ID for the current Solution
*/
abstract public long getOrid();
/**
* Return a LatLonZ object for this Solution. Returns an empty LatLonZ() object
* if either lat, lon, or depth are null.
*/
public LatLonZ getLatLonZ() {
if (lat.isNull() || lon.isNull() || depth.isNull()) return new LatLonZ();
return new LatLonZ (lat.doubleValue(), lon.doubleValue(), depth.doubleValue());
}
/**
* Set the LatLonZ of this Solution.
*/
public void setLatLonZ (double latitude, double longitude, double z) {
lat.setValue(latitude);
lon.setValue(longitude);
depth.setValue(z);
sortReadingLists();
}
/**
* Set the LatLonZ of this Solution.
*/
public void setLatLonZ (LatLonZ latlonz) {
setLatLonZ(latlonz.getLat(), latlonz.getLon(), latlonz.getZ());
}
/** Return a DataString containing the last analyist to locate this event.
* May be null. */
public DataString getWho() {
return who;
}
/** Set name of the last analyist to locate this event. */
public void setWho(String name) {
who.setValue(name);
}
/** Set name of the last analyist to locate this event. */
public void setWho(DataString name) {
who.setValue(name);
}
/** Sort/resort all the JasiReadingLists (phase, amp, coda) by distance from the
* location of the solution. Called automatically by setLatLonZ(). */
public void sortReadingLists(LatLonZ latlonz) {
phaseList.distanceSort(latlonz);
ampList.distanceSort(latlonz);
codaList.distanceSort(latlonz);
}
/** Sort/resort all the JasiReadingLists (phase, amp, coda) by distance from the
* location of the solution. Called automatically by setLatLonZ(). */
public void sortReadingLists() {
sortReadingLists(getLatLonZ());
}
/** Set the value of 'waveRecords' for this Solution if possible. This is
* done in a separate method because some data sources may not supply this
* information without doing an expensive search of a database. */
abstract public int countWaveforms();
/** Set the event type. Argument is a jasi-style event type description string.
* Checks validity of the string against list of types in EventTypeMap class.
* Returns 'true' if type is OK. If not returns 'false' and sets type to the
* default type.
* Concrete classes will need to translate to the event type identification scheme
* of the underlying data.
* @see org.trinet.jasi.EventTypeMap */
abstract public boolean setEventType (String type);
/** Set the event type. Argument is an enumerated int.
* Checks validity of the int against list of types in EventTypeMap class.
* Returns 'true' if type is OK. If not returns 'false' and sets type to the
* default type.
* @see org.trinet.jasi.EventTypeMap */
abstract public boolean setEventType (int type);
/** Return the local implentation's event type string.
* @see org.trinet.jasi.EventTypeMap */
abstract public String getEventTypeString ();
/**
* Return true if any Solution field is different from what's in the DataSource.
* Either, 1) its been changed and not saved or 2) it is newly created and not saved.
*/
abstract public boolean hasChanged () ;
// ***** Concrete classes *******
/** Returns true if there are alternate solutions for this solution. In some
* databases an "event" can have multiple solutions. For example, different
* programs, or crustal models might be used or solutions from different
* institutions might be stored and associated with this solution. */
public boolean hasAlternateSolutions() {
if (alternateSolutionCount() > 0) return true;
return false;
}
/** Return number of alternate solutions. */
public int alternateSolutionCount() {
return altSolList.size();
}
/** Returns Collection of Solution objects each containing an alternate solution.
* The primary or "prefered" solution is NOT included in this set */
public Collection getAlternateSolutions() {
return altSolList;
}
/** Returns array of Solution objects each containing an alternate solution.
* The primary or "prefered" solution is NOT included in this set */
public Solution[] getAlternateSolutionArray() {
return altSolList.getArray();
}
/** Add a solution to the list of alternate solutions. */
public void addAlternateSolution(Solution sol) {
altSolList.add(sol);
}
/** Set the primary or "preferred" solution to the solution passed in the
* arg. If there is a current preferred solution it is put into the
* altSolList. */
public void setPreferredSolution (Solution sol) {
// TODO: how do you do this??
}
/** Set the Magnitude object of this Solution. */
public void setPreferredMagnitude (Magnitude newMag)
{
if (newMag == magnitude) return; // no change
// make sure the new mag is associated with this sol
newMag.associate(this);
// there's a current prefmag, move it to altList
if (magnitude != null) altMagList.add(magnitude);
// remove new preferred mag from altList if present
altMagList.remove(newMag);
magnitude = newMag;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -