Skip to content

Commit c007ca9

Browse files
authored
Merge pull request #59 from Pazus/feature/cleanup
Cleanup base on IDEA Code Inspector and small refactoring
2 parents 9c7f855 + 141215a commit c007ca9

33 files changed

+161
-206
lines changed

src/main/java/org/utplsql/api/DBHelper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.utplsql.api;
22

33
import oracle.jdbc.OracleTypes;
4-
import org.utplsql.api.exception.DatabaseNotCompatibleException;
54
import org.utplsql.api.exception.UtPLSQLNotInstalledException;
65

76
import java.sql.*;

src/main/java/org/utplsql/api/EnvironmentVariableUtil.java

Lines changed: 4 additions & 0 deletions
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
}

src/main/java/org/utplsql/api/FileMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static Array buildFileMappingArray(
2020
Connection conn, FileMapperOptions mapperOptions) throws SQLException {
2121
OracleConnection oraConn = conn.unwrap(OracleConnection.class);
2222

23-
Map typeMap = conn.getTypeMap();
23+
Map<String, Class<?>> typeMap = conn.getTypeMap();
2424
typeMap.put(CustomTypes.UT_FILE_MAPPING, FileMapping.class);
2525
typeMap.put(CustomTypes.UT_KEY_VALUE_PAIR, KeyValuePair.class);
2626
conn.setTypeMap(typeMap);

src/main/java/org/utplsql/api/FileMapping.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,42 @@ public class FileMapping implements SQLData {
1717

1818
public FileMapping() {}
1919

20+
public FileMapping(String fileName, String objectOwner, String objectName, String objectType) {
21+
this.fileName = fileName;
22+
this.objectOwner = objectOwner;
23+
this.objectName = objectName;
24+
this.objectType = objectType;
25+
}
26+
2027
public String getFileName() {
2128
return fileName;
2229
}
2330

24-
public void setFileName(String fileName) {
31+
private void setFileName(String fileName) {
2532
this.fileName = fileName;
2633
}
2734

2835
public String getObjectOwner() {
2936
return objectOwner;
3037
}
3138

32-
public void setObjectOwner(String objectOwner) {
39+
private void setObjectOwner(String objectOwner) {
3340
this.objectOwner = objectOwner;
3441
}
3542

3643
public String getObjectName() {
3744
return objectName;
3845
}
3946

40-
public void setObjectName(String objectName) {
47+
private void setObjectName(String objectName) {
4148
this.objectName = objectName;
4249
}
4350

4451
public String getObjectType() {
4552
return objectType;
4653
}
4754

48-
public void setObjectType(String objectType) {
55+
private void setObjectType(String objectType) {
4956
this.objectType = objectType;
5057
}
5158

src/main/java/org/utplsql/api/JavaApiVersionInfo.java

Lines changed: 2 additions & 0 deletions
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";

src/main/java/org/utplsql/api/KeyValuePair.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,30 @@ public String getKey() {
2222
return key;
2323
}
2424

25-
public void setKey(String key) {
26-
this.key = key;
27-
}
28-
2925
public String getValue() {
3026
return value;
3127
}
3228

33-
public void setValue(String value) {
34-
this.value = value;
35-
}
36-
3729
@Override
3830
public String getSQLTypeName() throws SQLException {
3931
return CustomTypes.UT_KEY_VALUE_PAIR;
4032
}
4133

4234
@Override
4335
public void readSQL(SQLInput stream, String typeName) throws SQLException {
44-
setKey(stream.readString());
45-
setValue(stream.readString());
36+
key = stream.readString();
37+
value = stream.readString();
4638
}
4739

4840
@Override
4941
public void writeSQL(SQLOutput stream) throws SQLException {
50-
stream.writeString(getKey());
51-
stream.writeString(getValue());
42+
stream.writeString(key);
43+
stream.writeString(value);
5244
}
5345

5446
@Override
5547
public String toString() {
56-
return String.format("%s => %s", getKey(), getValue());
48+
return String.format("%s => %s", key, value);
5749
}
5850

5951
}

src/main/java/org/utplsql/api/ResourceUtil.java

Lines changed: 2 additions & 0 deletions
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
*

src/main/java/org/utplsql/api/TestRunner.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.utplsql.api;
22

3-
import oracle.jdbc.OracleConnection;
43
import org.utplsql.api.compatibility.CompatibilityProxy;
54
import org.utplsql.api.exception.DatabaseNotCompatibleException;
65
import org.utplsql.api.exception.SomeTestsFailedException;
@@ -10,7 +9,6 @@
109
import org.utplsql.api.reporter.ReporterFactory;
1110
import org.utplsql.api.testRunner.TestRunnerStatement;
1211

13-
import java.sql.CallableStatement;
1412
import java.sql.Connection;
1513
import java.sql.SQLException;
1614
import java.util.ArrayList;
@@ -24,18 +22,18 @@
2422
*/
2523
public class TestRunner {
2624

27-
private TestRunnerOptions options = new TestRunnerOptions();
25+
private final TestRunnerOptions options = new TestRunnerOptions();
2826
private CompatibilityProxy compatibilityProxy;
2927
private ReporterFactory reporterFactory;
30-
private List<String> reporterNames = new ArrayList<>();
28+
private final List<String> reporterNames = new ArrayList<>();
3129

3230
public TestRunner addPath(String path) {
3331
options.pathList.add(path);
3432
return this;
3533
}
3634

3735
public TestRunner addPathList(List<String> paths) {
38-
if (options.pathList != null) options.pathList.addAll(paths);
36+
options.pathList.addAll(paths);
3937
return this;
4038
}
4139

@@ -115,7 +113,7 @@ public TestRunner setReporterFactory( ReporterFactory reporterFactory ) {
115113

116114
private void delayedAddReporters() {
117115
if ( reporterFactory != null )
118-
reporterNames.stream().forEach( this::addReporter );
116+
reporterNames.forEach( this::addReporter );
119117
else
120118
throw new IllegalStateException("ReporterFactory must be set to add delayed Reporters!");
121119
}
@@ -142,13 +140,8 @@ public void run(Connection conn) throws SomeTestsFailedException, SQLException,
142140
options.reporterList.add(new DocumentationReporter().init(conn));
143141
}
144142

145-
TestRunnerStatement testRunnerStatement = null;
146-
147-
try {
148-
DBHelper.enableDBMSOutput(conn);
149-
150-
testRunnerStatement = compatibilityProxy.getTestRunnerStatement(options, conn);
151-
143+
DBHelper.enableDBMSOutput(conn);
144+
try(TestRunnerStatement testRunnerStatement = compatibilityProxy.getTestRunnerStatement(options, conn)) {
152145
testRunnerStatement.execute();
153146
} catch (SQLException e) {
154147
if (e.getErrorCode() == SomeTestsFailedException.ERROR_CODE) {
@@ -161,10 +154,6 @@ else if (e.getErrorCode() == UtPLSQLNotInstalledException.ERROR_CODE) {
161154
throw e;
162155
}
163156
} finally {
164-
if (testRunnerStatement != null) {
165-
testRunnerStatement.close();
166-
}
167-
168157
DBHelper.disableDBMSOutput(conn);
169158
}
170159
}

src/main/java/org/utplsql/api/TestRunnerOptions.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.utplsql.api.reporter.Reporter;
44

55
import java.nio.charset.Charset;
6-
import java.nio.charset.StandardCharsets;
76
import java.util.ArrayList;
87
import java.util.List;
98

@@ -12,14 +11,14 @@
1211
* @author pesse
1312
*/
1413
public class TestRunnerOptions {
15-
public List<String> pathList = new ArrayList<>();
16-
public List<Reporter> reporterList = new ArrayList<>();
14+
public final List<String> pathList = new ArrayList<>();
15+
public final List<Reporter> reporterList = new ArrayList<>();
1716
public boolean colorConsole = false;
18-
public List<String> coverageSchemes = new ArrayList<>();
19-
public List<String> sourceFiles = new ArrayList<>();
20-
public List<String> testFiles = new ArrayList<>();
21-
public List<String> includeObjects = new ArrayList<>();
22-
public List<String> excludeObjects = new ArrayList<>();
17+
public final List<String> coverageSchemes = new ArrayList<>();
18+
public final List<String> sourceFiles = new ArrayList<>();
19+
public final List<String> testFiles = new ArrayList<>();
20+
public final List<String> includeObjects = new ArrayList<>();
21+
public final List<String> excludeObjects = new ArrayList<>();
2322
public FileMapperOptions sourceMappingOptions;
2423
public FileMapperOptions testMappingOptions;
2524
public boolean failOnErrors = false;

src/main/java/org/utplsql/api/Version.java

Lines changed: 32 additions & 36 deletions
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
@@ -85,11 +93,11 @@ public String getNormalizedString()
8593
StringBuilder sb = new StringBuilder();
8694
sb.append(String.valueOf(major));
8795
if ( minor != null )
88-
sb.append("." + String.valueOf(minor));
96+
sb.append(".").append(String.valueOf(minor));
8997
if ( bugfix != null )
90-
sb.append("." + String.valueOf(bugfix));
98+
sb.append(".").append(String.valueOf(bugfix));
9199
if ( build != null )
92-
sb.append("." + String.valueOf(build));
100+
sb.append(".").append(String.valueOf(build));
93101

94102
return sb.toString();
95103
}
@@ -152,41 +160,29 @@ public boolean isGreaterOrEqualThan( Version v ) throws InvalidVersionException
152160

153161
versionsAreValid(v);
154162

155-
if ( compareTo(v) >= 0 )
156-
return true;
157-
else
158-
return false;
163+
return compareTo(v) >= 0;
159164
}
160165

161166

162167
public boolean isGreaterThan( Version v) throws InvalidVersionException
163168
{
164169
versionsAreValid(v);
165170

166-
if ( compareTo(v) > 0 )
167-
return true;
168-
else
169-
return false;
171+
return compareTo(v) > 0;
170172
}
171173

172174
public boolean isLessOrEqualThan( Version v ) throws InvalidVersionException
173175
{
174176

175177
versionsAreValid(v);
176178

177-
if ( compareTo(v) <= 0 )
178-
return true;
179-
else
180-
return false;
179+
return compareTo(v) <= 0;
181180
}
182181

183182
public boolean isLessThan( Version v) throws InvalidVersionException
184183
{
185184
versionsAreValid(v);
186185

187-
if ( compareTo(v) < 0 )
188-
return true;
189-
else
190-
return false;
186+
return compareTo(v) < 0;
191187
}
192188
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy