Package de.kilobyte22.app.kibibyte.misc

Source Code of de.kilobyte22.app.kibibyte.misc.Args

package de.kilobyte22.app.kibibyte.misc;


import de.kilobyte22.app.kibibyte.exceptions.UsageException;

import java.util.HashMap;

/**
* Created with IntelliJ IDEA.
* User: Stephan
* Date: 16.02.13
* Time: 12:23
*
* @author ${user}
* @copyright Copyright ${year} ${user}
*/
public class Args {
    public Args(HashMap<Object, String> args) {
        this.args = args;
    }
    HashMap<Object, String> args;

    public String getOrError(int param) {
        String ret = args.get(param);
        if (ret == null)
            throw new UsageException();
        return ret;
    }

    public String get(int param) {
        return args.get(param);
    }

    public String getNamedParam(String param) {
        return args.get("--" + param);
    }

    public String getNamedParam(char param) {
        return args.get("-" + param);
    }

    public int getIntOrError(int param) {
        try {
            return Integer.valueOf(getOrError(param));
        } catch (Exception ex) {
            throw new UsageException();
        }
    }
}
TOP

Related Classes of de.kilobyte22.app.kibibyte.misc.Args

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.