1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
|
import jpype
from typing import Union
class Iterable:
""" Customized interface for a container which can be iterated.
JPype wraps ``java.lang.Iterable`` as the Python iterator
interface.
"""
def __iter__(self):
""" Iterate over the members on this collect. """
...
class Collection:
""" Customized interface representing a collection of items.
JPype wraps ``java.util.Collection`` as a Python collection.
"""
def __len__(self) -> int:
""" Get the length of this collection.
Use ``len(collection)`` to find the number of items in this
collection.
"""
...
def __delitem__(self, item):
""" Collections do not support remove by index. """
...
def __contains__(self, item) -> bool:
""" Check if this collection contains this item.
Use ``item in collection`` to check if the item is
present.
Args:
item: is the item to check for. This must be a Java
object or an object which can be automatically converted
such as a string.
Returns:
bool: True if the item is in the collection.
"""
...
class List(Collection):
""" Customized container holding items in a specified order.
JPype customizes ``java.lang.List`` to be equivalent to a Python list.
Java list fulfill the contract for ``collection.abc.MutableSequence``.
"""
def __getitem__(self, ndx):
""" Access an item or set of items.
Use ``list[idx]`` to access a single item or ``list[i0:i1]`` to obtain
a slice of the list. Slices are views thus changing the view will
alter the original list. Slice stepping is not supported for Java
lists.
"""
...
def __setitem__(self, index: Union[int, slice], value):
""" Set an item on the list.
Use ``list[idx]=value`` to set a value on the list or
``list[i0:i1] = values`` to replace a section of a list with
another list of values.
"""
...
def __delitem__(self, idx: Union[int, slice]):
""" Delete an item by index.
Use ``del list[idx]`` to remove ont itme from the list or
``del list[i0:i1]`` to remove a section of the list.
"""
...
def __reversed__(self):
""" Obtain an iterator that walks the list in reverse order.
Use ``reversed(list)`` to traverse a list backwards.
"""
...
def index(self, obj) -> int:
""" Find the index that an item appears.
Args:
obj: A Java object or Python object which automatically
converts to Java.
Returns:
int: The index where the item first appears in the list.
Raises:
ValueError: If the item is not on the list.
"""
...
def count(self, obj):
""" Count the number of times an object appears in a list.
Args:
obj: A Java object or Python object which automatically
converts to Java.
Returns:
int: The number of times this object appears.
"""
...
def insert(self, idx: int, obj):
""" Insert an object at a specific position.
Args:
idx: The index to insert the item in front of.
obj: The object to insert.
Raises:
TypeError: If the object cannot be converted to Java.
"""
...
def append(self, obj):
""" Append an object to the list.
Args:
obj: The object to insert.
Raises:
TypeError: If the object cannot be converted to Java.
"""
...
def reverse(self):
""" Reverse the order of the list in place.
This is equivalent to ``java.util.Collections.reverse(list)``.
"""
def extend(self, lst):
""" Extends a list by adding a set of elements to the end.
Args:
lst: A Sequence holding items to be appended.
Raises:
TypeError: If the list to be added cannot be converted to Java.
"""
...
def pop(self, idx=-1):
""" Remove an item from the list.
Args:
idx (int, optional): Position to remove the item from. If not
specified the item is removed from the end of the list.
Returns:
The item or raises if index is outside of the list.
"""
...
def __iadd__(self, obj):
""" Add an items to the end of the list.
Use ``list += obj`` to append one item. This is simply an alias
for add.
"""
...
def __add__(self, obj):
""" Combine two lists.
Use ``list + seq`` to create a new list with additional members.
This is only supported if the list can be cloned.
"""
...
def remove(self, obj):
""" Remove an item from the list by finding the first
instance that matches.
This overrides the Java method to provide the Python remove.
Use ``lst.remove_`` to obtain the Java remove method.
Args:
obj: Must be a Java object or Python object that can
convert to Java automatically.
Raises:
ValueError: If the item is not present on the list.
"""
...
class Map:
""" Customized container holding pairs of items like a dictionary.
JPype customizes ``java.lang.List`` to be equivalent to a Python list.
Java maps fulfill the contract for ``collection.abc.Mapping``.
"""
def __len__(self):
""" Get the number of items in this map.
Use ``len(map)`` to get the number of items in the map.
"""
...
def __iter__(self):
""" Iterate the keys of the map.
"""
...
def __delitem__(self, i):
""" Remove an item by its key.
Raises:
TypeError: If the key cannot be converted to Java.
"""
...
def __getitem__(self, ndx):
""" Get a value by its key.
Use ``map[key]`` to get the value associate with a key.
Raises:
KeyError: If the key is not found in the map or the key
cannot be converted to Java.
"""
...
def __setitem__(self, key, value):
""" Set a value associated with a key..
Use ``map[key]=value`` to set the value associate with a key.
Raises:
TypeError: If the key or value cannot be converted to Java.
"""
...
def items(self):
""" Get a list of entries in the map.
The map entries are customized to appear as tuples with two
items. Maps can traversed as key value pairs using ``map.items()``
"""
...
def keys(self) -> list:
""" Get a list of keys for this map.
Use ``map.keySet()`` to obtain the keys as Java views them.
Returns:
list: A Python list holding all of the items.
"""
...
def __contains__(self, item):
""" Check if a key is in the map.
Use ``item in map`` to verify if the map contains the item.
This will return true whether on not the associated value
is an object or None.
Returns:
True is the key is found.
"""
...
class Set(object):
""" Customized Java Sets.
Java sets only provide the ability to delete items.
"""
...
class Iterator:
""" Customized Java Iterator.
Java iterators act just like Python iterators for the
purposed of list comprehensions and foreach loops.
"""
...
class Enumeration:
""" Customized Java enumeration.
Enumerations are used rarely in Java, but can be iterated like a Java
iterable using Python.
"""
...
|