Package melnorme.lang.utils

Source Code of melnorme.lang.utils.ParseHelper

/*******************************************************************************
* Copyright (c) 2014, 2014 Bruno Medeiros and other Contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     Bruno Medeiros - initial API and implementation
*******************************************************************************/
package melnorme.lang.utils;

import java.nio.file.Path;

import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.misc.MiscUtil;
import melnorme.utilbox.misc.PathUtil.InvalidPathExceptionX;

/**
* Fairly basic for now, more methods can be added.
*/
public class ParseHelper {
 
  protected int parsePositiveInt(String str) throws CommonException {
    int integer = parseInt(str);
    if(integer < 0) {
      throw new CommonException("Integer is not positive: " + str);
    }
    return integer;
  }
 
  protected int parseInt(String str) throws CommonException {
    try {
      int integer = Integer.parseInt(str);
      return integer;
    } catch (NumberFormatException e) {
      throw new CommonException("Invalid integer: " + str);
    }
  }
 
  protected Path parsePath(String string) throws CommonException {
    try {
      return MiscUtil.createPath(string);
    } catch (InvalidPathExceptionX e) {
      throw new CommonException("Invalid path. ", e);
    }
  }
 
}
TOP

Related Classes of melnorme.lang.utils.ParseHelper

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.