From 4ffca781693723574e1ca0c80f676cc3901f6056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A5=E4=B8=80?= Date: Sat, 1 Feb 2020 12:30:25 +0800 Subject: [PATCH 01/18] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=E6=8B=BC?= =?UTF-8?q?=E5=86=99=E9=94=99=E8=AF=AF=E7=9A=84uinnt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Length.java | 8 ++++---- src/test/java/LengthTest.java | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/Length.java b/src/main/java/Length.java index dbc9d2c..a078920 100644 --- a/src/main/java/Length.java +++ b/src/main/java/Length.java @@ -2,9 +2,9 @@ public class Length { private final double value; private final String unit; - public Length(double val, String uinnt) { + public Length(double val, String unit) { this.value = val; - this.unit = uinnt; + this.unit = unit; } public Length as(String u) { @@ -20,7 +20,7 @@ public Length as(String u) { if (this.unit.equals("yard")) { if (u.equals("inch")) { len = new Length(this.value * 36, u); - } else if (u.equals("f")){ + } else if (u.equals("f")) { len = new Length(this.value * 3, u); } } @@ -40,7 +40,7 @@ public double getVal() { return this.value; } - public String getUinnt() { + public String getUnit() { return this.unit; } } diff --git a/src/test/java/LengthTest.java b/src/test/java/LengthTest.java index 4cc0cb8..e9c376b 100644 --- a/src/test/java/LengthTest.java +++ b/src/test/java/LengthTest.java @@ -9,7 +9,7 @@ public void should_1_inch_equals_1_inch() { Length result = new Length(1, "inch").as("inch"); assertThat(result.getVal(), is(1.0)); - assertThat(result.getUinnt(), is("inch")); + assertThat(result.getUnit(), is("inch")); } @Test @@ -17,7 +17,7 @@ public void should_2_feet_equals_2_feet() { Length result = new Length(2, "f").as("f"); assertThat(result.getVal(), is(2.0)); - assertThat(result.getUinnt(), is("f")); + assertThat(result.getUnit(), is("f")); } @Test @@ -25,7 +25,7 @@ public void should_1_yard_equals_1_yard() { Length result = new Length(1, "yard").as("yard"); assertThat(result.getVal(), is(1.0)); - assertThat(result.getUinnt(), is("yard")); + assertThat(result.getUnit(), is("yard")); } @Test @@ -33,7 +33,7 @@ public void should_1_foot_equals_12_inches() { Length result = new Length(1, "f").as("inch"); assertThat(result.getVal(), is(12.0)); - assertThat(result.getUinnt(), is("inch")); + assertThat(result.getUnit(), is("inch")); } @Test @@ -41,7 +41,7 @@ public void should_3_foot_equals_1_yard() { Length result = new Length(3, "f").as("yard"); assertThat(result.getVal(), is(1.0)); - assertThat(result.getUinnt(), is("yard")); + assertThat(result.getUnit(), is("yard")); } @Test @@ -49,7 +49,7 @@ public void should_1_yard_equals_3_feet() { Length result = new Length(1, "yard").as("f"); assertThat(result.getVal(), is(3.0)); - assertThat(result.getUinnt(), is("f")); + assertThat(result.getUnit(), is("f")); } @Test @@ -57,7 +57,7 @@ public void should_1_yard_equals_36_inches() { Length result = new Length(1, "yard").as("inch"); assertThat(result.getVal(), is(36.0)); - assertThat(result.getUinnt(), is("inch")); + assertThat(result.getUnit(), is("inch")); } @Test @@ -65,7 +65,7 @@ public void should_2_yards_equals_72_inches() { Length result = new Length(2, "yard").as("inch"); assertThat(result.getVal(), is(72.0)); - assertThat(result.getUinnt(), is("inch")); + assertThat(result.getUnit(), is("inch")); } @Test @@ -73,7 +73,7 @@ public void should_12_inches_equals_1_foot() { Length result = new Length(12, "inch").as("f"); assertThat(result.getVal(), is(1.0)); - assertThat(result.getUinnt(), is("f")); + assertThat(result.getUnit(), is("f")); } @Test @@ -81,7 +81,7 @@ public void should_36_inches_equals_1_yard() { Length result = new Length(36, "inch").as("yard"); assertThat(result.getVal(), is(1.0)); - assertThat(result.getUinnt(), is("yard")); + assertThat(result.getUnit(), is("yard")); } @Test @@ -89,6 +89,6 @@ public void should_18_inches_equals_half_yard() { Length result = new Length(18, "inch").as("yard"); assertThat(result.getVal(), is(0.5)); - assertThat(result.getUinnt(), is("yard")); + assertThat(result.getUnit(), is("yard")); } } From 75c5a1832f1a4ee63eaf56d8ec7c0dcd0b67c7c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A5=E4=B8=80?= Date: Sat, 1 Feb 2020 12:32:16 +0800 Subject: [PATCH 02/18] =?UTF-8?q?=E6=8F=90=E5=8F=96=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E5=B8=B8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Length.java | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/Length.java b/src/main/java/Length.java index a078920..2e80576 100644 --- a/src/main/java/Length.java +++ b/src/main/java/Length.java @@ -1,4 +1,7 @@ public class Length { + private static final String YARD = "yard"; + private static final String FOOT = "f"; + private static final String INCH = "inch"; private final double value; private final String unit; @@ -9,26 +12,26 @@ public Length(double val, String unit) { public Length as(String u) { Length len = this; - if (this.unit.equals("f")) { - if (u.equals("yard")) { + if (this.unit.equals(Length.FOOT)) { + if (u.equals(Length.YARD)) { len = new Length(this.value / 3, u); - } else if (u.equals("inch")) { + } else if (u.equals(Length.INCH)) { len = new Length(this.value * 12, u); } } - if (this.unit.equals("yard")) { - if (u.equals("inch")) { + if (this.unit.equals(Length.YARD)) { + if (u.equals(Length.INCH)) { len = new Length(this.value * 36, u); - } else if (u.equals("f")) { + } else if (u.equals(Length.FOOT)) { len = new Length(this.value * 3, u); } } - if (this.unit.equals("inch")) { - if (u.equals("f")) { + if (this.unit.equals(Length.INCH)) { + if (u.equals(Length.FOOT)) { len = new Length(this.value / 12, u); - } else if (u.equals("yard")) { + } else if (u.equals(Length.YARD)) { len = new Length(this.value / 36, u); } } From ab975401275b03f4229c7521345e4b3cce1189b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A5=E4=B8=80?= Date: Sat, 1 Feb 2020 12:33:30 +0800 Subject: [PATCH 03/18] =?UTF-8?q?=E6=8F=90=E5=8F=96=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=B1=BB=E4=B8=AD=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=B8=B8?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Length.java | 6 ++--- src/test/java/LengthTest.java | 44 +++++++++++++++++------------------ 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/main/java/Length.java b/src/main/java/Length.java index 2e80576..7315883 100644 --- a/src/main/java/Length.java +++ b/src/main/java/Length.java @@ -1,7 +1,7 @@ public class Length { - private static final String YARD = "yard"; - private static final String FOOT = "f"; - private static final String INCH = "inch"; + static final String YARD = "yard"; + static final String FOOT = "f"; + static final String INCH = "inch"; private final double value; private final String unit; diff --git a/src/test/java/LengthTest.java b/src/test/java/LengthTest.java index e9c376b..dab5452 100644 --- a/src/test/java/LengthTest.java +++ b/src/test/java/LengthTest.java @@ -6,89 +6,89 @@ public class LengthTest { @Test public void should_1_inch_equals_1_inch() { - Length result = new Length(1, "inch").as("inch"); + Length result = new Length(1, Length.INCH).as(Length.INCH); assertThat(result.getVal(), is(1.0)); - assertThat(result.getUnit(), is("inch")); + assertThat(result.getUnit(), is(Length.INCH)); } @Test public void should_2_feet_equals_2_feet() { - Length result = new Length(2, "f").as("f"); + Length result = new Length(2, Length.FOOT).as(Length.FOOT); assertThat(result.getVal(), is(2.0)); - assertThat(result.getUnit(), is("f")); + assertThat(result.getUnit(), is(Length.FOOT)); } @Test public void should_1_yard_equals_1_yard() { - Length result = new Length(1, "yard").as("yard"); + Length result = new Length(1, Length.YARD).as(Length.YARD); assertThat(result.getVal(), is(1.0)); - assertThat(result.getUnit(), is("yard")); + assertThat(result.getUnit(), is(Length.YARD)); } @Test public void should_1_foot_equals_12_inches() { - Length result = new Length(1, "f").as("inch"); + Length result = new Length(1, Length.FOOT).as(Length.INCH); assertThat(result.getVal(), is(12.0)); - assertThat(result.getUnit(), is("inch")); + assertThat(result.getUnit(), is(Length.INCH)); } @Test public void should_3_foot_equals_1_yard() { - Length result = new Length(3, "f").as("yard"); + Length result = new Length(3, Length.FOOT).as(Length.YARD); assertThat(result.getVal(), is(1.0)); - assertThat(result.getUnit(), is("yard")); + assertThat(result.getUnit(), is(Length.YARD)); } @Test public void should_1_yard_equals_3_feet() { - Length result = new Length(1, "yard").as("f"); + Length result = new Length(1, Length.YARD).as(Length.FOOT); assertThat(result.getVal(), is(3.0)); - assertThat(result.getUnit(), is("f")); + assertThat(result.getUnit(), is(Length.FOOT)); } @Test public void should_1_yard_equals_36_inches() { - Length result = new Length(1, "yard").as("inch"); + Length result = new Length(1, Length.YARD).as(Length.INCH); assertThat(result.getVal(), is(36.0)); - assertThat(result.getUnit(), is("inch")); + assertThat(result.getUnit(), is(Length.INCH)); } @Test public void should_2_yards_equals_72_inches() { - Length result = new Length(2, "yard").as("inch"); + Length result = new Length(2, Length.YARD).as(Length.INCH); assertThat(result.getVal(), is(72.0)); - assertThat(result.getUnit(), is("inch")); + assertThat(result.getUnit(), is(Length.INCH)); } @Test public void should_12_inches_equals_1_foot() { - Length result = new Length(12, "inch").as("f"); + Length result = new Length(12, Length.INCH).as(Length.FOOT); assertThat(result.getVal(), is(1.0)); - assertThat(result.getUnit(), is("f")); + assertThat(result.getUnit(), is(Length.FOOT)); } @Test public void should_36_inches_equals_1_yard() { - Length result = new Length(36, "inch").as("yard"); + Length result = new Length(36, Length.INCH).as(Length.YARD); assertThat(result.getVal(), is(1.0)); - assertThat(result.getUnit(), is("yard")); + assertThat(result.getUnit(), is(Length.YARD)); } @Test public void should_18_inches_equals_half_yard() { - Length result = new Length(18, "inch").as("yard"); + Length result = new Length(18, Length.INCH).as(Length.YARD); assertThat(result.getVal(), is(0.5)); - assertThat(result.getUnit(), is("yard")); + assertThat(result.getUnit(), is(Length.YARD)); } } From ae9867f9324e1dcb5389ff864ff81d5938d3617d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A5=E4=B8=80?= Date: Sat, 1 Feb 2020 12:34:56 +0800 Subject: [PATCH 04/18] =?UTF-8?q?=E5=A4=8D=E5=88=B6as=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=B8=BAtemp=5Fas,=E5=B9=B6=E5=B0=86as=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E7=9B=B4=E6=8E=A5=E8=BF=94=E5=9B=9Etemp=5Fas?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Length.java | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/Length.java b/src/main/java/Length.java index 7315883..98c0f73 100644 --- a/src/main/java/Length.java +++ b/src/main/java/Length.java @@ -10,29 +10,33 @@ public Length(double val, String unit) { this.unit = unit; } - public Length as(String u) { + public Length as(String targetUnit) { + return temp_as(targetUnit); + } + + public Length temp_as(String targetUnit) { Length len = this; if (this.unit.equals(Length.FOOT)) { - if (u.equals(Length.YARD)) { - len = new Length(this.value / 3, u); - } else if (u.equals(Length.INCH)) { - len = new Length(this.value * 12, u); + if (targetUnit.equals(Length.YARD)) { + len = new Length(this.value / 3, targetUnit); + } else if (targetUnit.equals(Length.INCH)) { + len = new Length(this.value * 12, targetUnit); } } if (this.unit.equals(Length.YARD)) { - if (u.equals(Length.INCH)) { - len = new Length(this.value * 36, u); - } else if (u.equals(Length.FOOT)) { - len = new Length(this.value * 3, u); + if (targetUnit.equals(Length.INCH)) { + len = new Length(this.value * 36, targetUnit); + } else if (targetUnit.equals(Length.FOOT)) { + len = new Length(this.value * 3, targetUnit); } } if (this.unit.equals(Length.INCH)) { - if (u.equals(Length.FOOT)) { - len = new Length(this.value / 12, u); - } else if (u.equals(Length.YARD)) { - len = new Length(this.value / 36, u); + if (targetUnit.equals(Length.FOOT)) { + len = new Length(this.value / 12, targetUnit); + } else if (targetUnit.equals(Length.YARD)) { + len = new Length(this.value / 36, targetUnit); } } From 8098271f73ef27329e5848586c69ac61be556c20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A5=E4=B8=80?= Date: Sat, 1 Feb 2020 12:36:18 +0800 Subject: [PATCH 05/18] =?UTF-8?q?=E5=88=9B=E5=BB=BAUnit=E6=9E=9A=E4=B8=BE?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=EF=BC=8C=E4=BD=9C=E4=B8=BAtemp=5Fas=E4=BC=A0?= =?UTF-8?q?=E5=85=A5=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Length.java | 4 ++-- src/main/java/Unit.java | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 src/main/java/Unit.java diff --git a/src/main/java/Length.java b/src/main/java/Length.java index 98c0f73..b38ee56 100644 --- a/src/main/java/Length.java +++ b/src/main/java/Length.java @@ -11,10 +11,10 @@ public Length(double val, String unit) { } public Length as(String targetUnit) { - return temp_as(targetUnit); + return temp_as(targetUnit, null); } - public Length temp_as(String targetUnit) { + public Length temp_as(String targetUnit, Unit tempUnit) { Length len = this; if (this.unit.equals(Length.FOOT)) { if (targetUnit.equals(Length.YARD)) { diff --git a/src/main/java/Unit.java b/src/main/java/Unit.java new file mode 100644 index 0000000..db25879 --- /dev/null +++ b/src/main/java/Unit.java @@ -0,0 +1,8 @@ +/** + * Created with IntelliJ IDEA. + * User: lai.yi + * Date: 2020/2/1 + * Description: + **/ +public enum Unit { +} From 27deb25bb0d36c92be3bb31f1de9a36173fade19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A5=E4=B8=80?= Date: Sat, 1 Feb 2020 12:44:05 +0800 Subject: [PATCH 06/18] =?UTF-8?q?=E5=B0=86=E6=B5=8B=E8=AF=95=E4=B8=AD?= =?UTF-8?q?=E8=B0=83=E7=94=A8as=E6=96=B9=E6=B3=95=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E4=B8=BAtemp=5Fas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Length.java | 22 +++++++++++++++------- src/main/java/Unit.java | 1 + src/test/java/LengthTest.java | 22 +++++++++++----------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/main/java/Length.java b/src/main/java/Length.java index b38ee56..077be0f 100644 --- a/src/main/java/Length.java +++ b/src/main/java/Length.java @@ -11,31 +11,39 @@ public Length(double val, String unit) { } public Length as(String targetUnit) { - return temp_as(targetUnit, null); + Unit tempUnit = null; + if (targetUnit.equals(Length.YARD)) { + tempUnit = Unit.YARD; + } else if (targetUnit.equals(Length.FOOT)) { + tempUnit = Unit.FOOT; + } else if (targetUnit.equals(Length.INCH)) { + tempUnit = Unit.INCH; + } + return temp_as(targetUnit, tempUnit); } public Length temp_as(String targetUnit, Unit tempUnit) { Length len = this; if (this.unit.equals(Length.FOOT)) { - if (targetUnit.equals(Length.YARD)) { + if (tempUnit == Unit.YARD) { len = new Length(this.value / 3, targetUnit); - } else if (targetUnit.equals(Length.INCH)) { + } else if (tempUnit == Unit.INCH) { len = new Length(this.value * 12, targetUnit); } } if (this.unit.equals(Length.YARD)) { - if (targetUnit.equals(Length.INCH)) { + if (tempUnit == Unit.INCH) { len = new Length(this.value * 36, targetUnit); - } else if (targetUnit.equals(Length.FOOT)) { + } else if (tempUnit == Unit.FOOT) { len = new Length(this.value * 3, targetUnit); } } if (this.unit.equals(Length.INCH)) { - if (targetUnit.equals(Length.FOOT)) { + if (tempUnit == Unit.FOOT) { len = new Length(this.value / 12, targetUnit); - } else if (targetUnit.equals(Length.YARD)) { + } else if (tempUnit == Unit.YARD) { len = new Length(this.value / 36, targetUnit); } } diff --git a/src/main/java/Unit.java b/src/main/java/Unit.java index db25879..5726bc4 100644 --- a/src/main/java/Unit.java +++ b/src/main/java/Unit.java @@ -5,4 +5,5 @@ * Description: **/ public enum Unit { + FOOT, INCH, YARD } diff --git a/src/test/java/LengthTest.java b/src/test/java/LengthTest.java index dab5452..27c7ac2 100644 --- a/src/test/java/LengthTest.java +++ b/src/test/java/LengthTest.java @@ -6,7 +6,7 @@ public class LengthTest { @Test public void should_1_inch_equals_1_inch() { - Length result = new Length(1, Length.INCH).as(Length.INCH); + Length result = new Length(1, Length.INCH).temp_as(Length.INCH, Unit.INCH); assertThat(result.getVal(), is(1.0)); assertThat(result.getUnit(), is(Length.INCH)); @@ -14,7 +14,7 @@ public void should_1_inch_equals_1_inch() { @Test public void should_2_feet_equals_2_feet() { - Length result = new Length(2, Length.FOOT).as(Length.FOOT); + Length result = new Length(2, Length.FOOT).temp_as(Length.FOOT, Unit.FOOT); assertThat(result.getVal(), is(2.0)); assertThat(result.getUnit(), is(Length.FOOT)); @@ -22,7 +22,7 @@ public void should_2_feet_equals_2_feet() { @Test public void should_1_yard_equals_1_yard() { - Length result = new Length(1, Length.YARD).as(Length.YARD); + Length result = new Length(1, Length.YARD).temp_as(Length.YARD, Unit.YARD); assertThat(result.getVal(), is(1.0)); assertThat(result.getUnit(), is(Length.YARD)); @@ -30,7 +30,7 @@ public void should_1_yard_equals_1_yard() { @Test public void should_1_foot_equals_12_inches() { - Length result = new Length(1, Length.FOOT).as(Length.INCH); + Length result = new Length(1, Length.FOOT).temp_as(Length.INCH, Unit.INCH); assertThat(result.getVal(), is(12.0)); assertThat(result.getUnit(), is(Length.INCH)); @@ -38,7 +38,7 @@ public void should_1_foot_equals_12_inches() { @Test public void should_3_foot_equals_1_yard() { - Length result = new Length(3, Length.FOOT).as(Length.YARD); + Length result = new Length(3, Length.FOOT).temp_as(Length.YARD, Unit.YARD); assertThat(result.getVal(), is(1.0)); assertThat(result.getUnit(), is(Length.YARD)); @@ -46,7 +46,7 @@ public void should_3_foot_equals_1_yard() { @Test public void should_1_yard_equals_3_feet() { - Length result = new Length(1, Length.YARD).as(Length.FOOT); + Length result = new Length(1, Length.YARD).temp_as(Length.FOOT, Unit.FOOT); assertThat(result.getVal(), is(3.0)); assertThat(result.getUnit(), is(Length.FOOT)); @@ -54,7 +54,7 @@ public void should_1_yard_equals_3_feet() { @Test public void should_1_yard_equals_36_inches() { - Length result = new Length(1, Length.YARD).as(Length.INCH); + Length result = new Length(1, Length.YARD).temp_as(Length.INCH, Unit.INCH); assertThat(result.getVal(), is(36.0)); assertThat(result.getUnit(), is(Length.INCH)); @@ -62,7 +62,7 @@ public void should_1_yard_equals_36_inches() { @Test public void should_2_yards_equals_72_inches() { - Length result = new Length(2, Length.YARD).as(Length.INCH); + Length result = new Length(2, Length.YARD).temp_as(Length.INCH, Unit.INCH); assertThat(result.getVal(), is(72.0)); assertThat(result.getUnit(), is(Length.INCH)); @@ -70,7 +70,7 @@ public void should_2_yards_equals_72_inches() { @Test public void should_12_inches_equals_1_foot() { - Length result = new Length(12, Length.INCH).as(Length.FOOT); + Length result = new Length(12, Length.INCH).temp_as(Length.FOOT, Unit.FOOT); assertThat(result.getVal(), is(1.0)); assertThat(result.getUnit(), is(Length.FOOT)); @@ -78,7 +78,7 @@ public void should_12_inches_equals_1_foot() { @Test public void should_36_inches_equals_1_yard() { - Length result = new Length(36, Length.INCH).as(Length.YARD); + Length result = new Length(36, Length.INCH).temp_as(Length.YARD, Unit.YARD); assertThat(result.getVal(), is(1.0)); assertThat(result.getUnit(), is(Length.YARD)); @@ -86,7 +86,7 @@ public void should_36_inches_equals_1_yard() { @Test public void should_18_inches_equals_half_yard() { - Length result = new Length(18, Length.INCH).as(Length.YARD); + Length result = new Length(18, Length.INCH).temp_as(Length.YARD, Unit.YARD); assertThat(result.getVal(), is(0.5)); assertThat(result.getUnit(), is(Length.YARD)); From f39b80a92cee5544ee42deeb17b365b6ce8754ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A5=E4=B8=80?= Date: Sat, 1 Feb 2020 12:44:47 +0800 Subject: [PATCH 07/18] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=8E=9F=E6=9D=A5as?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E5=B9=B6=E9=87=8D=E5=91=BD=E5=90=8D?= =?UTF-8?q?temp=5Fas=E4=B8=BAas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Length.java | 14 +------------- src/test/java/LengthTest.java | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/main/java/Length.java b/src/main/java/Length.java index 077be0f..ff6073b 100644 --- a/src/main/java/Length.java +++ b/src/main/java/Length.java @@ -10,19 +10,7 @@ public Length(double val, String unit) { this.unit = unit; } - public Length as(String targetUnit) { - Unit tempUnit = null; - if (targetUnit.equals(Length.YARD)) { - tempUnit = Unit.YARD; - } else if (targetUnit.equals(Length.FOOT)) { - tempUnit = Unit.FOOT; - } else if (targetUnit.equals(Length.INCH)) { - tempUnit = Unit.INCH; - } - return temp_as(targetUnit, tempUnit); - } - - public Length temp_as(String targetUnit, Unit tempUnit) { + public Length as(String targetUnit, Unit tempUnit) { Length len = this; if (this.unit.equals(Length.FOOT)) { if (tempUnit == Unit.YARD) { diff --git a/src/test/java/LengthTest.java b/src/test/java/LengthTest.java index 27c7ac2..a15b900 100644 --- a/src/test/java/LengthTest.java +++ b/src/test/java/LengthTest.java @@ -6,7 +6,7 @@ public class LengthTest { @Test public void should_1_inch_equals_1_inch() { - Length result = new Length(1, Length.INCH).temp_as(Length.INCH, Unit.INCH); + Length result = new Length(1, Length.INCH).as(Length.INCH, Unit.INCH); assertThat(result.getVal(), is(1.0)); assertThat(result.getUnit(), is(Length.INCH)); @@ -14,7 +14,7 @@ public void should_1_inch_equals_1_inch() { @Test public void should_2_feet_equals_2_feet() { - Length result = new Length(2, Length.FOOT).temp_as(Length.FOOT, Unit.FOOT); + Length result = new Length(2, Length.FOOT).as(Length.FOOT, Unit.FOOT); assertThat(result.getVal(), is(2.0)); assertThat(result.getUnit(), is(Length.FOOT)); @@ -22,7 +22,7 @@ public void should_2_feet_equals_2_feet() { @Test public void should_1_yard_equals_1_yard() { - Length result = new Length(1, Length.YARD).temp_as(Length.YARD, Unit.YARD); + Length result = new Length(1, Length.YARD).as(Length.YARD, Unit.YARD); assertThat(result.getVal(), is(1.0)); assertThat(result.getUnit(), is(Length.YARD)); @@ -30,7 +30,7 @@ public void should_1_yard_equals_1_yard() { @Test public void should_1_foot_equals_12_inches() { - Length result = new Length(1, Length.FOOT).temp_as(Length.INCH, Unit.INCH); + Length result = new Length(1, Length.FOOT).as(Length.INCH, Unit.INCH); assertThat(result.getVal(), is(12.0)); assertThat(result.getUnit(), is(Length.INCH)); @@ -38,7 +38,7 @@ public void should_1_foot_equals_12_inches() { @Test public void should_3_foot_equals_1_yard() { - Length result = new Length(3, Length.FOOT).temp_as(Length.YARD, Unit.YARD); + Length result = new Length(3, Length.FOOT).as(Length.YARD, Unit.YARD); assertThat(result.getVal(), is(1.0)); assertThat(result.getUnit(), is(Length.YARD)); @@ -46,7 +46,7 @@ public void should_3_foot_equals_1_yard() { @Test public void should_1_yard_equals_3_feet() { - Length result = new Length(1, Length.YARD).temp_as(Length.FOOT, Unit.FOOT); + Length result = new Length(1, Length.YARD).as(Length.FOOT, Unit.FOOT); assertThat(result.getVal(), is(3.0)); assertThat(result.getUnit(), is(Length.FOOT)); @@ -54,7 +54,7 @@ public void should_1_yard_equals_3_feet() { @Test public void should_1_yard_equals_36_inches() { - Length result = new Length(1, Length.YARD).temp_as(Length.INCH, Unit.INCH); + Length result = new Length(1, Length.YARD).as(Length.INCH, Unit.INCH); assertThat(result.getVal(), is(36.0)); assertThat(result.getUnit(), is(Length.INCH)); @@ -62,7 +62,7 @@ public void should_1_yard_equals_36_inches() { @Test public void should_2_yards_equals_72_inches() { - Length result = new Length(2, Length.YARD).temp_as(Length.INCH, Unit.INCH); + Length result = new Length(2, Length.YARD).as(Length.INCH, Unit.INCH); assertThat(result.getVal(), is(72.0)); assertThat(result.getUnit(), is(Length.INCH)); @@ -70,7 +70,7 @@ public void should_2_yards_equals_72_inches() { @Test public void should_12_inches_equals_1_foot() { - Length result = new Length(12, Length.INCH).temp_as(Length.FOOT, Unit.FOOT); + Length result = new Length(12, Length.INCH).as(Length.FOOT, Unit.FOOT); assertThat(result.getVal(), is(1.0)); assertThat(result.getUnit(), is(Length.FOOT)); @@ -78,7 +78,7 @@ public void should_12_inches_equals_1_foot() { @Test public void should_36_inches_equals_1_yard() { - Length result = new Length(36, Length.INCH).temp_as(Length.YARD, Unit.YARD); + Length result = new Length(36, Length.INCH).as(Length.YARD, Unit.YARD); assertThat(result.getVal(), is(1.0)); assertThat(result.getUnit(), is(Length.YARD)); @@ -86,7 +86,7 @@ public void should_36_inches_equals_1_yard() { @Test public void should_18_inches_equals_half_yard() { - Length result = new Length(18, Length.INCH).temp_as(Length.YARD, Unit.YARD); + Length result = new Length(18, Length.INCH).as(Length.YARD, Unit.YARD); assertThat(result.getVal(), is(0.5)); assertThat(result.getUnit(), is(Length.YARD)); From 45dbad9ce68f437802d00337ade2838bf221f929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A5=E4=B8=80?= Date: Sat, 1 Feb 2020 12:50:40 +0800 Subject: [PATCH 08/18] =?UTF-8?q?=E5=9C=A8length=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0tempUnit=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Length.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/Length.java b/src/main/java/Length.java index ff6073b..2391afe 100644 --- a/src/main/java/Length.java +++ b/src/main/java/Length.java @@ -4,10 +4,12 @@ public class Length { static final String INCH = "inch"; private final double value; private final String unit; + private final Unit tempUnit; public Length(double val, String unit) { this.value = val; this.unit = unit; + this.tempUnit = null; } public Length as(String targetUnit, Unit tempUnit) { From ea2f7809e4a45dc4eb2c7cfb8c50c31bedd6597c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A5=E4=B8=80?= Date: Sat, 1 Feb 2020 12:51:38 +0800 Subject: [PATCH 09/18] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9C=89tempUnit?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E7=9A=84=E6=9E=84=E9=80=A0=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Length.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/Length.java b/src/main/java/Length.java index 2391afe..509e737 100644 --- a/src/main/java/Length.java +++ b/src/main/java/Length.java @@ -12,6 +12,12 @@ public Length(double val, String unit) { this.tempUnit = null; } + public Length(double val, String unit, Unit tempUnit) { + this.value = val; + this.unit = unit; + this.tempUnit = tempUnit; + } + public Length as(String targetUnit, Unit tempUnit) { Length len = this; if (this.unit.equals(Length.FOOT)) { From d4679d5771e6ad590131d3ded4362cb596f4bc9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A5=E4=B8=80?= Date: Sat, 1 Feb 2020 12:52:50 +0800 Subject: [PATCH 10/18] =?UTF-8?q?=E5=B0=86as=E6=96=B9=E6=B3=95=E4=B8=AD?= =?UTF-8?q?=E6=9E=84=E9=80=A0Length=E7=9A=84=E6=9E=84=E9=80=A0=E5=99=A8?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E4=B8=BA=E5=B8=A6tempUnit=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Length.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/Length.java b/src/main/java/Length.java index 509e737..b952f11 100644 --- a/src/main/java/Length.java +++ b/src/main/java/Length.java @@ -22,25 +22,25 @@ public Length as(String targetUnit, Unit tempUnit) { Length len = this; if (this.unit.equals(Length.FOOT)) { if (tempUnit == Unit.YARD) { - len = new Length(this.value / 3, targetUnit); + len = new Length(this.value / 3, targetUnit, tempUnit); } else if (tempUnit == Unit.INCH) { - len = new Length(this.value * 12, targetUnit); + len = new Length(this.value * 12, targetUnit, tempUnit); } } if (this.unit.equals(Length.YARD)) { if (tempUnit == Unit.INCH) { - len = new Length(this.value * 36, targetUnit); + len = new Length(this.value * 36, targetUnit, tempUnit); } else if (tempUnit == Unit.FOOT) { - len = new Length(this.value * 3, targetUnit); + len = new Length(this.value * 3, targetUnit, tempUnit); } } if (this.unit.equals(Length.INCH)) { if (tempUnit == Unit.FOOT) { - len = new Length(this.value / 12, targetUnit); + len = new Length(this.value / 12, targetUnit, tempUnit); } else if (tempUnit == Unit.YARD) { - len = new Length(this.value / 36, targetUnit); + len = new Length(this.value / 36, targetUnit, tempUnit); } } From 13da9a529cde11afc79483ee369a88f3924f0ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A5=E4=B8=80?= Date: Sat, 1 Feb 2020 12:53:23 +0800 Subject: [PATCH 11/18] =?UTF-8?q?=E6=B7=BB=E5=8A=A0getTempUnit=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Length.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/Length.java b/src/main/java/Length.java index b952f11..363dd15 100644 --- a/src/main/java/Length.java +++ b/src/main/java/Length.java @@ -54,4 +54,8 @@ public double getVal() { public String getUnit() { return this.unit; } + + public Unit getTempUnit() { + return this.tempUnit; + } } From 73d9fb6e1911b92200e219e51a872e6a73216a8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A5=E4=B8=80?= Date: Sat, 1 Feb 2020 12:55:40 +0800 Subject: [PATCH 12/18] =?UTF-8?q?=E5=B0=86=E6=B5=8B=E8=AF=95=E7=B1=BB?= =?UTF-8?q?=E4=B8=AD=E6=9E=84=E9=80=A0=E5=87=BD=E6=95=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E4=B8=BA=E5=B8=A6tempUnit=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/LengthTest.java | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/test/java/LengthTest.java b/src/test/java/LengthTest.java index a15b900..6a59a10 100644 --- a/src/test/java/LengthTest.java +++ b/src/test/java/LengthTest.java @@ -6,7 +6,7 @@ public class LengthTest { @Test public void should_1_inch_equals_1_inch() { - Length result = new Length(1, Length.INCH).as(Length.INCH, Unit.INCH); + Length result = new Length(1, Length.INCH, Unit.INCH).as(Length.INCH, Unit.INCH); assertThat(result.getVal(), is(1.0)); assertThat(result.getUnit(), is(Length.INCH)); @@ -14,7 +14,7 @@ public void should_1_inch_equals_1_inch() { @Test public void should_2_feet_equals_2_feet() { - Length result = new Length(2, Length.FOOT).as(Length.FOOT, Unit.FOOT); + Length result = new Length(2, Length.FOOT, Unit.FOOT).as(Length.FOOT, Unit.FOOT); assertThat(result.getVal(), is(2.0)); assertThat(result.getUnit(), is(Length.FOOT)); @@ -22,7 +22,7 @@ public void should_2_feet_equals_2_feet() { @Test public void should_1_yard_equals_1_yard() { - Length result = new Length(1, Length.YARD).as(Length.YARD, Unit.YARD); + Length result = new Length(1, Length.YARD, Unit.YARD).as(Length.YARD, Unit.YARD); assertThat(result.getVal(), is(1.0)); assertThat(result.getUnit(), is(Length.YARD)); @@ -30,7 +30,7 @@ public void should_1_yard_equals_1_yard() { @Test public void should_1_foot_equals_12_inches() { - Length result = new Length(1, Length.FOOT).as(Length.INCH, Unit.INCH); + Length result = new Length(1, Length.FOOT, Unit.FOOT).as(Length.INCH, Unit.INCH); assertThat(result.getVal(), is(12.0)); assertThat(result.getUnit(), is(Length.INCH)); @@ -38,7 +38,7 @@ public void should_1_foot_equals_12_inches() { @Test public void should_3_foot_equals_1_yard() { - Length result = new Length(3, Length.FOOT).as(Length.YARD, Unit.YARD); + Length result = new Length(3, Length.FOOT, Unit.FOOT).as(Length.YARD, Unit.YARD); assertThat(result.getVal(), is(1.0)); assertThat(result.getUnit(), is(Length.YARD)); @@ -46,7 +46,7 @@ public void should_3_foot_equals_1_yard() { @Test public void should_1_yard_equals_3_feet() { - Length result = new Length(1, Length.YARD).as(Length.FOOT, Unit.FOOT); + Length result = new Length(1, Length.YARD, Unit.YARD).as(Length.FOOT, Unit.FOOT); assertThat(result.getVal(), is(3.0)); assertThat(result.getUnit(), is(Length.FOOT)); @@ -54,7 +54,7 @@ public void should_1_yard_equals_3_feet() { @Test public void should_1_yard_equals_36_inches() { - Length result = new Length(1, Length.YARD).as(Length.INCH, Unit.INCH); + Length result = new Length(1, Length.YARD, Unit.YARD).as(Length.INCH, Unit.INCH); assertThat(result.getVal(), is(36.0)); assertThat(result.getUnit(), is(Length.INCH)); @@ -62,7 +62,7 @@ public void should_1_yard_equals_36_inches() { @Test public void should_2_yards_equals_72_inches() { - Length result = new Length(2, Length.YARD).as(Length.INCH, Unit.INCH); + Length result = new Length(2, Length.YARD, Unit.YARD).as(Length.INCH, Unit.INCH); assertThat(result.getVal(), is(72.0)); assertThat(result.getUnit(), is(Length.INCH)); @@ -70,7 +70,7 @@ public void should_2_yards_equals_72_inches() { @Test public void should_12_inches_equals_1_foot() { - Length result = new Length(12, Length.INCH).as(Length.FOOT, Unit.FOOT); + Length result = new Length(12, Length.INCH, Unit.INCH).as(Length.FOOT, Unit.FOOT); assertThat(result.getVal(), is(1.0)); assertThat(result.getUnit(), is(Length.FOOT)); @@ -78,7 +78,7 @@ public void should_12_inches_equals_1_foot() { @Test public void should_36_inches_equals_1_yard() { - Length result = new Length(36, Length.INCH).as(Length.YARD, Unit.YARD); + Length result = new Length(36, Length.INCH, Unit.INCH).as(Length.YARD, Unit.YARD); assertThat(result.getVal(), is(1.0)); assertThat(result.getUnit(), is(Length.YARD)); @@ -86,7 +86,7 @@ public void should_36_inches_equals_1_yard() { @Test public void should_18_inches_equals_half_yard() { - Length result = new Length(18, Length.INCH).as(Length.YARD, Unit.YARD); + Length result = new Length(18, Length.INCH, Unit.INCH).as(Length.YARD, Unit.YARD); assertThat(result.getVal(), is(0.5)); assertThat(result.getUnit(), is(Length.YARD)); From b8c44185a127c55e9b23ef3932a22738e2c76b72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A5=E4=B8=80?= Date: Sat, 1 Feb 2020 12:56:03 +0800 Subject: [PATCH 13/18] =?UTF-8?q?=E5=88=A0=E6=8E=89=E5=8E=9F=E6=9C=89?= =?UTF-8?q?=E6=9E=84=E9=80=A0=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Length.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/Length.java b/src/main/java/Length.java index 363dd15..44329a8 100644 --- a/src/main/java/Length.java +++ b/src/main/java/Length.java @@ -6,12 +6,6 @@ public class Length { private final String unit; private final Unit tempUnit; - public Length(double val, String unit) { - this.value = val; - this.unit = unit; - this.tempUnit = null; - } - public Length(double val, String unit, Unit tempUnit) { this.value = val; this.unit = unit; From 9d35531c5875338b4b5cad771072258eae585666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A5=E4=B8=80?= Date: Sat, 1 Feb 2020 12:57:53 +0800 Subject: [PATCH 14/18] =?UTF-8?q?=E5=B0=86=E6=B5=8B=E8=AF=95=E7=B1=BB?= =?UTF-8?q?=E4=B8=ADgetUnit=E6=96=B9=E6=B3=95=E6=9B=BF=E6=8D=A2=E4=B8=BAge?= =?UTF-8?q?tTempUnit=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/LengthTest.java | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/test/java/LengthTest.java b/src/test/java/LengthTest.java index 6a59a10..0a4f086 100644 --- a/src/test/java/LengthTest.java +++ b/src/test/java/LengthTest.java @@ -9,7 +9,7 @@ public void should_1_inch_equals_1_inch() { Length result = new Length(1, Length.INCH, Unit.INCH).as(Length.INCH, Unit.INCH); assertThat(result.getVal(), is(1.0)); - assertThat(result.getUnit(), is(Length.INCH)); + assertThat(result.getTempUnit(), is(Unit.INCH)); } @Test @@ -17,7 +17,7 @@ public void should_2_feet_equals_2_feet() { Length result = new Length(2, Length.FOOT, Unit.FOOT).as(Length.FOOT, Unit.FOOT); assertThat(result.getVal(), is(2.0)); - assertThat(result.getUnit(), is(Length.FOOT)); + assertThat(result.getTempUnit(), is(Unit.FOOT)); } @Test @@ -25,7 +25,7 @@ public void should_1_yard_equals_1_yard() { Length result = new Length(1, Length.YARD, Unit.YARD).as(Length.YARD, Unit.YARD); assertThat(result.getVal(), is(1.0)); - assertThat(result.getUnit(), is(Length.YARD)); + assertThat(result.getTempUnit(), is(Unit.YARD)); } @Test @@ -33,7 +33,7 @@ public void should_1_foot_equals_12_inches() { Length result = new Length(1, Length.FOOT, Unit.FOOT).as(Length.INCH, Unit.INCH); assertThat(result.getVal(), is(12.0)); - assertThat(result.getUnit(), is(Length.INCH)); + assertThat(result.getTempUnit(), is(Unit.INCH)); } @Test @@ -41,7 +41,7 @@ public void should_3_foot_equals_1_yard() { Length result = new Length(3, Length.FOOT, Unit.FOOT).as(Length.YARD, Unit.YARD); assertThat(result.getVal(), is(1.0)); - assertThat(result.getUnit(), is(Length.YARD)); + assertThat(result.getTempUnit(), is(Unit.YARD)); } @Test @@ -49,7 +49,7 @@ public void should_1_yard_equals_3_feet() { Length result = new Length(1, Length.YARD, Unit.YARD).as(Length.FOOT, Unit.FOOT); assertThat(result.getVal(), is(3.0)); - assertThat(result.getUnit(), is(Length.FOOT)); + assertThat(result.getTempUnit(), is(Unit.FOOT)); } @Test @@ -57,7 +57,7 @@ public void should_1_yard_equals_36_inches() { Length result = new Length(1, Length.YARD, Unit.YARD).as(Length.INCH, Unit.INCH); assertThat(result.getVal(), is(36.0)); - assertThat(result.getUnit(), is(Length.INCH)); + assertThat(result.getTempUnit(), is(Unit.INCH)); } @Test @@ -65,7 +65,7 @@ public void should_2_yards_equals_72_inches() { Length result = new Length(2, Length.YARD, Unit.YARD).as(Length.INCH, Unit.INCH); assertThat(result.getVal(), is(72.0)); - assertThat(result.getUnit(), is(Length.INCH)); + assertThat(result.getTempUnit(), is(Unit.INCH)); } @Test @@ -73,7 +73,7 @@ public void should_12_inches_equals_1_foot() { Length result = new Length(12, Length.INCH, Unit.INCH).as(Length.FOOT, Unit.FOOT); assertThat(result.getVal(), is(1.0)); - assertThat(result.getUnit(), is(Length.FOOT)); + assertThat(result.getTempUnit(), is(Unit.FOOT)); } @Test @@ -81,7 +81,7 @@ public void should_36_inches_equals_1_yard() { Length result = new Length(36, Length.INCH, Unit.INCH).as(Length.YARD, Unit.YARD); assertThat(result.getVal(), is(1.0)); - assertThat(result.getUnit(), is(Length.YARD)); + assertThat(result.getTempUnit(), is(Unit.YARD)); } @Test @@ -89,6 +89,6 @@ public void should_18_inches_equals_half_yard() { Length result = new Length(18, Length.INCH, Unit.INCH).as(Length.YARD, Unit.YARD); assertThat(result.getVal(), is(0.5)); - assertThat(result.getUnit(), is(Length.YARD)); + assertThat(result.getTempUnit(), is(Unit.YARD)); } } From 840bb41184d5d5c2ebd63bc7165d8d39ba79b3b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A5=E4=B8=80?= Date: Sat, 1 Feb 2020 12:58:30 +0800 Subject: [PATCH 15/18] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=8E=9F=E6=9C=89getUn?= =?UTF-8?q?it=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Length.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/Length.java b/src/main/java/Length.java index 44329a8..8c1f37a 100644 --- a/src/main/java/Length.java +++ b/src/main/java/Length.java @@ -45,10 +45,6 @@ public double getVal() { return this.value; } - public String getUnit() { - return this.unit; - } - public Unit getTempUnit() { return this.tempUnit; } From 882c832b48ccbd0649c65d0252ef2bfcbce7ecb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A5=E4=B8=80?= Date: Sat, 1 Feb 2020 12:59:18 +0800 Subject: [PATCH 16/18] =?UTF-8?q?=E5=B0=86=E5=8E=9F=E6=9C=89=E7=9A=84unit.?= =?UTF-8?q?equals=E6=9B=BF=E6=8D=A2=E4=B8=BAtempUnit=3D=3D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Length.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/Length.java b/src/main/java/Length.java index 8c1f37a..ea6a63c 100644 --- a/src/main/java/Length.java +++ b/src/main/java/Length.java @@ -14,7 +14,7 @@ public Length(double val, String unit, Unit tempUnit) { public Length as(String targetUnit, Unit tempUnit) { Length len = this; - if (this.unit.equals(Length.FOOT)) { + if (this.tempUnit==Unit.FOOT) { if (tempUnit == Unit.YARD) { len = new Length(this.value / 3, targetUnit, tempUnit); } else if (tempUnit == Unit.INCH) { @@ -22,7 +22,7 @@ public Length as(String targetUnit, Unit tempUnit) { } } - if (this.unit.equals(Length.YARD)) { + if (this.tempUnit==Unit.YARD) { if (tempUnit == Unit.INCH) { len = new Length(this.value * 36, targetUnit, tempUnit); } else if (tempUnit == Unit.FOOT) { @@ -30,7 +30,7 @@ public Length as(String targetUnit, Unit tempUnit) { } } - if (this.unit.equals(Length.INCH)) { + if (this.tempUnit==Unit.INCH) { if (tempUnit == Unit.FOOT) { len = new Length(this.value / 12, targetUnit, tempUnit); } else if (tempUnit == Unit.YARD) { From c7dd84b0acfbc7c230036541c9392f061441b0d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A5=E4=B8=80?= Date: Sat, 1 Feb 2020 13:00:46 +0800 Subject: [PATCH 17/18] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=8E=9F=E6=9C=89?= =?UTF-8?q?=E7=9A=84unit=E5=AD=97=E6=AE=B5=EF=BC=8C=E5=B9=B6=E9=87=8D?= =?UTF-8?q?=E5=91=BD=E5=90=8DtempUnit=E4=B8=BAunit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Length.java | 42 ++++++++++++++++----------------- src/test/java/LengthTest.java | 44 +++++++++++++++++------------------ 2 files changed, 42 insertions(+), 44 deletions(-) diff --git a/src/main/java/Length.java b/src/main/java/Length.java index ea6a63c..23e9d47 100644 --- a/src/main/java/Length.java +++ b/src/main/java/Length.java @@ -3,38 +3,36 @@ public class Length { static final String FOOT = "f"; static final String INCH = "inch"; private final double value; - private final String unit; - private final Unit tempUnit; + private final Unit unit; - public Length(double val, String unit, Unit tempUnit) { + public Length(double val, Unit unit) { this.value = val; this.unit = unit; - this.tempUnit = tempUnit; } - public Length as(String targetUnit, Unit tempUnit) { + public Length as(Unit unit) { Length len = this; - if (this.tempUnit==Unit.FOOT) { - if (tempUnit == Unit.YARD) { - len = new Length(this.value / 3, targetUnit, tempUnit); - } else if (tempUnit == Unit.INCH) { - len = new Length(this.value * 12, targetUnit, tempUnit); + if (this.unit ==Unit.FOOT) { + if (unit == Unit.YARD) { + len = new Length(this.value / 3, unit); + } else if (unit == Unit.INCH) { + len = new Length(this.value * 12, unit); } } - if (this.tempUnit==Unit.YARD) { - if (tempUnit == Unit.INCH) { - len = new Length(this.value * 36, targetUnit, tempUnit); - } else if (tempUnit == Unit.FOOT) { - len = new Length(this.value * 3, targetUnit, tempUnit); + if (this.unit ==Unit.YARD) { + if (unit == Unit.INCH) { + len = new Length(this.value * 36, unit); + } else if (unit == Unit.FOOT) { + len = new Length(this.value * 3, unit); } } - if (this.tempUnit==Unit.INCH) { - if (tempUnit == Unit.FOOT) { - len = new Length(this.value / 12, targetUnit, tempUnit); - } else if (tempUnit == Unit.YARD) { - len = new Length(this.value / 36, targetUnit, tempUnit); + if (this.unit ==Unit.INCH) { + if (unit == Unit.FOOT) { + len = new Length(this.value / 12, unit); + } else if (unit == Unit.YARD) { + len = new Length(this.value / 36, unit); } } @@ -45,7 +43,7 @@ public double getVal() { return this.value; } - public Unit getTempUnit() { - return this.tempUnit; + public Unit getUnit() { + return this.unit; } } diff --git a/src/test/java/LengthTest.java b/src/test/java/LengthTest.java index 0a4f086..271ae5b 100644 --- a/src/test/java/LengthTest.java +++ b/src/test/java/LengthTest.java @@ -6,89 +6,89 @@ public class LengthTest { @Test public void should_1_inch_equals_1_inch() { - Length result = new Length(1, Length.INCH, Unit.INCH).as(Length.INCH, Unit.INCH); + Length result = new Length(1, Unit.INCH).as(Unit.INCH); assertThat(result.getVal(), is(1.0)); - assertThat(result.getTempUnit(), is(Unit.INCH)); + assertThat(result.getUnit(), is(Unit.INCH)); } @Test public void should_2_feet_equals_2_feet() { - Length result = new Length(2, Length.FOOT, Unit.FOOT).as(Length.FOOT, Unit.FOOT); + Length result = new Length(2, Unit.FOOT).as(Unit.FOOT); assertThat(result.getVal(), is(2.0)); - assertThat(result.getTempUnit(), is(Unit.FOOT)); + assertThat(result.getUnit(), is(Unit.FOOT)); } @Test public void should_1_yard_equals_1_yard() { - Length result = new Length(1, Length.YARD, Unit.YARD).as(Length.YARD, Unit.YARD); + Length result = new Length(1, Unit.YARD).as(Unit.YARD); assertThat(result.getVal(), is(1.0)); - assertThat(result.getTempUnit(), is(Unit.YARD)); + assertThat(result.getUnit(), is(Unit.YARD)); } @Test public void should_1_foot_equals_12_inches() { - Length result = new Length(1, Length.FOOT, Unit.FOOT).as(Length.INCH, Unit.INCH); + Length result = new Length(1, Unit.FOOT).as(Unit.INCH); assertThat(result.getVal(), is(12.0)); - assertThat(result.getTempUnit(), is(Unit.INCH)); + assertThat(result.getUnit(), is(Unit.INCH)); } @Test public void should_3_foot_equals_1_yard() { - Length result = new Length(3, Length.FOOT, Unit.FOOT).as(Length.YARD, Unit.YARD); + Length result = new Length(3, Unit.FOOT).as(Unit.YARD); assertThat(result.getVal(), is(1.0)); - assertThat(result.getTempUnit(), is(Unit.YARD)); + assertThat(result.getUnit(), is(Unit.YARD)); } @Test public void should_1_yard_equals_3_feet() { - Length result = new Length(1, Length.YARD, Unit.YARD).as(Length.FOOT, Unit.FOOT); + Length result = new Length(1, Unit.YARD).as(Unit.FOOT); assertThat(result.getVal(), is(3.0)); - assertThat(result.getTempUnit(), is(Unit.FOOT)); + assertThat(result.getUnit(), is(Unit.FOOT)); } @Test public void should_1_yard_equals_36_inches() { - Length result = new Length(1, Length.YARD, Unit.YARD).as(Length.INCH, Unit.INCH); + Length result = new Length(1, Unit.YARD).as(Unit.INCH); assertThat(result.getVal(), is(36.0)); - assertThat(result.getTempUnit(), is(Unit.INCH)); + assertThat(result.getUnit(), is(Unit.INCH)); } @Test public void should_2_yards_equals_72_inches() { - Length result = new Length(2, Length.YARD, Unit.YARD).as(Length.INCH, Unit.INCH); + Length result = new Length(2, Unit.YARD).as(Unit.INCH); assertThat(result.getVal(), is(72.0)); - assertThat(result.getTempUnit(), is(Unit.INCH)); + assertThat(result.getUnit(), is(Unit.INCH)); } @Test public void should_12_inches_equals_1_foot() { - Length result = new Length(12, Length.INCH, Unit.INCH).as(Length.FOOT, Unit.FOOT); + Length result = new Length(12, Unit.INCH).as(Unit.FOOT); assertThat(result.getVal(), is(1.0)); - assertThat(result.getTempUnit(), is(Unit.FOOT)); + assertThat(result.getUnit(), is(Unit.FOOT)); } @Test public void should_36_inches_equals_1_yard() { - Length result = new Length(36, Length.INCH, Unit.INCH).as(Length.YARD, Unit.YARD); + Length result = new Length(36, Unit.INCH).as(Unit.YARD); assertThat(result.getVal(), is(1.0)); - assertThat(result.getTempUnit(), is(Unit.YARD)); + assertThat(result.getUnit(), is(Unit.YARD)); } @Test public void should_18_inches_equals_half_yard() { - Length result = new Length(18, Length.INCH, Unit.INCH).as(Length.YARD, Unit.YARD); + Length result = new Length(18, Unit.INCH).as(Unit.YARD); assertThat(result.getVal(), is(0.5)); - assertThat(result.getTempUnit(), is(Unit.YARD)); + assertThat(result.getUnit(), is(Unit.YARD)); } } From bc8e04e0d5a967a42b1f772171e8b9b4f0079673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A5=E4=B8=80?= Date: Sat, 1 Feb 2020 13:01:08 +0800 Subject: [PATCH 18/18] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=8E=9F=E6=9C=89?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=B8=B8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Length.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/Length.java b/src/main/java/Length.java index 23e9d47..deed865 100644 --- a/src/main/java/Length.java +++ b/src/main/java/Length.java @@ -1,7 +1,4 @@ public class Length { - static final String YARD = "yard"; - static final String FOOT = "f"; - static final String INCH = "inch"; private final double value; private final Unit unit;