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

📄 vstring.java

📁 一个简单的visio程序。
💻 JAVA
字号:
package HECore.stddata;
import HPCore.Exception.*;

public class VString extends Variant {

 private String str="";
 private boolean fixedLength=false;
 private int Length=0;
 private fixedString fixedStr=null; 
 /**   
   Constructs a non-fixed length String      
 **/
 public VString(String s)
    {
      this.str=s;
    }
 
 /**   
   Constructs a fixed length String      
 **/
 public VString(byte[] s){  
    fixedLength=true; 
    fixedStr=new fixedString(s);  
 }
 

 public VString(fixedString str){  
    
	this(str.strValue());
    
 }
 public VString(String s,int len){  
    fixedLength=true; 
    fixedStr=new fixedString(s,len);  
 }

 public fixedString getfixedLenStrValue(){
     if(fixedLength) 
	   return fixedStr;
      return null;
	   
 }
 public boolean isFixedLengthString(){  
     return fixedLength;
 }
 /**   
   Returns String value from a non-fixed String      
 **/
 public String strValue()
 {
      return toString();
 }


 public String toString() {
  if(!fixedLength) 
    return str;
  else
    return fixedStr.toString();
  }

 /**   
    Returns String value from a fixed String      
 **/
    public byte[] fixedString(){  
        if(fixedLength)
            return str.getBytes();
        return null;
    }

	

    /**
      *  Returns the short representation of the String argument. 
     **/            
    public short byteValue()  {  
        if(!checkNumberString())
           new HpException(13,"Type mismatch");
        return (short)(Double.valueOf(str)).doubleValue();
    }
    /**
      *   Returns the double representation of the String argument.  
     **/            
    public double dblValue() throws HpException
	{  
       if(str.equalsIgnoreCase("false"))
		   return 0.0;
	   else
		  if(str.equalsIgnoreCase("true"))
		   return -1.0;
		if(!checkNumberString())
         throw new HpException(13,"Type mismatch");
        return (Double.valueOf(str)).doubleValue();
    }
    /**
      *   Returns the float representation of the String argument. 
     **/            
    public float sglValue() throws HpException
	{  
        
        return (float)dblValue();
    }
    /**
      *   Returns the int representation of the String argument. 
     **/            
    public int lngValue() throws HpException
	{  
        
        return (int)dblValue();
    }
    /**
      *  Returns the boolean representation of the String argument. 
    **/         
    public boolean boolValue() throws HpException
	{  
        if(dblValue()==(double)0) 
             return false;
        else 
            return true;
    }
    
    
    
        /**
         *  if the string is a number string then return true ,
         *            else return false   
         **/

    private boolean checkNumberString(){  
       if(str.trim().length()==0)
           return false;
       int i=0;
	   int timesOfpoint=0;
	   String temp=str.trim();
       while(i<temp.length() && (temp.charAt(i)<='9' && temp.charAt(i)>='0')&&(timesOfpoint<=1)){
	       if(temp.charAt(i)=='.'){
             timesOfpoint++;
		   }
           i++;
		   }
       if(i==temp.length()) 
           return true;
       else 
           return false;
    }
        /**
         *   return the type of this object 
         **/ 
   public short getType()
   {  
      if(fixedLength) 
          return V_FIX_STR ;
      return V_STR;

   }
   /**
     *  concatenate the two string        
    **/         
   public  VString Link(Variant b) 
    {
     
        String s="";
        s=toString()+b.toString();
        return new VString(s);
         
    } 
  
 
  /******************************************
   * return type is Variant                 *
   * a type is Variant                      *
   * Action :                               *
   * if s1 is s2 subString return true.     *
   * else return false.                     *             
   ******************************************/
  public Variant Like(Variant a,boolean mode) throws HpException
  {
     return new VBoolean(Operator.Like(strValue(),a.toString(),mode));
  }  
   

public Variant Like(Variant a) throws HpException
  {
     return new VBoolean(Operator.Like(strValue(),a.toString(),false));
  }

  /**
  Used to perform a logical equivalence on two expressions.
  Returns a Variant whose value is (~this ^ b)
  **/ 
  public Variant Eqv(Variant b) throws HpException
  {
    int bvalue= (int)b.dblValue();
    double value = (double)(~((int)dblValue() ^ bvalue)); 
    return new  VInt(value);
  }
  
  public Variant Pow(Variant b) throws HpException
  {
    int bvalue= (int)b.dblValue();
    double value = (double)Math.pow(dblValue(),bvalue); 
    return  newVariant(V_DBL,value);
  }

  public Variant Mod(Variant b)  throws HpException
 {
    if(b.dblValue() ==0.0)
		throw new HpException(11,"Division by Zero.");
    double value = (double)((int)dblValue() % (int)b.dblValue()); 
    Variant result = newVariant(V_INT,value);
    return result;   

 }
  public Variant Great(Variant b,boolean flag) throws HpException
  {
     
       int result=0;
       if(flag)
          result=str.compareTo(b.strValue());
       else
           result=str.toLowerCase().compareTo(b.strValue().toLowerCase());

       if(result>0)
       return new VBoolean(true);
       else
       return new VBoolean(false);
     
 }
 
 
 public Variant Less(Variant b,boolean flag) throws HpException
 {  
     
     
       int result=0;
       if(flag)
          result=str.compareTo(b.strValue());
       else
           result=str.toLowerCase().compareTo(b.strValue().toLowerCase());

       if(result<0)
       return new VBoolean(true);
       else
       return new VBoolean(false);
	    }

 
 public Variant Equal(Variant b,boolean flag) throws HpException
 {  
 
       int result=0;
       if(flag)
          result=str.compareTo(b.strValue());
       else
          result=str.toLowerCase().compareTo(b.strValue().toLowerCase());

       if(result==0)
       return new VBoolean(true);
       else
       return new VBoolean(false);
 
 } 
 public Variant GreatEqual(Variant b,boolean flag) throws HpException
 {  
 
       int result=0;
       if(flag)
          result=str.compareTo(b.strValue());
       else
           result=str.toLowerCase().compareTo(b.strValue().toLowerCase());

       if(result>=0)
       return new VBoolean(true);
       else
       return new VBoolean(false);
 

 } 
 public Variant LessEqual(Variant b,boolean flag) throws HpException
 {  
 
       int result=0;
       if(flag)
          result=str.compareTo(b.strValue());
       else
           result=str.toLowerCase().compareTo(b.strValue().toLowerCase());

       if(result<=0)
       return new VBoolean(true);
       else
       return new VBoolean(false);
     
 }

 public Variant NotEqual(Variant b,boolean flag) throws HpException
 {  

     
       int result=0;
       if(flag)
          result=str.compareTo(b.strValue());
       else
           result=str.toLowerCase().compareTo(b.strValue().toLowerCase());

       if(result!=0)
       return new VBoolean(true);
       else
       return new VBoolean(false);
     
 } 

private short dealArithmeticalType(short type1,short type2){
         
       if(type1==V_NULL) 
            new HpException(13,"Type mismatch");
	  if(type1==V_DATE)
		  return V_DATE;
       if(type1==V_CURR)
		  return V_CURR; 
	   if( type1<=V_DBL && type1>=V_BYTE)  
	 	   return V_DBL;
	  short last_type = type1 > type2 ? type1:type2;
	  return last_type;

  }

  /**
    Used to perform a arithmetical addition operation on two expressions.
    Returns a Variant whose value is (this - b)
   **/  
   public  Variant Add(Variant b) throws HpException
    {
      if(b.getType()==Variant.V_STR || b.getType()==Variant.V_FIX_STR )
	   return new VString(toString()  + b.toString());
	  else
	  {
        short finaltype = dealArithmeticalType(b.getType(),getType());
        double value = dblValue() + b.dblValue();
        return newVariant(finaltype,value);
      }

    }
  /**
    Used to perform a arithmetical subtraction operation on two expressions.
    Returns a Variant whose value is (this - b)
   **/
  public  Variant Sub(Variant b) throws HpException
  { 
    if(fixedLength){
	  return new VDouble(fixedStr.Sub(b.strValue()));	
	  }
	   
    short finaltype = dealArithmeticalType(b.getType(),getType());
    double value = dblValue() - b.dblValue();
    Variant result = newVariant(finaltype,value);
    return result; 
  }
  
  
  /**
    Used to perform a arithmetical multiplication operation on two expressions.
    Returns a Variant whose value is (this / b)
   **/
  public  Variant Mult(Variant b) throws HpException 
  {
    if(fixedLength){
	  return new VDouble(fixedStr.Mult(b.strValue()));	
	  }
    short finaltype = dealArithmeticalType(b.getType(),getType());
    double value = dblValue() * b.dblValue();
    Variant result = newVariant(finaltype,value);
    return result; 
  }
   /**
    Used to perform a arithmetical division operation on two expressions.
    Returns a Variant whose value is (this / b)
   **/ 
  public  Variant DDiv(Variant b) throws HpException 
  {
    if(fixedLength){
	  return new VDouble(fixedStr.DDiv(b.strValue()));	
	  }
    if(b.dblValue() ==0.0)
		throw new HpException(11,"Division by Zero.");
	double value = (dblValue() / b.dblValue());
    Variant result = newVariant(V_INT,value);
    return result; 
  }

 
  public  Variant Div(Variant b) throws HpException
  {
    if(fixedLength){
	  return new VDouble(fixedStr.Div(b.strValue()));	
	  }
    if(b.dblValue() ==0.0)
		throw new HpException(11,"Division by Zero.");
    short finaltype = dealArithmeticalType(b.getType(),getType());
    double value = (dblValue() / b.dblValue());
    Variant result = newVariant(finaltype,value);
    return result; 
  }

  private boolean is_num(char c) 
  {  
    return (c >= '0' && c <= '9');
  }

 private short dealType(short type1,short type2){  
	  short last_type=0;
  
	 if(type2==V_NULL) 
            new HpException(13,"Type mismatch");
    if(type2==V_BYTE)  
		  last_type=V_INT;
	else
     if(type2>V_LONG)
	    last_type=V_LONG;
	else
       last_type = type2 > type1 ? type2:type1;  
	return last_type;
  }

  /**
    Returns a Variant whose value is (this & b)
  **/
  public Variant And(Variant b) throws HpException
  {
    
	if(fixedLength){
	  return new VLong(fixedStr.And(b.strValue()));	
	  } 
    short last_type = dealType(getType(),b.getType());
    double value = ((int)dblValue() & (int)b.dblValue());
    Variant result = newVariant(last_type,value);
    return result; 
  }
  
  /**
    Returns a Variant whose value is (this | b)
  **/
  public Variant Or(Variant b) throws HpException
  {
    if(fixedLength){
	  return new VLong(fixedStr.Or(b.strValue()));	
	  }  
    short last_type = dealType(getType(),b.getType());
    double value = ((int)dblValue() | (int)b.dblValue());
    Variant result = newVariant(last_type,value);
    return result; 

  }
  /**
    Returns a Variant whose value is (this ^ b)
  **/
  public Variant Xor(Variant b) throws HpException
  {
    if(fixedLength){
	  return new VLong(fixedStr.Xor(b.strValue()));	
	  }  
    short last_type = dealType(getType(),b.getType());
    double value = ((int)dblValue() ^ (int)b.dblValue());
    Variant result = newVariant(last_type,value);
    return result; 
  }

 /**
    Used to perform a logical implication on two expressions.
    Returns a Variant whose value is (~this & ~b)
 **/
 public Variant Imp(Variant b) throws HpException
 {  
    if(fixedLength){
	  return new VLong(fixedStr.Imp(b.strValue()));	
	  }  
	short last_type = dealType(getType(),b.getType());
	int bvalue= (int)b.dblValue();
    double value = (double)(~((int)dblValue()  &(~bvalue))); 
    Variant result = newVariant(last_type,value);
    return result;   
 }
 
 /*public Variant Not(Variant b)
 {
   return null; 
 }*/
 //public void assign()


    

 }

⌨️ 快捷键说明

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