package org.ruler;

import static org.ruler.Unit.FEET;
import static org.ruler.Unit.INCH;
import static org.ruler.Unit.MILE;
import static org.ruler.Unit.YARD;

class Length {
    private int value;
    private Unit unit;

    private Length(int value, Unit unit) {
        this.value = value;
        this.unit = unit;
    }

    static Length mile(int value) {
        return new Length(value, MILE);
    }

    static Length yard(int value) {
        return new Length(value, YARD);
    }

    static Length feet(int value) {
        return new Length(value, FEET);
    }

    static Length inch(int value) {
        return new Length(value, INCH);
    }

    @Override
    public boolean equals(Object obj) {
        Length that = (Length) obj;
        return obj != null && this.value * this.unit.value() == that.value * that.unit.value();
    }

    public Length plus(Length length) {
        int value = this.value * this.unit.value() + length.value * length.unit.value();
        return new Length(value, INCH);
    }
}

@@ -718,22 +718,42 @@
     
-Length that = 
+return obj != null && value() == (
 (Len
@@ -764,78 +764,71 @@
  obj
+).value()
 ;%0A    
+%7D%0A%0A
     
-return obj != null && this.value * this.unit.value() == that
+private int value() %7B%0A        return this
 .val
@@ -834,18 +834,18 @@
 lue * th
-at
+is
 .unit.va
@@ -910,75 +910,43 @@
     
-int value = this.value * this.unit.value() + l
+return new L
 ength
-.
+(
 value
- *
+() +
  length.
 unit
@@ -945,53 +945,15 @@
 gth.
-unit.
 value()
-;%0A        return new Length(value
 , IN

refactor to remove duplication