// Path: src/main/java/io/openio/sds/common/Check.java
// public static void checkArgument(boolean condition, String msg) {
//     if (!condition)
//         throw new IllegalArgumentException(msg);
// }


import static io.openio.sds.common.Check.checkArgument;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
package io.openio.sds.models;



/**
 * 
 *
 *
 */
public class Position {

    private static final Pattern POSITION_PATTERN = Pattern
            .compile("^([\\d]+)(\\.([\\d]+))?$");

    private int meta;
    private int sub;

    private Position(int meta, int sub) {
        this.meta = meta;
        this.sub = sub;
    }

    public static Position parse(String pos) {
        Matcher m = POSITION_PATTERN.matcher(pos);
        checkArgument(m.matches(),
                String.format("Invalid position %s", pos));
        if (null == m.group(2))
            return simple(Integer.parseInt(m.group(1)));
        return composed(Integer.parseInt(m.group(1)),
                Integer.parseInt(m.group(3)));
    }

    public static Position simple(int meta) {
        checkArgument(0 <= meta, "Invalid position");
        return new Position(meta, -1);
    }

    public static Position composed(int meta, int sub) {
        checkArgument(0 <= meta, "Invalid meta position");
        checkArgument(0 <= sub, "Invalid sub position");
// Path: src/main/java/io/openio/sds/common/Check.java
// public static void checkArgument(boolean condition, String msg) {
//     if (!condition)
//         throw new IllegalArgumentException(msg);
// }


// Path: src/main/java/io/openio/sds/models/Position.java
import static io.openio.sds.common.Check.checkArgument;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

package io.openio.sds.models;



/**
 * 
 *
 *
 */
public class Position {

    private static final Pattern POSITION_PATTERN = Pattern
            .compile("^([\\d]+)(\\.([\\d]+))?$");

    private int meta;
    private int sub;

    private Position(int meta, int sub) {
        this.meta = meta;
        this.sub = sub;
    }

    public static Position parse(String pos) {
        Matcher m = POSITION_PATTERN.matcher(pos);
        checkArgument(m.matches(),
                String.format("Invalid position %s", pos));
        if (null == m.group(2))
            return simple(Integer.parseInt(m.group(1)));
        return composed(Integer.parseInt(m.group(1)),
                Integer.parseInt(m.group(3)));
    }

    public static Position simple(int meta) {
        checkArgument(0 <= meta, "Invalid position");
        return new Position(meta, -1);
    }

    public static Position composed(int meta, int sub) {
        checkArgument(0 <= meta, "Invalid meta position");
        checkArgument(0 <= sub, "Invalid sub position");
        return new Position(meta, sub);