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

📄 baseunit.java

📁 Ftp服务1.0
💻 JAVA
字号:
package ranab.unit;

/**
 * This is the base class of all the unit converters. 
 *
 * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
 */
public 
abstract class BaseUnit {
    
    /**
     * Get all the possible units.
     */
    public abstract String[] getAllUnits();
    
    /**
     * Convert one unit from another
     */
    public abstract String convertUnit(String value, int from, int to) throws UnitException;
    
    /**
     * Get double value.
     */
    public static double getDoubleValue(String input) throws UnitException {
        
        if(input == null) {
            throw new UnitException("Input cannot be null");
        }
        
        input = input.trim();
        if(input.equals("")) {
            throw new UnitException("Input not found"); 
        }
        
        try {
            return Double.parseDouble(input);
        }
        catch(NumberFormatException ex) {
            throw new UnitException(input + " : not a valid input");
        }
    } 
     
}

⌨️ 快捷键说明

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