Skip to content

Commit 6e34be6

Browse files
committed
Added several new finals
added private constructors to pure utility static classes Refactored Version class to be immutable
1 parent 5c6f000 commit 6e34be6

8 files changed

+44
-24
lines changed

Diff for: src/main/java/org/utplsql/api/EnvironmentVariableUtil.java

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
public class EnvironmentVariableUtil {
2020

21+
private EnvironmentVariableUtil() {}
22+
2123
/**
2224
* Returns the value for a given key from environment (see class description)
2325
*
@@ -43,4 +45,6 @@ public static String getEnvValue(String key, String defaultValue) {
4345

4446
return val;
4547
}
48+
49+
4650
}

Diff for: src/main/java/org/utplsql/api/JavaApiVersionInfo.java

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*/
88
public class JavaApiVersionInfo {
99

10+
private JavaApiVersionInfo() { }
11+
1012
private static final String BUILD_NO = "123";
1113
private static final String MAVEN_PROJECT_NAME = "utPLSQL-java-api";
1214
private static final String MAVEN_PROJECT_VERSION = "3.1.1-SNAPSHOT";

Diff for: src/main/java/org/utplsql/api/ResourceUtil.java

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
*/
2222
public class ResourceUtil {
2323

24+
private ResourceUtil() {}
25+
2426
/**
2527
* Returns the Path to a resource so it is walkable no matter if it's inside a jar or on the file system
2628
*

Diff for: src/main/java/org/utplsql/api/Version.java

+25-17
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,52 @@
1010
* @author pesse
1111
*/
1212
public class Version implements Comparable<Version> {
13-
private String origString;
14-
private Integer major;
15-
private Integer minor;
16-
private Integer bugfix;
17-
private Integer build;
18-
private boolean valid = false;
13+
private final String origString;
14+
private final Integer major;
15+
private final Integer minor;
16+
private final Integer bugfix;
17+
private final Integer build;
18+
private final boolean valid;
1919

2020
public Version( String versionString ) {
2121
assert versionString != null;
22-
this.origString = versionString;
23-
parseVersionString();
24-
}
22+
this.origString = versionString.trim();
2523

26-
private void parseVersionString()
27-
{
2824
Pattern p = Pattern.compile("([0-9]+)\\.?([0-9]+)?\\.?([0-9]+)?\\.?([0-9]+)?");
2925

3026
Matcher m = p.matcher(origString);
3127

28+
Integer major = null;
29+
Integer minor = null;
30+
Integer bugfix = null;
31+
Integer build = null;
32+
boolean valid = false;
33+
3234
try {
3335
if (m.find()) {
34-
if ( m.group(1) != null )
36+
if (m.group(1) != null )
3537
major = Integer.valueOf(m.group(1));
36-
if ( m.group(2) != null )
38+
if (m.group(2) != null )
3739
minor = Integer.valueOf(m.group(2));
38-
if ( m.group(3) != null )
40+
if (m.group(3) != null )
3941
bugfix = Integer.valueOf(m.group(3));
40-
if ( m.group(4) != null )
42+
if (m.group(4) != null )
4143
build = Integer.valueOf(m.group(4));
4244

43-
if ( major != null ) // We need a valid major version as minimum requirement for a Version object to be valid
44-
valid = true;
45+
// We need a valid major version as minimum requirement for a Version object to be valid
46+
valid = major != null;
4547
}
4648
}
4749
catch ( NumberFormatException e )
4850
{
4951
valid = false;
5052
}
53+
54+
this.major = major;
55+
this.minor = minor;
56+
this.bugfix = bugfix;
57+
this.build = build;
58+
this.valid = valid;
5159
}
5260

5361
@Override

Diff for: src/main/java/org/utplsql/api/compatibility/OptionalFeatures.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ public enum OptionalFeatures {
1212
FRAMEWORK_COMPATIBILITY_CHECK("3.0.3", null),
1313
CUSTOM_REPORTERS("3.1.0", null);
1414

15-
private Version minVersion;
16-
private Version maxVersion;
15+
private final Version minVersion;
16+
private final Version maxVersion;
1717

1818
OptionalFeatures( String minVersion, String maxVersion )
1919
{
20-
if ( minVersion != null )
21-
this.minVersion = new Version(minVersion);
22-
if ( maxVersion != null)
23-
this.maxVersion = new Version(maxVersion);
20+
this.minVersion = minVersion != null ? new Version(minVersion) : null;
21+
this.maxVersion = maxVersion != null ? new Version(maxVersion) : null;
2422
}
2523

2624
public boolean isAvailableFor(Version version ) {

Diff for: src/main/java/org/utplsql/api/outputBuffer/AbstractOutputBuffer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
abstract class AbstractOutputBuffer implements OutputBuffer {
2121

22-
private Reporter reporter;
22+
private final Reporter reporter;
2323
private int fetchSize = 100;
2424

2525
/**

Diff for: src/main/java/org/utplsql/api/outputBuffer/OutputBufferProvider.java

+3
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,7 @@ private static boolean hasOutput( Reporter reporter, OracleConnection oraConn )
6060
}
6161
}
6262
}
63+
64+
private OutputBufferProvider() {
65+
}
6366
}

Diff for: src/main/java/org/utplsql/api/testRunner/TestRunnerStatementProvider.java

+3
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ else if (databaseVersion.isLessThan(new Version("3.1.2")))
3737

3838
return stmt;
3939
}
40+
41+
private TestRunnerStatementProvider() {
42+
}
4043
}

0 commit comments

Comments
 (0)