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

📄 solutionew.java

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

import org.trinet.jasi.*;
import java.util.Vector;
import org.trinet.jdbc.datatypes.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: </p>
 * @author unascribed
 * @version 1.0
 */


import java.sql.Connection;

public class SolutionEW extends Solution
{

  // CONSTANTS
  protected static final int EW_FLAG_EVENTS_VALID_ONLY     =  1;
  protected static final int EW_FLAG_EVENTS_INVALID_ONLY   =  0;
  protected static final int EW_FLAG_EVENTS_ALL            = -1;


  //protected static final int EW_FLAG_ET_ALL              = -1;

  protected static final int EW_FLAG_P_STATE_ALL           = -1;


  long idOrigin;
  EWSolution ewsSolution;
  String sOriginSource;

  public SolutionEW()
  {
    ewsSolution = new EWSolution();
    sOriginSource = new String("Jiggle0");
    idOrigin = 0;
  }

  public Solution[] getValidByTime(double start, double stop)
  {
    return(getByCriteria(start, stop, EW_FLAG_EVENTS_VALID_ONLY,
                         EventTypeMapEW.EW_FLAG_ET_ALL, EW_FLAG_P_STATE_ALL, null));
  }

  public Solution[] getValidByTime(Connection conn, double start, double stop)
  {
    return(getByCriteria(start, stop, EW_FLAG_EVENTS_VALID_ONLY,
                         EventTypeMapEW.EW_FLAG_ET_ALL, EW_FLAG_P_STATE_ALL, conn));
  }

  public Solution[] getByTime(Connection conn, double start, double stop)
  {
    return(getByTime(start,stop));
  }

  public Solution[] getByTime(double start, double stop)
  {
    return(getByCriteria(start, stop, EW_FLAG_EVENTS_ALL,
                         EventTypeMapEW.EW_FLAG_ET_ALL, EW_FLAG_P_STATE_ALL, null));
  }

  public Solution[] getByProperties(EventSelectionProperties properties)
  {
    return(getByProperties(null,properties));
  }


  public Solution getValidById(long id)
  {
    return(getById(null, id, EW_FLAG_EVENTS_VALID_ONLY));
  }


  public Solution getValidById(Connection conn, long id)
  {
    return(getById(conn, id, EW_FLAG_EVENTS_VALID_ONLY));
  }


  public Solution getById(long id)
  {
    return(getById(null, id, EW_FLAG_EVENTS_ALL));
  }


  public Solution getById(Connection conn, long id)
  {
    return(getById(conn, id, EW_FLAG_EVENTS_ALL));
  }


  public int countWaveforms()
  {
    if(this.waveformList == null)
    {
      Waveform wTemp = Waveform.create();
      this.waveformList = new java.util.ArrayList(wTemp.getBySolutionId(this.id.longValue()));
      waveRecords = new DataLong(waveformList.size());
    }
    return(this.waveRecords.intValue());
  }  // end SolutionEW::countWaveforms()


  public String getEventTypeString()
  {
    return(this.eventType.toString());
  }

  public long getOrid()
  {
    return(this.idOrigin);
  }

  public boolean hasChanged()
  {
    /**@todo: implement this org.trinet.jasi.Solution abstract method*/
    /* DK CLEANUP  This may not be the best way to determine if a
     * solution has changed.  We are checking to see if we have created
     * a new origin, or if some part of jiggle code has set our
     * Solution to stale, indicating that something was changed.
     **/
    if(this.idOrigin <= 0 || this.isStale())
      return(true);
    else
      return(false);
  }

  public void setUpdate(boolean tf)
  {
    /**@todo: implement this org.trinet.jasi.Solution abstract method*/
    // DK CLEANUP
  }

  public boolean finalCommit() throws org.trinet.jasi.JasiCommitException
  {
    /**@todo: implement this org.trinet.jasi.Solution abstract method*/
    return(false);
  }


  public boolean setEventType(int type)
  {
    if(EventTypeMap.isValid(type))
    {
      this.eventType.setValue(EventTypeMap.get(type));
      return(true);
    }
    else
    {
      return(false);
    }
  }

  public boolean setEventType(String type)
  {
    if(EventTypeMap.isValid(type))
    {
      this.eventType.setValue(type);
      return(true);
    }
    else
    {
      return(false);
    }
  }

  public long setUniqueId()
  {
    ewsSolution = new EWSolution();
    ewsSolution.Write();
    if(ewsSolution.idEvent <= 0)
    {
      // we bombed.  log it and return false.
      System.out.println("SolutionEW:  Failed with code " + ewsSolution.idEvent +
                          " while trying to Save event(" + ewsSolution.sSource +
                          "," + ewsSolution.sSourceEventID + ")");
    }
    this.id = new DataLong(ewsSolution.idEvent);

    return(ewsSolution.idEvent);
  }

  public boolean commit() throws org.trinet.jasi.JasiCommitException
  {
    /* DK 121802  This function just commits the current state to the
       DB, so it might be "save my recalculation", or it might be
       "save my deletion".
    */
    /* DK CLEANUP  Need to check delete flag and update the event as
       being dubious, so it no longer shows up in the event list.

    */
    if(this.isDeleted())
    {
      SolEW2EWSol();
      ewsSolution.iDubiocity = 1;
      ewsSolution.bSetDubiocity = 1;
      ewsSolution.Update();
      return(true);
    }

    boolean bRetCode = true;

    /**@todo: implement this org.trinet.jasi.Solution abstract method*/
    /* don't write ANYTHING - phases, magnitudes, stamags - unless
       the origin is new.
       What we should really be doing, is checking to see if the origin
       and magnitudes are stale. ????
     */
    if(this.idOrigin <= 0)
    {
       // Check to make sure that we have the solution locked
       if(!this.lockIsMine())
       {
         // We don't have event locked. disallow the commit.
         return(false);
       }

       // copy this object back to an EWSolution object
       SolEW2EWSol();

       if(this.id.longValue() <= 0)
         // if the solution has no DBid, then write the Event back to the DB
         bRetCode = bRetCode && (ewsSolution.Write() == null);

       if(ewsSolution.idEvent <= 0)
       {
        // we bombed.  log it and return false.
        System.out.println("SolutionEW:  Failed with code " + ewsSolution.idEvent +
                            " while trying to Save event(" + ewsSolution.sSource +
                            "," + ewsSolution.sSourceEventID + ")");
        return(false);
       }
       this.id.setValue(ewsSolution.idEvent);

      // Now process the phase list
      Phase[] Phases = (Phase[])this.phaseList.toArray(new Phase[0]);
      for(int i=0; i < Phases.length; i++)
      {
        // call commit for each phase.  PhaseEW.Commit() will determine
        // what if anything needs to be done
        Phases[i].commit();
      }

      // Now write the Origin
      bRetCode = bRetCode && (ewsSolution.ewOrigin.Write() != null);
      if(ewsSolution.ewOrigin.idOrigin <= 0)
      {
        return(false);
      }
      else
      {
        // copy the idOrigin from ewOrigin back to this object
        this.idOrigin = ewsSolution.ewOrigin.idOrigin;
      }

      /* now we have to do the phase associations */
      for(int i=0; i < Phases.length; i++)
      {
        // Call Phase.associate() it will determine what if anything needs
        //  to be done
        ((PhaseEW)Phases[i]).idOrigin = this.idOrigin;
        ((PhaseEW)Phases[i]).associate();
      }

      this.ewsSolution.idEvent = this.id.longValue();

      this.ewsSolution.idPrefered = this.ewsSolution.idOrigin = this.idOrigin;
      this.ewsSolution.PreferType = this.ewsSolution.PREFER_TYPE_ORIGIN;
      this.ewsSolution.UpdatePrefer();

      this.commitStatus = new String("Solution " + this.id.longValue() + " successfully saved to EW DB.");
      this.setStale(false);
    }
    else
    {
      bRetCode = false;
      this.commitStatus = new String("Solution " + this.id.longValue() + " already in DB. Not updated.");
    }

    // Check for a magnitude, commit it if there is one.
    if(this.magnitude != null)
    {
      bRetCode = bRetCode && this.magnitude.commit();
      if(this.magnitude != null)
      {
         this.ewsSolution.idPrefered = this.ewsSolution.idMag   = this.magnitude.magid.longValue();
         this.ewsSolution.PreferType = this.ewsSolution.PREFER_TYPE_MAGNITUDE;
         this.ewsSolution.UpdatePrefer();
         this.commitStatus = new String(this.commitStatus + " Magnitude " + this.magnitude.magid.longValue() + " successfully saved to EW DB.");
      }
    }

   return(bRetCode);
  }


  protected boolean SolEW2EWSol()
  {
    EWSolution ewSol;
    EWOrigin   ewOr;

    // We want to toss the existing ewSolution record, because
    // it might have old data, and we don't want any secret junk
    // hanging around.
    ewSol = ewsSolution = new EWSolution();
    ewOr = ewSol.ewOrigin = new EWOrigin();

    if(this.id.equals(new DataLong()))
    {
      // no idEvent Yet.  Need to create new event
      ewSol.idEvent = 0;
    }
    else
    {
      // already have an idEvent, copy it over
      ewSol.idEvent = this.id.longValue();
    }
    ewSol.tiEventType = 2;
    // DK CLEANUP We need to write an adapter to convert to from tiEventType
    //ewSol.tiEventType = EventTypeMap.getIntOfJasiCode(
    //                     EventTypeMap.toLocalCode(this.eventType.toString()));

    ewSol.iDubiocity = (this.validFlag.intValue()==0)?1:0;
    ewSol.sComment = this.comment.toString();
    ewSol.sSource =  this.source.toString();

    if(this.externalId.equals(new DataString()))
    {
     // no externalID either.  Don't know what we were expecting
     // make up our own id via cTime.
     long tNow = System.currentTimeMillis() / 1000;
     this.externalId = new DataString(tNow);
     ewSol.sSourceEventID = String.valueOf(tNow);
    }


    ewOr.idEvent = ewSol.idEvent;
    ewOr.bBindToEvent = 1;
    ewOr.idOrigin = 0;
    ewOr.dLat = this.lat.floatValue();
    ewOr.dLon = this.lon.floatValue();
    ewOr.dDepth = this.depth.floatValue();
    ewOr.tOrigin = this.datetime.doubleValue();

    ewOr.iFixedDepth = (this.depthFixed.booleanValue())?1:0;
    ewOr.dDmin = this.distance.floatValue();
  // DK Cleanup, added checks for NaN values for errorLat and ErrorLon,
  // they don't seem to get set anywhere, and when running utah data,
  // they appear to cause the save function to crash, because we are
  // trying to stuff a non-number into an oracle number slot.
  // DK 20030109
  if(Float.isNaN(this.errorLat.floatValue()))

⌨️ 快捷键说明

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