package com.github.miachm.sods;

class ColumnStyle {
    private Double width;
    private boolean isHidden;
    private static final double EQUIVALENCE_CM = 0.1;
    private static final double EQUIVALENCE_PX = 0.264583333;
    private static final double EQUIVALENCE_IN = 2.54 / 100.0;
    private static final double EQUIVALENCE_PT = EQUIVALENCE_IN / 72.0;
    private static final double EQUIVALENCE_PC = EQUIVALENCE_IN * 12.0;

    public Double getWidth() {
        return width;
    }

    public void setWidth(Double width) {
        this.width = width;
    }

    void setWidth(String width) {
        this.width = getValue(width);
    }

    public static Double getValue(String value)
    {
        if (value == null)
            return null;

        if (value.isEmpty() || value.equals("0"))
            return 0.0;

        if (value.length() > 2) {
            double number = Double.parseDouble(value.substring(0, value.length() - 2));
            if (value.endsWith("mm"))
                return number;
            else if (value.endsWith("cm"))
                return number * EQUIVALENCE_CM;
            else if (value.endsWith("in"))
                return number * EQUIVALENCE_IN;
            else if (value.endsWith("pt"))
                return number * EQUIVALENCE_PT;
            else if (value.endsWith("pc"))
                return number * EQUIVALENCE_PC;
            else if (value.endsWith("px"))
                return number * EQUIVALENCE_PX;
            else
                throw new IllegalArgumentException("Unit not recognized");
        }
        else
            throw new IllegalArgumentException("A unit is needed");
    }

    public boolean isHidden() {
        return isHidden;
    }

    public void setHidden(boolean hidden) {
        isHidden = hidden;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ColumnStyle that = (ColumnStyle) o;

        if (isHidden != that.isHidden) return false;
        return width != null ? width.equals(that.width) : that.width == null;
    }

    @Override
    public int hashCode() {
        int result = width != null ? width.hashCode() : 0;
        result = 31 * result + (isHidden ? 1 : 0);
        return result;
    }

    @Override
    public String toString() {
        return "ColumnStyle{" +
                "width=" + width +
                ", isHidden=" + isHidden +
                '}';
    }
}

@@ -155,11 +155,10 @@
 M = 
-0.
 1
+0
 ;%0A  
@@ -270,20 +270,19 @@
 N = 
+(
 2.54 
-/ 100.0
+* 10)
 ;%0A  
@@ -332,29 +332,19 @@
 T = 
-EQUIVALENCE_IN / 72.0
+72.0 / 25.4
 ;%0A  
@@ -394,29 +394,18 @@
 C = 
-EQUIVALENCE_IN * 12.0
+6.0 / 25.4
 ;%0A%0A 
@@ -1215,16 +1215,88 @@
 h(%22pt%22))
+ %7B%0A                System.out.println(number + %22 =%3E %22 + EQUIVALENCE_PT);
 %0A       
@@ -1336,16 +1336,30 @@
 NCE_PT;%0A
+            %7D%0A
         

Fix errors in units conversions