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

📄 channelname.java

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

import org.trinet.util.Format;
import java.util.*;

/**
 * Seed channel name identification object. This is an Abstract class that must be
 * extended for a specific implementation.
 */

public class ChannelName implements java.io.Serializable, AuthChannelIdIF, Comparable, Cloneable
{
    private String sta = "";
    private String net = "";
    private String auth = "";
    private String subsource = "";
    private String channel = "";
    private String channelsrc = "";
    private String seedchan = "";
    private String location = "";

    // switch to control if SEED Location code is to be used in comparisons
    static final boolean useLoc = false;

/**
 * Null constructor
 */
  public ChannelName() { }

/**
 * Constructor with another channel object. Note this is a copy and not
 * a reference to the original object.
 */
public ChannelName (ChannelName chan)
    {
	this.copy(chan);
    }

/**
 * Constructor with partial sta name. Missing fields are set to "".
 * It trims off spaces, else string compares
 * won't be correct later. Note this copies the strings rather then making
 * a reference to the original string objects.
 */
  public ChannelName (  String neti,
		    String sitei,
		    String compi)
 {
     this(neti, sitei, compi, null, null, null, null, null);
 }

/**
 * Constructor with partial sta name. Missing fields are set to "".
 * It trims off spaces, else string compares
 * won't be correct later. Note this copies the strings rather then making
 * a reference to the original string objects.
 */
  public ChannelName (  String neti,
		    String sitei,
		    String compi,
		    String seedchani)
 {
     this(neti, sitei, compi, null, null, null, seedchani, null);
 }

/**
 * Constructor with partial sta name. Missing fields are set to "".
 * It trims off spaces, else string compares
 * won't be correct later. Note this copies the strings rather then making
 * a reference to the original string objects.
 */
  public ChannelName (  String neti,
		    String sitei,
		    String compi,
		    String authi,
		    String subsourcei)
 {
     this(neti, sitei, compi, authi, subsourcei, null, null, null);

 }

/**
 * Constructor with with full spec. It trims off spaces, else string compares
 * won't be correct later. Note this copies the strings rather then making
 * a reference to the original string objects.
 */
  public ChannelName (  String neti,
		    String sitei,
		    String compi,
		    String authi,
		    String subsourcei,
		    String channelsrci,
		    String seedchani,
		    String locationi)
 {
     // guard against null's
    if (neti        != null)	net        = neti.trim();
    if (sitei       != null)	sta        = sitei.trim();
    if (compi       != null)	channel    = compi.trim();
    if (authi       != null)	auth       = authi.trim();
    if (subsourcei  != null)	subsource  = subsourcei.trim();
    if (channelsrci != null)	channelsrc = channelsrci.trim();
    if (seedchani   != null)	seedchan   = seedchani.trim();
    if (locationi   != null)	location   = locationi.trim();
 }

    public Object clone() {
        ChannelName chanName = null;
        try {
            chanName = (ChannelName) super.clone();
        }
        catch (CloneNotSupportedException ex) {
            ex.printStackTrace();
        }
        return chanName;
    }

/**
 * Make a "deep" copy.
 */
public ChannelName copy(ChannelName chan) {
	this.sta = safeCopy(chan.sta);
	this.net = safeCopy(chan.net);
	this.auth = safeCopy(chan.auth);
	this.subsource = safeCopy(chan.subsource);
	this.channel = safeCopy(chan.channel);
	this.channelsrc = safeCopy(chan.channelsrc);
	this.seedchan = safeCopy(chan.seedchan);
	this.location = safeCopy(chan.location);
	return this;
    }

    /** Prevents null pointer exception if the original string is null  */
    String safeCopy (String str) {
      if (str == null) return null;
      return new String(str);
    }

/**
 * Return a brief channel name string. Ex: "CI ABC HHZ"
 */
    public String toString() {
	return toDelimitedString(' ');
    }
/**
 * Return an IP address style name string. Ex: "CI.ABC.HHZ"
 */
    public String toDottedString() {
	return toDelimitedString('.');
    }
/**
 * Return a compact name string. Ex: "CIABCHHZ"
 */
    public String toCompactString() {
        return toCompactSeedString();
    }
/**
 * Return a compact name string. Ex: "CIABCHHZ"
 */
    public String toCompactSeedString() {
      return net + sta + seedchan ;
    }
/**
 * Return a name string delimited by the given character. Ex: delm = " " ->  "CI ABC HHZ"
 */
    public String toDelimitedString(char delm) {
      return toDelimitedSeedString(delm);
    }
/**
 * Return a name string delimited by the given character. Ex: delm = " " ->  "CI ABC HHZ"
 */
    public String toDelimitedString(String delm) {
      return toDelimitedSeedString(delm);
    }
/**
 * Return a name string delimited by spaces
 */
    public String toDelimitedString()  {
      //  return net +delm+ sta +delm+ seedchan;
      return toDelimitedSeedString(" ");
    }
/**
 * Return ChannelName based on parse of a name string delimited by spaces
 */
    public static ChannelName fromDelimitedString(String str)  {
      return fromDelimitedString(str, " ");
    }
/**
 * Return a name string delimited by the given character. Ex: delm = " " ->  "CI ABC HHZ"
 */
    public String toDelimitedSeedString(char delm) {

      //return net + delm + sta + delm + seedchan;
      return toDelimitedSeedString(String.valueOf(delm));     // can't cast char to String
    }
/**
 * Return a name string delimited by the given String. Ex: delm = "_." ->  "CI_.ABC_.HHZ"
 */
    public String toDelimitedSeedString(String delm) {
      return net + delm + sta + delm + seedchan;
    }
/**
 * Return ChannelName based on parse of a name string delimited by the given string
 * Assumes format: "nt.sta.chan" for example "NC.PDW.VHZ" or "CI ABXM EHN"
 */
    public static ChannelName fromDelimitedString(String str, String delim)  {

      StringTokenizer strTok = new StringTokenizer(str, delim);
      ChannelName chan = new ChannelName();

      try {
        chan.setNet(strTok.nextToken());
        chan.setSta(strTok.nextToken());
        chan.setSeedchan(strTok.nextToken());

        chan.setChannel(chan.getSeedchan());

      } catch (NoSuchElementException ex) {};

      return chan;

    }
 /**
 * Return a name string delimited by the given String. And with the Net/Sta/Chan fields
 * the size of the three fields passed as args. For example:
 <tt>
      chan.toFormattedString( " ", "xx", "xxxxx", "xxx");

      yields:  "CI ABC   HHZ"
                xx xxxxx xxx
 </tt>
 */
    public String toFormattedString(String delm,
           String field1, String field2, String field3) {

      return toFormattedString (delm,
            field1.length(), field2.length(), field3.length());
    }

    public String toCompleteString(String delim) {
	    return toCompleteString(this, delim);
    }

    /** Return a string with all the members of a ChannelName object, delimited
    * by the given string. The string must be a single character if you
    * will read it back with parseCompletString(). It also, should not be
    * a character that would appear in any of the members (letters and numbers). */
    public static String toCompleteString(ChannelName channelId, String delim) {
	    return channelId.getNet() +
	    delim + channelId.getSta() +
	    delim + channelId.getChannel() +
	    delim + channelId.getSeedchan() +
	    delim + channelId.getLocation()+
	    delim + channelId.getChannelsrc() ;
    }

    /** Parse a string for the format created by toCompleteString(). */
    public static ChannelName parseCompleteString (String str, String delim) {

       StringTokenizer strTok = new StringTokenizer(str, delim);

       return parseCompleteString(strTok);
    }

    /** Parse a string for the format created by toCompleteString().
    * Using a StringTokenizer allows us to parse the ChannelName from a longer
    * string and keep the "pointer" to parse other parts of the string. */
    public static ChannelName parseCompleteString (StringTokenizer strTok) {

       ChannelName channelId = new ChannelName();

       try {
	    channelId.setNet(strTok.nextToken());
	    channelId.setSta(strTok.nextToken());
	    channelId.setChannel(strTok.nextToken());
	    channelId.setSeedchan(strTok.nextToken());
	    channelId.setLocation(strTok.nextToken());
	    channelId.setChannelsrc(strTok.nextToken());
       } catch (NoSuchElementException ex) {}

⌨️ 快捷键说明

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