Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/com/nordstrom/common/file/OSInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
*/
public class OSInfo<T extends Enum<T> & OSInfo.OSProps> {

private static String osName = System.getProperty("os.name");
private static String version = System.getProperty("os.version");
private static String arch = System.getProperty("os.arch");
private static final String osName = System.getProperty("os.name");
private static final String version = System.getProperty("os.version");
private static final String arch = System.getProperty("os.arch");

private final Map<T, String> typeMap = new LinkedHashMap<>();

Expand Down
68 changes: 43 additions & 25 deletions src/main/java/com/nordstrom/common/file/PathUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public enum ReportsDirectory {
FAILSAFE_3("(.*)(ITCase)", FAILSAFE_PATH),
ARTIFACT(".*", "artifact-capture");

private String regex;
private String folder;
private final String regex;
private final String folder;

ReportsDirectory(String regex, String folder) {
this.regex = regex;
Expand Down Expand Up @@ -196,11 +196,12 @@ public static String getBaseDir() {

private static class Visitor implements FileVisitor<Path> {

private String baseName;
private String extension;
private int base, ext;
private PathMatcher pathMatcher;
private List<Integer> intList = new ArrayList<>();
private final String baseName;
private final String extension;
private final int base;
private final int ext;
private final PathMatcher pathMatcher;
private final List<Integer> intList = new ArrayList<>();

Visitor(String baseName, String extension) {
this.baseName = baseName;
Expand All @@ -221,7 +222,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
String name = file.getFileName().toString();
String iStr = "0" + name.substring(base, name.length() - ext);
iStr = iStr.replace("0-", "");
intList.add(Integer.valueOf(iStr) + 1);
intList.add(Integer.parseInt(iStr) + 1);
}
return FileVisitResult.CONTINUE;
}
Expand All @@ -242,7 +243,7 @@ public String getNewName() {
if (intList.isEmpty()) {
newName = baseName + "." + extension;
} else {
Collections.sort(intList, Collections.reverseOrder());
intList.sort(Collections.reverseOrder());
newName = baseName + "-" + intList.get(0) + "." + extension;
}

Expand Down Expand Up @@ -286,9 +287,9 @@ public static boolean addSystemPathList(List<String> pathList) {
}
}
String path = env.get(name);
return (path != null) ? pathList.addAll(Arrays.asList(path.split(File.pathSeparator))) : false;
return (path != null) && addNewPaths(pathList, Arrays.asList(path.split(File.pathSeparator)));
}

/**
* Append Macintosh path entries to the specified list.
* <p>
Expand All @@ -300,27 +301,44 @@ public static boolean addSystemPathList(List<String> pathList) {
*/
public static boolean addMacintoshPathList(List<String> pathList) {
boolean didChange = false;
if (System.getProperty("os.name").startsWith("Mac")) {
List<String> pathFileList = new ArrayList<>();
pathFileList.add("/etc/paths");
String[] paths = new File("/etc/paths.d").list();
if (paths != null) {
pathFileList.addAll(Arrays.asList(paths));
if (OSInfo.getDefault().getType() == OSInfo.OSType.MACINTOSH) {
List<File> fileList = new ArrayList<>();
File pathsFile = new File("/etc/paths");
if (pathsFile.exists()) fileList.add(pathsFile);
File[] pathsList = new File("/etc/paths.d").listFiles();
if (pathsList != null) {
fileList.addAll(Arrays.asList(pathsList));
}
for (String thisPathFile : pathFileList) {
File pathFile = new File(thisPathFile);
if (pathFile.exists()) {
try {
didChange |= pathList.addAll(Files.readAllLines(pathFile.toPath()));
} catch (IOException eaten) {
// nothing to do here
}
for (File thisFile : fileList) {
try {
didChange |= addNewPaths(pathList, Files.readAllLines(thisFile.toPath()));
} catch (IOException eaten) {
// nothing to do here
}
}
}
return didChange;
}

/**
* Append new path entries to the specified list.
* <p>
* <b>NOTE</b>: Entries from [newPaths] that already exist in [pathList] are ignored.
*
* @param pathList existing list to receive new path entries
* @param newPaths path entries to be evaluated for novelty
* @return {@code true} if entries were appended; otherwise {@code false}
*/
private static boolean addNewPaths(List<String> pathList, List<String> newPaths) {
boolean didChange = false;
for (String thisPath : newPaths) {
if (!pathList.contains(thisPath)) {
didChange |= pathList.add(thisPath);
}
}
return didChange;
}

/**
* Prepend the specified string to the indicated array.
*
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/nordstrom/common/file/VolumeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class VolumeInfo {

static final boolean IS_WINDOWS = (OSInfo.getDefault().getType() == OSType.WINDOWS);

private VolumeInfo() {
throw new AssertionError("VolumeInfo is a static utility class that cannot be instantiated");
}
Expand Down Expand Up @@ -80,7 +80,7 @@ public static class VolumeProps {
String type;
String[] opts;

private long size;
private final long size;
private long free;

VolumeProps(String spec, String file, String type, String... opts) {
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/nordstrom/common/jdbc/DatabaseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
*/
public class DatabaseUtils {

private static Pattern SPROC_PATTERN =
private static final Pattern SPROC_PATTERN =
Pattern.compile("([\\p{Alpha}_][\\p{Alpha}\\p{Digit}@$#_]*)(?:\\(([<>=](?:,\\s*[<>=])*)?(:)?\\))?");

private DatabaseUtils() {
Expand All @@ -94,7 +94,7 @@ private DatabaseUtils() {
*/
public static int update(QueryAPI query, Object... queryArgs) {
Integer result = executeQuery(null, query, queryArgs);
return (result != null) ? result.intValue() : -1;
return (result != null) ? result : -1;
}

/**
Expand All @@ -106,7 +106,7 @@ public static int update(QueryAPI query, Object... queryArgs) {
* @throws IllegalStateException if no rows were returned
*/
public static int getInt(QueryAPI query, Object... queryArgs) {
return requireResult(Integer.class, query, queryArgs).intValue();
return requireResult(Integer.class, query, queryArgs);
}

/**
Expand Down Expand Up @@ -240,7 +240,7 @@ public static <T> T executeQuery(Class<T> resultType, String connectionStr, Stri
* @throws IllegalStateException if no rows were returned
*/
public static int getInt(SProcAPI sproc, Object... params) {
return requireResult(Integer.class, sproc, params).intValue();
return requireResult(Integer.class, sproc, params);
}

/**
Expand Down Expand Up @@ -465,7 +465,7 @@ public static <T> T executeStoredProcedure(Class<T> resultType, String connectio
*
* @param <T> desired result type
* @param resultType desired result type (see TYPES above)
* @param connectionStr database connection string
* @param connection database connection string
* @param statement prepared statement to be executed (query or store procedure)
* @return for update operations, the number of rows affected; for query operations, an object of the indicated type
* <p>
Expand All @@ -481,7 +481,7 @@ private static <T> T executeStatement(Class<T> resultType, Connection connection

try {
if (resultType == null) {
result = Integer.valueOf(statement.executeUpdate());
result = statement.executeUpdate();
} else {
if (statement instanceof CallableStatement) {
if (statement.execute()) {
Expand All @@ -503,7 +503,7 @@ private static <T> T executeStatement(Class<T> resultType, Connection connection
if (resultType == ResultPackage.class) {
result = new ResultPackage(connection, statement, resultSet); //NOSONAR
} else if (resultType == Integer.class) {
result = Integer.valueOf((resultSet.next()) ? resultSet.getInt(1) : -1);
result = (resultSet.next()) ? resultSet.getInt(1) : -1;
} else if (resultType == String.class) {
result = (resultSet.next()) ? resultSet.getString(1) : null;
} else {
Expand Down Expand Up @@ -894,20 +894,20 @@ public void close() {
try {
resultSet.close();
resultSet = null;
} catch (SQLException e) { }
} catch (SQLException ignored) { }
}
if (statement != null) {
try {
statement.close();
statement = null;
} catch (SQLException e) { }
} catch (SQLException ignored) { }
}
if (connection != null) {
try {
connection.commit();
connection.close();
connection = null;
} catch (SQLException e) { }
} catch (SQLException ignored) { }
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/nordstrom/common/jdbc/Param.java
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@ public enum Mode {
private static final int INPUT = 1;
private static final int OUTPUT = 2;

private char chr;
private int val;
private final char chr;
private final int val;

/**
* Constructor
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/nordstrom/common/file/OSInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class OSInfoTest {

private static String osName = System.getProperty("os.name").toLowerCase();
private static final String osName = System.getProperty("os.name").toLowerCase();

@Test
public void testDefaultMapping() {
Expand Down
12 changes: 10 additions & 2 deletions src/test/java/com/nordstrom/common/file/PathUtilsTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.nordstrom.common.file;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;

import java.io.File;
import java.io.IOException;
Expand All @@ -15,6 +16,7 @@
import org.testng.ITestResult;
import org.testng.Reporter;
import org.testng.annotations.Test;
import org.testng.util.Strings;

public class PathUtilsTest {

Expand Down Expand Up @@ -81,8 +83,7 @@ private Path getOutputPath() {
ITestResult testResult = Reporter.getCurrentTestResult();
ITestContext testContext = testResult.getTestContext();
String outputDirectory = testContext.getOutputDirectory();
Path outputDir = Paths.get(outputDirectory);
return outputDir;
return Paths.get(outputDirectory);
}

private Path getBasePath() {
Expand Down Expand Up @@ -137,4 +138,11 @@ public void testNullExtenstion() throws IOException {
public void testEmptyExtension() throws IOException {
PathUtils.getNextPath(getOutputPath(), "test", "");
}

@Test
public void testGetSystemPath() {
String systemPath = PathUtils.getSystemPath();
assertFalse(Strings.isNullOrEmpty(systemPath));
}

}
2 changes: 1 addition & 1 deletion src/test/java/com/nordstrom/common/jar/JarUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public class JarUtilsTest {

private static String[] CONTEXTS = { "org.testng.annotations.Test", "com.beust.jcommander.JCommander",
private static final String[] CONTEXTS = { "org.testng.annotations.Test", "com.beust.jcommander.JCommander",
"org.apache.derby.jdbc.EmbeddedDriver", "com.google.common.base.Charsets" };

@Test
Expand Down
18 changes: 9 additions & 9 deletions src/test/java/com/nordstrom/common/jdbc/DatabaseUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void updateRows() {
public void showAddresses() {
try {
DatabaseUtils.update(TestQuery.SHOW_ADDRESSES);
} catch (Exception e) {
} catch (Exception ignored) {
}

ResultPackage pkg = DatabaseUtils.getResultPackage(TestSProc.SHOW_ADDRESSES);
Expand All @@ -97,7 +97,7 @@ public void showAddresses() {
String addr = pkg.getResultSet().getString("addr");
System.out.println("addr" + rowCount + ": " + num + " " + addr);
}
} catch (SQLException e) {
} catch (SQLException ignored) {
}
pkg.close();

Expand Down Expand Up @@ -130,7 +130,7 @@ public void dropTable() {
public void testInVarargs() {
try {
DatabaseUtils.update(TestQuery.IN_VARARGS);
} catch (Exception e) {
} catch (Exception ignored) {
}

String result = DatabaseUtils.getString(TestSProc.IN_VARARGS, "", 5, 4, 3);
Expand All @@ -142,7 +142,7 @@ public void testInVarargs() {
public void testOutVarargs() throws SQLException {
try {
DatabaseUtils.update(TestQuery.OUT_VARARGS);
} catch (Exception e) {
} catch (Exception ignored) {
}

ResultPackage pkg = DatabaseUtils.getResultPackage(TestSProc.OUT_VARARGS, 5, 0, 0, 0);
Expand All @@ -164,7 +164,7 @@ public void testOutVarargs() throws SQLException {
public void testInOutVarargs() throws SQLException {
try {
DatabaseUtils.update(TestQuery.INOUT_VARARGS);
} catch (Exception e) {
} catch (Exception ignored) {
}

ResultPackage pkg = DatabaseUtils.getResultPackage(TestSProc.INOUT_VARARGS, 5, 3, 10, 100);
Expand Down Expand Up @@ -207,8 +207,8 @@ enum TestQuery implements QueryAPI {
+ "external name 'com.nordstrom.common.jdbc.StoredProcedure.inoutVarargs'"),
DROP_PROC_INOUT("drop procedure INOUT_VARARGS");

private String query;
private String[] args;
private final String query;
private final String[] args;

TestQuery(String query, String... args) {
this.query = query;
Expand Down Expand Up @@ -246,8 +246,8 @@ enum TestSProc implements SProcAPI {
OUT_VARARGS("OUT_VARARGS(>, <:)", Types.INTEGER, Types.INTEGER),
INOUT_VARARGS("INOUT_VARARGS(>, =:)", Types.INTEGER, Types.INTEGER);

private int[] argTypes;
private String signature;
private final int[] argTypes;
private final String signature;

TestSProc(String signature, int... argTypes) {
this.signature = signature;
Expand Down
Loading