/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package function;

import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JOptionPane;

/**
 *
 * @author Administrator
 */
public class Function {

    public static long getCurrentMilis() {
        return new Date().getTime();
    }

    public static String formatMoney(String money) {
        return String.format("%,.0f", Double.parseDouble(money)).replaceAll(",", ".");
    }

    public static int getNumberFromString(String string) {
        String regex = "([0-9]+)";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(string);
        if (m.find()) {
            return Integer.parseInt(m.group().trim());
        }
        return -1;
    }

    public static String parseNameString(String string) {
        String regex = "\\](.+)";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(string);
        if (m.find()) {
            return m.group().substring(1).trim();
        }
        return null;
    }

    public static String parseIdString(String string) {
        String regex = "\\[(.+)\\]";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(string);
        if (m.find()) {
            return m.group().substring(1, m.group().length() - 1).trim();
        }
        return null;
    }

    public static void sleep(int sleep) {
        try {
            Thread.sleep(sleep);
        } catch (InterruptedException ex) {
        }
    }

    public static void alert(String content) {
        JOptionPane.showMessageDialog(null, content);
    }

    public static void exit() {
        System.exit(0);
    }
}
