ATM系统实现[17]——数据格式验证类[00原创]

来源:互联网 发布:钢铁侠玩具模型淘宝 编辑:程序博客网 时间:2024/04/28 12:23
package cn.edu.ynu.sei.atm.util;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import cn.edu.ynu.sei.atm.interfaceDef.IDataFormatChecker;

/**
 * 数据格式检测类,用于对用户输入的数据进行格式、类型合法性检测<br>
 * 
@author 88250
 
*/
public class DataFormatChecker extends UnicastRemoteObject implements
    IDataFormatChecker
{    
    
/**
     * 创建一个数据格式检测器实例
     * 
@throws RemoteException
     
*/
    
public DataFormatChecker() throws RemoteException
    {
    
super();
    }
    
    
/*
     * (non-Javadoc)
     * @see cn.edu.ynu.sei.atm.interfaceDef.IDataFormatChecker#checkAmount(java.lang.String)
     
*/
    
public boolean checkAmount(String amount)
    {
    
if (Float.parseFloat(amount) <= 0)
    {
        
throw new NumberFormatException("Amount is native!");
    }
    
    
try 
    {
        Float.parseFloat(amount);
    }
    
catch (NumberFormatException nfe)
    {
        
return false;
    }
    
catch (Exception e)
    {
        
return false;
    }
    
return true;
    }
}