From f4e383a7085748c9c402e8d968c7f9be94bf8376 Mon Sep 17 00:00:00 2001 From: SuperYoshi10000 <148275327+SuperYoshi10000@users.noreply.github.com> Date: Mon, 29 Apr 2024 10:22:13 -0400 Subject: [PATCH 1/5] Simple changes --- build.gradle | 2 + .../packagenamingpackage/impl/Constants.java | 7 +- .../impl/data/ActionResult.java | 14 ++++ .../impl/data/ActionResultCollection.java | 22 ++++++ .../ActionResultCollectionFactory.java | 23 +++++++ .../impl/factories/CharacterArrayFactory.java | 19 ++++++ .../ConditionalLoopComponentFactory.java | 67 +++++++++++++++++++ .../CountBasedLoopComponentFactory.java | 67 +++++++++++++++++++ .../{loop => loop copy}/LoopCondition.java | 0 .../impl/{loop => loop copy}/LoopContext.java | 16 +---- .../{loop => loop copy}/LoopFinalizer.java | 0 .../{loop => loop copy}/LoopInitializer.java | 0 .../impl/{loop => loop copy}/LoopRunner.java | 0 .../impl/loop copy/LoopState.java | 32 +++++++++ .../impl/{loop => loop copy}/LoopStep.java | 0 .../impl/loop copy/count/LoopCondition.java | 31 +++++++++ .../impl/loop copy/count/LoopContext.java | 61 +++++++++++++++++ .../impl/loop copy/count/LoopFinalizer.java | 25 +++++++ .../impl/loop copy/count/LoopInitializer.java | 20 ++++++ .../impl/loop copy/count/LoopRunner.java | 38 +++++++++++ .../impl/loop copy/count/LoopState.java | 32 +++++++++ .../impl/loop copy/count/LoopStep.java | 21 ++++++ .../conditional/ConditionalLoopCondition.java | 37 ++++++++++ .../conditional/ConditionalLoopContext.java | 61 +++++++++++++++++ .../conditional/ConditionalLoopFinalizer.java | 14 ++++ .../ConditionalLoopInitializer.java | 19 ++++++ .../ConditionalLoopIsFinishedChecker.java | 26 +++++++ .../conditional/ConditionalLoopRunner.java | 39 +++++++++++ .../conditional/ConditionalLoopState.java | 51 ++++++++++++++ .../loop/count/CountBasedLoopCondition.java | 33 +++++++++ .../loop/count/CountBasedLoopContext.java | 66 ++++++++++++++++++ .../loop/count/CountBasedLoopFinalizer.java | 26 +++++++ .../loop/count/CountBasedLoopInitializer.java | 20 ++++++ .../impl/loop/count/CountBasedLoopRunner.java | 39 +++++++++++ .../impl/loop/count/CountBasedLoopState.java | 52 ++++++++++++++ .../impl/loop/count/CountBasedLoopStep.java | 22 ++++++ ...terpriseGradeFizzBuzzSolutionStrategy.java | 4 +- .../impl/strategies/IteratorPayload.java | 42 ++++++++++++ ...OutputGenerationContextVisitorPayload.java | 42 ++++++++++++ .../SingleStepOutputGenerationStrategy.java | 22 +++++- ...haracterListToCharacterArrayConverter.java | 18 +++++ .../interfaces/data/Result.java | 9 +++ .../interfaces/data/ResultCollection.java | 11 +++ .../AbstractCharacterArrayFactory.java | 11 +++ .../factories/GeneratorFactory.java | 15 +++++ .../factories/GeneratorListFactory.java | 15 +++++ .../GeneratorListGeneratorFactory.java | 15 +++++ .../factories/IntegerGeneratorFactory.java | 15 +++++ .../factories/JsonObjectHolderFactory.java | 8 +++ .../factories/JsonReaderFactory.java | 5 ++ .../factories/ListGeneratorFactory.java | 15 +++++ .../factories/LoopComponentFactory.java | 37 ++-------- .../factories/ResultCollectionFactory.java | 10 +++ .../factories/StringGeneratorFactory.java | 15 +++++ .../interfaces/generators/Generator.java | 5 ++ .../interfaces/generators/GeneratorList.java | 6 ++ .../generators/GeneratorListGenerator.java | 5 ++ .../generators/IntegerGenerator.java | 6 ++ .../interfaces/generators/ListGenerator,java | 5 ++ .../generators/StringGenerator.java | 5 ++ .../interfaces/json/JsonElementHolder.java | 6 ++ .../interfaces/json/JsonElementType.java | 5 ++ .../interfaces/json/JsonLoader.java | 8 +++ .../interfaces/json/JsonObjectAccessor.java | 8 +++ .../json/JsonObjectHasKeyVerifier.java | 5 ++ .../interfaces/json/JsonObjectHolder.java | 7 ++ .../interfaces/json/JsonObjectKey.java | 0 .../interfaces/json/JsonObjectKeyReader.java | 5 ++ .../interfaces/json/JsonReader.java | 8 +++ .../interfaces/lang/Language.java | 6 ++ .../lang/translation/TranslationKey.java | 5 ++ .../interfaces/loop/LoopContext.java | 37 ++++++++++ .../loop/LoopContextStateRetrieval.java | 7 +- .../interfaces/loop/LoopFinalizer.java | 12 ++++ .../interfaces/loop/LoopInitializer.java | 18 +++++ .../interfaces/loop/LoopRunner.java | 16 +++++ .../interfaces/loop/LoopState.java | 21 ++++++ .../interfaces/loop/LoopStep.java | 19 ++++++ .../loop/count/CountBasedLoopCondition.java | 31 +++++++++ .../loop/count/CountBasedLoopContext.java | 61 +++++++++++++++++ .../loop/count/CountBasedLoopFinalizer.java | 25 +++++++ .../loop/count/CountBasedLoopInitializer.java | 20 ++++++ .../loop/count/CountBasedLoopRunner.java | 38 +++++++++++ .../loop/count/CountBasedLoopState.java | 32 +++++++++ .../loop/count/CountBasedLoopStep.java | 21 ++++++ .../CharacterArrayStringReturner.java | 8 +++ .../visitors/JsonObjectVisitor.java | 8 +++ .../visitors/JsonVisitorResult.java | 8 +++ 88 files changed, 1735 insertions(+), 53 deletions(-) create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/data/ActionResult.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/data/ActionResultCollection.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/ActionResultCollectionFactory.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/CharacterArrayFactory.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/ConditionalLoopComponentFactory.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/CountBasedLoopComponentFactory.java rename src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/{loop => loop copy}/LoopCondition.java (100%) rename src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/{loop => loop copy}/LoopContext.java (66%) rename src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/{loop => loop copy}/LoopFinalizer.java (100%) rename src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/{loop => loop copy}/LoopInitializer.java (100%) rename src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/{loop => loop copy}/LoopRunner.java (100%) create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopState.java rename src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/{loop => loop copy}/LoopStep.java (100%) create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopCondition.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopContext.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopFinalizer.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopInitializer.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopRunner.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopState.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopStep.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopCondition.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopContext.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopFinalizer.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopInitializer.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopIsFinishedChecker.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopRunner.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopState.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopCondition.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopContext.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopFinalizer.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopInitializer.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopRunner.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopState.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopStep.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/IteratorPayload.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/OutputGenerationContextVisitorPayload.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/converters/CharacterListToCharacterArrayConverter.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/data/Result.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/data/ResultCollection.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/AbstractCharacterArrayFactory.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/GeneratorFactory.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/GeneratorListFactory.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/GeneratorListGeneratorFactory.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/IntegerGeneratorFactory.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/JsonObjectHolderFactory.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/JsonReaderFactory.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/ListGeneratorFactory.java rename src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/{impl => interfaces}/factories/LoopComponentFactory.java (50%) create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/ResultCollectionFactory.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/StringGeneratorFactory.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/Generator.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/GeneratorList.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/GeneratorListGenerator.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/IntegerGenerator.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/ListGenerator,java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/StringGenerator.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonElementHolder.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonElementType.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonLoader.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectAccessor.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectHasKeyVerifier.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectHolder.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectKey.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectKeyReader.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonReader.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/Language.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/translation/TranslationKey.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopContext.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopFinalizer.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopInitializer.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopRunner.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopState.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopStep.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopCondition.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopContext.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopFinalizer.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopInitializer.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopRunner.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopState.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopStep.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/stringreturners/CharacterArrayStringReturner.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/visitors/JsonObjectVisitor.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/visitors/JsonVisitorResult.java diff --git a/build.gradle b/build.gradle index 39deaf16..fb3357b7 100644 --- a/build.gradle +++ b/build.gradle @@ -23,6 +23,8 @@ dependencies { 'org.springframework:spring-core:3.2.13.RELEASE', 'org.springframework:spring-expression:3.2.13.RELEASE' + compile 'org.json' + testCompile 'junit:junit:4.8.2' } diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Constants.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Constants.java index f351e327..ba875069 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Constants.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Constants.java @@ -4,16 +4,21 @@ * Constants */ public class Constants { - + public static final Object NULL_VALUE = null; + public static final String A_CONDITIONAL_LOOP_HAS_NO_CONTROL_PARAMETER = "A conditional loop has no control parameter."; + public static final String A_CONDITIONAL_LOOP_HAS_NO_FINALIZATION_POINT = "A conditional loop has no finalization point."; + public static final String A_CONDITIONAL_LOOP_HAS_NO_INITIALIZATION_POINT = "A conditional loop has no initialization point."; public static final String AN_ATTEMPT_WAS_MADE_TO_DIVIDE_BY_ZERO = "An attempt was made to divide by zero."; public static final String BUZZ = "Buzz"; public static final String COM_SERIOUSCOMPANY_BUSINESS_JAVA_FIZZBUZZ_PACKAGENAMINGPACKAGE_IMPL_PRINTERS_INTEGER_INTEGER_PRINTER_PRINT = "com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.printers.IntegerIntegerPrinter.print()"; + public static final String COULD_NOT_DETERMINE_IF_THE_LOOP_WAS_FINISHED = "Could not determine if the loop was finished."; public static final String FIZZ = "Fizz"; public static final String LINE_SEPARATOR = "line.separator"; public static final String LOOP_COMPONENT_FACTORY = "loopComponentFactory"; public static final String SPRING_XML = "spring.xml"; public static final String STANDARD_FIZZ_BUZZ = "standardFizzBuzz"; public static final String THE_INTEGERS_COULD_NOT_BE_COMPARED = "The integers could not be compared."; + public static final String THE_WRONG_TYPE_OF_LOOP_STATE_WAS_PROVIDED = "The wrong type of loop state was provided."; public static final int DEFAULT_FIZZ_BUZZ_UPPER_LIMIT_PARAMETER_VALUE = 100; public static final int INTEGER_DIVIDE_ZERO_VALUE = 0; public static final int INTEGER_ORIGIN_ZERO_VALUE = 0; diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/data/ActionResult.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/data/ActionResult.java new file mode 100644 index 00000000..e7383316 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/data/ActionResult.java @@ -0,0 +1,14 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies; + +/** + * Result for Action + */ +public class ActionResult implements Reslut { + private T result; + public T getResult() { + return this.result; + } + public void setResult(T result) { + this.result = result; + } +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/data/ActionResultCollection.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/data/ActionResultCollection.java new file mode 100644 index 00000000..d63759f1 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/data/ActionResultCollection.java @@ -0,0 +1,22 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.data; + +import java.util.List; +import java.util.ArrayList; + +/** + * ResultCollection for Action + */ +public class ActionResultCollection implements ResultCollection { + private final List _results; + + public ActionResultCollection() { + this._results = new ArrayList<>(); + } + + public List getResults() { + return this._results; + } + public void addResult(T result) { + this._results.add(result); + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/ActionResultCollectionFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/ActionResultCollectionFactory.java new file mode 100644 index 00000000..88a49d2b --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/ActionResultCollectionFactory.java @@ -0,0 +1,23 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories; + +import org.springframework.stereotype.Service; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.data.ActionResultCollection; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.data.ResultCollection; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories.ResultCollectionFactory; + +/** + * Factory for ActionResultCollection + */ +@Service +public class ActionResultCollectionFactory implements ResultCollectionFactory { + public BuzzStrategyFactory(final Class resultCollectionType) { + super(); + } + + @Override + public ResultCollection createResultCollection() { + return new ActionResultCollection<>(); + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/CharacterArrayFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/CharacterArrayFactory.java new file mode 100644 index 00000000..167c9501 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/CharacterArrayFactory.java @@ -0,0 +1,19 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories; + +import it.unimi.dsi.fastutils.chars.CharacterList; + +/** + * Factory for CharacterArray + */ +public class CharacterArrayFactory { + private final IntFunction myCharacterArrayMakerFunction; + + public CharacterArrayFactory(IntFunction characterArrayMakerFunction) { + this.myCharacterArrayMakerFunction = characterArrayMakerFunction; + } + + public char[] createCharacterArray(CharacterList characterList, final int characterArrayLength) { + char[] myCharacterArray = this.myCharacterArraySupplier.apply(characterArrayLength); + return myCharacterArray; + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/ConditionalLoopComponentFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/ConditionalLoopComponentFactory.java new file mode 100644 index 00000000..0954fa32 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/ConditionalLoopComponentFactory.java @@ -0,0 +1,67 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop.ConditionalLoopCondition; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop.ConditionalLoopFinalizer; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop.ConditionalLoopInitializer; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop.ConditionalLoopStep; + +/** + * Factory for ConditionalLoopComponent + */ +@Service +public class ConditionalLoopComponentFactory implements LoopComponentFactory { + + private final ConditionalLoopCondition _loopCondition; + + private final ConditionalLoopInitializer _loopInitializer; + + private final ConditionalLoopStep _loopStep; + + /** + * @param _loopCondition ConditionalLoopCondition + * @param _loopInitializer ConditionalLoopInitializer + * @param _loopStep ConditionalLoopStep + */ + @Autowired + public ConditionalLoopComponentFactory(final ConditionalLoopCondition _loopCondition, final ConditionalLoopInitializer _loopInitializer, + final ConditionalLoopStep _loopStep) { + super(); + this._loopCondition = _loopCondition; + this._loopInitializer = _loopInitializer; + this._loopStep = _loopStep; + } + + /** + * @return ConditionalLoopCondition + */ + public ConditionalLoopCondition createLoopCondition() { + return this._loopCondition; + } + + /** + * @return ConditionalLoopInitializer + */ + public ConditionalLoopInitializer createLoopInitializer() { + return this._loopInitializer; + } + + /** + * @param nConditionalLoopFinalValue int + * @return ConditionalLoopFinalizer + */ + public ConditionalLoopFinalizer createLoopFinalizer(final int nLoopFinalValue) { + final ConditionalLoopFinalizer myConditionalLoopFinalizer = new ConditionalLoopFinalizer(); + return myConditionalLoopFinalizer; + } + + /** + * @return ConditionalLoopStep + */ + public ConditionalLoopStep createLoopStep() { + return this._loopStep; + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/CountBasedLoopComponentFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/CountBasedLoopComponentFactory.java new file mode 100644 index 00000000..05303e84 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/CountBasedLoopComponentFactory.java @@ -0,0 +1,67 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop.CountBasedLoopCondition; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop.CountBasedLoopFinalizer; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop.CountBasedLoopInitializer; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop.CountBasedLoopStep; + +/** + * Factory for CountBasedLoopComponent + */ +@Service +public class CountBasedLoopComponentFactory implements LoopComponentFactory { + + private final CountBasedLoopCondition _loopCondition; + + private final CountBasedLoopInitializer _loopInitializer; + + private final CountBasedLoopStep _loopStep; + + /** + * @param _loopCondition CountBasedLoopCondition + * @param _loopInitializer CountBasedLoopInitializer + * @param _loopStep CountBasedLoopStep + */ + @Autowired + public CountBasedLoopComponentFactory(final CountBasedLoopCondition _loopCondition, final CountBasedLoopInitializer _loopInitializer, + final CountBasedLoopStep _loopStep) { + super(); + this._loopCondition = _loopCondition; + this._loopInitializer = _loopInitializer; + this._loopStep = _loopStep; + } + + /** + * @return CountBasedLoopCondition + */ + public CountBasedLoopCondition createLoopCondition() { + return this._loopCondition; + } + + /** + * @return CountBasedLoopInitializer + */ + public CountBasedLoopInitializer createLoopInitializer() { + return this._loopInitializer; + } + + /** + * @param nCountBasedLoopFinalValue int + * @return CountBasedLoopFinalizer + */ + public CountBasedLoopFinalizer createLoopFinalizer(final int nLoopFinalValue) { + final CountBasedLoopFinalizer myCountBasedLoopFinalizer = new CountBasedLoopFinalizer(nLoopFinalValue); + return myCountBasedLoopFinalizer; + } + + /** + * @return CountBasedLoopStep + */ + public CountBasedLoopStep createLoopStep() { + return this._loopStep; + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/LoopCondition.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopCondition.java similarity index 100% rename from src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/LoopCondition.java rename to src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopCondition.java diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/LoopContext.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopContext.java similarity index 66% rename from src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/LoopContext.java rename to src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopContext.java index 0a78d7f9..1dff6ba4 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/LoopContext.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopContext.java @@ -13,26 +13,14 @@ * LoopContext */ public final class LoopContext implements LoopContextStateManipulation, LoopContextStateRetrieval { - - private final LoopInitializer myLoopInitializer; - private final LoopFinalizer myLoopFinalizer; - private final LoopCondition myLoopCondition; - private final LoopStep myLoopStep; - private int myCurrentControlParameterValue; + private final LoopState myLoopState; /** * @param nLoopControlParameterFinalValue int */ public LoopContext(final int nLoopControlParameterFinalValue) { super(); - final ApplicationContext context = new ClassPathXmlApplicationContext(Constants.SPRING_XML); - final LoopComponentFactory myLoopComponentFactory = context.getBean(Constants.LOOP_COMPONENT_FACTORY, - LoopComponentFactory.class); - this.myLoopInitializer = myLoopComponentFactory.createLoopInitializer(); - this.myLoopFinalizer = myLoopComponentFactory.createLoopFinalizer(nLoopControlParameterFinalValue); - this.myLoopCondition = myLoopComponentFactory.createLoopCondition(); - this.myLoopStep = myLoopComponentFactory.createLoopStep(); - ((ConfigurableApplicationContext) context).close(); + this.myLoopState = new LoopState(); } /** diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/LoopFinalizer.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopFinalizer.java similarity index 100% rename from src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/LoopFinalizer.java rename to src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopFinalizer.java diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/LoopInitializer.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopInitializer.java similarity index 100% rename from src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/LoopInitializer.java rename to src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopInitializer.java diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/LoopRunner.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopRunner.java similarity index 100% rename from src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/LoopRunner.java rename to src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopRunner.java diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopState.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopState.java new file mode 100644 index 00000000..6ad7bde2 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopState.java @@ -0,0 +1,32 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories.LoopComponentFactory; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateManipulation; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; + +/** + * LoopState + */ +public class LoopState { + private final LoopInitializer myLoopInitializer; + private final LoopFinalizer myLoopFinalizer; + private final LoopCondition myLoopCondition; + private final LoopStep myLoopStep; + private int myCurrentControlParameterValue; + + public LoopState(final int nLoopControlParameterFinalValue) { + final ApplicationContext context = new ClassPathXmlApplicationContext(Constants.SPRING_XML); + final LoopComponentFactory myLoopComponentFactory = context.getBean(Constants.LOOP_COMPONENT_FACTORY, + LoopComponentFactory.class); + this.myLoopInitializer = myLoopComponentFactory.createLoopInitializer(); + this.myLoopFinalizer = myLoopComponentFactory.createLoopFinalizer(nLoopControlParameterFinalValue); + this.myLoopCondition = myLoopComponentFactory.createLoopCondition(); + this.myLoopStep = myLoopComponentFactory.createLoopStep(); + ((ConfigurableApplicationContext) context).close(); + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/LoopStep.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopStep.java similarity index 100% rename from src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/LoopStep.java rename to src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopStep.java diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopCondition.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopCondition.java new file mode 100644 index 00000000..0cdadafb --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopCondition.java @@ -0,0 +1,31 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.stereotype.Service; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.integercomparator.ThreeWayIntegerComparator; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.integercomparator.ThreeWayIntegerComparisonResult; + +/** + * LoopCondition + */ +@Service +public class LoopCondition { + + /** + * @param nCurrentNumber int + * @param nTotalCount int + * @return boolean + */ + public boolean evaluateLoop(final int nCurrentNumber, final int nTotalCount) { + final ThreeWayIntegerComparisonResult comparisonResult = ThreeWayIntegerComparator.Compare(nCurrentNumber, + nTotalCount); + if (ThreeWayIntegerComparisonResult.FirstIsLessThanSecond == comparisonResult) { + return true; + } else if (ThreeWayIntegerComparisonResult.FirstEqualsSecond == comparisonResult) { + return true; + } else { + return false; + } + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopContext.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopContext.java new file mode 100644 index 00000000..1dff6ba4 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopContext.java @@ -0,0 +1,61 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories.LoopComponentFactory; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateManipulation; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; + +/** + * LoopContext + */ +public final class LoopContext implements LoopContextStateManipulation, LoopContextStateRetrieval { + private final LoopState myLoopState; + + /** + * @param nLoopControlParameterFinalValue int + */ + public LoopContext(final int nLoopControlParameterFinalValue) { + super(); + this.myLoopState = new LoopState(); + } + + /** + * @return void + */ + @Override + public void start() { + this.myCurrentControlParameterValue = + this.myLoopInitializer.getLoopInitializationPoint(); + } + + /** + * @return boolean + */ + @Override + public boolean shouldProceed() { + return this.myLoopCondition.evaluateLoop(this.myCurrentControlParameterValue, + this.myLoopFinalizer.getLoopFinalizationPoint()); + } + + /** + * @return void + */ + @Override + public void proceed() { + this.myCurrentControlParameterValue = + this.myLoopStep.stepLoop(this.myCurrentControlParameterValue); + } + + /** + * @return int + */ + @Override + public int getControlParameter() { + return this.myCurrentControlParameterValue; + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopFinalizer.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopFinalizer.java new file mode 100644 index 00000000..2f104333 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopFinalizer.java @@ -0,0 +1,25 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +/** + * LoopFinalizer + */ +public final class LoopFinalizer { + + private final int nStoredLoopFinalValue; + + /** + * @param nLoopFinalValue int + */ + public LoopFinalizer(final int nLoopFinalValue) { + super(); + this.nStoredLoopFinalValue = nLoopFinalValue; + } + + /** + * @return int + */ + public int getLoopFinalizationPoint() { + return this.nStoredLoopFinalValue; + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopInitializer.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopInitializer.java new file mode 100644 index 00000000..2304800e --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopInitializer.java @@ -0,0 +1,20 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.stereotype.Service; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; + +/** + * LoopInitializer + */ +@Service +public class LoopInitializer { + + /** + * @return int + */ + public int getLoopInitializationPoint() { + return Constants.LOOP_INIT_VALUE; + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopRunner.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopRunner.java new file mode 100644 index 00000000..da29e3dc --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopRunner.java @@ -0,0 +1,38 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateManipulation; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopPayloadExecution; + +/** + * LoopRunner + */ +public final class LoopRunner { + + private final LoopContextStateManipulation myStateManipulation; + private final LoopContextStateRetrieval myStateRetrieval; + private final LoopPayloadExecution myPayload; + + /** + * @param stateManipulation LoopContextStateManipulation + * @param stateRetrieval LoopContextStateRetrieval + * @param payload LoopPayloadExecution + */ + public LoopRunner(final LoopContextStateManipulation stateManipulation, + final LoopContextStateRetrieval stateRetrieval, final LoopPayloadExecution payload) { + super(); + this.myStateManipulation = stateManipulation; + this.myStateRetrieval = stateRetrieval; + this.myPayload = payload; + } + + /** + * @return + */ + public void runLoop() { + for (this.myStateManipulation.start(); this.myStateManipulation.shouldProceed(); this.myStateManipulation.proceed()) { + this.myPayload.runLoopPayload(this.myStateRetrieval); + } + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopState.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopState.java new file mode 100644 index 00000000..6ad7bde2 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopState.java @@ -0,0 +1,32 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories.LoopComponentFactory; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateManipulation; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; + +/** + * LoopState + */ +public class LoopState { + private final LoopInitializer myLoopInitializer; + private final LoopFinalizer myLoopFinalizer; + private final LoopCondition myLoopCondition; + private final LoopStep myLoopStep; + private int myCurrentControlParameterValue; + + public LoopState(final int nLoopControlParameterFinalValue) { + final ApplicationContext context = new ClassPathXmlApplicationContext(Constants.SPRING_XML); + final LoopComponentFactory myLoopComponentFactory = context.getBean(Constants.LOOP_COMPONENT_FACTORY, + LoopComponentFactory.class); + this.myLoopInitializer = myLoopComponentFactory.createLoopInitializer(); + this.myLoopFinalizer = myLoopComponentFactory.createLoopFinalizer(nLoopControlParameterFinalValue); + this.myLoopCondition = myLoopComponentFactory.createLoopCondition(); + this.myLoopStep = myLoopComponentFactory.createLoopStep(); + ((ConfigurableApplicationContext) context).close(); + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopStep.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopStep.java new file mode 100644 index 00000000..ee3962cf --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopStep.java @@ -0,0 +1,21 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.stereotype.Service; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; + +/** + * LoopStep + */ +@Service +public class LoopStep { + + /** + * @param nCurrentNumber int + * @return int + */ + public int stepLoop(final int nCurrentNumber) { + return nCurrentNumber + Constants.LOOP_INC_VALUE; + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopCondition.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopCondition.java new file mode 100644 index 00000000..f51e68ff --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopCondition.java @@ -0,0 +1,37 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.stereotype.Service; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.integercomparator.ThreeWayIntegerComparator; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.integercomparator.ThreeWayIntegerComparisonResult; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopCondition; + +/** + * Conditional LoopCondition + */ +@Service +public class ConditionalLoopCondition implements LoopCondition { + + /** + * @param loopState LoopState + * @param conditionalLoopIsFinishedChecker ConditionalLoopIsFinishedChecker + * @return boolean + */ + public boolean evaluateLoop(final LoopState loopState, final ConditionalLoopIsFinishedChecker conditionalLoopIsFinishedChecker) { + ConditionalLoopState myConditionalLoopState; + if (loopState instanceof ConditionalLoopState) { + myConditionalLoopState = (ConditionalLoopState) loopState; + } else { + throw new IllegalArgumentException(Constants.THE_WRONG_TYPE_OF_LOOP_STATE_WAS_PROVIDED); + } + boolean conditionalLoopIsFinished = conditionalLoopIsFinishedChecker.checkIfConditionalLoopIsFinished(loopState); + if (conditionalLoopIsFinished == true) { + return true; + } else if (conditionalLoopIsFinished == false) { + return false; + } else { + return new UnsupportedOperationException(Constants.COULD_NOT_DETERMINE_IF_THE_LOOP_WAS_FINISHED); + } + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopContext.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopContext.java new file mode 100644 index 00000000..6bf0600d --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopContext.java @@ -0,0 +1,61 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories.LoopComponentFactory; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateManipulation; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContext; + +/** + * Conditional LoopContext + */ +public final class ConditionalLoopContext implements LoopContext { + private final ConditionalLoopState myLoopState; + + /** + * @param nLoopControlParameterFinalValue int + */ + public LoopContext(final Predicate loopFinishedCondition) { + super(); + this.myLoopState = new ConditionalLoopState(loopFinishedCondition); + } + + /** + * @return void + */ + @Override + public void start() { + } + + /** + * @return boolean + */ + @Override + public boolean shouldProceed() { + return this.myLoopState.getLoopCondition().evaluateLoop(this.myLoopState, this.myLoopState.getLoopIsFinishedChecker()); + } + + /** + * @return void + */ + @Override + public void proceed() { + } + + /** + * @return int + */ + @Override + public int getControlParameter() { + throw new UnsupportedOperationException(Constants.A_CONDITIONAL_LOOP_HAS_NO_CONTROL_PARAMETER); + } + + @Override + public ConditionalLoopState getLoopState() { + return this.myLoopState; + } +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopFinalizer.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopFinalizer.java new file mode 100644 index 00000000..132e5334 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopFinalizer.java @@ -0,0 +1,14 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopFinalizer; + +/** + * Conditional LoopFinalizer + */ +public final class ConditionalLoopFinalizer implements LoopFinalizer { + /** + * @return int + */ + public int getLoopFinalizationPoint() { + throw new UnsupportedOperationException(Constants.A_CONDITIONAL_LOOP_HAS_NO_FINALIZATION_POINT); + } +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopInitializer.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopInitializer.java new file mode 100644 index 00000000..8b7e741d --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopInitializer.java @@ -0,0 +1,19 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.stereotype.Service; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopInitializer; + +/** + * Conditional LoopInitializer + */ +@Service +public class ConditionalLoopInitializer implements LoopInitializer { + /** + * @return int + */ + public int getLoopInitializationPoint() { + throw new UnsupportedOperationException(Constants.A_CONDITIONAL_LOOP_HAS_NO_INITIALIZATION_POINT); + } +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopIsFinishedChecker.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopIsFinishedChecker.java new file mode 100644 index 00000000..010dfbb8 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopIsFinishedChecker.java @@ -0,0 +1,26 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.stereotype.Service; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.integercomparator.ThreeWayIntegerComparator; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.integercomparator.ThreeWayIntegerComparisonResult; + +/** + * Conditional LoopIsFinishedChecker + */ +@Service +public class ConditionalLoopIsFinishedChecker { + private final Predicate _loopFinishedCondition; + public ConditionalLoopIsFinishedChecker(Predicate loopFinishedCondition) { + this._loopFinishedCondition = loopFinishedCondition; + } + + /** + * @param conditionalLoopState ConditionalLoopState + * @return boolean + */ + public boolean checkIfConditionalLoopIsFinished(final ConditionalLoopState conditionalLoopState) { + return this._loopFinishedCondition.test(conditionalLoopState); + } + +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopRunner.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopRunner.java new file mode 100644 index 00000000..7c33518a --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopRunner.java @@ -0,0 +1,39 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateManipulation; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopPayloadExecution; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopRunner; + +/** + * Conditional LoopRunner + */ +public final class ConditionalLoopRunner implements LoopRunner { + + private final LoopContextStateManipulation myStateManipulation; + private final LoopContextStateRetrieval myStateRetrieval; + private final LoopPayloadExecution myPayload; + + /** + * @param stateManipulation LoopContextStateManipulation + * @param stateRetrieval LoopContextStateRetrieval + * @param payload LoopPayloadExecution + */ + public ConditionalLoopRunner(final LoopContextStateManipulation stateManipulation, + final LoopContextStateRetrieval stateRetrieval, final LoopPayloadExecution payload) { + super(); + this.myStateManipulation = stateManipulation; + this.myStateRetrieval = stateRetrieval; + this.myPayload = payload; + } + + /** + * @return + */ + public void runLoop() { + while (this.myStateManipulation.shouldProceed()) { + this.myPayload.runLoopPayload(Constants.NULL_VALUE); + } + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopState.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopState.java new file mode 100644 index 00000000..077cb3b1 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopState.java @@ -0,0 +1,51 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories.LoopComponentFactory; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateManipulation; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopState; + +/** + * Conditional LoopState + */ +public class ConditionalLoopState implements LoopState { + private final ConditionalLoopInitializer myLoopInitializer; + private final ConditionalLoopFinalizer myLoopFinalizer; + private final ConditionalLoopCondition myLoopCondition; + private final ConditionalLoopStep myLoopStep; + private final ConditionalLoopIsFinishedChecker myLoopCompletionConditionChecker; + + public LoopState(final Predicate loopFinishedCondition) { + final ApplicationContext context = new ClassPathXmlApplicationContext(Constants.SPRING_XML); + final LoopComponentFactory myLoopComponentFactory = context.getBean(Constants.LOOP_COMPONENT_FACTORY, + LoopComponentFactory.class); + this.myLoopInitializer = myLoopComponentFactory.createLoopInitializer(); + this.myLoopFinalizer = myLoopComponentFactory.createLoopFinalizer(nLoopControlParameterFinalValue); + this.myLoopCondition = myLoopComponentFactory.createLoopCondition(); + this.myLoopStep = myLoopComponentFactory.createLoopStep(); + this.myLoopCompletionConditionChecker = + ((ConfigurableApplicationContext) context).close(); + } + + public ConditionalLoopInitializer getLoopInitializer() { + return this.myLoopInitializer; + } + public ConditionalLoopFinalizer getLoopFinalizer() { + return this.myLoopFinalizer; + } + public ConditionalLoopCondition getLoopCondition() { + return this.myLoopCondition; + } + public ConditionalLoopStep getLoopStep() { + return this.myLoopStep; + } + public ConditionalLoopIsFinishedChecker getLoopCompletionConditionChecker() { + return this.myLoopCompletionConditionChecker; + } + +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopCondition.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopCondition.java new file mode 100644 index 00000000..34a52353 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopCondition.java @@ -0,0 +1,33 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.stereotype.Service; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.integercomparator.ThreeWayIntegerComparator; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.integercomparator.ThreeWayIntegerComparisonResult; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopCondition; +import java.util.function.IntSupplier; + +/** + * Count-based LoopCondition + */ +@Service +public class CountBasedLoopCondition { + + /** + * @param nCurrentNumber int + * @param nTotalCount int + * @return boolean + */ + public boolean evaluateLoop(final LoopState loopState, final IntSupplier nCurrentNumber, final IntSupplier nTotalCount) { + final ThreeWayIntegerComparisonResult comparisonResult = ThreeWayIntegerComparator.Compare(nCurrentNumber.get(), + nTotalCount.get()); + if (ThreeWayIntegerComparisonResult.FirstIsLessThanSecond == comparisonResult) { + return true; + } else if (ThreeWayIntegerComparisonResult.FirstEqualsSecond == comparisonResult) { + return true; + } else { + return false; + } + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopContext.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopContext.java new file mode 100644 index 00000000..0089fad9 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopContext.java @@ -0,0 +1,66 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories.LoopComponentFactory; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateManipulation; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContext; + +/** + * Count-based LoopContext + */ +public final class CountBasedLoopContext implements LoopContext { + private final CountBasedLoopState myLoopState; + + /** + * @param nLoopControlParameterFinalValue int + */ + public CountBasedLoopContext(final int nLoopControlParameterFinalValue) { + super(); + this.myLoopState = new CountBasedLoopState(nLoopControlParameterFinalValue); + } + + /** + * @return void + */ + @Override + public void start() { + this.myLoopState.setCurrentControlParameterValue( + this.myLoopState.getLoopInitializer().getLoopInitializationPoint()); + } + + /** + * @return boolean + */ + @Override + public boolean shouldProceed() { + return this.myLoopState.getLoopCondition().evaluateLoop(this.myLoopState.getCurrentControlParameterValue(), + this.myLoopState.getLoopFinalizer().getLoopFinalizationPoint()); + } + + /** + * @return void + */ + @Override + public void proceed() { + this.myLoopState.setCurrentControlParameterValue( + this.myLoopState.getLoopStep().stepLoop(this.myCurrentControlParameterValue)); + } + + /** + * @return int + */ + @Override + public int getControlParameter() { + return this.myLoopState.getCurrentControlParameterValue(); + } + + @Override + public CountBasedLoopState getLoopState() { + return this.myLoopState; + } +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopFinalizer.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopFinalizer.java new file mode 100644 index 00000000..da2f8f43 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopFinalizer.java @@ -0,0 +1,26 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopFinalizer; + +/** + * Count-based LoopFinalizer + */ +public final class CountBasedLoopFinalizer implements LoopFinalizer { + + private final int nStoredLoopFinalValue; + + /** + * @param nLoopFinalValue int + */ + public CountBasedLoopFinalizer(final int nLoopFinalValue) { + super(); + this.nStoredLoopFinalValue = nLoopFinalValue; + } + + /** + * @return int + */ + public int getLoopFinalizationPoint() { + return this.nStoredLoopFinalValue; + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopInitializer.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopInitializer.java new file mode 100644 index 00000000..345bc98d --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopInitializer.java @@ -0,0 +1,20 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.stereotype.Service; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; + +/** + * Count-based LoopInitializer + */ +@Service +public class CountBasedLoopInitializer implements LoopInitializer { + + /** + * @return int + */ + public int getLoopInitializationPoint() { + return Constants.LOOP_INIT_VALUE; + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopRunner.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopRunner.java new file mode 100644 index 00000000..951aaae7 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopRunner.java @@ -0,0 +1,39 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateManipulation; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopPayloadExecution; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopRunner; + +/** + * Count-based LoopRunner + */ +public final class CountBasedLoopRunner implements LoopRunner { + + private final LoopContextStateManipulation myStateManipulation; + private final LoopContextStateRetrieval myStateRetrieval; + private final LoopPayloadExecution myPayload; + + /** + * @param stateManipulation LoopContextStateManipulation + * @param stateRetrieval LoopContextStateRetrieval + * @param payload LoopPayloadExecution + */ + public LoopRunner(final LoopContextStateManipulation stateManipulation, + final LoopContextStateRetrieval stateRetrieval, final LoopPayloadExecution payload) { + super(); + this.myStateManipulation = stateManipulation; + this.myStateRetrieval = stateRetrieval; + this.myPayload = payload; + } + + /** + * @return + */ + public void runLoop() { + for (this.myStateManipulation.start(); this.myStateManipulation.shouldProceed(); this.myStateManipulation.proceed()) { + this.myPayload.runLoopPayload(this.myStateRetrieval); + } + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopState.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopState.java new file mode 100644 index 00000000..6f0336ac --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopState.java @@ -0,0 +1,52 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories.LoopComponentFactory; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateManipulation; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopState; + +/** + * Count-based LoopState + */ +public class CountBasedLoopState implements LoopState { + private final CountBasedLoopInitializer myLoopInitializer; + private final CountBasedLoopFinalizer myLoopFinalizer; + private final CountBasedLoopCondition myLoopCondition; + private final CountBasedLoopStep myLoopStep; + private int myCurrentControlParameterValue; + + public LoopState(final int nLoopControlParameterFinalValue) { + final ApplicationContext context = new ClassPathXmlApplicationContext(Constants.SPRING_XML); + final LoopComponentFactory myLoopComponentFactory = context.getBean(Constants.LOOP_COMPONENT_FACTORY, + LoopComponentFactory.class); + this.myLoopInitializer = myLoopComponentFactory.createLoopInitializer(); + this.myLoopFinalizer = myLoopComponentFactory.createLoopFinalizer(nLoopControlParameterFinalValue); + this.myLoopCondition = myLoopComponentFactory.createLoopCondition(); + this.myLoopStep = myLoopComponentFactory.createLoopStep(); + ((ConfigurableApplicationContext) context).close(); + } + + public ConditionalLoopInitializer getLoopInitializer() { + return this.myLoopInitializer; + } + public ConditionalLoopFinalizer getLoopFinalizer() { + return this.myLoopFinalizer; + } + public ConditionalLoopCondition getLoopCondition() { + return this.myLoopCondition; + } + public ConditionalLoopStep getLoopStep() { + return this.myLoopStep; + } + public int getCurrentControlParameterValue() { + return this.myCurrentControlParameterValue; + } + public int setCurrentControlParameterValue(int currentControlParameterValue) { + return this.myCurrentControlParameterValue = currentControlParameterValue; + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopStep.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopStep.java new file mode 100644 index 00000000..5454cbd0 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/count/CountBasedLoopStep.java @@ -0,0 +1,22 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.stereotype.Service; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopStep; + +/** + * Count-based LoopStep + */ +@Service +public class CountBasedLoopStep implements LoopStep { + + /** + * @param nCurrentNumber int + * @return int + */ + public int stepLoop(final int nCurrentNumber) { + return nCurrentNumber + Constants.LOOP_INC_VALUE; + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/EnterpriseGradeFizzBuzzSolutionStrategy.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/EnterpriseGradeFizzBuzzSolutionStrategy.java index 314d5243..32706f76 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/EnterpriseGradeFizzBuzzSolutionStrategy.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/EnterpriseGradeFizzBuzzSolutionStrategy.java @@ -31,8 +31,8 @@ public EnterpriseGradeFizzBuzzSolutionStrategy(final LoopPayloadExecution _loopP */ @Override public void runSolution(final int nFizzBuzzUpperLimit) { - final LoopContext loopContext = new LoopContext(nFizzBuzzUpperLimit); - final LoopRunner loopRunner = new LoopRunner(loopContext, loopContext, this._loopPayloadExecution); + final CountBasedLoopContext loopContext = new CountBasedLoopContext(nFizzBuzzUpperLimit); + final CountBasedLoopRunner loopRunner = new CountBasedLoopRunner(loopContext, loopContext, this._loopPayloadExecution); loopRunner.runLoop(); } diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/IteratorPayload.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/IteratorPayload.java new file mode 100644 index 00000000..2c46f2ad --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/IteratorPayload.java @@ -0,0 +1,42 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.adapters.LoopContextStateRetrievalToSingleStepOutputGenerationAdapter; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopPayloadExecution; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.OutputGenerationStrategy; + +/** + * Payload for Iterator + */ +@Service +public class IteratorPayload implements LoopPayloadExecution { + + private final Iterator _iterator; + private final ResultCollection _results; + + /** + * @param _iterator Iterator + * @param _results ResultCollection + */ + @Autowired + public IteratorPayload(final Iterator _iterator, final ResultCollection _results) { + super(); + this._iterator = _iterator; + } + + /** + * @param stateRetrieval LoopContextStateRetrieval + * @return void + */ + @Override + public void runLoopPayload(final LoopContextStateRetrieval stateRetrieval) { + T resultValue = this._iterator.next(); + Result result = new ActionResult(); + result.setResult(resultValue); + this._results.addResult(result); + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/OutputGenerationContextVisitorPayload.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/OutputGenerationContextVisitorPayload.java new file mode 100644 index 00000000..5236b514 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/OutputGenerationContextVisitorPayload.java @@ -0,0 +1,42 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.adapters.LoopContextStateRetrievalToSingleStepOutputGenerationAdapter; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopPayloadExecution; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.OutputGenerationStrategy; + +/** + * Payload for OutputGenerationContextVisitor + */ +@Service +public class OutputGenerationContextVisitorPayload implements LoopPayloadExecution { + private final ResultCollection _results; + private final OutputGenerationContextVisitor contextVisitor; + + /** + * @param _results ResultCollection + * @param contextVisitor OutputGenerationContextVisitor + */ + @Autowired + public OutputGenerationContextVisitorPayload(final ResultCollection _results, final OutputGenerationContextVisitor contextVisitor) { + super(); + this._results = _results; + this.contextVisitor = contextVisitor; + } + + /** + * @param stateRetrieval LoopContextStateRetrieval + * @return void + */ + @Override + public void runLoopPayload(final LoopContextStateRetrieval stateRetrieval) { + int controlParameterValue = stateRetrieval.getControlParameter(); + List> resultsList = _results.getResults(); + OutputGenerationContext outputGenerationContext = resultsList.get(controlParameterValue); + this.contextVisitor.visit(outputGenerationContext, controlParameterValue); + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/SingleStepOutputGenerationStrategy.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/SingleStepOutputGenerationStrategy.java index ff818716..30c859f3 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/SingleStepOutputGenerationStrategy.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/SingleStepOutputGenerationStrategy.java @@ -15,6 +15,9 @@ import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.visitors.OutputGenerationContext; import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.visitors.OutputGenerationContextVisitor; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.data.ResultCollection; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.data.ActionResultCollection; + /** * Strategy for SingleStepOutputGeneration */ @@ -64,13 +67,30 @@ public SingleStepOutputGenerationStrategy( * @return void */ public void performGenerationForCurrentStep(final SingleStepOutputGenerationParameter generationParameter) { - final int nGenerationParameter = generationParameter.retrieveIntegerValue(); final Iterator iterator = this.contexts.iterator(); + final ResultCollectionFactory resultCollectionFactory = new ActionResultCollectionFactory<>(); + // switch to ConditionalLoop while (iterator.hasNext()) { final OutputGenerationContext context = iterator.next(); this.contextVisitor.visit(context, nGenerationParameter); } + // + final ResultCollection results = resultCollectionFactory.createResultCollection(); + final IteratorPayload iteratorPayload = new IteratorPayload<>(iterator, results); + //end this.myNewLinePrinter.print(); } + private void generateResultCollection(Iterator iterator, IteratorPayload iteratorPayload) { + final ConditionalLoopContext loopContext = new ConditionalLoopContext(iterator::hasNext); + final ConditionalLoopRunner loopRunner = new ConditionalLoopRunner(loopContext, loopContext, iteratorPayload); + loopRunner.runLoop(); + } + + private void generateOutputFromResultCollection(ResultCollection results, final OutputGenerationContextVisitor contextVisitor, final SingleStepOutputGenerationParameter nGenerationParameter) { + final OutputGenerationContextVisitorPayload outputGenerationContextVisitorPayload = new OutputGenerationContextVisitorPayload(); + final CountBasedLoopContext loopContext = new CountBasedLoopContext(results.size()); + final CountBasedLoopRunner loopRunner = new CountBasedLoopRunner(loopContext, loopContext, outputGenerationContextVisitorPayload); + loopRunner.runLoop(); + } } diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/converters/CharacterListToCharacterArrayConverter.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/converters/CharacterListToCharacterArrayConverter.java new file mode 100644 index 00000000..6c955f3f --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/converters/CharacterListToCharacterArrayConverter.java @@ -0,0 +1,18 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.adapters; + +import it.unimi.dsi.fastutils.chars.CharacterList; + +/** + * Converter for CharacterListToCharacterArray + */ +public class CharacterListToCharacterArrayConverter { + + private CharListToCharacterArrayAdapter() {} + + public static char[] Convert(CharacterList characterList) { + + final ConditionalLoopContext loopContext = new ConditionalLoopContext(context -> context.); + final ConditionalLoopRunner loopRunner = new ConditionalLoopRunner(loopContext, loopContext, this._loopPayloadExecution); + loopRunner.runLoop(); + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/data/Result.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/data/Result.java new file mode 100644 index 00000000..4750917b --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/data/Result.java @@ -0,0 +1,9 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.data; + +/** + * Result + */ +public interface Result { + public T getResult(); + public void setResult(T result); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/data/ResultCollection.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/data/ResultCollection.java new file mode 100644 index 00000000..9b3d7f36 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/data/ResultCollection.java @@ -0,0 +1,11 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.data; + +import java.util.List; + +/** + * ResultCollection + */ +public interface ResultCollection { + public List> getResults(); + public void addResult(Result result); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/AbstractCharacterArrayFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/AbstractCharacterArrayFactory.java new file mode 100644 index 00000000..35ef7426 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/AbstractCharacterArrayFactory.java @@ -0,0 +1,11 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories; + +import it.unimi.dsi.fastutils.chars.CharacterList; + +/** + * Factory for CharacterArray + */ +public class AbstractCharacterArrayFactory { + + public static char[] createCharacterArray(CharacterList characterList); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/GeneratorFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/GeneratorFactory.java new file mode 100644 index 00000000..349cf023 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/GeneratorFactory.java @@ -0,0 +1,15 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.generators.Generator; + +/** + * Factory for Generator + */ +public interface GeneratorFactory { + + /** + * @return + */ + public Generator createGenerator(); + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/GeneratorListFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/GeneratorListFactory.java new file mode 100644 index 00000000..0e025100 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/GeneratorListFactory.java @@ -0,0 +1,15 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.generators.GeneratorList; + +/** + * Factory for GeneratorList + */ +public interface GeneratorListFactory> { + + /** + * @return + */ + public GeneratorList createGeneratorList(); + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/GeneratorListGeneratorFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/GeneratorListGeneratorFactory.java new file mode 100644 index 00000000..149ecaaa --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/GeneratorListGeneratorFactory.java @@ -0,0 +1,15 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.generators.GeneratorListGenerator; + +/** + * Factory for GeneratorListGenerator + */ +public interface GeneratorListGeneratorFactory, L extends GeneratorList> { + + /** + * @return + */ + public GeneratorListGenerator createGeneratorListGenerator(); + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/IntegerGeneratorFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/IntegerGeneratorFactory.java new file mode 100644 index 00000000..0cd4b9ad --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/IntegerGeneratorFactory.java @@ -0,0 +1,15 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.generators.IntegerGenerator; + +/** + * Factory for IntegerGenerator + */ +public interface IntegerGeneratorFactory { + + /** + * @return + */ + public IntegerGenerator createIntegerGenerator(); + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/JsonObjectHolderFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/JsonObjectHolderFactory.java new file mode 100644 index 00000000..d8ece1af --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/JsonObjectHolderFactory.java @@ -0,0 +1,8 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json; + +import org.json.JsonObject; + +public interface JsonObjectHolderFactory { + void initialize(JsonObject object); + JsonObjectHolder createJsonObjectHolder(); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/JsonReaderFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/JsonReaderFactory.java new file mode 100644 index 00000000..1dbc3dc9 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/JsonReaderFactory.java @@ -0,0 +1,5 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories; + +public interface JsonReaderFactory { + JsonReader createJsonReader(); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/ListGeneratorFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/ListGeneratorFactory.java new file mode 100644 index 00000000..e73b873e --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/ListGeneratorFactory.java @@ -0,0 +1,15 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.generators.ListGenerator; + +/** + * Factory for ListGenerator + */ +public interface ListGeneratorFactory> { + + /** + * @return + */ + public ListGenerator createListGenerator(); + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/LoopComponentFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/LoopComponentFactory.java similarity index 50% rename from src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/LoopComponentFactory.java rename to src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/LoopComponentFactory.java index 4daa6984..2a543bf1 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/LoopComponentFactory.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/LoopComponentFactory.java @@ -14,54 +14,25 @@ @Service public class LoopComponentFactory { - private final LoopCondition _loopCondition; - - private final LoopInitializer _loopInitializer; - - private final LoopStep _loopStep; - - /** - * @param _loopCondition LoopCondition - * @param _loopInitializer LoopInitializer - * @param _loopStep LoopStep - */ - @Autowired - public LoopComponentFactory(final LoopCondition _loopCondition, final LoopInitializer _loopInitializer, - final LoopStep _loopStep) { - super(); - this._loopCondition = _loopCondition; - this._loopInitializer = _loopInitializer; - this._loopStep = _loopStep; - } - /** * @return LoopCondition */ - public LoopCondition createLoopCondition() { - return this._loopCondition; - } + public LoopCondition createLoopCondition(); /** * @return LoopInitializer */ - public LoopInitializer createLoopInitializer() { - return this._loopInitializer; - } + public LoopInitializer createLoopInitializer(); /** * @param nLoopFinalValue int * @return LoopFinalizer */ - public LoopFinalizer createLoopFinalizer(final int nLoopFinalValue) { - final LoopFinalizer myLoopFinalizer = new LoopFinalizer(nLoopFinalValue); - return myLoopFinalizer; - } + public LoopFinalizer createLoopFinalizer(final int nLoopFinalValue); /** * @return LoopStep */ - public LoopStep createLoopStep() { - return this._loopStep; - } + public LoopStep createLoopStep(); } diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/ResultCollectionFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/ResultCollectionFactory.java new file mode 100644 index 00000000..03e4e230 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/ResultCollectionFactory.java @@ -0,0 +1,10 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.data.ResultCollection; + +/** + * Factory for ResultCollection + */ +public interface ResultCollectionFactory { + public ResultCollection createResultCollection(); +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/StringGeneratorFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/StringGeneratorFactory.java new file mode 100644 index 00000000..fe9271eb --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/StringGeneratorFactory.java @@ -0,0 +1,15 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.generators.StringGenerator; + +/** + * Factory for StringGenerator + */ +public interface StringGeneratorFactory { + + /** + * @return + */ + public StringGenerator createStringGenerator(); + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/Generator.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/Generator.java new file mode 100644 index 00000000..9a7c9ff0 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/Generator.java @@ -0,0 +1,5 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.generators; + +public interface Generator { + public T get(); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/GeneratorList.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/GeneratorList.java new file mode 100644 index 00000000..0071c5fd --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/GeneratorList.java @@ -0,0 +1,6 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.generators; + +public interface GeneratorList> extends List { + public List getList(); + +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/GeneratorListGenerator.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/GeneratorListGenerator.java new file mode 100644 index 00000000..2ab57b57 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/GeneratorListGenerator.java @@ -0,0 +1,5 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.generators; + +public interface GeneratorListGenerator, L extends GeneratorList> extends ListGenerator { + public L get(); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/IntegerGenerator.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/IntegerGenerator.java new file mode 100644 index 00000000..29d49fc0 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/IntegerGenerator.java @@ -0,0 +1,6 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.generators; + +public interface IntegerGenerator extends Generator { + public T get(); + public int getAsInt(); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/ListGenerator,java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/ListGenerator,java new file mode 100644 index 00000000..c26878c8 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/ListGenerator,java @@ -0,0 +1,5 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.generators; + +public interface ListGenerator> extends Generator { + public L get(); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/StringGenerator.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/StringGenerator.java new file mode 100644 index 00000000..71127f30 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/StringGenerator.java @@ -0,0 +1,5 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.generators; + +public interface StringGenerator extends Generator { + public T get(); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonElementHolder.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonElementHolder.java new file mode 100644 index 00000000..dfaffa05 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonElementHolder.java @@ -0,0 +1,6 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json; + +public interface JsonElementHolder { + E getElement(); + JsonElementType getType(); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonElementType.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonElementType.java new file mode 100644 index 00000000..8c935010 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonElementType.java @@ -0,0 +1,5 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json; + +public interface JsonElementType { + Class getClass(); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonLoader.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonLoader.java new file mode 100644 index 00000000..09de294b --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonLoader.java @@ -0,0 +1,8 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories.JsonReaderFactory; + +public interface JsonLoader { + void loadJson(ByteArrayInputStream stream); + JsonReaderFactory getJsonReaderFactory(); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectAccessor.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectAccessor.java new file mode 100644 index 00000000..717fce8d --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectAccessor.java @@ -0,0 +1,8 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json; + +import org.json.JsonObject; + +public interface JsonObjectAccessor { + JsonObjectHasKeyVerifier getHasKeyVerifier(JsonObjectKey jsonObjectKey); + JsonObjectKeyReader getKeyReader(JsonObjectKey jsonObjectKey); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectHasKeyVerifier.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectHasKeyVerifier.java new file mode 100644 index 00000000..8fcbfc79 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectHasKeyVerifier.java @@ -0,0 +1,5 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json; + +public interface JsonObjectHasKeyVerifier { + boolean verifyJsonObjectHasKey(); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectHolder.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectHolder.java new file mode 100644 index 00000000..14fcae09 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectHolder.java @@ -0,0 +1,7 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json; + +import org.json.JsonObject; + +public interface JsonObjectHolder { + JsonObjectAccessor getJsonObjectAccessor(); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectKey.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectKey.java new file mode 100644 index 00000000..e69de29b diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectKeyReader.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectKeyReader.java new file mode 100644 index 00000000..057a0796 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectKeyReader.java @@ -0,0 +1,5 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json; + +public interface JsonObjectKeyReader { + JsonElementHolder readKey(); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonReader.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonReader.java new file mode 100644 index 00000000..d5c11ed8 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonReader.java @@ -0,0 +1,8 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json; + +import org.json.JsonObject; +import java.io.ByteBuffer; + +public interface JsonReader { + JsonObject readJson(); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/Language.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/Language.java new file mode 100644 index 00000000..f7351053 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/Language.java @@ -0,0 +1,6 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.lang.translation; + +public interface Language { + TranslationKey getNameTranslationKey(); + String getStringForTranslationKey(TranslationKey key); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/translation/TranslationKey.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/translation/TranslationKey.java new file mode 100644 index 00000000..45356329 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/translation/TranslationKey.java @@ -0,0 +1,5 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.lang.translation; + +public interface TranslationKey { + +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopContext.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopContext.java new file mode 100644 index 00000000..1be59a95 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopContext.java @@ -0,0 +1,37 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + + +/** + * LoopContext + */ +public interface LoopContext extends LoopContextStateManipulation, LoopContextStateRetrieval { + + /** + * @return void + */ + @Override + public void start(); + + /** + * @return boolean + */ + @Override + public boolean shouldProceed(); + + /** + * @return void + */ + @Override + public void proceed(); + + /** + * @return int + */ + @Override + public int getControlParameter(); + +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopContextStateRetrieval.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopContextStateRetrieval.java index 388d264d..67ddc266 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopContextStateRetrieval.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopContextStateRetrieval.java @@ -6,8 +6,11 @@ public interface LoopContextStateRetrieval { /** - * @return + * @return int */ public int getControlParameter(); - + /** + * @return LoopState + */ + public LoopState getLoopState(); } diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopFinalizer.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopFinalizer.java new file mode 100644 index 00000000..3ba81f2c --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopFinalizer.java @@ -0,0 +1,12 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +/** + * LoopFinalizer + */ +public final class LoopFinalizer { + /** + * @return int + */ + public int getLoopFinalizationPoint(); + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopInitializer.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopInitializer.java new file mode 100644 index 00000000..52e7af3a --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopInitializer.java @@ -0,0 +1,18 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.stereotype.Service; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; + +/** + * LoopInitializer + */ +@Service +public class LoopInitializer { + + /** + * @return int + */ + public int getLoopInitializationPoint(); + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopRunner.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopRunner.java new file mode 100644 index 00000000..395f351e --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopRunner.java @@ -0,0 +1,16 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateManipulation; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopPayloadExecution; + +/** + * LoopRunner + */ +public final class LoopRunner { + /** + * @return + */ + public void runLoop(); + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopState.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopState.java new file mode 100644 index 00000000..282ebcef --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopState.java @@ -0,0 +1,21 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories.LoopComponentFactory; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateManipulation; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; + +/** + * LoopState + */ +public class LoopState { + public ConditionalLoopInitializer getLoopInitializer(); + public ConditionalLoopFinalizer getLoopFinalizer(); + public ConditionalLoopCondition getLoopCondition(); + public ConditionalLoopStep getLoopStep(); + +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopStep.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopStep.java new file mode 100644 index 00000000..ebe84e7c --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/LoopStep.java @@ -0,0 +1,19 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.stereotype.Service; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; + +/** + * LoopStep + */ +@Service +public class LoopStep { + + /** + * @param nCurrentNumber int + * @return int + */ + public int stepLoop(final int nCurrentNumber); + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopCondition.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopCondition.java new file mode 100644 index 00000000..0cdadafb --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopCondition.java @@ -0,0 +1,31 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.stereotype.Service; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.integercomparator.ThreeWayIntegerComparator; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.integercomparator.ThreeWayIntegerComparisonResult; + +/** + * LoopCondition + */ +@Service +public class LoopCondition { + + /** + * @param nCurrentNumber int + * @param nTotalCount int + * @return boolean + */ + public boolean evaluateLoop(final int nCurrentNumber, final int nTotalCount) { + final ThreeWayIntegerComparisonResult comparisonResult = ThreeWayIntegerComparator.Compare(nCurrentNumber, + nTotalCount); + if (ThreeWayIntegerComparisonResult.FirstIsLessThanSecond == comparisonResult) { + return true; + } else if (ThreeWayIntegerComparisonResult.FirstEqualsSecond == comparisonResult) { + return true; + } else { + return false; + } + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopContext.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopContext.java new file mode 100644 index 00000000..1dff6ba4 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopContext.java @@ -0,0 +1,61 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories.LoopComponentFactory; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateManipulation; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; + +/** + * LoopContext + */ +public final class LoopContext implements LoopContextStateManipulation, LoopContextStateRetrieval { + private final LoopState myLoopState; + + /** + * @param nLoopControlParameterFinalValue int + */ + public LoopContext(final int nLoopControlParameterFinalValue) { + super(); + this.myLoopState = new LoopState(); + } + + /** + * @return void + */ + @Override + public void start() { + this.myCurrentControlParameterValue = + this.myLoopInitializer.getLoopInitializationPoint(); + } + + /** + * @return boolean + */ + @Override + public boolean shouldProceed() { + return this.myLoopCondition.evaluateLoop(this.myCurrentControlParameterValue, + this.myLoopFinalizer.getLoopFinalizationPoint()); + } + + /** + * @return void + */ + @Override + public void proceed() { + this.myCurrentControlParameterValue = + this.myLoopStep.stepLoop(this.myCurrentControlParameterValue); + } + + /** + * @return int + */ + @Override + public int getControlParameter() { + return this.myCurrentControlParameterValue; + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopFinalizer.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopFinalizer.java new file mode 100644 index 00000000..2f104333 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopFinalizer.java @@ -0,0 +1,25 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +/** + * LoopFinalizer + */ +public final class LoopFinalizer { + + private final int nStoredLoopFinalValue; + + /** + * @param nLoopFinalValue int + */ + public LoopFinalizer(final int nLoopFinalValue) { + super(); + this.nStoredLoopFinalValue = nLoopFinalValue; + } + + /** + * @return int + */ + public int getLoopFinalizationPoint() { + return this.nStoredLoopFinalValue; + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopInitializer.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopInitializer.java new file mode 100644 index 00000000..2304800e --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopInitializer.java @@ -0,0 +1,20 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.stereotype.Service; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; + +/** + * LoopInitializer + */ +@Service +public class LoopInitializer { + + /** + * @return int + */ + public int getLoopInitializationPoint() { + return Constants.LOOP_INIT_VALUE; + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopRunner.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopRunner.java new file mode 100644 index 00000000..da29e3dc --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopRunner.java @@ -0,0 +1,38 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateManipulation; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopPayloadExecution; + +/** + * LoopRunner + */ +public final class LoopRunner { + + private final LoopContextStateManipulation myStateManipulation; + private final LoopContextStateRetrieval myStateRetrieval; + private final LoopPayloadExecution myPayload; + + /** + * @param stateManipulation LoopContextStateManipulation + * @param stateRetrieval LoopContextStateRetrieval + * @param payload LoopPayloadExecution + */ + public LoopRunner(final LoopContextStateManipulation stateManipulation, + final LoopContextStateRetrieval stateRetrieval, final LoopPayloadExecution payload) { + super(); + this.myStateManipulation = stateManipulation; + this.myStateRetrieval = stateRetrieval; + this.myPayload = payload; + } + + /** + * @return + */ + public void runLoop() { + for (this.myStateManipulation.start(); this.myStateManipulation.shouldProceed(); this.myStateManipulation.proceed()) { + this.myPayload.runLoopPayload(this.myStateRetrieval); + } + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopState.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopState.java new file mode 100644 index 00000000..6ad7bde2 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopState.java @@ -0,0 +1,32 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories.LoopComponentFactory; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateManipulation; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; + +/** + * LoopState + */ +public class LoopState { + private final LoopInitializer myLoopInitializer; + private final LoopFinalizer myLoopFinalizer; + private final LoopCondition myLoopCondition; + private final LoopStep myLoopStep; + private int myCurrentControlParameterValue; + + public LoopState(final int nLoopControlParameterFinalValue) { + final ApplicationContext context = new ClassPathXmlApplicationContext(Constants.SPRING_XML); + final LoopComponentFactory myLoopComponentFactory = context.getBean(Constants.LOOP_COMPONENT_FACTORY, + LoopComponentFactory.class); + this.myLoopInitializer = myLoopComponentFactory.createLoopInitializer(); + this.myLoopFinalizer = myLoopComponentFactory.createLoopFinalizer(nLoopControlParameterFinalValue); + this.myLoopCondition = myLoopComponentFactory.createLoopCondition(); + this.myLoopStep = myLoopComponentFactory.createLoopStep(); + ((ConfigurableApplicationContext) context).close(); + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopStep.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopStep.java new file mode 100644 index 00000000..ee3962cf --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/loop/count/CountBasedLoopStep.java @@ -0,0 +1,21 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; + +import org.springframework.stereotype.Service; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; + +/** + * LoopStep + */ +@Service +public class LoopStep { + + /** + * @param nCurrentNumber int + * @return int + */ + public int stepLoop(final int nCurrentNumber) { + return nCurrentNumber + Constants.LOOP_INC_VALUE; + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/stringreturners/CharacterArrayStringReturner.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/stringreturners/CharacterArrayStringReturner.java new file mode 100644 index 00000000..b53c65b4 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/stringreturners/CharacterArrayStringReturner.java @@ -0,0 +1,8 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json; + +import org.json.JsonObject; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.visitors.JsonVisitorResult; + +public interface CharacterArrayStringReturner { + String getResultContents(char[] jsonVisitorResult); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/visitors/JsonObjectVisitor.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/visitors/JsonObjectVisitor.java new file mode 100644 index 00000000..e602147d --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/visitors/JsonObjectVisitor.java @@ -0,0 +1,8 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.visitors; + +import org.json.JsonObject; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json.JsonObjectAccessor; + +public interface JsonObjectVisitor { + JsonVisitorResult visit(JsonObjectAccessor jsonObjectAccessor); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/visitors/JsonVisitorResult.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/visitors/JsonVisitorResult.java new file mode 100644 index 00000000..0c3aa774 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/visitors/JsonVisitorResult.java @@ -0,0 +1,8 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.visitors; + +import it.unimi.dsi.fastutils.chars.CharList; + + +public interface JsonVisitorResult { + CharList getResultData(); +} \ No newline at end of file From 28bf9bd1258c775b1277f49d83641ed21e718244 Mon Sep 17 00:00:00 2001 From: SuperYoshi10000 <148275327+SuperYoshi10000@users.noreply.github.com> Date: Tue, 7 May 2024 16:03:48 -0400 Subject: [PATCH 2/5] A few minor changes --- .../packagenamingpackage/impl/Constants.java | 75 +++++++++++++++---- .../impl/data/BooleanResult.java | 21 ++++++ .../impl/data/TextComponent.java | 13 ++++ .../impl/data/TranslationComponent.java | 13 ++++ .../FileContentReaderStrategyFactory.java | 33 ++++++++ .../JsonObjectHolderImplFactory.java | 9 +++ .../impl/factories/JsonReaderImplFactory.java | 17 +++++ .../impl/factories/SimpleExceptionType.java | 32 ++++++++ .../factories/TranslationDataImplFactory.java | 18 +++++ .../factories/TranslationKeyImplFactory.java | 19 +++++ .../impl/json/JsonElementHolderImpl.java | 20 +++++ .../impl/json/JsonElementTypeImpl.java | 18 +++++ .../impl/json/JsonLoaderImpl.java | 14 ++++ .../impl/json/JsonObjectAccessorImpl.java | 19 +++++ .../json/JsonObjectHasKeyVerifierImpl.java | 29 +++++++ .../impl/json/JsonObjectHolderImpl.java | 17 +++++ .../impl/json/JsonObjectKeyImpl.java | 25 +++++++ .../impl/json/JsonObjectKeyReaderImpl.java | 32 ++++++++ .../impl/json/JsonReaderImpl.java | 33 ++++++++ .../impl/lang/English.java | 26 +++++++ .../lang/translation/TranslationDataImpl.java | 51 +++++++++++++ .../lang/translation/TranslationKeyImpl.java | 15 ++++ .../translation/TranslationKeyReaderImpl.java | 25 +++++++ .../impl/loop copy/LoopCondition.java | 31 -------- .../impl/loop copy/LoopContext.java | 61 --------------- .../impl/loop copy/LoopFinalizer.java | 25 ------- .../impl/loop copy/LoopInitializer.java | 20 ----- .../impl/loop copy/LoopRunner.java | 38 ---------- .../impl/loop copy/LoopState.java | 32 -------- .../impl/loop copy/LoopStep.java | 21 ------ .../impl/loop copy/count/LoopCondition.java | 31 -------- .../impl/loop copy/count/LoopContext.java | 61 --------------- .../impl/loop copy/count/LoopFinalizer.java | 25 ------- .../impl/loop copy/count/LoopInitializer.java | 20 ----- .../impl/loop copy/count/LoopRunner.java | 38 ---------- .../impl/loop copy/count/LoopState.java | 32 -------- .../impl/loop copy/count/LoopStep.java | 21 ------ .../conditional/ConditionalLoopCondition.java | 4 +- .../conditional/ConditionalLoopContext.java | 2 +- .../conditional/ConditionalLoopFinalizer.java | 2 +- .../ConditionalLoopInitializer.java | 2 +- .../conditional/ConditionalLoopRunner.java | 2 +- .../impl/math/arithmetics/IntegerDivider.java | 2 +- .../strategies/FileContentReaderStrategy.java | 33 ++++++++ .../strategies/JsonKeyReaderStrategyImpl.java | 23 ++++++ ...OutputGenerationContextVisitorPayload.java | 5 +- .../SingleStepOutputGenerationStrategy.java | 17 ++--- .../adapters/FunctionBindAdapter.java | 13 ++++ .../ReaderToByteArrayInputStreamAdapter.java | 39 ++++++++++ .../comparators/ObjectEqualityComparator.java | 28 +++++++ .../ThreeWayIntegerComparator.java | 2 +- .../strategies/stream/AbstractPipeline.java | 16 ++++ .../strategies/stream/ActionPipeline.java | 19 +++++ .../strategies/stream/MergedPipeline.java | 18 +++++ .../strategies/stream/StandardPipeline.java | 19 +++++ .../stringreturners/BuzzStringReturner.java | 2 +- .../stringreturners/FizzStringReturner.java | 3 +- .../interfaces/data/Component.java | 5 ++ .../interfaces/factories/ExceptionType.java | 11 +++ .../factories/FileContentStrategyFactory.java | 16 ++++ .../factories/JsonObjectHolderFactory.java | 3 +- .../factories/TranslationDataFactory.java | 15 ++++ .../factories/TranslationKeyFactory.java | 15 ++++ .../interfaces/generators/Generator.java | 5 -- .../interfaces/generators/GeneratorList.java | 6 -- .../generators/GeneratorListGenerator.java | 5 -- .../generators/IntegerGenerator.java | 6 -- .../interfaces/generators/ListGenerator,java | 5 -- .../generators/StringGenerator.java | 5 -- .../interfaces/json/JsonElementHolder.java | 4 +- .../interfaces/json/JsonElementType.java | 2 +- .../interfaces/json/JsonLoader.java | 2 +- .../interfaces/json/JsonObjectKey.java | 6 ++ .../interfaces/json/JsonReader.java | 5 +- .../interfaces/lang/Language.java | 7 +- .../lang/translation/TranslationData.java | 5 ++ .../lang/translation/TranslationKey.java | 2 +- .../translation/TranslationKeyReader.java | 5 ++ .../strategies/FileContentStrategy.java | 13 ++++ .../InputStreamGenerationStrategy.java | 16 ++++ .../strategies/JsonKeyReaderStrategy.java | 5 ++ .../interfaces/strategies/Pipeline.java | 7 ++ src/main/resources/assets/lang/en_us.json | 17 +++++ .../assets/values/numbers.properties | 11 +++ 84 files changed, 948 insertions(+), 537 deletions(-) create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/data/BooleanResult.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/data/TextComponent.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/data/TranslationComponent.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/FileContentReaderStrategyFactory.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/JsonObjectHolderImplFactory.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/JsonReaderImplFactory.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/SimpleExceptionType.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/TranslationDataImplFactory.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/TranslationKeyImplFactory.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonElementHolderImpl.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonElementTypeImpl.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonLoaderImpl.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonObjectAccessorImpl.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonObjectHasKeyVerifierImpl.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonObjectHolderImpl.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonObjectKeyImpl.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonObjectKeyReaderImpl.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonReaderImpl.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/lang/English.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/lang/translation/TranslationDataImpl.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/lang/translation/TranslationKeyImpl.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/lang/translation/TranslationKeyReaderImpl.java delete mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopCondition.java delete mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopContext.java delete mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopFinalizer.java delete mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopInitializer.java delete mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopRunner.java delete mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopState.java delete mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopStep.java delete mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopCondition.java delete mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopContext.java delete mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopFinalizer.java delete mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopInitializer.java delete mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopRunner.java delete mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopState.java delete mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopStep.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/FileContentReaderStrategy.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/JsonKeyReaderStrategyImpl.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/adapters/FunctionBindAdapter.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/adapters/ReaderToByteArrayInputStreamAdapter.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/comparators/ObjectEqualityComparator.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/stream/AbstractPipeline.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/stream/ActionPipeline.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/stream/MergedPipeline.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/stream/StandardPipeline.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/data/Component.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/ExceptionType.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/FileContentStrategyFactory.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/TranslationDataFactory.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/TranslationKeyFactory.java delete mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/Generator.java delete mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/GeneratorList.java delete mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/GeneratorListGenerator.java delete mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/IntegerGenerator.java delete mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/ListGenerator,java delete mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/StringGenerator.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/translation/TranslationData.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/translation/TranslationKeyReader.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/strategies/FileContentStrategy.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/strategies/InputStreamGenerationStrategy.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/strategies/JsonKeyReaderStrategy.java create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/strategies/Pipeline.java create mode 100644 src/main/resources/assets/lang/en_us.json create mode 100644 src/main/resources/assets/values/numbers.properties diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Constants.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Constants.java index ba875069..0f410b32 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Constants.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Constants.java @@ -1,28 +1,73 @@ package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories.SimpleExceptionType; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories.ExceptionType; +import java.io.File; +import java.io.FileInputStream; +import java.util.Properties; + /** * Constants */ public class Constants { - public static final Object NULL_VALUE = null; - public static final String A_CONDITIONAL_LOOP_HAS_NO_CONTROL_PARAMETER = "A conditional loop has no control parameter."; - public static final String A_CONDITIONAL_LOOP_HAS_NO_FINALIZATION_POINT = "A conditional loop has no finalization point."; - public static final String A_CONDITIONAL_LOOP_HAS_NO_INITIALIZATION_POINT = "A conditional loop has no initialization point."; - public static final String AN_ATTEMPT_WAS_MADE_TO_DIVIDE_BY_ZERO = "An attempt was made to divide by zero."; - public static final String BUZZ = "Buzz"; + private Constants() {} + + private static final Object NULL_VALUE = null; + @SuppressWarnings("unchecked") + public static final T NULL_VALUE() { + return (T) Constants.NULL_VALUE; + } + + private static final TranslationKey A_CONDITIONAL_LOOP_HAS_NO_CONTROL_PARAMETER_KEY = new TranslationKeyImpl("fizzbuzz.string.error.A_CONDITIONAL_LOOP_HAS_NO_CONTROL_PARAMETER"); + private static final TranslationKey A_CONDITIONAL_LOOP_HAS_NO_FINALIZATION_POINT_KEY = new TranslationKeyImpl("fizzbuzz.string.error.A_CONDITIONAL_LOOP_HAS_NO_FINALIZATION_POINT"); + private static final TranslationKey A_CONDITIONAL_LOOP_HAS_NO_INITIALIZATION_POINT_KEY = new TranslationKeyImpl("fizzbuzz.string.error.A_CONDITIONAL_LOOP_HAS_NO_INITIALIZATION_POINT"); + private static final TranslationKey AN_ATTEMPT_WAS_MADE_TO_DIVIDE_BY_ZERO_KEY = new TranslationKeyImpl("fizzbuzz.string.error.AN_ATTEMPT_WAS_MADE_TO_DIVIDE_BY_ZERO"); + private static final TranslationKey COULD_NOT_DETERMINE_IF_THE_LOOP_WAS_FINISHED_KEY = new TranslationKeyImpl("fizzbuzz.string.error.COULD_NOT_DETERMINE_IF_THE_LOOP_WAS_FINISHED"); + private static final TranslationKey KEY_NOT_FOUND_KEY = new TranslationKeyImpl("fizzbuzz.string.error.KEY_NOT_FOUND"); + private static final TranslationKey THE_INTEGERS_COULD_NOT_BE_COMPARED_KEY = new TranslationKeyImpl("fizzbuzz.string.error.THE_INTEGERS_COULD_NOT_BE_COMPARED"); + private static final TranslationKey THE_OBJECTS_COULD_NOT_BE_COMPARED_KEY = new TranslationKeyImpl("fizzbuzz.string.error.THE_OBJECTS_COULD_NOT_BE_COMPARED"); + private static final TranslationKey THE_WRONG_TYPE_OF_LOOP_STATE_WAS_PROVIDED_KEY = new TranslationKeyImpl("fizzbuzz.string.error.THE_WRONG_TYPE_OF_LOOP_STATE_WAS_PROVIDED"); + + private static final TranslationKey FIZZ_KEY = new TranslationKeyImpl("fizzbuzz.string.output.FIZZ"); + private static final TranslationKey BUZZ_KEY = new TranslationKeyImpl("fizzbuzz.string.output.BUZZ"); + + public static final Function A_CONDITIONAL_LOOP_HAS_NO_CONTROL_PARAMETER = lang -> new SimpleExceptionType(lang.getStringForTranslationKey(A_CONDITIONAL_LOOP_HAS_NO_CONTROL_PARAMETER_KEY), UnsupportedOperationException::new); + public static final Function A_CONDITIONAL_LOOP_HAS_NO_FINALIZATION_POINT = lang -> new SimpleExceptionType(lang.getStringForTranslationKey(A_CONDITIONAL_LOOP_HAS_NO_FINALIZATION_POINT_KEY), UnsupportedOperationException::new); + public static final Function A_CONDITIONAL_LOOP_HAS_NO_INITIALIZATION_POINT = lang -> new SimpleExceptionType(lang.getStringForTranslationKey(A_CONDITIONAL_LOOP_HAS_NO_INITIALIZATION_POINT_KEY), UnsupportedOperationException::new); + public static final Function AN_ATTEMPT_WAS_MADE_TO_DIVIDE_BY_ZERO = lang -> new SimpleExceptionType(lang.getStringForTranslationKey(AN_ATTEMPT_WAS_MADE_TO_DIVIDE_BY_ZERO_KEY), ArithmeticException::new); + public static final Function COULD_NOT_DETERMINE_IF_THE_LOOP_WAS_FINISHED = lang -> new SimpleExceptionType(lang.getStringForTranslationKey(COULD_NOT_DETERMINE_IF_THE_LOOP_WAS_FINISHED_KEY), UnsupportedOperationException::new); + public static final Function KEY_NOT_FOUND = lang -> new SimpleExceptionType(lang.getStringForTranslationKey(KEY_NOT_FOUND_KEY), IllegalArgumentException::new); + public static final Function THE_INTEGERS_COULD_NOT_BE_COMPARED = lang -> new SimpleExceptionType(lang.getStringForTranslationKey(THE_INTEGERS_COULD_NOT_BE_COMPARED_KEY), UnsupportedOperationException::new); + public static final Function THE_OBJECTS_COULD_NOT_BE_COMPARED = lang -> new SimpleExceptionType(lang.getStringForTranslationKey(THE_OBJECTS_COULD_NOT_BE_COMPARED_KEY), UnsupportedOperationException::new); + public static final Function THE_WRONG_TYPE_OF_LOOP_STATE_WAS_PROVIDED = lang -> new SimpleExceptionType(lang.getStringForTranslationKey(THE_WRONG_TYPE_OF_LOOP_STATE_WAS_PROVIDED_KEY), IllegalArgumentException::new); + + public static final Function BUZZ = FunctionBindAdapter.bindSecond(Language::getStringForTranslationKey, BUZZ_KEY); + public static final Function FIZZ = FunctionBindAdapter.bindSecond(Language::getStringForTranslationKey, FIZZ_KEY); + + public static final String ASSETS_VALUES_NUMBERS_PROPERTIES = "assets/values/numbers.properties"; + public static final String ASSETS_LANG = "assets/lang/"; public static final String COM_SERIOUSCOMPANY_BUSINESS_JAVA_FIZZBUZZ_PACKAGENAMINGPACKAGE_IMPL_PRINTERS_INTEGER_INTEGER_PRINTER_PRINT = "com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.printers.IntegerIntegerPrinter.print()"; - public static final String COULD_NOT_DETERMINE_IF_THE_LOOP_WAS_FINISHED = "Could not determine if the loop was finished."; - public static final String FIZZ = "Fizz"; + public static final String DEFAULT = "default"; public static final String LINE_SEPARATOR = "line.separator"; public static final String LOOP_COMPONENT_FACTORY = "loopComponentFactory"; public static final String SPRING_XML = "spring.xml"; public static final String STANDARD_FIZZ_BUZZ = "standardFizzBuzz"; - public static final String THE_INTEGERS_COULD_NOT_BE_COMPARED = "The integers could not be compared."; - public static final String THE_WRONG_TYPE_OF_LOOP_STATE_WAS_PROVIDED = "The wrong type of loop state was provided."; - public static final int DEFAULT_FIZZ_BUZZ_UPPER_LIMIT_PARAMETER_VALUE = 100; - public static final int INTEGER_DIVIDE_ZERO_VALUE = 0; - public static final int INTEGER_ORIGIN_ZERO_VALUE = 0; - public static final int LOOP_INC_VALUE = 1; - public static final int LOOP_INIT_VALUE = 1; + public static final String TRANSLATIONS = "translations"; + + public static final int DEFAULT_FIZZ_BUZZ_UPPER_LIMIT_PARAMETER_VALUE; + public static final int INTEGER_DIVIDE_ZERO_VALUE; + public static final int INTEGER_ORIGIN_ZERO_VALUE; + public static final int LOOP_INC_VALUE; + public static final int LOOP_INIT_VALUE; + static { + InputStream inputStream = Constants.class.getClassLoader().getResourceAsStream(ASSETS_VALUES_NUMBERS_PROPERTIES); + Properties properties = new Properties(); + properties.load(inputStream); + DEFAULT_FIZZ_BUZZ_UPPER_LIMIT_PARAMETER_VALUE = Integer.parseInt(properties.get("default_fizz_buzz_upper_limit_parameter_value")); + INTEGER_DIVIDE_ZERO_VALUE = Integer.parseInt(properties.get("integer_divide_zero_value")); + INTEGER_ORIGIN_ZERO_VALUE = Integer.parseInt(properties.get("integer_origin_zero_value")); + LOOP_INC_VALUE = Integer.parseInt(properties.get("loop_inc_value")); + LOOP_INIT_VALUE = Integer.parseInt(properties.get("loop_init_value")); + } } diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/data/BooleanResult.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/data/BooleanResult.java new file mode 100644 index 00000000..2ad9ba59 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/data/BooleanResult.java @@ -0,0 +1,21 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.data; + +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.function.BiFunction; +import java.util.function.BiPredicate; + +/** + * Result for Boolean + */ +public enum BooleanResult { + TRUE, + FALSE; + + public static Function from(Predicate predicate) { + return t -> predicate.test(t) ? BooleanResult.TRUE : BooleanResult.FALSE; + } + public static BiFunction from(BiPredicate predicate) { + return (t, u) -> predicate.test(t, u) ? BooleanResult.TRUE : BooleanResult.FALSE; + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/data/TextComponent.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/data/TextComponent.java new file mode 100644 index 00000000..0e151ebe --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/data/TextComponent.java @@ -0,0 +1,13 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.data; + +public class TextComponent implements Component { + private String text; + + public TextComponent(String text) { + this.text = text; + } + + public String resolve() { + return text; + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/data/TranslationComponent.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/data/TranslationComponent.java new file mode 100644 index 00000000..43e45040 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/data/TranslationComponent.java @@ -0,0 +1,13 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.data; + +public class TranslationComponent implements Component { + private TranslationKey key; + + public TranslationComponent(TranslationKey key) { + this.key = key; + } + + public String resolve() { + return Language.DEFAULT.getStringForTranslationKey(key); + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/FileContentReaderStrategyFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/FileContentReaderStrategyFactory.java new file mode 100644 index 00000000..ada67318 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/FileContentReaderStrategyFactory.java @@ -0,0 +1,33 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.FileContentReaderStrategy; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories.FileContentStrategyFactory; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.FileContentStrategy; + +/** + * Factory for FileContentReaderStrategy + */ +@Service +public class FileContentReaderStrategyFactory implements FileContentStrategyFactory { + private final FileContentReaderStrategy _fileContentReaderStrategy; + + /** + * @param _fileContentReaderStrategy BuzzStrategy + */ + @Autowired + public FileContentReaderStrategyFactory(final FileContentReaderStrategy _fileContentReaderStrategy) { + super(); + this._fileContentReaderStrategy = _fileContentReaderStrategy; + } + + /** + * @return FileContentStrategy + */ + @Override + public FileContentStrategy createFileContentStrategy() { + return this._fileContentReaderStrategy; + } +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/JsonObjectHolderImplFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/JsonObjectHolderImplFactory.java new file mode 100644 index 00000000..2caf6b4f --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/JsonObjectHolderImplFactory.java @@ -0,0 +1,9 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.json; + +import org.json.JsonObject; + +public interface JsonObjectHolderImplFactory { + public JsonObjectHolder createJsonObjectHolder(JsonObject jsonObject) { + return new JsonObjectHolderImpl(jsonObject); + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/JsonReaderImplFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/JsonReaderImplFactory.java new file mode 100644 index 00000000..ec8cf33b --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/JsonReaderImplFactory.java @@ -0,0 +1,17 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories; + +/** + * Factory for JsonReaderImpl + */ +@Service +public class JsonReaderImplFactory implements JsonReaderFactory { + private final InputStream inputStream; + + public JsonReaderImplFactory(InputStream inputStream) { + this.inputStream = inputStream; + } + + public JsonReader createJsonReader() { + return new JsonReaderImpl(inputStream); + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/SimpleExceptionType.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/SimpleExceptionType.java new file mode 100644 index 00000000..02270736 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/SimpleExceptionType.java @@ -0,0 +1,32 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories; + +import java.util.function.Function; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories.ExceptionType; + +/** + * SimpleExceptionType + */ +@Service +public class SimpleExceptionType implements ExceptionType { + + private final String message; + private final Function exceptionGenerator; + + /** + * @param message String + * @param exceptionGenerator Function + */ + public SimpleExceptionType(final String message, Function exceptionGenerator) { + super(); + this.message = message; + this.exceptionGenerator = exceptionGenerator; + } + + /** + * @return Exception + */ + @Override + public Exception createException() { + return this.exceptionGenerator.apply(this.message); + } +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/TranslationDataImplFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/TranslationDataImplFactory.java new file mode 100644 index 00000000..1b4a57b3 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/TranslationDataImplFactory.java @@ -0,0 +1,18 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories.TranslationDataFactory; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.lang.translation.TranslationData; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.lang.translation.TranslationDataImpl; +/** + * Factory for TranslationDataImpl + */ +public class TranslationDataImplFactory implements TranslationDataFactory { + + /** + * @return TranslationData + */ + public TranslationData createTranslationData(Language language) { + return new TranslationDataImpl(language); + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/TranslationKeyImplFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/TranslationKeyImplFactory.java new file mode 100644 index 00000000..e63ee58c --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/factories/TranslationKeyImplFactory.java @@ -0,0 +1,19 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories.TranslationKeyFactory; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.lang.translation.TranslationKey; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.lang.translation.TranslationKeyImpl; + +/** + * Factory for TranslationKeyImpl + */ +public class TranslationKeyImplFactory implements TranslationKeyFactory { + + /** + * @return TranslationKey + */ + public TranslationKey createTranslationKey(String string) { + return new TranslationKeyImpl(string); + } + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonElementHolderImpl.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonElementHolderImpl.java new file mode 100644 index 00000000..748ce764 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonElementHolderImpl.java @@ -0,0 +1,20 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.json; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json.JsonElementHolder; + +public class JsonElementHolderImpl implements JsonElementHolder { + private final E elementValue; + private final JsonElementType elementType; + + public JsonElementHolderImpl(E elementValue, JsonElementType elementType) { + this.elementValue = elementValue; + this.elementType = elementType; + } + + public E getElementValue() { + return this.elementValue; + } + public JsonElementType getElementType() { + return this.elementType + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonElementTypeImpl.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonElementTypeImpl.java new file mode 100644 index 00000000..1f92d438 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonElementTypeImpl.java @@ -0,0 +1,18 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.json; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json.JsonElementType; + +public class JsonElementTypeImpl implements JsonElementType { + private final Class elementClass; + + JsonElementTypeImpl(Class elementClass) { + this.elementClass = elementClass; + } + + public Class getElementClass() { + return this.elementClass; + } + + public static final JsonElementType JSON_OBJECT_HOLDER = new JsonElementTypeImpl(JsonObjectHolder.class); + public static final JsonElementType JSON_STRING = new JsonElementTypeImpl(String.class); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonLoaderImpl.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonLoaderImpl.java new file mode 100644 index 00000000..a7148792 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonLoaderImpl.java @@ -0,0 +1,14 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.json; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories.JsonReaderFactory; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json.JsonLoader; + +public class JsonLoaderImpl implements JsonLoader { + private InputStream inputStream; + void loadJson(InputStream inputStream) { + this.inputStream = inputStream; + } + JsonReaderFactory getJsonReaderFactory() { + return new JsonReaderImplFactory(inputStream); + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonObjectAccessorImpl.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonObjectAccessorImpl.java new file mode 100644 index 00000000..29e84294 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonObjectAccessorImpl.java @@ -0,0 +1,19 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.json; + +import org.json.JsonObject; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json.JsonObjectAccessor; + +public class JsonObjectAccessorImpl implements JsonObjectAccessor { + private final JsonObject jsonObject; + + public JsonObjectAccessorImpl(JsonObject jsonObject) { + this.jsonObject = jsonObject; + } + + public JsonObjectHasKeyVerifier getHasKeyVerifier(JsonObjectKey jsonObjectKey) { + return new JsonObjectHasKeyVerifierImpl(jsonObject, jsonObjectKey); + } + public JsonObjectKeyReader getKeyReader(JsonObjectKey jsonObjectKey) { + return new JsonObjectKeyReaderImpl(jsonObject, jsonObjectKey); + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonObjectHasKeyVerifierImpl.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonObjectHasKeyVerifierImpl.java new file mode 100644 index 00000000..aba8a4a5 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonObjectHasKeyVerifierImpl.java @@ -0,0 +1,29 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.data.BooleanResult; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.stream.StandardPipeline; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json.JsonObjectHasKeyVerifier; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.Pipeline; +import java.util.Map.Entry; +import java.util.Set; +import org.json.JsonObject; + +public class JsonObjectHasKeyVerifierImpl implements JsonObjectHasKeyVerifier { + private final JsonObject jsonObject; + private final JsonObjectKey jsonObjectKey; + + public JsonObjectHasKeyVerifierImpl(JsonObject jsonObject, JsonObjectKey jsonObjectKey) { + this.jsonObject = jsonObject; + this.jsonObjectKey = jsonObjectKey; + } + + public BooleanResult verifyJsonObjectHasKey() { + Pipeline jsonObjectHasKeyPipeline = StandardPipeline + .of(JsonObject::entrySet) + .next(Set::stream) + .next(FunctionBindAdapter.bindSecond(Stream::map, Entry::getKey)) + .next(FunctionBindAdapter.bindSecond(BooleanResult.from(Stream::anyMatch), JsonObjectKey::nameIs)); + BooleanResult booleanResult = jsonObjectHasKeyPipeline.run(this.jsonObjectKey); + return booleanResult; + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonObjectHolderImpl.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonObjectHolderImpl.java new file mode 100644 index 00000000..ae7ae0e9 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonObjectHolderImpl.java @@ -0,0 +1,17 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.json; + +import org.json.JsonObject; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json.JsonObjectHolder; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json.JsonObjectAccessor; + +public class JsonObjectHolderImpl implements JsonObjectHolder { + private final JsonObject jsonObject; + + public JsonObjectHolderImpl(JsonObject jsonObject) { + this.jsonObject = jsonObject; + } + + public JsonObjectAccessor getJsonObjectAccessor() { + return new JsonObjectAccessor(this.jsonObject); + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonObjectKeyImpl.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonObjectKeyImpl.java new file mode 100644 index 00000000..57916f6b --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonObjectKeyImpl.java @@ -0,0 +1,25 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.json; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json.JsonObjectKey; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.ObjectEqualityComparator; + +public class JsonObjectKeyImpl implements JsonObjectKey { + private final String name; + public JsonObjectKeyImpl(String name) { + this.name = name; + } + + public String getKey() { + return this.name; + } + public boolean nameIs(String string) { + BooleanResult booleanResult = ObjectEqualityComparator.compareObjects(this.getKey(), string); + if (booleanResult == BooleanResult.TRUE) { + return true; + } else if (booleanResult == BooleanResult.FALSE) { + return false; + } else { + throw Constants.THE_OBJECTS_COULD_NOT_BE_COMPARED.apply(Language.DEFAULT).createException(); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonObjectKeyReaderImpl.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonObjectKeyReaderImpl.java new file mode 100644 index 00000000..a297e486 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonObjectKeyReaderImpl.java @@ -0,0 +1,32 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.json; + +import org.json.JsonObject; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json.JsonObjectKey; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json.JsonObjectKeyReader; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json.JsonElementHolder; + +public class JsonObjectKeyReaderImpl implements JsonObjectKeyReader { + private final JsonObject jsonObject; + private final JsonObjectKey jsonObjectKey; + + private static final JsonObjectHolderFactory jsonObjectHolderFactory = new JsonObjectHolderImplFactory(); + + public JsonObjectKeyReaderImpl(JsonObject jsonObject, JsonObjectKey jsonObjectKey) { + this.jsonObject = jsonObject; + this.jsonObjectKey = jsonObjectKey; + } + + public JsonElementHolder readKey() { + String jsonObjectKeyName = this.jsonObjectKey.getName(); + Object value = this.jsonObject.get(jsonObjectKeyName); + if (value instanceof JsonObject jsonObjectValue) return new JsonElementHolder( + jsonObjectHolderFactory.createJsonObjectHolder(jsonObjectValue), + JsonElementTypeImpl.JSON_OBJECT_HOLDER + ); + if (value instanceof String stringValue) return new JsonElementHolder( + stringValue, JsonElementTypeImpl.JSON_STRING + ); + return (JsonElementHolder) Constants.NULL_VALUE(); + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonReaderImpl.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonReaderImpl.java new file mode 100644 index 00000000..c8e4787a --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/json/JsonReaderImpl.java @@ -0,0 +1,33 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.json; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.StandardPipeline; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.Pipeline; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json.JsonReader; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.stream.Collectors; + +public class JsonReaderImpl implements JsonReader { + private static final JsonObjectHolderFactory jsonObjectHolderFactory = new JsonObjectHolderFactoryImpl(); + private final InputStream inputStream; + public JsonReaderImpl(InputStream inputStream) { + this.inputStream = inputStream + } + + public JsonObjectHolder readJson() { + final String systemDefaultNewLineString = System.getProperty(com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants.LINE_SEPARATOR); + Pipeline inputStreamStringifier = StandardPipeline + .of(is -> new InputStreamReader(is, StandardCharsets.UTF_8)) + .next(BufferedReader::new) + .next(BufferedReader::lines) + .next(l -> l.collect(Collectors.joining(systemDefaultNewLineString))); + String text = inputStreamStringifier.run(this.inputStream); + JsonTokener jsonTokener = new JsonTokener(text); + JsonParserConfiguration jsonParserConfiguration = new JsonParserConfiguration(); + JsonObject jsonObject = new JsonObject(jsonTokener, jsonParserConfiguration); + JsonObjectHolder jsonObjectHolder = this.jsonObjectHolderFactory.createJsonObjectHolder(jsonObject); + return jsonObjectHolder; + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/lang/English.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/lang/English.java new file mode 100644 index 00000000..22b2c68a --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/lang/English.java @@ -0,0 +1,26 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.lang; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.lang.Language; +import java.io.ByteArrayInputStream; + +public class English implements Language { + private static final String LANGUAGE_KEY = "en_us"; + public static final English ENGLISH = new English(); + TranslationDataFactory translationDataFactory = new TranslationDataImplFactory(); + + private English() {} + + public String getStringForTranslationKey(TranslationKey key) { + TranslationData translationData = translationDataFactory.createTranslationData(English.ENGLISH); + TranslationKeyReader translationKeyReader = new TranslationKeyReaderImpl(key, translationData); + String value = translationKeyReader.readTranslationKey(); + if (ObjectEqualityComparator.compareObjects(jsonElementHolder.getElementType().getElementClass(), String.class) == BooleanResult.TRUE) { + return jsonElementHolder.getElementValue(); + } + return value; + } + + public String getLanguageKey() { + return English.LANGUAGE_KEY; + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/lang/translation/TranslationDataImpl.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/lang/translation/TranslationDataImpl.java new file mode 100644 index 00000000..72f80383 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/lang/translation/TranslationDataImpl.java @@ -0,0 +1,51 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.lang.translation; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.stream.Collectors; + +import org.json.JsonObject; +import org.json.JsonParserConfiguration; +import org.json.JsonTokener; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.FileContentReaderStrategy; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.lang.translation.TranslationData; + +public class TranslationDataImpl implements TranslationData { + private static final JsonObjectHolderFactory jsonObjectHolderFactory = new JsonObjectHolderImplFactory(); + private final Language language; + public TranslationDataImpl(Language language) { + this.language = language; + } + public JsonObjectHolder getTranslationDataHolder() { + String languageKey = this.language.getLanguageKey(); + FileContentReaderStrategy fileContentReaderStrategy = new FileContentReaderStrategy(); + InputStream inputStream = fileContentReaderStrategy.getFileContents(Constants.ASSETS_LANG + languageKey); + + JsonLoader jsonLoader = new JsonLoaderImpl(); + jsonLoader.loadJson(inputStream); + JsonReaderFactory jsonReaderFactory = jsonLoader.getJsonReaderFactory(); + JsonReader jsonReader = jsonReaderFactory.createJsonReader(); + JsonObjectHolder jsonObjectHolder = jsonReader.readJson(); + return jsonObjectHolder; + } + + public static JsonObjectHolder getDefaultTranslations(JsonObjectHolder jsonObjectHolder) { + JsonKeyReaderStrategy jsonKeyReaderStrategy = new JsonKeyReaderStrategyImpl(jsonObjectHolder); + JsonObjectKey jsonObjectKey_translations = new JsonObjectKeyImpl(Constants.TRANSLATIONS); + JsonElementHolder jsonElementHolder_translations = (JsonElementHolder) jsonKeyReaderStrategy.readJsonKey(jsonObjectKey_translations); + JsonObjectHolder jsonObjectHolder_translations; + if (jsonElementHolder_translations.getElementType().getElementClass() == JsonObjectHolder.class) jsonObjectHolder_translations = jsonElementHolder_translations.getElementValue(); + else return (JsonObjectHolder) Constants.NULL_VALUE(); + JsonKeyReaderStrategy jsonKeyReaderStrategy_translations = new JsonKeyReaderStrategyImpl(jsonObjectHolder_translations); + JsonObjectKey jsonObjectKey_default = new JsonObjectKeyImpl(Constants.DEFAULT); + JsonElementHolder jsonElementHolder_default = (JsonElementHolder) jsonKeyReaderStrategy_translations.readJsonKey(jsonObjectKey_default); + JsonObjectHolder jsonObjectHolder_default; + if (jsonElementHolder_default.getElementType().getElementClass() == JsonObjectHolder.class) jsonObjectHolder_default = jsonElementHolder_default.getElementValue(); + else return (JsonObjectHolder) Constants.NULL_VALUE(); + return jsonObjectHolder_default; + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/lang/translation/TranslationKeyImpl.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/lang/translation/TranslationKeyImpl.java new file mode 100644 index 00000000..496edfe0 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/lang/translation/TranslationKeyImpl.java @@ -0,0 +1,15 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.lang.translation; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.lang.translation.TranslationKey; + +public class TranslationKeyImpl implements TranslationKey { + private final String name; + + public TranslationKeyImpl(String name) { + this.name = name; + } + + public String getName() { + return this.name; + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/lang/translation/TranslationKeyReaderImpl.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/lang/translation/TranslationKeyReaderImpl.java new file mode 100644 index 00000000..557a2dc8 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/lang/translation/TranslationKeyReaderImpl.java @@ -0,0 +1,25 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.lang.translation; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.lang.translation.TranslationKeyReader; + +public class TranslationKeyReaderImpl implements TranslationKeyReader { + private final TranslationData translationData; + private final TranslationKey translationKey; + + public TranslationKeyReaderImpl(TranslationData translationData, TranslationKey translationKey) { + this.translationData = translationData; + this.translationKey = translationKey; + } + + public String readTranslationKey() { + String name = this.translationKey.getName(); + JsonObjectKey jsonObjectKey = new JsonObjectKeyImpl(name); + JsonObjectHolder jsonObjectHolder = translationData.getTranslationDataHolder(); + JsonKeyReaderStrategy jsonKeyReaderStrategy = new JsonKeyReaderStrategyImpl(jsonObjectHolder); + JsonElementHolder jsonElementHolder = jsonKeyReaderStrategy.readJsonKey(jsonObjectKey); + String value; + if (jsonElementHolder.getElementType().getElementClass() == String.class) value = jsonElementHolder.getElementValue(); + else return (String) Constants.NULL_VALUE(); + return value; + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopCondition.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopCondition.java deleted file mode 100644 index 0cdadafb..00000000 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopCondition.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; - -import org.springframework.stereotype.Service; - -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.integercomparator.ThreeWayIntegerComparator; -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.integercomparator.ThreeWayIntegerComparisonResult; - -/** - * LoopCondition - */ -@Service -public class LoopCondition { - - /** - * @param nCurrentNumber int - * @param nTotalCount int - * @return boolean - */ - public boolean evaluateLoop(final int nCurrentNumber, final int nTotalCount) { - final ThreeWayIntegerComparisonResult comparisonResult = ThreeWayIntegerComparator.Compare(nCurrentNumber, - nTotalCount); - if (ThreeWayIntegerComparisonResult.FirstIsLessThanSecond == comparisonResult) { - return true; - } else if (ThreeWayIntegerComparisonResult.FirstEqualsSecond == comparisonResult) { - return true; - } else { - return false; - } - } - -} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopContext.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopContext.java deleted file mode 100644 index 1dff6ba4..00000000 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopContext.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; - -import org.springframework.context.ApplicationContext; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories.LoopComponentFactory; -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateManipulation; -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; - -/** - * LoopContext - */ -public final class LoopContext implements LoopContextStateManipulation, LoopContextStateRetrieval { - private final LoopState myLoopState; - - /** - * @param nLoopControlParameterFinalValue int - */ - public LoopContext(final int nLoopControlParameterFinalValue) { - super(); - this.myLoopState = new LoopState(); - } - - /** - * @return void - */ - @Override - public void start() { - this.myCurrentControlParameterValue = - this.myLoopInitializer.getLoopInitializationPoint(); - } - - /** - * @return boolean - */ - @Override - public boolean shouldProceed() { - return this.myLoopCondition.evaluateLoop(this.myCurrentControlParameterValue, - this.myLoopFinalizer.getLoopFinalizationPoint()); - } - - /** - * @return void - */ - @Override - public void proceed() { - this.myCurrentControlParameterValue = - this.myLoopStep.stepLoop(this.myCurrentControlParameterValue); - } - - /** - * @return int - */ - @Override - public int getControlParameter() { - return this.myCurrentControlParameterValue; - } - -} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopFinalizer.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopFinalizer.java deleted file mode 100644 index 2f104333..00000000 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopFinalizer.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; - -/** - * LoopFinalizer - */ -public final class LoopFinalizer { - - private final int nStoredLoopFinalValue; - - /** - * @param nLoopFinalValue int - */ - public LoopFinalizer(final int nLoopFinalValue) { - super(); - this.nStoredLoopFinalValue = nLoopFinalValue; - } - - /** - * @return int - */ - public int getLoopFinalizationPoint() { - return this.nStoredLoopFinalValue; - } - -} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopInitializer.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopInitializer.java deleted file mode 100644 index 2304800e..00000000 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopInitializer.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; - -import org.springframework.stereotype.Service; - -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; - -/** - * LoopInitializer - */ -@Service -public class LoopInitializer { - - /** - * @return int - */ - public int getLoopInitializationPoint() { - return Constants.LOOP_INIT_VALUE; - } - -} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopRunner.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopRunner.java deleted file mode 100644 index da29e3dc..00000000 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopRunner.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; - -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateManipulation; -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopPayloadExecution; - -/** - * LoopRunner - */ -public final class LoopRunner { - - private final LoopContextStateManipulation myStateManipulation; - private final LoopContextStateRetrieval myStateRetrieval; - private final LoopPayloadExecution myPayload; - - /** - * @param stateManipulation LoopContextStateManipulation - * @param stateRetrieval LoopContextStateRetrieval - * @param payload LoopPayloadExecution - */ - public LoopRunner(final LoopContextStateManipulation stateManipulation, - final LoopContextStateRetrieval stateRetrieval, final LoopPayloadExecution payload) { - super(); - this.myStateManipulation = stateManipulation; - this.myStateRetrieval = stateRetrieval; - this.myPayload = payload; - } - - /** - * @return - */ - public void runLoop() { - for (this.myStateManipulation.start(); this.myStateManipulation.shouldProceed(); this.myStateManipulation.proceed()) { - this.myPayload.runLoopPayload(this.myStateRetrieval); - } - } - -} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopState.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopState.java deleted file mode 100644 index 6ad7bde2..00000000 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopState.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; - -import org.springframework.context.ApplicationContext; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories.LoopComponentFactory; -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateManipulation; -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; - -/** - * LoopState - */ -public class LoopState { - private final LoopInitializer myLoopInitializer; - private final LoopFinalizer myLoopFinalizer; - private final LoopCondition myLoopCondition; - private final LoopStep myLoopStep; - private int myCurrentControlParameterValue; - - public LoopState(final int nLoopControlParameterFinalValue) { - final ApplicationContext context = new ClassPathXmlApplicationContext(Constants.SPRING_XML); - final LoopComponentFactory myLoopComponentFactory = context.getBean(Constants.LOOP_COMPONENT_FACTORY, - LoopComponentFactory.class); - this.myLoopInitializer = myLoopComponentFactory.createLoopInitializer(); - this.myLoopFinalizer = myLoopComponentFactory.createLoopFinalizer(nLoopControlParameterFinalValue); - this.myLoopCondition = myLoopComponentFactory.createLoopCondition(); - this.myLoopStep = myLoopComponentFactory.createLoopStep(); - ((ConfigurableApplicationContext) context).close(); - } -} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopStep.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopStep.java deleted file mode 100644 index ee3962cf..00000000 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/LoopStep.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; - -import org.springframework.stereotype.Service; - -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; - -/** - * LoopStep - */ -@Service -public class LoopStep { - - /** - * @param nCurrentNumber int - * @return int - */ - public int stepLoop(final int nCurrentNumber) { - return nCurrentNumber + Constants.LOOP_INC_VALUE; - } - -} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopCondition.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopCondition.java deleted file mode 100644 index 0cdadafb..00000000 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopCondition.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; - -import org.springframework.stereotype.Service; - -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.integercomparator.ThreeWayIntegerComparator; -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.integercomparator.ThreeWayIntegerComparisonResult; - -/** - * LoopCondition - */ -@Service -public class LoopCondition { - - /** - * @param nCurrentNumber int - * @param nTotalCount int - * @return boolean - */ - public boolean evaluateLoop(final int nCurrentNumber, final int nTotalCount) { - final ThreeWayIntegerComparisonResult comparisonResult = ThreeWayIntegerComparator.Compare(nCurrentNumber, - nTotalCount); - if (ThreeWayIntegerComparisonResult.FirstIsLessThanSecond == comparisonResult) { - return true; - } else if (ThreeWayIntegerComparisonResult.FirstEqualsSecond == comparisonResult) { - return true; - } else { - return false; - } - } - -} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopContext.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopContext.java deleted file mode 100644 index 1dff6ba4..00000000 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopContext.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; - -import org.springframework.context.ApplicationContext; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories.LoopComponentFactory; -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateManipulation; -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; - -/** - * LoopContext - */ -public final class LoopContext implements LoopContextStateManipulation, LoopContextStateRetrieval { - private final LoopState myLoopState; - - /** - * @param nLoopControlParameterFinalValue int - */ - public LoopContext(final int nLoopControlParameterFinalValue) { - super(); - this.myLoopState = new LoopState(); - } - - /** - * @return void - */ - @Override - public void start() { - this.myCurrentControlParameterValue = - this.myLoopInitializer.getLoopInitializationPoint(); - } - - /** - * @return boolean - */ - @Override - public boolean shouldProceed() { - return this.myLoopCondition.evaluateLoop(this.myCurrentControlParameterValue, - this.myLoopFinalizer.getLoopFinalizationPoint()); - } - - /** - * @return void - */ - @Override - public void proceed() { - this.myCurrentControlParameterValue = - this.myLoopStep.stepLoop(this.myCurrentControlParameterValue); - } - - /** - * @return int - */ - @Override - public int getControlParameter() { - return this.myCurrentControlParameterValue; - } - -} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopFinalizer.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopFinalizer.java deleted file mode 100644 index 2f104333..00000000 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopFinalizer.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; - -/** - * LoopFinalizer - */ -public final class LoopFinalizer { - - private final int nStoredLoopFinalValue; - - /** - * @param nLoopFinalValue int - */ - public LoopFinalizer(final int nLoopFinalValue) { - super(); - this.nStoredLoopFinalValue = nLoopFinalValue; - } - - /** - * @return int - */ - public int getLoopFinalizationPoint() { - return this.nStoredLoopFinalValue; - } - -} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopInitializer.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopInitializer.java deleted file mode 100644 index 2304800e..00000000 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopInitializer.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; - -import org.springframework.stereotype.Service; - -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; - -/** - * LoopInitializer - */ -@Service -public class LoopInitializer { - - /** - * @return int - */ - public int getLoopInitializationPoint() { - return Constants.LOOP_INIT_VALUE; - } - -} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopRunner.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopRunner.java deleted file mode 100644 index da29e3dc..00000000 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopRunner.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; - -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateManipulation; -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopPayloadExecution; - -/** - * LoopRunner - */ -public final class LoopRunner { - - private final LoopContextStateManipulation myStateManipulation; - private final LoopContextStateRetrieval myStateRetrieval; - private final LoopPayloadExecution myPayload; - - /** - * @param stateManipulation LoopContextStateManipulation - * @param stateRetrieval LoopContextStateRetrieval - * @param payload LoopPayloadExecution - */ - public LoopRunner(final LoopContextStateManipulation stateManipulation, - final LoopContextStateRetrieval stateRetrieval, final LoopPayloadExecution payload) { - super(); - this.myStateManipulation = stateManipulation; - this.myStateRetrieval = stateRetrieval; - this.myPayload = payload; - } - - /** - * @return - */ - public void runLoop() { - for (this.myStateManipulation.start(); this.myStateManipulation.shouldProceed(); this.myStateManipulation.proceed()) { - this.myPayload.runLoopPayload(this.myStateRetrieval); - } - } - -} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopState.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopState.java deleted file mode 100644 index 6ad7bde2..00000000 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopState.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; - -import org.springframework.context.ApplicationContext; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories.LoopComponentFactory; -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateManipulation; -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.loop.LoopContextStateRetrieval; - -/** - * LoopState - */ -public class LoopState { - private final LoopInitializer myLoopInitializer; - private final LoopFinalizer myLoopFinalizer; - private final LoopCondition myLoopCondition; - private final LoopStep myLoopStep; - private int myCurrentControlParameterValue; - - public LoopState(final int nLoopControlParameterFinalValue) { - final ApplicationContext context = new ClassPathXmlApplicationContext(Constants.SPRING_XML); - final LoopComponentFactory myLoopComponentFactory = context.getBean(Constants.LOOP_COMPONENT_FACTORY, - LoopComponentFactory.class); - this.myLoopInitializer = myLoopComponentFactory.createLoopInitializer(); - this.myLoopFinalizer = myLoopComponentFactory.createLoopFinalizer(nLoopControlParameterFinalValue); - this.myLoopCondition = myLoopComponentFactory.createLoopCondition(); - this.myLoopStep = myLoopComponentFactory.createLoopStep(); - ((ConfigurableApplicationContext) context).close(); - } -} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopStep.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopStep.java deleted file mode 100644 index ee3962cf..00000000 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop copy/count/LoopStep.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.loop; - -import org.springframework.stereotype.Service; - -import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; - -/** - * LoopStep - */ -@Service -public class LoopStep { - - /** - * @param nCurrentNumber int - * @return int - */ - public int stepLoop(final int nCurrentNumber) { - return nCurrentNumber + Constants.LOOP_INC_VALUE; - } - -} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopCondition.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopCondition.java index f51e68ff..79dbb1d8 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopCondition.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopCondition.java @@ -22,7 +22,7 @@ public boolean evaluateLoop(final LoopState loopState, final ConditionalLoopIsFi if (loopState instanceof ConditionalLoopState) { myConditionalLoopState = (ConditionalLoopState) loopState; } else { - throw new IllegalArgumentException(Constants.THE_WRONG_TYPE_OF_LOOP_STATE_WAS_PROVIDED); + throw Constants.THE_WRONG_TYPE_OF_LOOP_STATE_WAS_PROVIDED.apply(Language.DEFAULT).createException(); } boolean conditionalLoopIsFinished = conditionalLoopIsFinishedChecker.checkIfConditionalLoopIsFinished(loopState); if (conditionalLoopIsFinished == true) { @@ -30,7 +30,7 @@ public boolean evaluateLoop(final LoopState loopState, final ConditionalLoopIsFi } else if (conditionalLoopIsFinished == false) { return false; } else { - return new UnsupportedOperationException(Constants.COULD_NOT_DETERMINE_IF_THE_LOOP_WAS_FINISHED); + return Constants.COULD_NOT_DETERMINE_IF_THE_LOOP_WAS_FINISHED.apply(Language.DEFAULT).createException(); } } diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopContext.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopContext.java index 6bf0600d..d3890f37 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopContext.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopContext.java @@ -51,7 +51,7 @@ public void proceed() { */ @Override public int getControlParameter() { - throw new UnsupportedOperationException(Constants.A_CONDITIONAL_LOOP_HAS_NO_CONTROL_PARAMETER); + throw Constants.A_CONDITIONAL_LOOP_HAS_NO_CONTROL_PARAMETER.apply(Language.DEFAULT).createException(); } @Override diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopFinalizer.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopFinalizer.java index 132e5334..9093fdab 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopFinalizer.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopFinalizer.java @@ -9,6 +9,6 @@ public final class ConditionalLoopFinalizer implements LoopFinalizer { * @return int */ public int getLoopFinalizationPoint() { - throw new UnsupportedOperationException(Constants.A_CONDITIONAL_LOOP_HAS_NO_FINALIZATION_POINT); + throw Constants.A_CONDITIONAL_LOOP_HAS_NO_FINALIZATION_POINT.apply(Language.DEFAULT).createException(); } } diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopInitializer.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopInitializer.java index 8b7e741d..d664765e 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopInitializer.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopInitializer.java @@ -14,6 +14,6 @@ public class ConditionalLoopInitializer implements LoopInitializer { * @return int */ public int getLoopInitializationPoint() { - throw new UnsupportedOperationException(Constants.A_CONDITIONAL_LOOP_HAS_NO_INITIALIZATION_POINT); + throw Constants.A_CONDITIONAL_LOOP_HAS_NO_INITIALIZATION_POINT.apply(Language.DEFAULT).createException(); } } diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopRunner.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopRunner.java index 7c33518a..ff8f8d25 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopRunner.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/loop/conditional/ConditionalLoopRunner.java @@ -32,7 +32,7 @@ public ConditionalLoopRunner(final LoopContextStateManipulation stateManipulatio */ public void runLoop() { while (this.myStateManipulation.shouldProceed()) { - this.myPayload.runLoopPayload(Constants.NULL_VALUE); + this.myPayload.runLoopPayload(Constants.NULL_VALUE()); } } diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/math/arithmetics/IntegerDivider.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/math/arithmetics/IntegerDivider.java index 7230dfdb..61d3efbd 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/math/arithmetics/IntegerDivider.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/math/arithmetics/IntegerDivider.java @@ -40,7 +40,7 @@ public int divide(final int nFirstInteger, final int nSecondInteger) { final boolean denominatorEqualsZero = IntegerForEqualityComparator.areTwoIntegersEqual(nSecondInteger, Constants.INTEGER_DIVIDE_ZERO_VALUE); if (denominatorEqualsZero) { - throw new ArithmeticException(Constants.AN_ATTEMPT_WAS_MADE_TO_DIVIDE_BY_ZERO); + throw Constants.AN_ATTEMPT_WAS_MADE_TO_DIVIDE_BY_ZERO.apply(Language.DEFAULT).createException(); } else { final double dbFirstNumber = IntToDoubleConverter.Convert(nFirstInteger); final double dbSecondNumber = IntToDoubleConverter.Convert(nSecondInteger); diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/FileContentReaderStrategy.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/FileContentReaderStrategy.java new file mode 100644 index 00000000..d18046ae --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/FileContentReaderStrategy.java @@ -0,0 +1,33 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies; + +import java.io.File; +import java.io.FileReader; +import java.io.InputStream; +import java.io.IOException; + +import org.springframework.stereotype.Service; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.FileContentStrategy; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.adapters.ReaderToByteArrayInputStreamAdapter; + +/** + * Strategy for FileContentReader + */ +@Service +public class FileContentReaderStrategy implements FileContentStrategy { + + /** + * @param filename String + * @throws IOException + * @return InputStream + */ + @Override + public InputStream getFileContents(String filename) throws IOException { + ClassLoader classLoader = getClass().getClassLoader(); + File file = new File(classLoader.getResource(filename).getFile()); + FileReader fileReader = new FileReader(file); + ReaderToByteArrayInputStreamAdapter readerToByteArrayInputStreamAdapter = new ReaderToByteArrayInputStreamAdapter(fileReader); + InputStream inputStream = readerToByteArrayInputStreamAdapter.generateInputStream(); + return inputStream; + } +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/JsonKeyReaderStrategyImpl.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/JsonKeyReaderStrategyImpl.java new file mode 100644 index 00000000..cf206f83 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/JsonKeyReaderStrategyImpl.java @@ -0,0 +1,23 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.JsonKeyReaderStrategy; + +public class JsonKeyReaderStrategyImpl implements JsonKeyReaderStrategy { + private final JsonObjectHolder jsonObjectHolder; + + public JsonKeyReaderStrategyImpl(JsonObjectHolder jsonObjectHolder) { + this.jsonObjectHolder = jsonObjectHolder; + } + + public JsonElementHolder readJsonKey(JsonObjectKey key) { + JsonObjectAccessor jsonObjectAccessor = this.jsonObjectHolder.getJsonObjectAccessor(); + JsonObjectHasKeyVerifier jsonObjectHasKeyVerifier = jsonObjectAccessor.getHasKeyVerifier(key); + if (jsonObjectHasKeyVerifier.verifyJsonObjectHasKey() == BooleanResult.TRUE) { + JsonObjectKeyReader jsonObjectKeyReader = jsonObjectAccessor.getKeyReader(key); + JsonElementHolder jsonElementHolder = jsonObjectKeyReader.readKey(); + return jsonElementHolder; + } else { + throw Constants.KEY_NOT_FOUND.apply(Language.DEFAULT).createException(); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/OutputGenerationContextVisitorPayload.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/OutputGenerationContextVisitorPayload.java index 5236b514..f346f391 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/OutputGenerationContextVisitorPayload.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/OutputGenerationContextVisitorPayload.java @@ -1,5 +1,7 @@ package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies; +import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,7 +22,6 @@ public class OutputGenerationContextVisitorPayload implements LoopPayloadExecuti * @param _results ResultCollection * @param contextVisitor OutputGenerationContextVisitor */ - @Autowired public OutputGenerationContextVisitorPayload(final ResultCollection _results, final OutputGenerationContextVisitor contextVisitor) { super(); this._results = _results; @@ -34,7 +35,7 @@ public OutputGenerationContextVisitorPayload(final ResultCollection> resultsList = _results.getResults(); + List> resultsList = this._results.getResults(); OutputGenerationContext outputGenerationContext = resultsList.get(controlParameterValue); this.contextVisitor.visit(outputGenerationContext, controlParameterValue); } diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/SingleStepOutputGenerationStrategy.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/SingleStepOutputGenerationStrategy.java index 30c859f3..b2de762d 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/SingleStepOutputGenerationStrategy.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/SingleStepOutputGenerationStrategy.java @@ -69,15 +69,15 @@ public SingleStepOutputGenerationStrategy( public void performGenerationForCurrentStep(final SingleStepOutputGenerationParameter generationParameter) { final Iterator iterator = this.contexts.iterator(); final ResultCollectionFactory resultCollectionFactory = new ActionResultCollectionFactory<>(); - // switch to ConditionalLoop - while (iterator.hasNext()) { - final OutputGenerationContext context = iterator.next(); - this.contextVisitor.visit(context, nGenerationParameter); - } - // + // while (iterator.hasNext()) { + // final OutputGenerationContext context = iterator.next(); + // this.contextVisitor.visit(context, nGenerationParameter); + // } final ResultCollection results = resultCollectionFactory.createResultCollection(); final IteratorPayload iteratorPayload = new IteratorPayload<>(iterator, results); - //end + final OutputGenerationContextVisitorPayload outputGenerationContextVisitorPayload = new OutputGenerationContextVisitorPayload(); + generateResultCollection(iterator, iteratorPayload); + generateOutputFromResultCollection(outputGenerationContextVisitorPayload, results, this.contextVisitor); this.myNewLinePrinter.print(); } @@ -87,8 +87,7 @@ private void generateResultCollection(Iterator iterator loopRunner.runLoop(); } - private void generateOutputFromResultCollection(ResultCollection results, final OutputGenerationContextVisitor contextVisitor, final SingleStepOutputGenerationParameter nGenerationParameter) { - final OutputGenerationContextVisitorPayload outputGenerationContextVisitorPayload = new OutputGenerationContextVisitorPayload(); + private void generateOutputFromResultCollection(final OutputGenerationContextVisitorPayload outputGenerationContextVisitorPayload, ResultCollection results, OutputGenerationContextVisitor contextVisitor) { final CountBasedLoopContext loopContext = new CountBasedLoopContext(results.size()); final CountBasedLoopRunner loopRunner = new CountBasedLoopRunner(loopContext, loopContext, outputGenerationContextVisitorPayload); loopRunner.runLoop(); diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/adapters/FunctionBindAdapter.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/adapters/FunctionBindAdapter.java new file mode 100644 index 00000000..46db739e --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/adapters/FunctionBindAdapter.java @@ -0,0 +1,13 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.adapters; + +public class FunctionBindAdapter { + private FunctionBindAdapter() {} + + public static Function bindFirst(BiFunction biFunction, T t) { + return u -> biFunction.apply(t, u); + } + + public static Function bindSecond(BiFunction biFunction, U u) { + return t -> biFunction.apply(u, t); + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/adapters/ReaderToByteArrayInputStreamAdapter.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/adapters/ReaderToByteArrayInputStreamAdapter.java new file mode 100644 index 00000000..bbf7e405 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/adapters/ReaderToByteArrayInputStreamAdapter.java @@ -0,0 +1,39 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.adapters; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.FizzBuzzOutputStrategy; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.FizzBuzzExceptionSafeOutputStrategy; +import java.io.InputStream; + +/** + * Adapter for ReaderToByteInputStream + */ +public final class ReaderToByteArrayInputStreamAdapter implements InputStreamGenerationStrategy { + private final Reader _reader; + + /** + * @param reader Reader + */ + public ReaderToByteArrayInputStreamAdapter(final Reader reader) { + this._reader = reader; + } + + /** + * @return InputStream + */ + @Override + public InputStream generateInputStream() throws IOException { + Reader reader = this._reader; + + char[] charBuffer = new char[8 * 1024]; + StringBuilder builder = new StringBuilder(); + int numCharsRead; + + while ((numCharsRead = reader.read(charBuffer, 0, charBuffer.length)) != -1) { + builder.append(charBuffer, 0, numCharsRead); + } + InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes(StandardCharsets.UTF_8)); + + reader.close(); + return inputStream; + } +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/comparators/ObjectEqualityComparator.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/comparators/ObjectEqualityComparator.java new file mode 100644 index 00000000..6e4b292e --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/comparators/ObjectEqualityComparator.java @@ -0,0 +1,28 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators; + +import org.springframework.stereotype.Service; + +/** + * Comparator for ObjectEquality + */ +@Service +public final class ObjectEqualityComparator { + + private ObjectEqualityComparator() {} + + /** + * @param firstObject + * @param secondObject + * @return boolean + */ + public static BooleanResult compareObjects(final Object firstObject, final Object secondObject) { + final boolean objectsAreEqual = Object.equals(firstObject, secondObject); + if (objectsAreEqual == true) { + return BooleanResult.TRUE; + } else if (objectsAreEqual == false) { + return BooleanResult.FALSE; + } else { + return (BooleanResult) Constants.NULL_VALUE(); + } + } +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/comparators/integercomparator/ThreeWayIntegerComparator.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/comparators/integercomparator/ThreeWayIntegerComparator.java index c24032d0..a2b63544 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/comparators/integercomparator/ThreeWayIntegerComparator.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/comparators/integercomparator/ThreeWayIntegerComparator.java @@ -26,7 +26,7 @@ public static ThreeWayIntegerComparisonResult Compare(final int nFirstInteger, f return ThreeWayIntegerComparisonResult.FirstIsGreaterThanSecond; } else { // If the integers cannot be compared, then something is seriously wrong with the numbers. - throw new UnsupportedOperationException(Constants.THE_INTEGERS_COULD_NOT_BE_COMPARED); + throw Constants.THE_INTEGERS_COULD_NOT_BE_COMPARED.apply(Language.DEFAULT).createException(); } } diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/stream/AbstractPipeline.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/stream/AbstractPipeline.java new file mode 100644 index 00000000..e1bd4bb8 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/stream/AbstractPipeline.java @@ -0,0 +1,16 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.stream; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.Pipeline; + +public abstract class MergedPipeline implements Pipeline { + AbstractPipeline() { + } + + public Pipeline next(Pipeline nextPipeline) { + return new MergedPipeline<>(this, nextPipeline); + } + public abstract R run(T value); + public Stream run(Stream valueStream) { + return valueStream.map(this::run); + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/stream/ActionPipeline.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/stream/ActionPipeline.java new file mode 100644 index 00000000..d7f8fe3d --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/stream/ActionPipeline.java @@ -0,0 +1,19 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.stream; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.Pipeline; + +public class ActionPipeline implements Pipeline { + private final Consumer consumer; + ActionPipeline(Consumer consumer) { + this.consumer = consumer; + } + + public static Pipeline of(Consumer consumer) { + return new ActionPipeline<>(consumer); + } + + public R run(T value) { + this.consumer.accept(value); + return value; + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/stream/MergedPipeline.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/stream/MergedPipeline.java new file mode 100644 index 00000000..f4ae6a12 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/stream/MergedPipeline.java @@ -0,0 +1,18 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.stream; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.Pipeline; + +public class MergedPipeline extends AbstractPipeline { + private final Pipeline first; + private final Pipeline second; + MergedPipeline(Pipeline first, Pipeline second) { + this.first = first; + this.second = second; + } + + public R run(T value) { + U next = first.run(value); + R last = second.run(next); + return last; + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/stream/StandardPipeline.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/stream/StandardPipeline.java new file mode 100644 index 00000000..77699fa5 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/stream/StandardPipeline.java @@ -0,0 +1,19 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.stream; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.Pipeline; + +public class StandardPipeline extends AbstractPipeline { + private final Function function; + private StandardPipeline(Function function) { + this.function = function; + } + + public static Pipeline of(Function function) { + return new StandardPipeline<>(function); + } + + public R run(T value) { + R result = this.function.apply(value); + return result; + } +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/stringreturners/BuzzStringReturner.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/stringreturners/BuzzStringReturner.java index d54464f3..297380c7 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/stringreturners/BuzzStringReturner.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/stringreturners/BuzzStringReturner.java @@ -15,7 +15,7 @@ public class BuzzStringReturner implements StringStringReturner { */ public String getReturnString() { final StringBuilder myStringBuilder = new StringBuilder( - com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants.BUZZ); + com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants.BUZZ.apply(Language.DEFAULT)); final String myString = myStringBuilder.toString(); return new String(myString); } diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/stringreturners/FizzStringReturner.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/stringreturners/FizzStringReturner.java index 92648612..07d71cc9 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/stringreturners/FizzStringReturner.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/stringreturners/FizzStringReturner.java @@ -14,8 +14,7 @@ public class FizzStringReturner implements StringStringReturner { * @return String */ public String getReturnString() { - final StringBuilder myStringBuilder = new StringBuilder( - com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants.FIZZ); + final StringBuilder myStringBuilder = new StringBuilder(com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants.FIZZ.apply(Language.DEFAULT)); final String myString = myStringBuilder.toString(); final char[] myCharacters = myString.toCharArray(); return new String(myCharacters, 0, myCharacters.length); diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/data/Component.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/data/Component.java new file mode 100644 index 00000000..4780f254 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/data/Component.java @@ -0,0 +1,5 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.data; + +public interface Component { + public String resolve(); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/ExceptionType.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/ExceptionType.java new file mode 100644 index 00000000..3cccd193 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/ExceptionType.java @@ -0,0 +1,11 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories; + +/** + * ExceptionType + */ +public interface ExceptionType { + /** + * @return FizzBuzzOutputStrategy + */ + public Exception createException(); +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/FileContentStrategyFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/FileContentStrategyFactory.java new file mode 100644 index 00000000..cc2d1e22 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/FileContentStrategyFactory.java @@ -0,0 +1,16 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.factories; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.FileContentStrategy; + +/** + * Factory for FileContentStrategy + */ +@Service +public interface FileContentStrategyFactory { + /** + * @return FileContentStrategy + */ + public FileContentStrategy createFileContentStrategy() { + return this._fileContentReaderStrategy; + } +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/JsonObjectHolderFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/JsonObjectHolderFactory.java index d8ece1af..3ab19458 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/JsonObjectHolderFactory.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/JsonObjectHolderFactory.java @@ -3,6 +3,5 @@ import org.json.JsonObject; public interface JsonObjectHolderFactory { - void initialize(JsonObject object); - JsonObjectHolder createJsonObjectHolder(); + JsonObjectHolder createJsonObjectHolder(JsonObject jsonObject); } \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/TranslationDataFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/TranslationDataFactory.java new file mode 100644 index 00000000..94b3c29f --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/TranslationDataFactory.java @@ -0,0 +1,15 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.lang.translation.TranslationData; + +/** + * Factory for TranslationData + */ +public interface TranslationDataFactory { + + /** + * @return TranslationData + */ + public TranslationData createTranslationData(Language language); + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/TranslationKeyFactory.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/TranslationKeyFactory.java new file mode 100644 index 00000000..080f9777 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/factories/TranslationKeyFactory.java @@ -0,0 +1,15 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.lang.translation.TranslationKey; + +/** + * Factory for TranslationKey + */ +public interface TranslationKeyFactory { + + /** + * @return TranslationKey + */ + public TranslationKey createTranslationKey(String string); + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/Generator.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/Generator.java deleted file mode 100644 index 9a7c9ff0..00000000 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/Generator.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.generators; - -public interface Generator { - public T get(); -} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/GeneratorList.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/GeneratorList.java deleted file mode 100644 index 0071c5fd..00000000 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/GeneratorList.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.generators; - -public interface GeneratorList> extends List { - public List getList(); - -} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/GeneratorListGenerator.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/GeneratorListGenerator.java deleted file mode 100644 index 2ab57b57..00000000 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/GeneratorListGenerator.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.generators; - -public interface GeneratorListGenerator, L extends GeneratorList> extends ListGenerator { - public L get(); -} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/IntegerGenerator.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/IntegerGenerator.java deleted file mode 100644 index 29d49fc0..00000000 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/IntegerGenerator.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.generators; - -public interface IntegerGenerator extends Generator { - public T get(); - public int getAsInt(); -} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/ListGenerator,java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/ListGenerator,java deleted file mode 100644 index c26878c8..00000000 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/ListGenerator,java +++ /dev/null @@ -1,5 +0,0 @@ -package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.generators; - -public interface ListGenerator> extends Generator { - public L get(); -} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/StringGenerator.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/StringGenerator.java deleted file mode 100644 index 71127f30..00000000 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/generators/StringGenerator.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.generators; - -public interface StringGenerator extends Generator { - public T get(); -} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonElementHolder.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonElementHolder.java index dfaffa05..b0cee391 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonElementHolder.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonElementHolder.java @@ -1,6 +1,6 @@ package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json; public interface JsonElementHolder { - E getElement(); - JsonElementType getType(); + E getElementValue(); + JsonElementType getElementType(); } \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonElementType.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonElementType.java index 8c935010..d0346fd6 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonElementType.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonElementType.java @@ -1,5 +1,5 @@ package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json; public interface JsonElementType { - Class getClass(); + Class getElementClass(); } \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonLoader.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonLoader.java index 09de294b..6801548f 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonLoader.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonLoader.java @@ -3,6 +3,6 @@ import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories.JsonReaderFactory; public interface JsonLoader { - void loadJson(ByteArrayInputStream stream); + void loadJson(InputStream inputStream); JsonReaderFactory getJsonReaderFactory(); } \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectKey.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectKey.java index e69de29b..b573681d 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectKey.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonObjectKey.java @@ -0,0 +1,6 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json; + +public interface JsonObjectKey { + String getKey(); + boolean nameIs(); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonReader.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonReader.java index d5c11ed8..d1ae6e21 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonReader.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/json/JsonReader.java @@ -1,8 +1,7 @@ package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.json; -import org.json.JsonObject; -import java.io.ByteBuffer; +import java.io.InputStream; public interface JsonReader { - JsonObject readJson(); + JsonObjectHolder readJson(); } \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/Language.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/Language.java index f7351053..e0079e2e 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/Language.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/Language.java @@ -1,6 +1,9 @@ -package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.lang.translation; +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.lang; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.lang.English; public interface Language { - TranslationKey getNameTranslationKey(); + public static final Language DEFAULT = English.ENGLISH; String getStringForTranslationKey(TranslationKey key); + String getLanguageKey(); } \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/translation/TranslationData.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/translation/TranslationData.java new file mode 100644 index 00000000..b277bef5 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/translation/TranslationData.java @@ -0,0 +1,5 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.lang.translation; + +public interface TranslationData { + JsonObjectHolder getTranslationDataHolder(); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/translation/TranslationKey.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/translation/TranslationKey.java index 45356329..c07e7114 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/translation/TranslationKey.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/translation/TranslationKey.java @@ -1,5 +1,5 @@ package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.lang.translation; public interface TranslationKey { - + String getName(); } \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/translation/TranslationKeyReader.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/translation/TranslationKeyReader.java new file mode 100644 index 00000000..06d84df2 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/lang/translation/TranslationKeyReader.java @@ -0,0 +1,5 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.lang.translation; + +public interface TranslationKeyReader { + String readTranslationKey(); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/strategies/FileContentStrategy.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/strategies/FileContentStrategy.java new file mode 100644 index 00000000..72fe41e3 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/strategies/FileContentStrategy.java @@ -0,0 +1,13 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies; + +import java.io.IOException; +import java.io.InputStream; + +public interface FileContentStrategy { + /** + * @param filename String + * @throws IOException + * @return InputStream + */ + public InputStream getFileContents(String filename) throws IOException; +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/strategies/InputStreamGenerationStrategy.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/strategies/InputStreamGenerationStrategy.java new file mode 100644 index 00000000..322bffa4 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/strategies/InputStreamGenerationStrategy.java @@ -0,0 +1,16 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies; + +import java.io.InputStream; + +/** + * Strategy for InputStreamGeneration + */ +public interface InputStreamGenerationStrategy { + + /** + * @param value + * @return InputStream + */ + public InputStream generateInputStream(); + +} diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/strategies/JsonKeyReaderStrategy.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/strategies/JsonKeyReaderStrategy.java new file mode 100644 index 00000000..7da8cc8e --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/strategies/JsonKeyReaderStrategy.java @@ -0,0 +1,5 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies; + +public interface JsonKeyReaderStrategy { + public String readJsonKey(JsonObjectKey key); +} \ No newline at end of file diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/strategies/Pipeline.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/strategies/Pipeline.java new file mode 100644 index 00000000..f5503bb7 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/interfaces/strategies/Pipeline.java @@ -0,0 +1,7 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies; + +public interface Pipeline { + public Pipeline next(Pipeline nextPipeline); + public R run(T value); + public Stream run(Stream valueStream); +} \ No newline at end of file diff --git a/src/main/resources/assets/lang/en_us.json b/src/main/resources/assets/lang/en_us.json new file mode 100644 index 00000000..a87cbff7 --- /dev/null +++ b/src/main/resources/assets/lang/en_us.json @@ -0,0 +1,17 @@ +{ + "translations": { + "default": { + "fizzbuzz.string.error.A_CONDITIONAL_LOOP_HAS_NO_CONTROL_PARAMETER": "A conditional loop has no control parameter.", + "fizzbuzz.string.error.A_CONDITIONAL_LOOP_HAS_NO_FINALIZATION_POINT": "A conditional loop has no finalization point.", + "fizzbuzz.string.error.A_CONDITIONAL_LOOP_HAS_NO_INITIALIZATION_POINT": "A conditional loop has no initialization point.", + "fizzbuzz.string.error.AN_ATTEMPT_WAS_MADE_TO_DIVIDE_BY_ZERO": "An attempt was made to divide by zero.", + "fizzbuzz.string.error.COULD_NOT_DETERMINE_IF_THE_LOOP_WAS_FINISHED": "Could not determine if the loop was finished.", + "fizzbuzz.string.error.KEY_NOT_FOUND": "Key not found.", + "fizzbuzz.string.error.THE_INTEGERS_COULD_NOT_BE_COMPARED": "The integers could not be compared.", + "fizzbuzz.string.error.THE_OBJECTS_COULD_NOT_BE_COMPARED": "The objects could not be compared.", + "fizzbuzz.string.error.THE_WRONG_TYPE_OF_LOOP_STATE_WAS_PROVIDED": "The wrong type of loop state was provided.", + "fizzbuzz.string.output.buzz": "Buzz", + "fizzbuzz.string.output.fizz": "Fizz" + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/values/numbers.properties b/src/main/resources/assets/values/numbers.properties new file mode 100644 index 00000000..af46be11 --- /dev/null +++ b/src/main/resources/assets/values/numbers.properties @@ -0,0 +1,11 @@ +## Numbers Properties ## +# Default Fizz Buzz upper limit parameter value +default_fizz_buzz_upper_limit_parameter_value=100 +# Integer divide zero value +integer_divide_zero_value=0 +# Integer origin zero value +integer_origin_zero_value=0 +# Loop inc value +loop_inc_value=1 +# Loop init value +loop_init_value=1 \ No newline at end of file From 00a5af4e53fc02879b2c4f634edc85eb0ebdaa42 Mon Sep 17 00:00:00 2001 From: SuperYoshi10000 <148275327+SuperYoshi10000@users.noreply.github.com> Date: Wed, 8 May 2024 09:05:47 -0400 Subject: [PATCH 3/5] Update tests --- src/test/java/FizzBuzzTest.java | 8 +- src/test/java/TestConstants.java | 85 ++++++++++++------- .../resources/values/test-numbers.properties | 33 +++++++ 3 files changed, 95 insertions(+), 31 deletions(-) create mode 100644 src/test/resources/values/test-numbers.properties diff --git a/src/test/java/FizzBuzzTest.java b/src/test/java/FizzBuzzTest.java index 73ab761c..a4617f18 100644 --- a/src/test/java/FizzBuzzTest.java +++ b/src/test/java/FizzBuzzTest.java @@ -13,6 +13,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.FizzBuzz; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.lang.Language; /** * Tests for FizzBuzz @@ -54,7 +55,12 @@ private void doFizzBuzz(final int n, final String s) throws IOException { this.fb.fizzBuzz(n); System.out.flush(); - String platformDependentExpectedResult = s.replaceAll("\\n", System.getProperty("line.separator")); + String platformDependentExpectedResult = s + .replaceAll("\\n", System.getProperty(TestConstants.LINE_SEPARATOR)) + .formatted( + com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants.FIZZ.apply(Language.DEFAULT), + com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants.BUZZ.apply(Language.DEFAULT) + ); assertEquals(platformDependentExpectedResult, baos.toString()); } diff --git a/src/test/java/TestConstants.java b/src/test/java/TestConstants.java index 6b8c5883..cc8512fb 100644 --- a/src/test/java/TestConstants.java +++ b/src/test/java/TestConstants.java @@ -7,39 +7,64 @@ private TestConstants() { super(); } - static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13_14_FIZZ_BUZZ_16 = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz\n16\n"; - static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13_14_FIZZ_BUZZ = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz\n"; - static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13_14 = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\n"; - static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13 = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n"; - static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n"; - static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11 = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\n"; - static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n"; - static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\n"; - static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8 = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\n"; - static final String _1_2_FIZZ_4_BUZZ_FIZZ_7 = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n"; - static final String _1_2_FIZZ_4_BUZZ_FIZZ = "1\n2\nFizz\n4\nBuzz\nFizz\n"; - static final String _1_2_FIZZ_4_BUZZ = "1\n2\nFizz\n4\nBuzz\n"; - static final String _1_2_FIZZ_4 = "1\n2\nFizz\n4\n"; - static final String _1_2_FIZZ = "1\n2\nFizz\n"; + static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13_14_FIZZ_BUZZ_16 = "1\n2\n%1$s\n4\n%2$s\n%1$s\n7\n8\n%1$s\n%2$s\n11\n%1$s\n13\n14\n%1$s%2$s\n16\n"; + static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13_14_FIZZ_BUZZ = "1\n2\n%1$s\n4\n%2$s\n%1$s\n7\n8\n%1$s\n%2$s\n11\n%1$s\n13\n14\n%1$s%2$s\n"; + static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13_14 = "1\n2\n%1$s\n4\n%2$s\n%1$s\n7\n8\n%1$s\n%2$s\n11\n%1$s\n13\n14\n"; + static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ_13 = "1\n2\n%1$s\n4\n%2$s\n%1$s\n7\n8\n%1$s\n%2$s\n11\n%1$s\n13\n"; + static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11_FIZZ = "1\n2\n%1$s\n4\n%2$s\n%1$s\n7\n8\n%1$s\n%2$s\n11\n%1$s\n"; + static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ_11 = "1\n2\n%1$s\n4\n%2$s\n%1$s\n7\n8\n%1$s\n%2$s\n11\n"; + static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ_BUZZ = "1\n2\n%1$s\n4\n%2$s\n%1$s\n7\n8\n%1$s\n%2$s\n"; + static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8_FIZZ = "1\n2\n%1$s\n4\n%2$s\n%1$s\n7\n8\n%1$s\n"; + static final String _1_2_FIZZ_4_BUZZ_FIZZ_7_8 = "1\n2\n%1$s\n4\n%2$s\n%1$s\n7\n8\n"; + static final String _1_2_FIZZ_4_BUZZ_FIZZ_7 = "1\n2\n%1$s\n4\n%2$s\n%1$s\n7\n"; + static final String _1_2_FIZZ_4_BUZZ_FIZZ = "1\n2\n%1$s\n4\n%2$s\n%1$s\n"; + static final String _1_2_FIZZ_4_BUZZ = "1\n2\n%1$s\n4\n%2$s\n"; + static final String _1_2_FIZZ_4 = "1\n2\n%1$s\n4\n"; + static final String _1_2_FIZZ = "1\n2\n%1$s\n"; static final String _1_2_ = "1\n2\n"; static final String _1_ = "1\n"; + + static final String LINE_SEPARATOR = "line.separator"; + static final String ASSETS_VALUES_TEST_NUMBERS_PROPERTIES = "assets/values/test-numbers.properties"; static final String STANDARD_FIZZ_BUZZ = "standardFizzBuzz"; static final String SPRING_XML = "spring.xml"; - static final int INT_1 = 1; - static final int INT_2 = 2; - static final int INT_3 = 3; - static final int INT_4 = 4; - static final int INT_5 = 5; - static final int INT_6 = 6; - static final int INT_7 = 7; - static final int INT_8 = 8; - static final int INT_9 = 9; - static final int INT_10 = 10; - static final int INT_11 = 11; - static final int INT_12 = 12; - static final int INT_13 = 13; - static final int INT_14 = 14; - static final int INT_15 = 15; - static final int INT_16 = 16; + static final int INT_1; + static final int INT_2; + static final int INT_3; + static final int INT_4; + static final int INT_5; + static final int INT_6; + static final int INT_7; + static final int INT_8; + static final int INT_9; + static final int INT_10; + static final int INT_11; + static final int INT_12; + static final int INT_13; + static final int INT_14; + static final int INT_15; + static final int INT_16; + + static { + InputStream inputStream = TestConstants.class.getClassLoader().getResourceAsStream(ASSETS_VALUES_TEST_NUMBERS_PROPERTIES); + Properties properties = new Properties(); + properties.load(inputStream); + INT_1 = Integer.parseInt(properties.get("int_1")); + INT_2 = Integer.parseInt(properties.get("int_2")); + INT_3 = Integer.parseInt(properties.get("int_3")); + INT_4 = Integer.parseInt(properties.get("int_4")); + INT_5 = Integer.parseInt(properties.get("int_5")); + INT_6 = Integer.parseInt(properties.get("int_6")); + INT_7 = Integer.parseInt(properties.get("int_7")); + INT_8 = Integer.parseInt(properties.get("int_8")); + INT_9 = Integer.parseInt(properties.get("int_9")); + INT_10 = Integer.parseInt(properties.get("int_10")); + INT_11 = Integer.parseInt(properties.get("int_11")); + INT_12 = Integer.parseInt(properties.get("int_12")); + INT_13 = Integer.parseInt(properties.get("int_13")); + INT_14 = Integer.parseInt(properties.get("int_14")); + INT_15 = Integer.parseInt(properties.get("int_15")); + INT_16 = Integer.parseInt(properties.get("int_16")); + } } diff --git a/src/test/resources/values/test-numbers.properties b/src/test/resources/values/test-numbers.properties new file mode 100644 index 00000000..3174cb3b --- /dev/null +++ b/src/test/resources/values/test-numbers.properties @@ -0,0 +1,33 @@ +## Test Numbers Properties ## +# Int 1 +int_1=1 +# Int 2 +int_2=2 +# Int 3 +int_3=3 +# Int 4 +int_4=4 +# Int 5 +int_5=5 +# Int 6 +int_6=6 +# Int 7 +int_7=7 +# Int 8 +int_8=8 +# Int 9 +int_9=9 +# Int 10 +int_10=10 +# Int 11 +int_11=11 +# Int 12 +int_12=12 +# Int 13 +int_13=13 +# Int 14 +int_14=14 +# Int 15 +int_15=15 +# Int 16 +int_16=16 \ No newline at end of file From c74ea3f324cbf9f714e66502eca2c8fa5860d4e6 Mon Sep 17 00:00:00 2001 From: SuperYoshi10000 <148275327+SuperYoshi10000@users.noreply.github.com> Date: Wed, 8 May 2024 09:18:35 -0400 Subject: [PATCH 4/5] Minor formatting changes --- .../CharacterListToCharacterArrayConverter.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/converters/CharacterListToCharacterArrayConverter.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/converters/CharacterListToCharacterArrayConverter.java index 6c955f3f..190cd15f 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/converters/CharacterListToCharacterArrayConverter.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/converters/CharacterListToCharacterArrayConverter.java @@ -6,13 +6,13 @@ * Converter for CharacterListToCharacterArray */ public class CharacterListToCharacterArrayConverter { - - private CharListToCharacterArrayAdapter() {} + + private CharListToCharacterArrayAdapter() {} - public static char[] Convert(CharacterList characterList) { - - final ConditionalLoopContext loopContext = new ConditionalLoopContext(context -> context.); - final ConditionalLoopRunner loopRunner = new ConditionalLoopRunner(loopContext, loopContext, this._loopPayloadExecution); + public static char[] Convert(CharacterList characterList) { + + final ConditionalLoopContext loopContext = new ConditionalLoopContext(context -> context.); + final ConditionalLoopRunner loopRunner = new ConditionalLoopRunner(loopContext, loopContext, this._loopPayloadExecution); loopRunner.runLoop(); - } + } } \ No newline at end of file From fcd49ad3f1f7e6655e33705b5ff2a705edb8a46f Mon Sep 17 00:00:00 2001 From: SuperYoshi10000 <148275327+SuperYoshi10000@users.noreply.github.com> Date: Wed, 8 May 2024 09:30:12 -0400 Subject: [PATCH 5/5] Update build.gradle --- build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index fb3357b7..b5aaef88 100644 --- a/build.gradle +++ b/build.gradle @@ -24,8 +24,9 @@ dependencies { 'org.springframework:spring-expression:3.2.13.RELEASE' compile 'org.json' + compile 'it.unimi.dsi:fastutil:8.2.1' testCompile 'junit:junit:4.8.2' } -mainClassName = 'com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Main' \ No newline at end of file +mainClassName = 'com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Main'