Top Description Fields Constructors Methods
com.sun.org.apache.bcel.internal.generic

public final Class SWITCH

extends Object
implements CompoundInstruction
Class Inheritance
All Implemented Interfaces
com.sun.org.apache.bcel.internal.generic.CompoundInstruction
Imports
java.util.Arrays

SWITCH - Branch depending on int value, generates either LOOKUPSWITCH or TABLESWITCH instruction, depending on whether the match values (int[]) can be sorted with no gaps between the numbers.

Field Summary

Modifier and TypeField and Description
private final Select

Constructor Summary

AccessConstructor and Description
public
SWITCH(final int[] match, final InstructionHandle[] targets, final InstructionHandle target)

public
SWITCH(final int[]
array of match values (case 2: ... case 7: ..., etc.)
match
,
final InstructionHandle[]
the instructions to be branched to for each case
targets
,
final InstructionHandle
the default target
target
,
final int
maximum gap that may between case branches
maxGap
)

Template for switch() constructs.

Method Summary

Modifier and TypeMethod and Description
public Instruction
public InstructionList
private static boolean

Returns:

match is sorted in ascending order with no gap bigger than maxGap?
matchIsOrdered
(final int[] match, final int matchLength, final int maxGap)

private static void
sort(final int l, final int r, final int[] match, final InstructionHandle[] targets)

Sorts match and targets array with QuickSort.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

instructionback to summary
private final Select instruction

Constructor Detail

SWITCHback to summary
public SWITCH(final int[] match, final InstructionHandle[] targets, final InstructionHandle target)
SWITCHback to summary
public SWITCH(final int[] match, final InstructionHandle[] targets, final InstructionHandle target, final int maxGap)

Template for switch() constructs. If the match array can be sorted in ascending order with gaps no larger than maxGap between the numbers, a TABLESWITCH instruction is generated, and a LOOKUPSWITCH otherwise. The former may be more efficient, but needs more space. Note, that the key array always will be sorted, though we leave the original arrays unaltered.

Parameters
match:int[]

array of match values (case 2: ... case 7: ..., etc.)

targets:InstructionHandle[]

the instructions to be branched to for each case

target:InstructionHandle

the default target

maxGap:int

maximum gap that may between case branches

Method Detail

getInstructionback to summary
public Instruction getInstruction()
getInstructionListback to summary
public InstructionList getInstructionList()

Implements com.sun.org.apache.bcel.internal.generic.CompoundInstruction.getInstructionList.

Annotations
@Override
matchIsOrderedback to summary
private static boolean matchIsOrdered(final int[] match, final int matchLength, final int maxGap)
Returns:boolean

match is sorted in ascending order with no gap bigger than maxGap?

sortback to summary
private static void sort(final int l, final int r, final int[] match, final InstructionHandle[] targets)

Sorts match and targets array with QuickSort.