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

📄 solutiontn.java

📁 一个用java写的地震分析软件(无源码)
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
  /*
    The fields prefmag & prefmec exist in BOTH the Event & Origin tables
    Which to use?? Made decision to use those in Origin.
   */

  // MAKE SURE "NOT NULL" COLUMNS HAVE VALUES
  if (id.isUpdate())	  eventRow.setValue(Event.EVID, id);

     /* Do NOT change Event.subsource and Event.AUTH if it was originally from
         the dbase, else you'll overwrite the original source of a relocated event.
         See: toOriginRow().
         However, a brand new event must populate these attributes. */
//     if (!fromDbase) {
//	  eventRow.setValue(Event.AUTH, getEventAuthority());
//	  eventRow.setValue(Event.SUBSOURCE, getEventSource());
//     }

  if (eventAuthority.isUpdate()) eventRow.setValue(Event.AUTH, getEventAuthority());
  if (eventSource.isUpdate())    eventRow.setValue(Event.SUBSOURCE, getEventSource());

    // foreign keys (PROTECTED)
  if (commid.isUpdate())    eventRow.setValue(Event.COMMID, commid);

  if (prefmag.isUpdate())   eventRow.setValue(Event.PREFMAG, prefmag);
  if (prefmec.isUpdate())   eventRow.setValue(Event.PREFMEC, prefmec);
  if (prefor.isUpdate())    eventRow.setValue(Event.PREFOR, prefor);

     // must convert to TriNet style 2-char event type
  if (eventType.isUpdate())
         eventRow.setValue(Event.ETYPE, EventTypeMap.create().toLocalCode(eventType.toString()));

  // note: validFlag is written to both Event.selectflag and Origin.bogusflag
  if (validFlag.isUpdate()) eventRow.setValue(Event.SELECTFLAG, validFlag);
    }

    /**
     * Suck contents out of an Origin (TableRow) object to populate
     * DataObjects of this Solution.
     */
    // Note that this gets COPIES of DataObjects not references.

    protected SolutionTN parseOriginRow(Origin org) {

  // use EVID we got from EVENT table if avail
  if (id.isNull()) {
      this.id = (DataLong) org.getDataObject(Origin.EVID);
      id.setUpdate(false);	// DataTableRow weirdness: sets key field isUpdate = true
  }

  // foreign keys (PROTECTED)
  this.prefmag       = (DataLong) org.getDataObject(Origin.PREFMAG);
  this.prefmec       = (DataLong) org.getDataObject(Origin.PREFMEC);
  this.commid        = (DataLong) org.getDataObject(Origin.COMMID);

  this.datetime	    = (DataDouble) org.getDataObject(Origin.DATETIME);
  this.lat           = (DataDouble) org.getDataObject(Origin.LAT);
  this.lon           = (DataDouble) org.getDataObject(Origin.LON);
  this.depth	    = (DataDouble) org.getDataObject(Origin.DEPTH);

  this.horizDatum    = (DataString) org.getDataObject(Origin.DATUMHOR);
  this.vertDatum	    = (DataString) org.getDataObject(Origin.DATUMVER);

  this.type	         = (DataString) org.getDataObject(Origin.TYPE);
  this.method	    = (DataString) org.getDataObject(Origin.ALGORITHM);
// NCDC schema cmodel & vmodel are numbers not strings.
// For now just turn the number into a string.
// TODO: Look in a data dictionary for a translation?
  DataLong modelId   = (DataLong)   org.getDataObject(Origin.CMODELID);
  this.crustModel.setValue(modelId.toString());
  this.crustModel.setUpdate(false);            // don't mark as changed by program

  DataLong velModel  = (DataLong)   org.getDataObject(Origin.VMODELID);
  this.velModel.setValue(velModel.toString());
  this.velModel.setUpdate(false);              // don't mark as changed by program

  this.authority	    = (DataString) org.getDataObject(Origin.AUTH);
  this.source	    = (DataString) org.getDataObject(Origin.SUBSOURCE);

  this.gap           = (DataDouble) org.getDataObject(Origin.GAP);
  this.distance	    = (DataDouble) org.getDataObject(Origin.DISTANCE);
  this.rms           = (DataDouble) org.getDataObject(Origin.WRMS);
  this.errorTime	    = (DataDouble) org.getDataObject(Origin.STIME) ;
  this.errorHoriz    = (DataDouble) org.getDataObject(Origin.ERHOR) ;
  this.errorVert	    = (DataDouble) org.getDataObject(Origin.SDEP);
  this.errorLat      = (DataDouble) org.getDataObject(Origin.ERLAT) ;
  this.errorLon      = (DataDouble) org.getDataObject(Origin.ERLON) ;

  this.totalReadings = (DataLong)  org.getDataObject(Origin.TOTALARR) ;
  this.usedReadings  = (DataLong)  org.getDataObject(Origin.NDEF) ;
  this.sReadings	    = (DataLong)  org.getDataObject(Origin.NBS) ;
  this.firstMotions  = (DataLong)  org.getDataObject(Origin.NBFM) ;
  this.externalId    = (DataString) org.getDataObject(Origin.LOCEVID);
  this.quality       = (DataDouble) org.getDataObject(Origin.QUALITY);

  this.dummyFlag     = (DataLong) org.getDataObject(Origin.BOGUSFLAG);
  this.processingState = (DataString) org.getDataObject(Origin.RFLAG);

        // fixed flags: default is "false" and "null" so if null or NOT="Y" they're left false.
        String fix = ((DataString) org.getDataObject(Origin.FDEPTH)).toString();
  if (fix.equalsIgnoreCase("y")) depthFixed = new DataBoolean(true);

  fix = ((DataString) org.getDataObject(Origin.FEPI)).toString();
  if (fix.equalsIgnoreCase("y")) locationFixed = new DataBoolean(true);

  fix = ((DataString) org.getDataObject(Origin.FTIME)).toString();
  if (fix.equalsIgnoreCase("y")) timeFixed = new DataBoolean(true);

  return this;

    }

/**
 * Return true if any Event or Origin field is different from what's in the dbase.
 * Either, 1) its been changed and not saved or 2) it is newly created and not saved.
 * Does NOT check the magnitude. If you want the status of the magnitude you
 * need to check that with magnitude.hasChanged() */
public boolean hasChanged () {

          return  eventHasChanged() || originHasChanged();
}
/**
 * Set the isUpdate() flag for all data dbase members the given boolean value.  */
public void setUpdate (boolean tf) {

       fromDbase = !tf;
       eventSetUpdate(tf);
       originSetUpdate(tf);
}
/**
 * Return true if any Event field has changed from what was read in from the
 * dbase. Returns true if phase was not originally from the dbase.  */
protected boolean eventHasChanged () {

  if (!fromDbase )           return true;

  if (id.isUpdate())	       return true;
  if (eventAuthority.isUpdate())  return true;
  if (eventSource.isUpdate())     return true;

  if (commid.isUpdate())     return true;
  if (comment.isUpdate())     return true;
  if (prefmag.isUpdate())    return true;
  if (prefmec.isUpdate())    return true;
  if (prefor.isUpdate())     return true;

  if (eventType.isUpdate())  return true;
  if (validFlag.isUpdate())  return true;    // appears in Origin, too.

     return false;
}

/**
 * Set the setUpdate() flag for all data dbase members the given boolean value.  */
protected void eventSetUpdate (boolean tf) {

  id.setUpdate(tf);
  eventAuthority.setUpdate(tf);
  eventSource.setUpdate(tf);

  commid.setUpdate(tf);
  prefmag.setUpdate(tf);
  prefmec.setUpdate(tf);
  prefor.setUpdate(tf);

  eventType.setUpdate(tf);
  validFlag.setUpdate(tf);
}

/**
 * Return true if any field has changed from what was read in from the
 * dbase. Returns true if phase was not originally from the dbase.  */
protected boolean originHasChanged () {

  if (!fromDbase)          return true;

  if (datetime.isUpdate())   return true;
  if (lat.isUpdate())        return true;
  if (lon.isUpdate())        return true;
  if (depth.isUpdate())	  return true;
  if (horizDatum.isUpdate()) return true;
  if (vertDatum.isUpdate())  return true;

  if (type.isUpdate())       return true;
  if (method.isUpdate())     return true;
  if (crustModel.isUpdate()) return true;
  if (velModel.isUpdate())   return true;
  if (authority.isUpdate())  return true;
  if (source.isUpdate())     return true;

  if (gap.isUpdate())        return true;
  if (distance.isUpdate())   return true;
  if (rms.isUpdate())        return true;
  if (errorTime.isUpdate())  return true;
  if (errorHoriz.isUpdate()) return true;
  if (errorVert.isUpdate())  return true;
  if (errorLat.isUpdate())   return true;
  if (errorLon.isUpdate())   return true;

  if (totalReadings.isUpdate()) return true;
  if (usedReadings.isUpdate()) return true;
  if (sReadings.isUpdate())  return true;
  if (firstMotions.isUpdate()) return true;
  if (externalId.isUpdate()) return true;
  if (quality.isUpdate())    return true;

  if (processingState.isUpdate()) return true;
  if (validFlag.isUpdate()) return true;    // appears in Event, too.
  if (dummyFlag.isUpdate()) return true;

  if (depthFixed.isUpdate()) return true;
  if (locationFixed.isUpdate()) return true;
  if (timeFixed.isUpdate())  return true;

    return false;
}


/**
 * Set the setUpdate() flag for all data dbase members the given boolean value.  */
protected void originSetUpdate (boolean tf) {

  datetime.setUpdate(tf)   ;
  lat.setUpdate(tf)        ;
  lon.setUpdate(tf)        ;
  depth.setUpdate(tf)	  ;
  horizDatum.setUpdate(tf) ;
  vertDatum.setUpdate(tf)  ;

  type.setUpdate(tf)       ;
  method.setUpdate(tf)     ;
  crustModel.setUpdate(tf) ;
  velModel.setUpdate(tf)   ;
  authority.setUpdate(tf)  ;
  source.setUpdate(tf)     ;

  gap.setUpdate(tf)        ;
  distance.setUpdate(tf)   ;
  rms.setUpdate(tf)        ;
  errorTime.setUpdate(tf)  ;
  errorHoriz.setUpdate(tf) ;
  errorVert.setUpdate(tf)  ;
  errorLat.setUpdate(tf)   ;
  errorLon.setUpdate(tf)   ;

  totalReadings.setUpdate(tf) ;
  usedReadings.setUpdate(tf) ;
  sReadings.setUpdate(tf)  ;
  firstMotions.setUpdate(tf) ;
  externalId.setUpdate(tf) ;
  quality.setUpdate(tf)    ;

  processingState.setUpdate(tf) ;
  validFlag.setUpdate(tf) ;
  dummyFlag.setUpdate(tf) ;

  depthFixed.setUpdate(tf) ;
  locationFixed.setUpdate(tf) ;
  timeFixed.setUpdate(tf)  ;
}
    /**
     * Stuff contents of this Solution into a NEW Origin (TableRow) object.
     */

    protected void toOriginRow () {
        long newOrid = getOrid();  // it will be null so a new one will be seq'ed

  // make a NEW Origin table row object
  originRow = new Origin(newOrid,
             id.longValue(),
             getAuthority());

  // allow updating the row
  originRow.setUpdate(true);

  // set NOT NULL values
  //(already done above)// originRow.setValue(Origin.AUTH, getAuthority());

  // set NOT NULL values (these were NOT set in constructor)
  if (datetime.isNull()) {
      originRow.setValue(Origin.DATETIME, 0);
  } else {
      originRow.setValue(Origin.DATETIME, datetime);
  }
  if (lat.isNull()) {
      originRow.setValue(Origin.LAT, 0.0);
  } else {
      originRow.setValue(Origin.LAT, lat);
  }
  if (lon.isNull()) {
      originRow.setValue(Origin.LON, 0.0);
  } else {
      originRow.setValue(Origin.LON, lon);
  }

  // foreign keys (PROTECTED)
  //WARNING:
  // This will cause an UPDATE even if nothing has changed !!!
  if (!commid.isNull())     originRow.setValue(Origin.COMMID, commid);
  if (!prefmag.isNull())    originRow.setValue(Origin.PREFMAG, prefmag);
  if (!prefmec.isNull())    originRow.setValue(Origin.PREFMEC, prefmec);

  if (!depth.isNull())	 originRow.setValue(Origin.DEPTH, depth);
  if (!horizDatum.isNull()) originRow.setValue(Origin.DATUMHOR, horizDatum);
  if (!vertDatum.isNull())  originRow.setValue(Origin.DATUMVER, vertDatum);
  if (!type.isNull())       originRow.setValue(Origin.TYPE, type);
  if (!method.isNull())     originRow.setValue(Origin.ALGORITHM, method);
     // note: crustModel is a String, dbase expects an int!
/*
     int cmodelId = getCrustalModelId(crustModel);
     int vmodelId = getVelocityModelId(velModel);
  if (!crustModel.isNull()) originRow.setValue(Origin.CMODELID, cmodelId);
  if (!velModel.isNull())   originRow.setValue(Origin.VMODELID, vmodelId);
*/
  if (!source.isNull())     originRow.setValue(Origin.SUBSOURCE, getSource());
  if (!gap.isNull())        originRow.setValue(Origin.GAP, gap);
  if (!distance.isNull())   originRow.setValue(Origin.DISTANCE, distance);
  if (!rms.isNull())        originRow.setValue(Origin.WRMS, rms);
  if (!errorTime.isNull())  originRow.setValue(Origin.STIME, errorTime);
  if (!errorHoriz.isNull()) originRow.setValue(Origin.ERHOR, errorHoriz);
  if (!errorVert.isNull())  originRow.setValue(Origin.SDEP, errorVert);
  if (!errorLat.isNull())   originRow.setValue(Origin.ERLAT, errorLat);
  if (!errorLon.isNull())   originRow.setValue(Origin.ERLON, errorLon);

  if (!totalReadings.isNull()) originRow.setValue(Origin.TOTALARR, totalReadings);
  if (!usedReadings.isNull())  originRow.setValue(Origin.NDEF, usedReadings);
  if (!sReadings.isNull())     originRow.setValue(Origin.NBS,sReadings );
  if (!firstMotions.isNull())  originRow.setValue(Origin.NBFM,firstMotions );
  if (!externalId.isNull())    originRow.setValue(Origin.LOCEVID, externalId);
  if (!quality.isNull())       originRow.setValue(Origin.QUALITY, quality);

  if (!dummyFlag.isNull())     originRow.setValue(Origin.BOGUSFLAG, dummyFlag);

  if (!processingState.isNull())
                               originRow .setValue(Origin.RFLAG, processingState);

     // translate fixed flags
  if (!depthFixed.isNull()) {
        if (depthFixed.booleanValue()) {
           originRow.setValue(Origin.FDEPTH, "y");
        } else {
           originRow.setValue(Origin.FDEPTH, "n");
        }
     }

  if (!locationFixed.isNull()) {
        if (locationFixed.booleanValue()) {
           originRow.setValue(Origin.FEPI, "y");
        } else {
           originRow.setValue(Origin.FEPI, "n");
        }
     }

  if (!timeFixed.isNull()) {
        if (timeFixed.booleanValue()) {
           originRow.setValue(Origin.FTIME, "y");
        } else {
           originRow.setValue(Origin.FTIME, "n");
        }
     }

    }

    /** Schema constraint for size of AUTH attribute */
    static final int MaxAuthSize = 15;
    /** Schema constraint for size of SUBSOURCE attribute */
    static final int MaxSubsourceSize = 8;

    /** get ORIGIN.auth
    * Enforce schema length and notnull constraints. Truncate if necessary.
    * AUTH is a 'NOT NULL' attribute so if the internal value is null
    * default to "??". That shouldn't happen because the Solution constructor
    * always sets it to "?". */
    String getAuthority() {
        String str = authority.toString();
        if (authority.isNull()) str = "??";
        int end = Math.min(str.length(), MaxAuthSize) ;
        return str.substring(0, end);
    }
    /** Get ORIGIN.subsource.

⌨️ 快捷键说明

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