📄 magnitude.java
字号:
* 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;
}
/**
* Associates the amp with this magnitude.
* deprecated: use associate()
*/
boolean addAmp(Amplitude amp) {
return associate(amp);
}
/**
* Add an amplitude to this mag's list. Also associates the amp with this
* magnitude.
*/
public boolean associate(Amplitude amp) {
if (ampList.add(amp)) { // add to the mag's list
amp.magnitude = this; // using amp.associateMag() would be recursive
amp.associate(sol); // add to the Sol's list
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) ) {
amp.unassociateMag();
setStale(true);
return true;
}
return false;
}
/**
* Add any codas that are associated in the DataSource to this
* Magnitude's coda list. Note that references are used, the codas are
* not copied. Returns a count of the number that were added. Sets
* staleMagnitude 'true' if any are added */
public int getCodas()
{
return addCodas(Coda.create().getByMagnitude(this));
}
/**
* Given a Collection of Codas, add to codaList if associated Solution and Magnitude are the same.
* Note that references are used, the codas are
* not copied. Returns a count of the number that were added. Sets
* staleMagnitude 'true' if any are added */
public int addCodas(Collection list)
{
Coda coda[] = new Coda[list.size()];
list.toArray(coda);
int knt = 0;
for (int i = 0; i<coda.length; i++) {
if (coda[i].isAssociatedWith(this.sol)) { // only adds if same solution assoc
if (addCoda(coda[i])) knt++ ; // only adds if same magnitude assoc
}
}
return knt;
}
/**
* Add an coda to this mag's list if coda associated with this magnitude.
*/
public boolean addCoda(Coda coda) {
if (codaList.contains(coda)) {
System.out.println ("Magnitude: List already contains: "+coda.toString());
return false;
}
if (coda.getAssociatedMag() == this) {
codaList.add(coda);
setStale(true);
return true;
}
else return false;
}
/**
* Remove this coda from the codaList. Returns 'true' if the coda was in the
* list to start with. NOTE: this should NOT be confused with Coda.delete()
* which marks a coda for deletion from the data source. Sets staleLocation
* 'true' if codas are removed. */
public boolean removeCoda(Coda coda)
{
if (codaList.remove(coda) ) {
coda.unassociateMag();
setStale(true);
return true;
}
return false;
}
/**
* Return the number of amps associated with this magnitude
*/
public int getCodaCount() {
return codaList.size();
}
/** Return true if there are readings (amps or codas) connected to this
* magnitude. */
public boolean hasReadings() {
return (getAmpCount() > 0 || getCodaCount() > 0);
}
/** Return count of channels (not stations) used in summary. */
public int getReadingsUsed() {
return ampList.getChannelUsedCount();
}
/** Return count of stations (not channels) used in summary. */
/* Because the damn RT system doesn't set weights = 1.0 we can't
* count them and must read the 'nsta' value into usedStations. */
public int getStationsUsed() {
if (usedStations.isNull()) usedStations.setValue(ampList.getStationUsedCount());
return usedStations.intValue();
}
/** Set value of isStale flag. */
public void setStale (boolean tf) { isStale = tf; }
/** True if changes have been made to the amp list and a recalc is
needed. */
public boolean hasStaleMagnitude () { return isStale; };
public boolean isStale () { return isStale; };
/** Return true if this is the associated Solution's preferred magnitude. */
public boolean isPreferred() {
return (sol.magnitude == this);
}
public boolean isNull() { return value.isNull(); }
/**
* Return true if any Magnitude 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 () ;
/**
* Return the number of amps associated with this magnitude
*/
public int getAmpCount() {
return ampList.size();
}
/**
* Dump all the data members of this class.
*/
public String toDumpString() {
//Format df1 = new Format("%7.2f");
Format df2 = new Format("%5.2f");
String id;
if (magid.isNull()) {
id = "-none-";
} else {
id = magid.toString();
}
return "id= "+ id + " " +
"value= "+ df2.form(value.floatValue()) +" " +
"type = "+ getTypeString() +" " +
"authority= "+ authority.toString() +" "+
"source= "+ source.toString() +" "+
"method= "+ method.toString() +" "+
"usedAmps= "+ getReadingsUsed()+" "+
"usedStas= "+ getStationsUsed()+" "+
"error= "+ df2.form(error.floatValue()) +" "+
"gap= "+ df2.form(gap.floatValue()) +" "+
"distance= "+ df2.form(distance.floatValue()) +" "+
"quality= "+ quality.toString() +" "+
"state= "+ processingState.toString() ;
}
/*
Return a fixed format string of the form:
<tt>
Event ID mag type source method #sta error gap dist qual
dddddddddd ffff.ff ssssssss ssssssss ssssssss dddd ffff.ff ffff.ff ffff.ff ffff.ff
</tt>
You must call getNeatStringHeader() to get the header line shown above.
@see getNeatStringHeader()
*/
public String toNeatString() {
Format df1 = new Format("%7.2f");
Format df2 = new Format("%9.4f");
Format df3 = new Format("%8s");
Format df4 = new Format("%4d");
String idStr ;
if (sol == null || sol.id.isNull()) {
idStr = " -none- ";
} else {
Format df0 = new Format("%10d");
idStr = df0.form(sol.id.longValue());
}
String meth = method.toString();
if (meth.length() > 8) meth = meth.substring(0,8);
return idStr + " " +
df1.form(value.floatValue()) + " " +
df3.form(getTypeString()) + " "+
df3.form(source.toString()) +" "+
df3.form(meth) +" "+
df4.form(getStationsUsed()) +" "+
df1.form(error.floatValue()) +" "+
df1.form(gap.floatValue()) +" "+
df1.form(distance.floatValue()) +" "+
df1.form(quality.floatValue());
}
/*
Return a fixed format header to match output from toNeatString(). Has the form:
<tt>
Event ID mag type source method #sta error gap dist qual
dddddddddd ffff.ff ssssssss ssssssss ssssssss dddd ffff.ff ffff.ff ffff.ff ffff.ff
</tt>
@see: toNeatString()
*/
public static String getNeatStringHeader() {
return " Event ID mag type source method #sta error gap dist qual";
}
/**
* Return 2 character Magnitude type descriptive string of the form: "Ml", "Mb", etc.
* If the type is null returns "M "
*/
public String getTypeString()
{
if (subScript.isNull() || subScript.toString().equals("NULL")) return "M ";
return "M"+ subScript.toString() ;
}
/** Return a string with the magnitude and the list of amplitudes or codas.*/
public String neatDump () {
String str = this.getNeatStringHeader()+"\n";
str += this.toNeatString();
if (!ampList.isEmpty()) {
str += "\n"+ ampList.toNeatString();
}
if (!codaList.isEmpty()) str += "\n" + codaList.toNeatString();
return str;
}
} // end of class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -