-
Notifications
You must be signed in to change notification settings - Fork 0
/
comparable.py
49 lines (37 loc) · 1.28 KB
/
comparable.py
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
"""
File: comparable.py
Author: Ken Lambert
Editor: Leigh Stauffer
Project 7
Wrapper class for tagging data with priority values.
To instantiate, use
<variable> = Comparable(<datum>, <optional int priority value>)
The priority value is 1 default.
"""
class Comparable(object):
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, other):
"""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