baseunit.java

来自「Ftp服务1.0」· Java 代码 · 共 43 行

JAVA
43
字号
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 + =
减小字号Ctrl + -
显示快捷键?