-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatcher.txt
More file actions
31 lines (24 loc) · 809 Bytes
/
Matcher.txt
File metadata and controls
31 lines (24 loc) · 809 Bytes
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
1. What design principles does this code violate?
Single Responsibility
2. Refactor the code to improve its design.
Matcher.java
public class Matcher {
public Matcher() {}
public void clip(int[] actual, int clipLimit){
// Clip "too-large" values
for (int i = 0; i < actual.length; i++)
if (actual[i] > clipLimit)
actual[i] = clipLimit;
}
public boolean match(int[] expected, int[] actual, int delta)
{
// Check for length differences
if (actual.length != expected.length)
return false;
// Check that each entry within expected +/- delta
for (int i = 0; i < actual.length; i++)
if (Math.abs(expected[i] - actual[i]) > delta)
return false;
return true;
}
}