⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 magnitude.java

📁 一个用java写的地震分析软件(无源码)-used to write a seismic analysis software (without source)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.trinet.jasi;

import java.sql.Connection;
import java.text.*;
import java.util.*;
import org.trinet.jasi.coda.*;
import org.trinet.jdbc.datatypes.*;	// for DataObjects

import org.trinet.util.Format;		// CoreJava printf-like Format class

/**
 * Description of a calculated magnitude associated with a Solution. <p> This is
 * a component of the Java Seismic Abstraction Interface (jasi) which allows
 * applications to interact with different schemas tranparently. <p> All data
 * members are DataObjects rather than primative types so they can handle the
 * concept of "nullness" because databases can contain null values for certain
 * fields. Also, applications may not want to write a "bogus" value like 0 into
 * the database when the real value is not known. Data primatives can't be null
 * and are initiallize to zero.<p>
 *
 * @See: JasiObject */

public abstract class Magnitude extends JasiObject implements Cloneable
{
    /*
      Here's the list of public data members for a Magnitude. These need to be
      supported by any port of this abstract layer
     */

    /** A unique ID number for this magnitude. May be null. May be a dbase key. */
    public DataLong    magid		= new DataLong();

    /** The value of the magnitude */
    public DataDouble  value		= new DataDouble();
    /** The subScript of magnitude. Includes only the suffix part of the type without
     * "M".  For example: for an "Ms" subScript="s".
     * @See: MagnitudeMethod */
    public DataString  subScript		= new DataString();

    /** Data authority. The 2-character FDSN network code from which this
        reading came. Default to network code set in EnvironmentInfo.
        @See: EnvironmentInfo.getNetworkCode */
    public DataString  authority  = new DataString(EnvironmentInfo.getNetworkCode());

    /** Data source string. Optional site defined source string.
        Default to application name set in EnvironmentInfo.
        @See: EnvironmentInfo.getApplicationName */
    public DataString  source	  = new DataString(EnvironmentInfo.getApplicationName());

    /** The method used to calculate the magnitude. May be a program name or
        some other string that is meaningful to the underlying DataSource. */
    public DataString  method		= new DataString();

    /** Number of stations that contributed to this magnitude */
    /* Forced to do this rather than use getStationsUsed() because the RT system
    * does not give a weight to used amps. */
    public DataLong    usedStations	= new DataLong();

    /** The standard deviation of the magnitude */
    public DataDouble  error		= new DataDouble();
    /** Largest azmuthal gap in stations contributing to the magnitude */
    public DataDouble  gap		= new DataDouble();
    /** Distance in km to the nearest station contributing to the magnitude */
    public DataDouble  distance		= new DataDouble();
    /** Estimate of magnitude quality 0.0<=quality<=1.0, 1.0 is best */
    public DataDouble  quality		= new DataDouble();

    /** State of processing. 'A'=automatic, 'H'=human */
    public DataString  processingState	=
           new DataString(EnvironmentInfo.getAutoString());	// rflag

    /** List of Codas associated with this Magnitude */
    public CodaList codaList = new CodaList();  // AWW

    /** List of Amplitudes associated with this Magnitude */
    public AmpList ampList = new AmpList();

    /** Solution with which this magnitude is associated. */
    public Solution sol = null;

    /** Set true if this mag is virtually deleted. */
    boolean deleteFlag = false;

    /** True if amps list has changed which makes the magnitude invalid or stale. */
    boolean isStale = false;

// //////////////////////////////////////////////////////////////////////

// -- Concrete FACTORY METHODS ---
    /**
     * Factory Method: This is how you instantiate a magnitude object. You do
     * NOT use a constructor. This is so that this "factory" method can create
     * the type of magnitude that is appropriate for your site's database.
     */
// ////////////////////////////////////////////////////////////////////////////
    /**
     * Instantiate an object of this type. You do
     * NOT use a constructor. This "factory" method creates various
     * concrete implementations. Creates a Solution of the DEFAULT type.
     * @See: JasiObject
     */
     public static final Magnitude create() {
	return create(DEFAULT);
     }

    /**
     * Instantiate an object of this type. You do
     * NOT use a constructor. This "factory" method creates various
     * concrete implementations. The argument is an integer implementation type.
     * @See: JasiObject
     */
     public static final Magnitude create(int schemaType) {
        return create(JasiFactory.suffix[schemaType]);
     }

    /**
     * Instantiate an object of this type. You do
     * NOT use a constructor. This "factory" method creates various
     * concrete implementations. The argument is as 2-char implementation suffix.
     * @See: JasiObject
     */
     public static final Magnitude create(String suffix) {
	return (Magnitude) JasiObject.newInstance("org.trinet.jasi.Magnitude", suffix);
     }
// ////////////////////////////////////////////////////////////////////////////
/** Clone the magnitude. Note that the codaList and ampList are not deep copied.*/
    public Object clone() {
        Magnitude mag = null;
        try {
            mag = (Magnitude) super.clone();
        }
        catch (CloneNotSupportedException ex) {
            ex.printStackTrace();
        }
        mag.magid        = (DataLong) magid.clone();
        mag.usedStations = (DataLong) usedStations.clone();
	mag.value        = (DataDouble) value.clone();
	mag.error        = (DataDouble) error.clone();
	mag.gap          = (DataDouble) gap.clone();
	mag.distance     = (DataDouble) distance.clone();
	mag.quality      = (DataDouble) quality.clone();

        mag.subScript       = (DataString) subScript.clone();
        mag.authority       = (DataString) authority.clone();
        mag.source          = (DataString) source.clone();
        mag.method          = (DataString) method.clone();
        mag.processingState = (DataString) processingState.clone();

// NOTE: these are not deep copied!
	mag.codaList = codaList;
	mag.ampList  = ampList;

        return mag;
    }

   /**
     * Returns the Magnitude for the event with this ID number from the data source.
     * Returns null if no mag is found.<p>
     * Uses the default DataSource.
     */
    abstract public Magnitude getBySolutionId (long id);

    /**
     * Returns the Magnitude for the event with this ID number from the data source.
     * Returns null if no mag is found.
     */
    abstract public Magnitude getBySolutionId (Connection conn, long id);

   /**
     * Returns ALL the Magnitudes associate with the event with this ID number
     * from the data source. This will return a Collection of alternate Magnitude
     * objects and will NOT contain the preferred mag.
     * Returns null if no mags are found.<p>
     * Uses the default DataSource.
     */
    abstract public Collection getAltBySolutionId (long id);

   /**
     * Returns ALL the Magnitudes associate with the event with this ID number
     * from the data source. Ust the passed connection to connect to the datasource.
     * This will return a Collection of alternate Magnitude
     * objects and will NOT contain the preferred mag.
     * Returns null if no mags are found.<p>
     * Uses the default DataSource.
     */
    abstract public Collection getAltBySolutionId (Connection conn, long id);

    /** Commit any changes or deletions to the data source */
    abstract public boolean commit() throws JasiCommitException;

    /**
     * Marks this object for delete from the data source.
     * The object is not actually deleted until commit() is called.
     */
    public boolean delete() {

	deleteFlag = true;

	return true;
    }

    /**
     * Return true if this magnitude has been virtually deleted.
     */
    public boolean isDeleted() {

	return deleteFlag;
    }

    /**
     *
     */
    public String toString()
    {
	return value.toString() + " "+getTypeString() ;
    }
    /**
     * Associate this reading with this Solution.
     */
    public void associate(Solution sol)
    {
	this.sol = sol;
    }

    /**
     * Unassociate, that is, set Solution to null.
     */
    public void unassociate()
    {
	this.sol = null;
        // shouldn't the codaList, ampList sol association for same solution be nulled AWW?
    }

    /** Return the associated solution. Returns null if unassociated. */
    public Solution getAssociatedSolution () {
	return sol;
    }

    /** Return 'true' if this is associated with a Solution */
    public boolean isAssociated()
    {
	return (sol != null) ;
    }

    /** Return 'true' if this is associated with this Solution */
    public boolean isAssociatedWith(Solution compSol)
    {
	return (sol == compSol) ;
    }

    public boolean isCodaMag() {

      if (subScript.isNull()) return false;

      return (subScript.toString().equalsIgnoreCase("c") ||
              subScript.toString().equalsIgnoreCase("ca")  ||
              subScript.toString().equalsIgnoreCase("d")  ||   // DK3 Added "Md" to list of CodaMags
              subScript.toString().equalsIgnoreCase("cd") );

    }

/**
 *  Add any amps that are associated in the DataSource to this
 *  Magnitude's ampList.  Note that references are used, the amps are
 *  not copied.  Returns a count of the number of amps in ampList. Sets
 *  staleMagnitude 'true' if any are added. */
    public int fetchAmps() {

	ampList = Amplitude.create().getByMagnitude(this);

	setStale(true);

	return ampList.size();

    }
/**
 * Given a Collection of Amps, add any that are associated with this

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -