📄 fixedstring.java
字号:
package HECore.stddata;
import HPCore.Exception.HpException;
public class fixedString implements Cloneable{
private byte[] byteArr;
private int length;
private String str="";
public fixedString(int len) {
this(null,len);
}
public fixedString(String s,int len){
if(s==null ||str==""){
if(len>0){
str=generateAString(s,len);
length=len;
byteArr=str.getBytes();
}else
{
byteArr=null;
length=0;
str=null;
}
return;
}
if(s.length()>=len)
str=s.substring(0,len);
else
str=generateAString(s,len);
byteArr=str.getBytes();
length=len;
}
private String generateAString(String s,int len){
int i=0;
if(s=="" || s==null){
String temp =new String("");
while(i<len) {
temp=temp.concat(" ");
i++;
}
return temp;
}
if(len >s.length() ){
int j=s.length();
while(i<len-j) {
s=s.concat(" ");
i++;
}
return s;
}
return s.substring(0,len);
}
public fixedString(String s){
length=s.length();
this.str=s;
byteArr=str.getBytes();
}
public fixedString(byte[] s){
length=s.length;
str=new String(s);
byteArr=s;
}
public boolean isFixedLengthString(){
return true;
}
public String strValue() {
return str;
}
public short getType() {
return 9;
}
public int getLength(){
return length;
}
public String toString()
{
return str;
}
public byte[] getfixedString(){
return byteArr;
}
/**
* Returns the short representation of the String argument.
**/
public short byteValue() {
if(!checkNumberString())
new HpException(13,"Type mismatch");
return (short)(Double.valueOf(str)).doubleValue();
}
public short intValue() {
if(!checkNumberString())
new HpException(13,"Type mismatch");
return (short)(Double.valueOf(str)).doubleValue();
}
/**
* Returns the double representation of the String argument.
**/
public double dblValue(){
if(!checkNumberString())
new HpException(13,"Type mismatch");
return (Double.valueOf(str)).doubleValue();
}
/**
* Returns the float representation of the String argument.
**/
public float sglValue(){
if(!checkNumberString())
new HpException(13,"Type mismatch");
return (float)(Double.valueOf(str)).doubleValue();
}
/**
* Returns the int representation of the String argument.
**/
public int lngValue(){
if(!checkNumberString())
new HpException(13,"Type mismatch");
return (int)(Double.valueOf(str)).doubleValue();
}
/**
* Returns the boolean representation of the String argument.
**/
public boolean boolValue(){
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;
}
/**
* concatenate the two string
**/
public String Link(String b)
{
return str + b;
}
/**
Used to perform a logical equivalence on two expressions.
Returns a Variant whose value is (~this ^ b)
**/
public int Eqv(String b)
{
double bvalue= (double)(Double.valueOf(str)).doubleValue();
double value = (double)(~((int)dblValue() ^ (int)bvalue));
return (int)value;
}
public double Pow(String b)
{
double bvalue= (double)(Double.valueOf(str)).doubleValue();
double value = (double)Math.pow(dblValue(),bvalue);
return value;
}
public int Mod(String b)
{
int bvalue= (int)(Double.valueOf(b)).doubleValue();
int value = ((int)dblValue() % (int)bvalue);
return (int)value;
}
public boolean Great(String b,boolean flag) {
int result=0;
if(flag)
result=str.compareTo(b);
else
result=str.toLowerCase().compareTo(b.toLowerCase());
if(result>0)
return true;
else
return false;
}
public boolean Less(String b,boolean flag) {
int result=0;
if(flag)
result=str.compareTo(b);
else
result=str.toLowerCase().compareTo(b.toLowerCase());
if(result<0)
return true;
return false;
}
public boolean Equal(String b,boolean flag) {
int result=0;
if(flag)
result=str.compareTo(b);
else
result=str.toLowerCase().compareTo(b.toLowerCase());
if(result==0)
return true;
return false;
}
public boolean GreatEqual(String b,boolean flag) {
int result=0;
if(flag)
result=str.compareTo(b);
else
result=str.toLowerCase().compareTo(b.toLowerCase());
if(result>=0)
return true;
return false;
}
public boolean LessEqual(String b,boolean flag) {
int result=0;
if(flag)
result=str.compareTo(b);
else
result=str.toLowerCase().compareTo(b.toLowerCase());
if(result<=0)
return true;
return false;
}
public boolean NotEqual(String b,boolean flag) {
int result=0;
if(flag)
result=str.compareTo(b);
else
result=str.toLowerCase().compareTo(b.toLowerCase());
if(result!=0)
return true;
return false;
}
/**
Used to perform a arithmetical addition operation on two expressions.
Returns a Variant whose value is (this - b)
**/
public String Add(String b)
{
return str+b;
}
/**
Used to perform a arithmetical subtraction operation on two expressions.
Returns a Variant whose value is (this - b)
**/
public double Sub(String b)
{
double dvalue= (Double.valueOf(b)).doubleValue();
double value = dblValue() - dvalue;
return value;
}
/**
Used to perform a arithmetical multiplication operation on two expressions.
Returns a Variant whose value is (this / b)
**/
public double Mult(String b)
{
double dvalue= (Double.valueOf(b)).doubleValue();
double value = dblValue() * dvalue;
return value;
}
/**
Used to perform a arithmetical division operation on two expressions.
Returns a Variant whose value is (this / b)
**/
public int DDiv(String b)
{
double dvalue= (Double.valueOf(b)).doubleValue();
return (int)(dblValue() / dvalue);
}
public double Div(String b)
{
double dvalue= (Double.valueOf(b)).doubleValue();
double value = dblValue() / dvalue;
return value;
}
private boolean is_num(char c)
{
return (c >= '0' && c <= '9');
}
/**
Returns a Variant whose value is (this & b)
**/
public int And(String b)
{
double dvalue= (Double.valueOf(b)).doubleValue();
double value = ((int)dblValue() & (int)dvalue);
return (int)value;
}
/**
Returns a Variant whose value is (this | b)
**/
public int Or(String b)
{
double dvalue= (Double.valueOf(b)).doubleValue();
double value = ((int)dblValue() | (int)dvalue);
return (int)value;
}
/**
Returns a Variant whose value is (this ^ b)
**/
public int Xor(String b)
{
double dvalue= (Double.valueOf(b)).doubleValue();
double value = ((int)dblValue() ^ (int)dvalue);
return (int)value;
}
/**
Used to perform a logical implication on two expressions.
Returns a Variant whose value is (~this & ~b)
**/
public int Imp(String b)
{
double dvalue= (Double.valueOf(b)).doubleValue();
double value = (double)(~((int)dblValue() &(~(int)dvalue)));
return (int)value;
}
public Object clone()
{
try
{
fixedString e = (fixedString)super.clone();
return e;
} catch (CloneNotSupportedException e)
{
return null;
}
}
public boolean Like(fixedString a,boolean mode) throws HpException {
return Operator.Like(toString(),a.toString(),mode);
}
public void assign(String s){
int len =getLength();
if(s==null ||str==""){
if(len>0){
str=generateAString(s,len);
length=len;
byteArr=str.getBytes();
}else
{
byteArr=null;
length=0;
str=null;
}
return;
}
if(s.length()>=len)
str=s.substring(0,len);
else
str=generateAString(s,len);
byteArr=str.getBytes();
length=len;
}
public void assign(short s){
String st=convert.int2str(s);
assign(st);
}
public void assign(int i){
String st=convert.lng2str(i);
assign(st);
}
public void assign(byte b){
String st=convert.byte2str(b);
assign(st);
}
public void assign(HByte b){
String st=convert.byte2str(b);
assign(st);
}
public void assign(double d){
String st=convert.dbl2str(d);
assign(st);
}
public void assign(float sg){
String st=convert.sgl2str(sg);
assign(st);
}
/*public Variant Not(Variant b)
{
return null;
}*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -