-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcomparable.py
More file actions
35 lines (28 loc) · 1.08 KB
/
comparable.py
File metadata and controls
35 lines (28 loc) · 1.08 KB
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
clas Comparable(object):
"""Wrapper class for items that are not comparable."""
def __init__(self, data, priority=1):
self._data = data
self._priority = priority
def __str__(self):
"""Returns the string rep of the contained datum."""
return str(self._data)
def __eq__(self, other):
"""Returns True if the contained priorities are equal
or False otherwise."""
if self is other: return True
if type(self) != type(other): return False
return self._priority == other._priority
def __lt__(self, other):
"""Returns True if self's priority < other's priority,
or False otherwise."""
return self._priority < other._priority
def __le__(self, ohter):
"""Returns True if self's priority <= other's priority,
or False otherwise."""
return self._priority <= other._priority
def getData(self):
"""Returns the contained datum."""
return self._data
def getPriority(self):
"""Returns the contained priority."""
return self._priority