Java Properties Parse parseProps(Properties p)

Here you can find the source of parseProps(Properties p)

Description

parse Props

License

Open Source License

Declaration

public static Map<String, int[]> parseProps(Properties p) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    public static Map<String, int[]> parseProps(Properties p) {
        Map<String, int[]> h = new HashMap<String, int[]>();
        Enumeration<Object> it = p.keys();
        while (it.hasMoreElements()) {
            String key = (String) it.nextElement();
            String val = (String) p.getProperty(key);
            // System.out.println("Key " + key + " = " + val);
            int[] data = new int[3];
            // parse val, store in data
            StringTokenizer st = new StringTokenizer(val);
            // TODO if (st.countTokens() != 3) throw exception
            int ix = 0;
            while (st.hasMoreElements()) {
                String t = (String) st.nextElement();
                data[ix++] = mmssToInt(t);
            }/*from   w w  w .  j av  a 2s.  c om*/
            h.put(key, data);
        }
        return h;
    }

    public static int mmssToInt(String t) {
        int i;
        if ((i = t.indexOf(':')) < 0)
            return Integer.parseInt(t);
        else {
            String mm = t.substring(0, i);
            String ss = t.substring(i + 1);
            // System.out.println(mm + "--" + ss);
            int nSec = Integer.parseInt(mm) * 60 + Integer.parseInt(ss);
            return nSec;
        }
    }
}

Related

  1. parseBooleanProperty(Properties props, String keyword, boolean defaultValue)
  2. parseHtmlProperties(String s)
  3. parseProperties(final String string)
  4. parsePropertiesString(String s)