Skip to content

Commit

Permalink
RAT-98: Refactored DocumentName and removed FileProcessor and FilePro…
Browse files Browse the repository at this point in the history
…cessorTest (#443)

* refactored DocumentName

* removed FileProcessor and FileProcessorTest

---------

Co-authored-by: P. Ottlinger <[email protected]>
  • Loading branch information
Claudenw and ottlinger authored Feb 9, 2025
1 parent f5b80da commit 16a7756
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 225 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -67,46 +67,8 @@ public class DocumentName implements Comparable<DocumentName> {
private final String root;

/**
* Determines if the file system is case-sensitive.
* @param fileSystem the file system to check
* @return {@code true} if the file system is case-sensitive.
*/
private static boolean isCaseSensitive(final FileSystem fileSystem) {
boolean isCaseSensitive = false;
Path nameSet = null;
Path filea = null;
Path fileA = null;
try {
try {
Path root = fileSystem.getPath("");
nameSet = Files.createTempDirectory(root, "NameSet");
filea = nameSet.resolve("a");
fileA = nameSet.resolve("A");
Files.createFile(filea);
Files.createFile(fileA);
isCaseSensitive = true;
} catch (IOException e) {
// do nothing
} finally {
if (filea != null) {
Files.deleteIfExists(filea);
}
if (fileA != null) {
Files.deleteIfExists(fileA);
}
if (nameSet != null) {
Files.deleteIfExists(nameSet);
}
}
} catch (IOException e) {
// do nothing.
}
return isCaseSensitive;
}

/**
* Creates a Builder with the default File system info.
* @return the Builder.
* Creates a Builder with the default file system info.
* @return the builder.
* @see FSInfo
*/
public static Builder builder() {
Expand All @@ -124,7 +86,7 @@ public static Builder builder(final FSInfo fsInfo) {

/**
* Creates a builder for the specified file system.
* @param fileSystem the file system to create ethe builder on.
* @param fileSystem the file system to create the builder on.
* @return a new builder.
*/
public static Builder builder(final FileSystem fileSystem) {
Expand All @@ -135,16 +97,16 @@ public static Builder builder(final FileSystem fileSystem) {
* Creates a builder from a File. The {@link #baseName} is set to the file name if it is a directory otherwise
* it is set to the directory containing the file.
* @param file The file to set defaults from.
* @return the Builder.
* @return the builder.
*/
public static Builder builder(final File file) {
return new Builder(file);
}

/**
* Creates a Builder from a document name. The Builder will be configured to create a clone of the DocumentName.
* Creates a builder from a document name. The builder will be configured to create a clone of the DocumentName.
* @param documentName the document name to set the defaults from.
* @return the Builder.
* @return the builder.
*/
public static Builder builder(final DocumentName documentName) {
return new Builder(documentName);
Expand Down Expand Up @@ -188,15 +150,15 @@ public DocumentName resolve(final String child) {
if (StringUtils.isBlank(child)) {
return this;
}
String separator = fsInfo.dirSeparator();
String separator = getDirectorySeparator();
String pattern = separator.equals("/") ? child.replace('\\', '/') :
child.replace('/', '\\');

if (!pattern.startsWith(separator)) {
pattern = name + separator + pattern;
}

return new Builder(this).setName(pattern).build();
return new Builder(this).setName(fsInfo.normalize(pattern)).build();
}

/**
Expand Down Expand Up @@ -241,7 +203,7 @@ public String getDirectorySeparator() {

/**
* Determines if the candidate starts with the root or separator strings.
* @param candidate the candidate ot check. If blank method will return {@code false}.
* @param candidate the candidate to check. If blank method will return {@code false}.
* @param root the root to check. If blank the root check is skipped.
* @param separator the separator to check. If blank the check is skipped.
* @return true if either the root or separator check returned {@code true}.
Expand Down Expand Up @@ -370,11 +332,49 @@ public FSInfo(final FileSystem fileSystem) {
public FSInfo(final String name, final FileSystem fileSystem) {
this.name = name;
this.separator = fileSystem.getSeparator();
this.isCaseSensitive = DocumentName.isCaseSensitive(fileSystem);
this.isCaseSensitive = isCaseSensitive(fileSystem);
roots = new ArrayList<>();
fileSystem.getRootDirectories().forEach(r -> roots.add(r.toString()));
}

/**
* Determines if the file system is case-sensitive.
* @param fileSystem the file system to check.
* @return {@code true} if the file system is case-sensitive.
*/
private static boolean isCaseSensitive(final FileSystem fileSystem) {
boolean isCaseSensitive = false;
Path nameSet = null;
Path filea = null;
Path fileA = null;
try {
try {
Path root = fileSystem.getPath("");
nameSet = Files.createTempDirectory(root, "NameSet");
filea = nameSet.resolve("a");
fileA = nameSet.resolve("A");
Files.createFile(filea);
Files.createFile(fileA);
isCaseSensitive = true;
} catch (IOException e) {
// do nothing
} finally {
if (filea != null) {
Files.deleteIfExists(filea);
}
if (fileA != null) {
Files.deleteIfExists(fileA);
}
if (nameSet != null) {
Files.deleteIfExists(nameSet);
}
}
} catch (IOException e) {
// do nothing.
}
return isCaseSensitive;
}

/**
* Gets the common name for the underlying file system.
* @return the common file system name.
Expand Down

This file was deleted.

0 comments on commit 16a7756

Please sign in to comment.