aboutsummaryrefslogtreecommitdiffstats
path: root/host/migration/src/RowParser.java
blob: e1c0de7543144427b60880105b924d3ab9096431 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by adnan on 11/17/15.
 */
public class RowParser {
    private static final String REGEX = "=(.+)";
    private static Pattern p = Pattern.compile(REGEX);

    public static Setting parseAndPopulate(boolean fromCursor, String line) {
        Setting setting = new Setting();
        String[] splitStrings = line.split(",");
        for (int i = 0; i < 4; i++) {
            Matcher matcher = p.matcher(splitStrings[i]);
            while (matcher.find()) {
                String value = matcher.group(0).replace("=", "").trim();
                switch (i) {
                    case 0:
                        setting.setKey(value);
                        break;
                    case 1:
                        //Seriously?
                        if (fromCursor) {
                            setting.setKeyType(
                                    Setting.SettingType.mapNumericToType(
                                            Integer.parseInt(value)));
                        } else {
                            setting.setKeyType(value);
                        }
                        break;
                    case 2:
                        setting.setValue(value);
                        break;
                    case 3:
                        //Who the fuck decided to do this?
                        if (fromCursor) {
                            setting.setValueType(
                                    Setting.SettingType.mapNumericToType(
                                            Integer.parseInt(value)));
                        } else {
                            setting.setValueType(value);
                        }
                        break;
                }
            }
        }
        return setting;
    }
}