Conditions | 10 |
Total Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like Allen.relation() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | """ |
||
30 | @staticmethod |
||
31 | def relation(x_start, x_end, y_start, y_end): |
||
32 | """ |
||
33 | Returns the relation between two intervals. |
||
34 | |||
35 | :param int x_start: The start point of the first interval. |
||
36 | :param int x_end: The end point of the first interval. |
||
37 | :param int y_start: The start point of the second interval. |
||
38 | :param int y_end: The end point of the second interval. |
||
39 | |||
40 | :rtype: int |
||
41 | """ |
||
42 | diff_start = y_start - x_start |
||
43 | diff_end = y_end - x_end |
||
44 | gab = y_start - x_end |
||
45 | |||
46 | if diff_end == 0: |
||
47 | if diff_start == 0: |
||
48 | return Allen.X_EQUAL_Y |
||
49 | |||
50 | if diff_start < 0: |
||
51 | return Allen.X_FINISHES_Y |
||
52 | |||
53 | return Allen.X_FINISHES_Y_INVERSE |
||
54 | |||
55 | if diff_end < 0: |
||
56 | return -Allen.relation(y_start, y_end, x_start, x_end) |
||
57 | |||
58 | if gab > 1: |
||
59 | return Allen.X_BEFORE_Y |
||
60 | |||
61 | if gab == 1: |
||
62 | return Allen.X_MEETS_Y |
||
63 | |||
64 | if diff_start > 0: |
||
65 | return Allen.X_OVERLAPS_WITH_Y |
||
66 | |||
67 | if diff_start == 0: |
||
68 | return Allen.X_STARTS_Y |
||
69 | |||
70 | if diff_start < 0: |
||
71 | return Allen.X_DURING_Y |
||
72 | |||
74 |