IfElseMutator

public class IfElseMutator extends Mutator

Mutator for the if/else if/else block. This class modifies the block model, but is not responsible for updating the view hierarchy or showing an editor to the user.

Constant Summary

String MUTATOR_ID
String TAG

Inherited Constant Summary

Field Summary

public static final Factory FACTORY

Inherited Field Summary

Public Constructor Summary

IfElseMutator(Factory<IfElseMutator> factory, Context context, BlocklyController controller)
Create a new mutator for the given context and controller.

Public Method Summary

int
boolean
void
mutate(int elseIfCount, boolean hasElse)
Convenience method for invoking a mutation event programmatically, updating the Mutator with the provided values.
void
onAttached(Block block)
Called immediately after the mutator is attached to the block.
void
serialize(XmlSerializer serializer)
Serializes the Mutator's state to an XML <mutation> element.
void
update(XmlPullParser parser)
Updates the mutator state from the provided <mutation> XML.
static String
writeMutationString(int elseIfCount, boolean hasElseStatement)
Writes an XML mutation string for the provided values.

Inherited Method Summary

Constants

public static final String MUTATOR_ID

Constant Value: "controls_if_mutator"

public static final String TAG

Constant Value: "IfElseMutator"

Fields

public static final Factory FACTORY

Public Constructors

public IfElseMutator (Factory<IfElseMutator> factory, Context context, BlocklyController controller)

Create a new mutator for the given context and controller.

Parameters
factory The factory used to create this mutator.
context Used to load strings and other configuration.
controller Controller for sending events.

Public Methods

public int getElseIfCount ()

Returns
  • The number of else if inputs on this block.

public boolean hasElse ()

Returns
  • True if this block has an else statement at the end, false otherwise.

public void mutate (int elseIfCount, boolean hasElse)

Convenience method for invoking a mutation event programmatically, updating the Mutator with the provided values.

Parameters
elseIfCount The number of else if inputs for this block.
hasElse True if this block should have a final else statement.

public void onAttached (Block block)

Called immediately after the mutator is attached to the block. Can be used to perform additional block initialization related to this mutator.

Parameters
block

public void serialize (XmlSerializer serializer)

Serializes the Mutator's state to an XML <mutation> element. Compare with block.mutationToDom() on web Blockly (added by extensions or mixins), or Mutator.toXMLElement() on blockly-ios.

Throws
IOException

public void update (XmlPullParser parser)

Updates the mutator state from the provided <mutation> XML. The parser state is such that parser.next() will return START_TAG, the beginning of the <mutation> element. Compare with block.domToMutation() on web Blockly (added by extensions or mixins), or Mutator.update() on blockly-ios.

Parameters
parser The parser with the <mutation> element.
Throws
IOException
XmlPullParserException

public static String writeMutationString (int elseIfCount, boolean hasElseStatement)

Writes an XML mutation string for the provided values.

Parameters
elseIfCount The count of else if <test> <statement> sections.
hasElseStatement Whether the mutation should include a separate else statement.
Returns
  • Serialized XML <mutation> tag, encoding the values.