package vut.msa.utilities;

import java.util.StringTokenizer;

/**
 * Trieda poskytuje metody pre pracu s retazcami.
 *
 * @author starosta
 */
public class StringUtilities {

    private StringTokenizer tokenizer;

    /**
     * Metoda rozdeli retazec na pole retazcov na zaklade zadaneho deliaceho
     * znaku.
     *
     * @param source retazec, ktory sa ma rozdelit
     * @param delimiter deliaci znak
     * @return pole retazcov
     */
    public String[] tokenizeString (String source, String delimiter) {

        this.tokenizer = new StringTokenizer(source, delimiter);
        String[] tokens = new String[tokenizer.countTokens()];

        int i = 0;
        while(tokenizer.hasMoreTokens()) {
            tokens[i++] = tokenizer.nextToken();
        }

        return tokens;
    }

    /**
     * Metoda naformatuje cas behu systemu v milisekundach na textovy retazec.
     *
     * @param uptime cas v milisekundach
     * @return retazec v tvare "# dní, # hodín, # min."
     */
    public static String getFormatedUptime(int uptime) {

        int days = uptime/86400;
        int temp = uptime % 86400;
        int hours = temp/3600;
        int minutes = (temp % 3600) /60;
        return days + " dní, " + hours + " hodín, " + minutes + "min.";
    }

}
