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

📄 solutionlist.java

📁 一个用java写的地震分析软件(无源码)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
 * Insert an object at this index. Will not add object if its already in the list.
 * Overrides ArrayList.add() to inforce no-duplicates rule.
 */
    public void add(int index, Object obj)  {

        super.add(index, obj);  // this piece-of-crap doesn't return a boolean!
        setColor((Solution) obj);

    }
/**
 * Add a solution to the list, maintain sorting by time.
 */

public void addByTime (Solution newSol) {

    Solution sol[] = this.getArray();
    double newDateTime = newSol.datetime.doubleValue();

    for (int i = 0; i< sol.length; i++) {
      if (sol[i].datetime.doubleValue() > newDateTime) {
		this.add(i, newSol);
		return;
      }
    }
    //System.out.println ("Inserting at end "+sol.length);
    add(newSol);	// add to end
}
    /**
     * Actually deletes the Solution from the list (rather then doing a virtual delete).
     * If the deleted event is the selected event, the next event in the list will be
     * selected. If there are no more events in the list the selected event will become null.
     */
    public boolean delete (Object sol) {   // must be Object to override ActiveArrayList.delete()

      Solution zombie = (Solution) sol;
    // must look-up next sol BEFORE deletion, else you can't ref deleted sol's position
      Solution nextSol = null;
      if (zombie.getId().longValue() == this.getSelectedId()) {
	nextSol = getNext((Solution) sol);
      }

      if (super.delete(sol)) {
         if (nextSol != null) setSelected(nextSol);
         return true;
      } else {
         return false;
      }
    }

/**
 * Count the wfid entries in the wvevidassoc table for each Solution.
 * This is done seperately because its slow buy not always necessary.
 */
    public void countWaveforms() {

	Solution sol[] = this.getArray();

	for (int i = 0; i < sol.length; i++) {
	    sol[i].countWaveforms();
	}
    }

/**
 * Return a Solution[]
 */
	// This weirdness is necessary because the 'List' stores Objects
	// So we must both cast and use the arg to tell the List class what the
	// object type really is.
public Solution[] getArray() {

     return (Solution[]) this.toArray(new Solution[0]);
}
/**
 * Return true if this id is in the solution list.
 */
public boolean contains (long id) {
	Solution sol[] = this.getArray();

	for (int i = 0; i < sol.length; i++) {
	    if (sol[i].id.longValue() == id) return true;
	}

	return false;
}

/**
 * Extract a Solution from this list with this id (evid). Return null if not found.
 */
public Solution getById(long id) {

	Solution sol[] = this.getArray();

	for (int i = 0; i < sol.length; i++) {
	    if (sol[i].id.longValue() == id) return sol[i];
	}

	return null;
}
/**
 * Return the index in the list for the Solution with this id (evid).
 * Return -1 if not found.
 */
public int getIndex(long id) {

	Solution sol[] = this.getArray();

	for (int i = 0; i < sol.length; i++) {
	    if (sol[i].id.longValue() == id) return i;
	}

	return -1;
}
/**
 * Return the index in the list for this Solution.
 * Return -1 if not found.
 */
public int getIndex(Solution sol) {

	return getIndex(sol.id.longValue());
}
/**
 * Return the Solution following the selected Solution. If it is the last in the
 * list this will "wrap" and return the first Solution in the list.
 * Return null if the list is empty.  Same as getNext(getSelected()).
 */
public Solution getNext() {
    return getNext(getSelected());
}
/**
 * Return the Solution following this id (evid). If the given id is the last in the
 * list this will "wrap" and return the first id in the list.
 * Return null if the list is empty. If the id is not found the first Solution in the
 * list is returned.
 */
public Solution getNext(long id) {

       if (isEmpty()) return null;

       int idx = getIndex(id);

       if (idx < 0) {
          return (Solution) get(0);
       } else if (idx >= size()-1) {   // last in list, wrap
          return (Solution) get(0);
       } else {
          return (Solution) get(idx+1);
       }

}

/**
 * Return the Solution following this one. Return null if list is empty.
 * If the given Solution is the last in the
 * list or the Solution is not found the first Solution in the list is returned.
 */
public Solution getNext(Solution sol) {

    long id = -1;             // this will cause 1st to select if sol is bogus
    if (sol != null && !sol.id.isNull()) id = sol.id.longValue();

    return getNext(id);
}

/**
 * Extract a Solution from this list with this ORID. Return null if not found.
 */
public Solution getByOrid (long orid)
{
	Solution sol[] = this.getArray();

	if (sol != null) {

	    for (int i = 0; i < sol.length; i++)
		{
		    if ((sol[i]).getOrid() == orid) return sol[i]; 
		}
	}

	return null;
}

/**
 * Dump the list contents in Solution.toSummaryString() format
 */
public void dump() {

    System.out.println (dumpToString());

}
/**
 * Dump the list contents in Solution.toSummaryString() format
 */
public String dumpToString() {
    String str = "";
    Solution sol[] = this.getArray();
    if (sol != null) {
	for (int i = 0; i < sol.length; i++)
	    {
		str += sol[i].toSummaryString()+"\n";
	    }
    }
    return str;
}


/**
 * Main for testing: % SolutionList [hours-back]  (default = 1)
 */
    public static void main (String args[]) {

	double hoursBack;
	final int secondsPerHour = 60*60;

	if (args.length > 0)	// translate epoch second on command-line value
	{
	  Double val = Double.valueOf(args[0]);	    // convert arg String to 'double'
	  hoursBack = (double) val.doubleValue();
	} else {
	  System.out.println ("Usage: java SolutionList [hours-back]  (default=24)");
	  hoursBack = 24;	// default
	}

        System.out.println ("Making connection...");
	DataSource ds = new TestDataSource();

//	catView.setLatRange (25.0, 45.0);
//	catView.setLonRange (-140.0, -110.0);

        Calendar cal = Calendar.getInstance();

// must distinguish between 'java.util.Date'  and 'java.sql.Date'
	java.util.Date date = cal.getTime();	// current epoch millisec
	long now = date.getTime()/1000;	// current epoch sec (millisecs -> seconds)

	long then = now - (long) (secondsPerHour * hoursBack);	// convert to seconds
    // add 1000 to now just to be sure we get everything

	// read in saved eventProperties file
     EventSelectionProperties props = new EventSelectionProperties("eventProperties");

	// set time properties
//	props.setDateTime("startTime", new DateTime(then));
//	props.setDateTime("endTime", new DateTime(now));

     props.setTimeSpan (then, now);

	props.setProperty("validFlag", "TRUE");
//	props.setProperty("validFlag", "FALSE");
//	props.setProperty("dummyFlag", "TRUE");
	props.setProperty("dummyFlag", "FALSE");

     props.setProperty(EventSelectionProperties.prefix+"local", "TRUE");
     props.setProperty(EventSelectionProperties.prefix+"human", "TRUE");
     props.setProperty(EventSelectionProperties.prefix+"automatic", "TRUE");

	System.out.println ("-- Event Selection Properties --");

     props.dumpProperties();

	System.out.println ("Fetching last "+hoursBack+" hours...");

// Get a catalogview
	SolutionList catList = new SolutionList(props);

	Solution sol[] = catList.getArray();

	//	System.out.println ("found ="+sol.length);

	if (sol.length == 0) System.out.println (" * No events found.");

	for (int i = 0; i < sol.length; i++)
	{
	    System.out.println (sol[i].toSummaryString() +" "+
				sol[i].source.toString() );
	}

	// test addition by time
/*
	Solution solx = Solution.create().getById(sol[0].id.longValue());

	System.out.println (" Test insertion of: \n"+solx.toSummaryString());
	System.out.println (" ");

	catList.addByTime(solx);
	//	catList.add(solx);
	//	catList.add(1, solx);

        Solution sol2[] = catList.getArray();
	for (int i = 0; i < sol2.length; i++)
	{
	    System.out.println (sol2[i].toSummaryString() +" "+
				sol2[i].waveRecords.toString());
	}
*/
    }

// Support event color coding

    /**
     * Return a unique color for this solution. The SolutionList keeps track
     * of a color for each solution in the list. Colors are assigned as solutions are
     * added to the list according t the scheme in org.trinet.util.ColorList.
     * The colors are used by GUI's to distingush between data like phases and amps
     * associated with the solutions
     */
    public Color getColorOf (Solution sol) {

     if (sol == null) return ColorList.UNASSOC;
	return (Color) colorTable.get(sol.id);	      //sol.id is a DataObject
    }

    /** Set the unique color for this solution. The SolutionList keeps track
     * of a color for each solution in the list. Colors are assigned as solutions are
     * added to the list according t the scheme in org.trinet.util.ColorList.
     * The colors are used by GUI's to distingush between data like phases and amps
     * associated with the solutions. */
    void setColor (Solution sol) {
	colorTable.put(sol.id, ColorList.getColor(maxColor++));
    }
    /** Set unique colors for for all solutions in list. The SolutionList keeps track
     * of a color for each solution in the list. Colors are assigned as solutions are
     * added to the list according t the scheme in org.trinet.util.ColorList.
     * The colors are used by GUI's to distingush between data like phases and amps
     * associated with the solutions. */
    void setColors () {

	Solution sol[] = getArray();

	for (int i = 0; i < sol.length; i++) {

	    setColor(sol[i]);
	}
    }
} // end of class


⌨️ 快捷键说明

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