From e3ba90ea78ae8da2c321992ec3fcf17c5dc6f06c Mon Sep 17 00:00:00 2001 From: Gaetan Zoritchak Date: Fri, 2 Dec 2011 10:27:47 +0100 Subject: [PATCH 1/9] =?UTF-8?q?Premi=C3=A8re=20version.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/FooBarQix.java | 84 +++++++++++++++++++++++++++++++++++++++++ src/TestFooBarQuix.java | 33 ++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 src/FooBarQix.java create mode 100644 src/TestFooBarQuix.java diff --git a/src/FooBarQix.java b/src/FooBarQix.java new file mode 100644 index 0000000..5140bbd --- /dev/null +++ b/src/FooBarQix.java @@ -0,0 +1,84 @@ +/** + */ +public class FooBarQix { + + public static final int START = 1; + public static final int END = 100; + + public static final String FOO = "Foo"; + public static final String BAR = "Bar"; + public static final String QIX = "Qix"; + +// -------------------------- INSTANCE -------------------------- + + StringBuilder sb = new StringBuilder(); + + int intToProcess; + + private boolean noFooBarQix = true; + +// --------------------------- CONSTRUCTORS --------------------------- + + public FooBarQix(final int start, final int end) { + for (intToProcess = start; intToProcess < end + 1; intToProcess++) { + processLine(); + } + } + + private void processLine() { + appendDiviseurs(); + appendContenus(); + appendNumberIfNoFooBarQix(); + newLine(); + } + + private void newLine() { + sb.append('\n'); + noFooBarQix = true; + } + + private void appendDiviseurs() { + appendDiviseur(3, "Foo"); + appendDiviseur(5, "Bar"); + appendDiviseur(7, "Qix"); + } + + private void appendDiviseur(int i, String foo) { + if (intToProcess % i == 0) { + sb.append(foo); + noFooBarQix = false; + } + } + + private void appendContenus() { + String st = String.valueOf(intToProcess); + for (char c : st.toCharArray()) { + appendFooBarQuixIfEquals('3', c, FOO); + appendFooBarQuixIfEquals('5', c, BAR); + appendFooBarQuixIfEquals('7', c, QIX); + } + } + + private void appendFooBarQuixIfEquals(char c1, char c, String fooOrBarOrQix) { + if (c == c1){ + sb.append(fooOrBarOrQix); + noFooBarQix = false; + } + } + + private void appendNumberIfNoFooBarQix() { + if (noFooBarQix) + sb.append(intToProcess); + } + + @Override + public String toString() { + return sb.toString(); + } + + // --------------------------- main() method --------------------------- + + public static void main(String[] args) { + System.out.println(new FooBarQix(START, END)); + } +} diff --git a/src/TestFooBarQuix.java b/src/TestFooBarQuix.java new file mode 100644 index 0000000..c3cc1fe --- /dev/null +++ b/src/TestFooBarQuix.java @@ -0,0 +1,33 @@ +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class TestFooBarQuix { + + @Test + public void highLevelTests(){ + assertIntToFooBarQix(51 , "FooBar"); + assertIntToFooBarQix(53 , "BarFoo"); + assertIntToFooBarQix(21 , "FooQix"); + assertIntToFooBarQix(13 , "Foo"); + assertIntToFooBarQix(15 , "FooBarBar"); + assertIntToFooBarQix(33 , "FooFooFoo"); + + } + + private void assertIntToFooBarQix(int i, String fooBar) { + assertEquals(new FooBarQix(i,i).toString(), fooBar+'\n'); + } + + @Test + public void perf(){ + long startTime = System.currentTimeMillis(); + new FooBarQix(1, 1000000); + System.out.println("1 000 000 en " + (System.currentTimeMillis() - startTime) + " ms."); + } + + + +} From f841d8e4f0fb626aaefa5fca8ece1df487c6afba Mon Sep 17 00:00:00 2001 From: Gaetan Zoritchak Date: Fri, 2 Dec 2011 10:34:53 +0100 Subject: [PATCH 2/9] =?UTF-8?q?Pas=20besoin=20de=20constante=20=C3=A0=20ce?= =?UTF-8?q?t=20endroit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 ++++ src/FooBarQix.java | 11 ++++------- 2 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..101796c --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ + +*.iml +out/** +.idea/** \ No newline at end of file diff --git a/src/FooBarQix.java b/src/FooBarQix.java index 5140bbd..0335ecd 100644 --- a/src/FooBarQix.java +++ b/src/FooBarQix.java @@ -2,9 +2,6 @@ */ public class FooBarQix { - public static final int START = 1; - public static final int END = 100; - public static final String FOO = "Foo"; public static final String BAR = "Bar"; public static final String QIX = "Qix"; @@ -38,9 +35,9 @@ private void newLine() { } private void appendDiviseurs() { - appendDiviseur(3, "Foo"); - appendDiviseur(5, "Bar"); - appendDiviseur(7, "Qix"); + appendDiviseur(3, FOO); + appendDiviseur(5, BAR); + appendDiviseur(7, QIX); } private void appendDiviseur(int i, String foo) { @@ -79,6 +76,6 @@ public String toString() { // --------------------------- main() method --------------------------- public static void main(String[] args) { - System.out.println(new FooBarQix(START, END)); + System.out.println(new FooBarQix(1, 100)); } } From 17952efc1de12245b6dc55c1f9c067c1a8ecb448 Mon Sep 17 00:00:00 2001 From: Gaetan Zoritchak Date: Fri, 2 Dec 2011 10:50:16 +0100 Subject: [PATCH 3/9] Explications sur les choix. --- Choix-implem.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Choix-implem.md diff --git a/Choix-implem.md b/Choix-implem.md new file mode 100644 index 0000000..3195e3f --- /dev/null +++ b/Choix-implem.md @@ -0,0 +1,13 @@ + +Une version de plus en java. + +Choix d'implémentation +====================== + +Sont privilégés la concision, la lisibilité et la performance. Pas besoin de sortir toute l'artillerie lourde pour +le moment. + +Tant que le besoin fonctionnel n'évolue pas, les 2 champs StringBuilder et int me permettent de simplifier les +signatures de méthodes. La contrepartie est que je ne teste pas le code méthode par méthode. + + From 0122a482b7a932c15ddc3a1807d41ae06f006821 Mon Sep 17 00:00:00 2001 From: Gaetan Zoritchak Date: Fri, 2 Dec 2011 17:09:38 +0100 Subject: [PATCH 4/9] Verion avec enum. Plus extensible, moins lisible, 4 fois moins performante. --- src/FooBarQix.java | 49 ++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/src/FooBarQix.java b/src/FooBarQix.java index 0335ecd..d0c869c 100644 --- a/src/FooBarQix.java +++ b/src/FooBarQix.java @@ -2,9 +2,21 @@ */ public class FooBarQix { - public static final String FOO = "Foo"; - public static final String BAR = "Bar"; - public static final String QIX = "Qix"; + private static enum FBQEnum{ + FOO (3, "Foo"), BAR(5, "Bar"), QIX(7, "Qix"); + + private int value; + private String replacement; + private char chValue; + + FBQEnum(int value, String replacement) { + assert value < 10; + this.value = value; + this.replacement = replacement; + this.chValue = String.valueOf(value).charAt(0); + } + } + // -------------------------- INSTANCE -------------------------- @@ -35,34 +47,33 @@ private void newLine() { } private void appendDiviseurs() { - appendDiviseur(3, FOO); - appendDiviseur(5, BAR); - appendDiviseur(7, QIX); - } - - private void appendDiviseur(int i, String foo) { - if (intToProcess % i == 0) { - sb.append(foo); - noFooBarQix = false; + for (FBQEnum fbqEnum : FBQEnum.values()) { + if (intToProcess % fbqEnum.value == 0) { + appendFBQ(fbqEnum); + } } } private void appendContenus() { String st = String.valueOf(intToProcess); for (char c : st.toCharArray()) { - appendFooBarQuixIfEquals('3', c, FOO); - appendFooBarQuixIfEquals('5', c, BAR); - appendFooBarQuixIfEquals('7', c, QIX); + appendFooBarQuixIfEquals(c); } } - private void appendFooBarQuixIfEquals(char c1, char c, String fooOrBarOrQix) { - if (c == c1){ - sb.append(fooOrBarOrQix); - noFooBarQix = false; + private void appendFooBarQuixIfEquals(char c) { + for (FBQEnum fbqEnum : FBQEnum.values()) { + if (c == fbqEnum.chValue){ + appendFBQ(fbqEnum); + } } } + private void appendFBQ(FBQEnum fbqEnum) { + sb.append(fbqEnum.replacement); + noFooBarQix = false; + } + private void appendNumberIfNoFooBarQix() { if (noFooBarQix) sb.append(intToProcess); From 6d8efbff33633741b7779091f7f615ea0dca4e82 Mon Sep 17 00:00:00 2001 From: Gaetan Zoritchak Date: Mon, 5 Dec 2011 00:02:41 +0100 Subject: [PATCH 5/9] Utilisation de enum.name(). --- src/FooBarQix.java | 43 +++++++++++++++++++---------------------- src/TestFooBarQuix.java | 5 +---- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/FooBarQix.java b/src/FooBarQix.java index d0c869c..c15dc5b 100644 --- a/src/FooBarQix.java +++ b/src/FooBarQix.java @@ -2,29 +2,27 @@ */ public class FooBarQix { +// -------------------------- INNER CLASSES -------------------------- + private static enum FBQEnum{ - FOO (3, "Foo"), BAR(5, "Bar"), QIX(7, "Qix"); + Foo(3), Bar(5), Qix(7); private int value; - private String replacement; private char chValue; - FBQEnum(int value, String replacement) { + FBQEnum(int value) { assert value < 10; this.value = value; - this.replacement = replacement; this.chValue = String.valueOf(value).charAt(0); } } - // -------------------------- INSTANCE -------------------------- - StringBuilder sb = new StringBuilder(); - int intToProcess; + StringBuilder sb = new StringBuilder(); - private boolean noFooBarQix = true; + private boolean fooBarQixForLine = false; // --------------------------- CONSTRUCTORS --------------------------- @@ -41,11 +39,6 @@ private void processLine() { newLine(); } - private void newLine() { - sb.append('\n'); - noFooBarQix = true; - } - private void appendDiviseurs() { for (FBQEnum fbqEnum : FBQEnum.values()) { if (intToProcess % fbqEnum.value == 0) { @@ -54,6 +47,11 @@ private void appendDiviseurs() { } } + private void appendFBQ(FBQEnum fbqEnum) { + sb.append(fbqEnum.name()); + fooBarQixForLine = true; + } + private void appendContenus() { String st = String.valueOf(intToProcess); for (char c : st.toCharArray()) { @@ -69,24 +67,23 @@ private void appendFooBarQuixIfEquals(char c) { } } - private void appendFBQ(FBQEnum fbqEnum) { - sb.append(fbqEnum.replacement); - noFooBarQix = false; - } - private void appendNumberIfNoFooBarQix() { - if (noFooBarQix) + if (fooBarQixForLine == false) sb.append(intToProcess); } - @Override - public String toString() { + private void newLine() { + sb.append('\n'); + fooBarQixForLine = false; + } + + public String allLines() { return sb.toString(); } - // --------------------------- main() method --------------------------- +// --------------------------- main() method --------------------------- public static void main(String[] args) { - System.out.println(new FooBarQix(1, 100)); + System.out.println(new FooBarQix(1, 100).allLines()); } } diff --git a/src/TestFooBarQuix.java b/src/TestFooBarQuix.java index c3cc1fe..0858152 100644 --- a/src/TestFooBarQuix.java +++ b/src/TestFooBarQuix.java @@ -14,11 +14,10 @@ public void highLevelTests(){ assertIntToFooBarQix(13 , "Foo"); assertIntToFooBarQix(15 , "FooBarBar"); assertIntToFooBarQix(33 , "FooFooFoo"); - } private void assertIntToFooBarQix(int i, String fooBar) { - assertEquals(new FooBarQix(i,i).toString(), fooBar+'\n'); + assertEquals(new FooBarQix(i,i).allLines(), fooBar+'\n'); } @Test @@ -28,6 +27,4 @@ public void perf(){ System.out.println("1 000 000 en " + (System.currentTimeMillis() - startTime) + " ms."); } - - } From 8c066722f22856eac820ff1a273007d77f5e5b6b Mon Sep 17 00:00:00 2001 From: Gaetan Zoritchak Date: Sat, 10 Dec 2011 01:39:08 +0100 Subject: [PATCH 6/9] Rename et gestion par ligne. --- src/FooBarQix.java | 59 +++++++++++++++-------------------------- src/TestFooBarQuix.java | 6 +++-- 2 files changed, 26 insertions(+), 39 deletions(-) diff --git a/src/FooBarQix.java b/src/FooBarQix.java index c15dc5b..df32f18 100644 --- a/src/FooBarQix.java +++ b/src/FooBarQix.java @@ -1,7 +1,6 @@ /** */ public class FooBarQix { - // -------------------------- INNER CLASSES -------------------------- private static enum FBQEnum{ @@ -17,42 +16,31 @@ private static enum FBQEnum{ } } -// -------------------------- INSTANCE -------------------------- - - int intToProcess; - StringBuilder sb = new StringBuilder(); - - private boolean fooBarQixForLine = false; + private final int intToProcess; -// --------------------------- CONSTRUCTORS --------------------------- + private final StringBuilder line; - public FooBarQix(final int start, final int end) { - for (intToProcess = start; intToProcess < end + 1; intToProcess++) { - processLine(); - } + public FooBarQix(int i) { + intToProcess = i; + line = new StringBuilder(); } - private void processLine() { - appendDiviseurs(); - appendContenus(); - appendNumberIfNoFooBarQix(); - newLine(); + public String getFBQLine() { + appendFBQPourDiviseur(); + appendFBQPourChar(); + appendNumberIfNoFBQ(); + return line.toString(); } - private void appendDiviseurs() { + private void appendFBQPourDiviseur() { for (FBQEnum fbqEnum : FBQEnum.values()) { if (intToProcess % fbqEnum.value == 0) { - appendFBQ(fbqEnum); + appendFBQName(fbqEnum); } } } - private void appendFBQ(FBQEnum fbqEnum) { - sb.append(fbqEnum.name()); - fooBarQixForLine = true; - } - - private void appendContenus() { + private void appendFBQPourChar() { String st = String.valueOf(intToProcess); for (char c : st.toCharArray()) { appendFooBarQuixIfEquals(c); @@ -62,28 +50,25 @@ private void appendContenus() { private void appendFooBarQuixIfEquals(char c) { for (FBQEnum fbqEnum : FBQEnum.values()) { if (c == fbqEnum.chValue){ - appendFBQ(fbqEnum); + appendFBQName(fbqEnum); } } } - private void appendNumberIfNoFooBarQix() { - if (fooBarQixForLine == false) - sb.append(intToProcess); - } - - private void newLine() { - sb.append('\n'); - fooBarQixForLine = false; + private void appendFBQName(FBQEnum fbqEnum) { + line.append(fbqEnum.name()); } - public String allLines() { - return sb.toString(); + private void appendNumberIfNoFBQ() { + if(line.length() == 0) + line.append(intToProcess); } // --------------------------- main() method --------------------------- public static void main(String[] args) { - System.out.println(new FooBarQix(1, 100).allLines()); + for (int i = 1; i < 100; i++) { + System.out.println(new FooBarQix(i).getFBQLine()); + } } } diff --git a/src/TestFooBarQuix.java b/src/TestFooBarQuix.java index 0858152..5d798a8 100644 --- a/src/TestFooBarQuix.java +++ b/src/TestFooBarQuix.java @@ -17,13 +17,15 @@ public void highLevelTests(){ } private void assertIntToFooBarQix(int i, String fooBar) { - assertEquals(new FooBarQix(i,i).allLines(), fooBar+'\n'); + assertEquals(new FooBarQix(i).getFBQLine(), fooBar); } @Test public void perf(){ long startTime = System.currentTimeMillis(); - new FooBarQix(1, 1000000); + for (int i = 1; i < 1000000; i++) { + new FooBarQix(i).getFBQLine(); + } System.out.println("1 000 000 en " + (System.currentTimeMillis() - startTime) + " ms."); } From fd1ac116d4c5dd5a363bbbc5ccbbff632db1b96f Mon Sep 17 00:00:00 2001 From: Gaetan Zoritchak Date: Wed, 14 Dec 2011 01:48:05 +0100 Subject: [PATCH 7/9] Renommage. --- src/FooBarQix.java | 84 +++++++++++++++++++++-------------------- src/TestFooBarQuix.java | 9 +++-- 2 files changed, 50 insertions(+), 43 deletions(-) diff --git a/src/FooBarQix.java b/src/FooBarQix.java index df32f18..2c62a71 100644 --- a/src/FooBarQix.java +++ b/src/FooBarQix.java @@ -1,74 +1,78 @@ -/** - */ +import java.util.HashMap; +import java.util.Map; + public class FooBarQix { -// -------------------------- INNER CLASSES -------------------------- - private static enum FBQEnum{ + public static void main(String[] args) { + for (int i = 1; i < 100; i++) { + System.out.println(new FooBarQix(i).getReplacementLine()); + } + } + + private static enum FBQEnum { Foo(3), Bar(5), Qix(7); private int value; - private char chValue; FBQEnum(int value) { assert value < 10; this.value = value; - this.chValue = String.valueOf(value).charAt(0); } } - private final int intToProcess; + private static final Map ST_VALUE_TO_FBQ = new HashMap(); + static { + for (FBQEnum fbqEnum : FBQEnum.values()) { + ST_VALUE_TO_FBQ.put(String.valueOf(fbqEnum.value), fbqEnum); + } + } - private final StringBuilder line; + private final int input; + private final StringBuilder replacementLine; - public FooBarQix(int i) { - intToProcess = i; - line = new StringBuilder(); + public FooBarQix(int toAnalyse) { + input = toAnalyse; + replacementLine = new StringBuilder(); } - public String getFBQLine() { - appendFBQPourDiviseur(); - appendFBQPourChar(); - appendNumberIfNoFBQ(); - return line.toString(); + public String getReplacementLine() { + appendNamesByDivisibles(); + appendNamesByContent(); + appendNumberIfNoName(); + return replacementLine.toString(); } - private void appendFBQPourDiviseur() { + private void appendNamesByDivisibles() { for (FBQEnum fbqEnum : FBQEnum.values()) { - if (intToProcess % fbqEnum.value == 0) { - appendFBQName(fbqEnum); + if (isDivisibleBy(fbqEnum)) { + appendName(fbqEnum); } } } - private void appendFBQPourChar() { - String st = String.valueOf(intToProcess); - for (char c : st.toCharArray()) { - appendFooBarQuixIfEquals(c); - } + private boolean isDivisibleBy(FBQEnum fbqEnum) { + return input % fbqEnum.value == 0; } - private void appendFooBarQuixIfEquals(char c) { - for (FBQEnum fbqEnum : FBQEnum.values()) { - if (c == fbqEnum.chValue){ - appendFBQName(fbqEnum); - } + private void appendNamesByContent() { + String st = String.valueOf(input); + for (char c : st.toCharArray()) { + appendNameIfExistsReplacementFor(c); } } - private void appendFBQName(FBQEnum fbqEnum) { - line.append(fbqEnum.name()); + private void appendNameIfExistsReplacementFor(char c) { + FBQEnum fbqEnum = ST_VALUE_TO_FBQ.get(String.valueOf(c)); + if (fbqEnum != null) + appendName(fbqEnum); } - private void appendNumberIfNoFBQ() { - if(line.length() == 0) - line.append(intToProcess); + private void appendName(FBQEnum fbqEnum) { + replacementLine.append(fbqEnum.name()); } -// --------------------------- main() method --------------------------- - - public static void main(String[] args) { - for (int i = 1; i < 100; i++) { - System.out.println(new FooBarQix(i).getFBQLine()); - } + private void appendNumberIfNoName() { + if (replacementLine.length() == 0) + replacementLine.append(input); } } diff --git a/src/TestFooBarQuix.java b/src/TestFooBarQuix.java index 5d798a8..da5edfa 100644 --- a/src/TestFooBarQuix.java +++ b/src/TestFooBarQuix.java @@ -8,6 +8,9 @@ public class TestFooBarQuix { @Test public void highLevelTests(){ + assertIntToFooBarQix(1 , "1"); + assertIntToFooBarQix(3 , "FooFoo"); + assertIntToFooBarQix(6 , "Foo"); assertIntToFooBarQix(51 , "FooBar"); assertIntToFooBarQix(53 , "BarFoo"); assertIntToFooBarQix(21 , "FooQix"); @@ -17,14 +20,14 @@ public void highLevelTests(){ } private void assertIntToFooBarQix(int i, String fooBar) { - assertEquals(new FooBarQix(i).getFBQLine(), fooBar); + assertEquals(new FooBarQix(i).getReplacementLine(), fooBar); } @Test public void perf(){ long startTime = System.currentTimeMillis(); - for (int i = 1; i < 1000000; i++) { - new FooBarQix(i).getFBQLine(); + for (int i = 1; i < 1000001; i++) { + new FooBarQix(i).getReplacementLine(); } System.out.println("1 000 000 en " + (System.currentTimeMillis() - startTime) + " ms."); } From 49eb5f703fb6c877ca9335ecfe965ca26b37237e Mon Sep 17 00:00:00 2001 From: Gaetan Zoritchak Date: Wed, 14 Dec 2011 01:54:20 +0100 Subject: [PATCH 8/9] Renommage. --- src/FooBarQix.java | 3 +-- src/TestFooBarQuix.java | 13 +++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/FooBarQix.java b/src/FooBarQix.java index 2c62a71..7eab849 100644 --- a/src/FooBarQix.java +++ b/src/FooBarQix.java @@ -55,8 +55,7 @@ private boolean isDivisibleBy(FBQEnum fbqEnum) { } private void appendNamesByContent() { - String st = String.valueOf(input); - for (char c : st.toCharArray()) { + for (char c : String.valueOf(input).toCharArray()) { appendNameIfExistsReplacementFor(c); } } diff --git a/src/TestFooBarQuix.java b/src/TestFooBarQuix.java index da5edfa..fad24f9 100644 --- a/src/TestFooBarQuix.java +++ b/src/TestFooBarQuix.java @@ -8,15 +8,16 @@ public class TestFooBarQuix { @Test public void highLevelTests(){ - assertIntToFooBarQix(1 , "1"); - assertIntToFooBarQix(3 , "FooFoo"); - assertIntToFooBarQix(6 , "Foo"); - assertIntToFooBarQix(51 , "FooBar"); - assertIntToFooBarQix(53 , "BarFoo"); - assertIntToFooBarQix(21 , "FooQix"); + assertIntToFooBarQix(1 , "1"); + assertIntToFooBarQix(2 , "2"); + assertIntToFooBarQix(3 , "FooFoo"); + assertIntToFooBarQix(6 , "Foo"); assertIntToFooBarQix(13 , "Foo"); assertIntToFooBarQix(15 , "FooBarBar"); assertIntToFooBarQix(33 , "FooFooFoo"); + assertIntToFooBarQix(21 , "FooQix"); + assertIntToFooBarQix(51 , "FooBar"); + assertIntToFooBarQix(53 , "BarFoo"); } private void assertIntToFooBarQix(int i, String fooBar) { From 508f51b7306869545d762c0dad7f35a33847a553 Mon Sep 17 00:00:00 2001 From: Gaetan Zoritchak Date: Fri, 16 Dec 2011 09:07:42 +0100 Subject: [PATCH 9/9] Renommage. --- src/FooBarQix.java | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/FooBarQix.java b/src/FooBarQix.java index 7eab849..079761d 100644 --- a/src/FooBarQix.java +++ b/src/FooBarQix.java @@ -3,39 +3,22 @@ public class FooBarQix { + public static void main(String[] args) { for (int i = 1; i < 100; i++) { System.out.println(new FooBarQix(i).getReplacementLine()); } } - private static enum FBQEnum { - Foo(3), Bar(5), Qix(7); - - private int value; - - FBQEnum(int value) { - assert value < 10; - this.value = value; - } - } - - private static final Map ST_VALUE_TO_FBQ = new HashMap(); - static { - for (FBQEnum fbqEnum : FBQEnum.values()) { - ST_VALUE_TO_FBQ.put(String.valueOf(fbqEnum.value), fbqEnum); - } - } - private final int input; - private final StringBuilder replacementLine; + private StringBuilder replacementLine; public FooBarQix(int toAnalyse) { input = toAnalyse; - replacementLine = new StringBuilder(); } public String getReplacementLine() { + replacementLine = new StringBuilder(); appendNamesByDivisibles(); appendNamesByContent(); appendNumberIfNoName(); @@ -74,4 +57,23 @@ private void appendNumberIfNoName() { if (replacementLine.length() == 0) replacementLine.append(input); } + + private static enum FBQEnum { + Foo(3), Bar(5), Qix(7); + + private int value; + + FBQEnum(int value) { + assert value < 10; + this.value = value; + } + } + + private static final Map ST_VALUE_TO_FBQ = new HashMap(); + static { + for (FBQEnum fbqEnum : FBQEnum.values()) { + ST_VALUE_TO_FBQ.put(String.valueOf(fbqEnum.value), fbqEnum); + } + } + }