Package dev.zemco.codegame.programs
Interface IProgramBuilder
- All Known Implementing Classes:
ProgramBuilder
public interface IProgramBuilder
Interface for simplifying
program creation process.
This interface is useful when full program context has not been fully created,
but will be at later point. The final program can be built using the build() method.- Author:
- Erik Zemčík
- See Also:
-
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.
-
Method Details
-
addInstruction
Appendsinstructionto all instructions of theprogram.- Parameters:
instruction-instructionto addlinePosition- line position associated with theinstruction- Throws:
IllegalArgumentException- ifinstructionisnullor iflinePositionis not a positive integer
-
addJumpLabelMapping
Adds unique jump label mapping to theprogram. If addition of the same jump label is attempted, this method should throwIllegalStateException. Dedicated methodhasJumpLabelMapping(String)can be used to check if label has been already added.- Parameters:
label- jump label of the mappinglinePosition- zero-based line position to jump to- Throws:
IllegalArgumentException- iflabelisnullor empty or iflinePositionis not a positive integerIllegalStateException- iflabelis already assigned to different mapping- See Also:
-
hasJumpLabelMapping
Check if jump label has been added to theprogram.- Parameters:
label- jump label to check- Returns:
- true if the builder already contains the jump label, else false
- Throws:
IllegalArgumentException- iflabelisnullor empty
-
build
Program build()Builds theprogrambased on the data specified during the lifetime of the builder.- Returns:
- program
-