Top Description Fields Constructors Methods
org.python.core

pack-priv sealed Enum Comparison

extends Enum<Comparison>
Class Inheritance
Imports
java.lang.invoke.MethodHandle, org.python.core.Slot.EmptyException

Selects a particular "rich comparison" operation from the repertoire supported by Opcode.COMPARE_OP, the argument to which is the code attribute of the name in this enum.

API Note

The order matches CPython's enumeration of operations used in the argument to COMPARE_OP, so that we can rely on it in the CPython byte code interpreter.

Field Summary

Modifier and TypeField and Description
public static final Comparison
BAD

A dummy operation representing an invalid comparison.

public static final Comparison
EQ

The __eq__ operation.

public static final Comparison
EXC_MATCH

The exception matching operation.

private static final Comparison[]
public static final Comparison
GE

The __ge__ operation.

public static final Comparison
GT

The __gt__ operation.

public static final Comparison
IN

The in operation (reflected __contains__).

public static final Comparison
IS

The identity operation.

public static final Comparison
IS_NOT

The inverted identity operation.

public static final Comparison
LE

The __le__ operation.

public static final Comparison
LT

The __lt__ operation.

public static final Comparison
NE

The __ne__ operation.

private static String
public static final Comparison
NOT_IN

The inverted in operation (reflected __contains__).

private static String
pack-priv final Slot
private static final Comparison[]
pack-priv final String

Constructor Summary

AccessConstructor and Description
private
Comparison(String text, Slot slot)

private

Method Summary

Modifier and TypeMethod and Description
pack-priv Object

Returns:

comparison result
apply
(Object
left operand
v
,
Object
right operand
w
)

Perform this comparison, raising TypeError when the requested comparison operator is not supported.

pack-priv PyException

Returns:

the exception
comparisonTypeError
(Object
left arg
v
,
Object
right arg
w
)

Create a TypeError along the lines "OP not supported between instances of V and W"

pack-priv static Comparison

Returns:

equivalent Comparison object
from
(int
opcode argument
oparg
)

Translate CPython Opcode311#COMPARE_OP opcode argument to Comparison constant.

pack-priv Comparison

Returns:

swapped version of this comparison
swapped
()

The swapped version of this comparison, e.g. LT with GT.

pack-priv abstract boolean

Returns:

boolean equivalent for this operation
toBool
(int
comparison result
c
)

Translate a comparison result into the appropriate boolean, for example GE.toBool(1) is Py#True.

public String

Returns:

text corresponding
toString
()

Overrides java.lang.Enum.toString.

The text corresponding to the value, e.g. "!=" for NE, "is not" for IS_NOT.
public static Comparison
public static Comparison[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinalvalueOf

Field Detail

BADback to summary
public static final Comparison BAD

A dummy operation representing an invalid comparison.

EQback to summary
public static final Comparison EQ

The __eq__ operation.

EXC_MATCHback to summary
public static final Comparison EXC_MATCH

The exception matching operation.

fromback to summary
private static final Comparison[] from
GEback to summary
public static final Comparison GE

The __ge__ operation.

GTback to summary
public static final Comparison GT

The __gt__ operation.

INback to summary
public static final Comparison IN

The in operation (reflected __contains__). Note that "v in seq" compiles to

   LOAD_NAME    0 (v)
   LOAD_NAME    1 (seq)
   COMPARE_OP   6 (in)
which must lead to seq.__contains__(v).
ISback to summary
public static final Comparison IS

The identity operation.

IS_NOTback to summary
public static final Comparison IS_NOT

The inverted identity operation.

LEback to summary
public static final Comparison LE

The __le__ operation.

LTback to summary
public static final Comparison LT

The __lt__ operation.

NEback to summary
public static final Comparison NE

The __ne__ operation.

NOT_CONTAINERback to summary
private static String NOT_CONTAINER
NOT_INback to summary
public static final Comparison NOT_IN

The inverted in operation (reflected __contains__).

NOT_SUPPORTEDback to summary
private static String NOT_SUPPORTED
slotback to summary
pack-priv final Slot slot
swapback to summary
private static final Comparison[] swap
textback to summary
pack-priv final String text

Constructor Detail

Comparisonback to summary
private Comparison(String text, Slot slot)
Comparisonback to summary
private Comparison(String text)

Method Detail

applyback to summary
pack-priv Object apply(Object v, Object w) throws Throwable

Perform this comparison, raising TypeError when the requested comparison operator is not supported.

Parameters
v:Object

left operand

w:Object

right operand

Returns:Object

comparison result

Exceptions
Throwable:
from the implementation of the comparison
comparisonTypeErrorback to summary
pack-priv PyException comparisonTypeError(Object v, Object w)

Create a TypeError along the lines "OP not supported between instances of V and W"

Parameters
v:Object

left arg

w:Object

right arg

Returns:PyException

the exception

fromback to summary
pack-priv static Comparison from(int oparg)

Translate CPython Opcode311#COMPARE_OP opcode argument to Comparison constant.

Parameters
oparg:int

opcode argument

Returns:Comparison

equivalent Comparison object

swappedback to summary
pack-priv Comparison swapped()

The swapped version of this comparison, e.g. LT with GT.

Returns:Comparison

swapped version of this comparison

toBoolback to summary
pack-priv abstract boolean toBool(int c)

Translate a comparison result into the appropriate boolean, for example GE.toBool(1) is Py#True. For the the six operations LT to GE inclusive, this is typically wrapped onto a call to Comparable.compareTo()). For the others we assume c==0 indicates equality.

Avoid the temptation to use the result of a subtraction here unless there is no possibility of overflow in the subtraction.

Parameters
c:int

comparison result

Returns:boolean

boolean equivalent for this operation

toStringback to summary
public String toString()

Overrides java.lang.Enum.toString.

The text corresponding to the value, e.g. "!=" for NE, "is not" for IS_NOT. Mostly for error messages.

Returns:String

text corresponding

Annotations
@Override
valueOfback to summary
public static Comparison valueOf(String name)
valuesback to summary
public static Comparison[] values()