Package dev.zemco.codegame.programs
Class ProgramBuilder
java.lang.Object
dev.zemco.codegame.programs.ProgramBuilder
- All Implemented Interfaces:
IProgramBuilder
Simple implementation for building
programs based on the required rules.- Author:
- Erik Zemčík
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddInstruction(IInstruction instruction, int linePosition) Appendsinstructionto all instructions of theprogram.voidaddJumpLabelMapping(String label, int linePosition) Adds unique jump label mapping to theprogram.build()Builds theprogrambased on the data specified during the lifetime of the builder.booleanhasJumpLabelMapping(String label) Check if jump label has been added to theprogram.
-
Constructor Details
-
ProgramBuilder
public ProgramBuilder()Creates an instance ofProgramBuilderready for use.
-
-
Method Details
-
addInstruction
Description copied from interface:IProgramBuilderAppendsinstructionto all instructions of theprogram.- Specified by:
addInstructionin interfaceIProgramBuilder- Parameters:
instruction-instructionto addlinePosition- line position associated with theinstruction
-
addJumpLabelMapping
Description copied from interface:IProgramBuilderAdds unique jump label mapping to theprogram. If addition of the same jump label is attempted, this method should throwIllegalStateException. Dedicated methodIProgramBuilder.hasJumpLabelMapping(String)can be used to check if label has been already added.- Specified by:
addJumpLabelMappingin interfaceIProgramBuilder- Parameters:
label- jump label of the mappinglinePosition- zero-based line position to jump to- See Also:
-
hasJumpLabelMapping
Description copied from interface:IProgramBuilderCheck if jump label has been added to theprogram.- Specified by:
hasJumpLabelMappingin interfaceIProgramBuilder- Parameters:
label- jump label to check- Returns:
- true if the builder already contains the jump label, else false
-
build
Description copied from interface:IProgramBuilderBuilds theprogrambased on the data specified during the lifetime of the builder.- Specified by:
buildin interfaceIProgramBuilder- Returns:
- program
-