Conditions | 29 |
Total Lines | 52 |
Code Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like unicon.matthews.entity.risk.RiskScore.equals(Object) 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 | package unicon.matthews.entity.risk; |
||
77 | @Override |
||
78 | public boolean equals(Object obj) { |
||
79 | if (this == obj) |
||
80 | return true; |
||
81 | if (obj == null) |
||
82 | return false; |
||
83 | if (getClass() != obj.getClass()) |
||
84 | return false; |
||
85 | RiskScore other = (RiskScore) obj; |
||
86 | if (active != other.active) |
||
87 | return false; |
||
88 | if (classSourcedId == null) { |
||
89 | if (other.classSourcedId != null) |
||
90 | return false; |
||
91 | } else if (!classSourcedId.equals(other.classSourcedId)) |
||
92 | return false; |
||
93 | if (dateTime == null) { |
||
94 | if (other.dateTime != null) |
||
95 | return false; |
||
96 | } else if (!dateTime.equals(other.dateTime)) |
||
97 | return false; |
||
98 | if (id == null) { |
||
99 | if (other.id != null) |
||
100 | return false; |
||
101 | } else if (!id.equals(other.id)) |
||
102 | return false; |
||
103 | if (modelType == null) { |
||
104 | if (other.modelType != null) |
||
105 | return false; |
||
106 | } else if (!modelType.equals(other.modelType)) |
||
107 | return false; |
||
108 | if (orgId == null) { |
||
109 | if (other.orgId != null) |
||
110 | return false; |
||
111 | } else if (!orgId.equals(other.orgId)) |
||
112 | return false; |
||
113 | if (score == null) { |
||
114 | if (other.score != null) |
||
115 | return false; |
||
116 | } else if (!score.equals(other.score)) |
||
117 | return false; |
||
118 | if (tenantId == null) { |
||
119 | if (other.tenantId != null) |
||
120 | return false; |
||
121 | } else if (!tenantId.equals(other.tenantId)) |
||
122 | return false; |
||
123 | if (userSourcedId == null) { |
||
124 | if (other.userSourcedId != null) |
||
125 | return false; |
||
126 | } else if (!userSourcedId.equals(other.userSourcedId)) |
||
127 | return false; |
||
128 | return true; |
||
129 | } |
||
180 |