Skip to content

Commit

Permalink
Sonar cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ctmay4 committed Jul 12, 2023
1 parent e80c1e4 commit c3b4ba4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
9 changes: 6 additions & 3 deletions src/main/java/com/imsweb/seerutils/SeerMath.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ public static RegressionResult calculateRegressionResult(List<? extends Number>
// first pass: read in data, compute xbar and ybar
double[] x = new double[n];
double[] y = new double[n];
double sumx = 0.0, sumy = 0.0;
double sumx = 0.0;
double sumy = 0.0;
for (int i = 0; i < n; i++) {
x[i] = Integer.valueOf(i).doubleValue(); // we don't have the X variables so just use 0 to number-of-value...
x[i] = i; // we don't have the X variables so just use 0 to number-of-value...
y[i] = input.get(i).doubleValue();
sumx += x[i];
sumy += y[i];
Expand All @@ -69,7 +70,9 @@ public static RegressionResult calculateRegressionResult(List<? extends Number>
double ybar = sumy / n;

// second pass: compute summary statistics
double xxbar = 0.0, yybar = 0.0, xybar = 0.0;
double xxbar = 0.0;
double yybar = 0.0;
double xybar = 0.0;
for (int i = 0; i < n; i++) {
xxbar += (x[i] - xbar) * (x[i] - xbar);
yybar += (y[i] - ybar) * (y[i] - ybar);
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/imsweb/seerutils/SeerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ public static int compareSeerVersions(String version1, String version2) {
String v2 = _VERSION_CLEANUP_PATTERN.matcher(version2.toLowerCase()).replaceAll("");

if (!_VERSIONS_PATTERN.matcher(v1).matches())
throw new RuntimeException("Invalid version format: " + v1);
throw new IllegalArgumentException("Invalid version format: " + v1);
if (!_VERSIONS_PATTERN.matcher(v2).matches())
throw new RuntimeException("Invalid version format: " + v2);
throw new IllegalArgumentException("Invalid version format: " + v2);

String[] parts1 = StringUtils.split(v1, '.');
String[] parts2 = StringUtils.split(v2, '.');

List<Integer> list1 = new ArrayList<>(), list2 = new ArrayList<>();
List<Integer> list1 = new ArrayList<>();
List<Integer> list2 = new ArrayList<>();
for (int i = 0; i < Math.max(parts1.length, parts2.length); i++) {
if (i < parts1.length)
list1.add(Integer.valueOf(parts1[i]));
Expand Down
20 changes: 10 additions & 10 deletions src/test/java/com/imsweb/seerutils/SeerUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ public void testPad() {
@Test
public void testTrimLeft() {
Assert.assertNull(null, SeerUtils.trimLeft(null));
Assert.assertEquals(SeerUtils.trimLeft(""), "");
Assert.assertEquals(SeerUtils.trimLeft(" Hello"), "Hello");
Assert.assertEquals(SeerUtils.trimLeft(" Hello "), "Hello ");
Assert.assertEquals(SeerUtils.trimLeft("Hello "), "Hello ");
Assert.assertEquals(SeerUtils.trimLeft(" Hello Hello "), "Hello Hello ");
Assert.assertEquals("", SeerUtils.trimLeft(""));
Assert.assertEquals("Hello", SeerUtils.trimLeft(" Hello"));
Assert.assertEquals("Hello ", SeerUtils.trimLeft(" Hello "));
Assert.assertEquals("Hello ", SeerUtils.trimLeft("Hello "));
Assert.assertEquals("Hello Hello ", SeerUtils.trimLeft(" Hello Hello "));
}

@Test
public void testTrimRight() {
Assert.assertNull(null, SeerUtils.trimRight(null));
Assert.assertEquals(SeerUtils.trimRight(""), "");
Assert.assertEquals(SeerUtils.trimRight(" Hello"), " Hello");
Assert.assertEquals(SeerUtils.trimRight(" Hello "), " Hello");
Assert.assertEquals(SeerUtils.trimRight("Hello "), "Hello");
Assert.assertEquals(SeerUtils.trimRight(" Hello Hello "), " Hello Hello");
Assert.assertEquals("", SeerUtils.trimRight(""));
Assert.assertEquals(" Hello", SeerUtils.trimRight(" Hello"));
Assert.assertEquals(" Hello", SeerUtils.trimRight(" Hello "));
Assert.assertEquals("Hello", SeerUtils.trimRight("Hello "));
Assert.assertEquals(" Hello Hello", SeerUtils.trimRight(" Hello Hello "));
}

@Test
Expand Down

0 comments on commit c3b4ba4

Please sign in to comment.