Completed
Push — master ( 82ea15...69aa0a )
by Michael
07:50
created

TimeConstraints.anyConstraints()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 2
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 2
dl 2
loc 2
rs 10
c 0
b 0
f 0
cc 1
nop 1
1
##
2
##
3
4
# File auto-generated against equivalent DynamicSerialize Java class
5
#
6
# 03/20/2013     #1774    randerso  Removed setters, added isValid.
7
8
9
import logging
10
11
HOUR = 3600;
0 ignored issues
show
Coding Style introduced by
Unnecessary semicolon
Loading history...
12
DAY = 24 * HOUR;
0 ignored issues
show
Coding Style introduced by
Unnecessary semicolon
Loading history...
13
14 View Code Duplication
class TimeConstraints(object):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
15
16
    def __init__(self, duration=0, repeatInterval=0, startTime=0):
17
        duration = int(duration)
18
        repeatInterval = int(repeatInterval)
19
        startTime = int(startTime)
20
21
        self.valid = False;
0 ignored issues
show
Coding Style introduced by
Unnecessary semicolon
Loading history...
22
        if duration == 0 and repeatInterval == 0 and startTime == 0:
23
            self.valid = True;
0 ignored issues
show
Coding Style introduced by
Unnecessary semicolon
Loading history...
24
        else:
25
            if self.isInvalidInterval(repeatInterval, duration, startTime):
26
                logging.warning("Bad init values for TimeConstraints: ", self);
0 ignored issues
show
Coding Style introduced by
Unnecessary semicolon
Loading history...
Bug introduced by
Too many arguments for logging format string
Loading history...
27
                self.valid = False;
0 ignored issues
show
Coding Style introduced by
Unnecessary semicolon
Loading history...
28
                duration = 0;
0 ignored issues
show
Coding Style introduced by
Unnecessary semicolon
Loading history...
29
                repeatInterval = 0;
0 ignored issues
show
Coding Style introduced by
Unnecessary semicolon
Loading history...
30
                startTime = 0;
0 ignored issues
show
Coding Style introduced by
Unnecessary semicolon
Loading history...
31
            else:
32
                self.valid = True;
0 ignored issues
show
Coding Style introduced by
Unnecessary semicolon
Loading history...
33
34
        self.duration = duration
35
        self.repeatInterval = repeatInterval
36
        self.startTime = startTime
37
38
    def __str__(self):
39
        return self.__repr__()
40
41
    def __repr__(self):
42
        if not self.isValid():
0 ignored issues
show
unused-code introduced by
Unnecessary "else" after "return"
Loading history...
43
            return "<Invalid>"
44
        elif not self.anyConstraints():
45
            return "<NoConstraints>"
46
        else:
47
            return "[s=" + str(self.startTime / HOUR) + "h, i=" + \
48
                   str(self.repeatInterval / HOUR) + "h, d=" + \
49
                   str(self.duration / HOUR) + "h]"
50
51
    def __eq__(self, other):
52
        if not isinstance(other, TimeConstraints):
53
            return False
54
        if self.isValid() != other.isValid():
55
            return False
56
        if self.duration != other.duration:
57
            return False
58
        if self.repeatInterval != other.repeatInterval:
59
            return False
60
        return (self.startTime == other.startTime)
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after return.
Loading history...
61
62
    def __ne__(self, other):
63
        return (not self.__eq__(other))
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after return.
Loading history...
64
65
    def anyConstraints(self):
66
        return (self.duration != 0)
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after return.
Loading history...
67
68
    def isValid(self):
69
        return self.valid
70
71
    def getDuration(self):
72
        return self.duration
73
74
    def getRepeatInterval(self):
75
        return self.repeatInterval
76
77
    def getStartTime(self):
78
        return self.startTime
79
80
    def isInvalidInterval(self, interval, duration, startTime):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
81
        if interval <= 0 or interval > DAY or interval < duration:
82
            return False
83
        if startTime < 0 or startTime > DAY:
84
            return False
85
        if duration < 0 or duration > DAY:
86
            return False
87
        if DAY % interval != 0:
88
            return False
89
        return True
90