Commit 077ce169 authored by Dr. Martin Goik's avatar Dr. Martin Goik

NO_DRIVE

parent b8b99a4e
......@@ -8,13 +8,19 @@ import java.util.StringTokenizer;
*
*/
public class FileMetaInfo {
/**
* This is »/« on Unix/MacOS and »\« on Windows file systems.
*/
static public final char fileSeparatorChar = System.getProperty("file.separator").charAt(0);
static public final String fileSeparatorString = // Essentially the same, but we'd otherwise need tons of
System.getProperty("file.separator"); // String.valueOf(fileSeparatorChar) calls cluttering our code
public static final char noDrive = 0;
/**
* Indicating the absence of a drive letter like e.g. »C:«
*/
public static final char NO_DRIVE = 0;
static final boolean isWindowsOs = System.getProperty("os.name").startsWith("Windows"); // true for Windows ... XP / 7 / 8 / 10 / ...
......@@ -45,11 +51,11 @@ public class FileMetaInfo {
pathComponents = new StringTokenizer(filePathName.substring(2), fileSeparatorString); // Ignoring first two drive related letters
} else { // relative path not starting with a drive letter
isRelative = true;
drive = noDrive;
drive = NO_DRIVE;
pathComponents = new StringTokenizer(filePathName, fileSeparatorString);
}
} else {
drive = noDrive;
drive = NO_DRIVE;
if (filePathName.charAt(0) == fileSeparatorChar) {
isRelative = false;
} else {
......
......@@ -20,7 +20,7 @@ public class MetaInfoUnixTest {
final FileMetaInfo fmi = new FileMetaInfo("/usr/openvpn/hdm");
Assert.assertFalse(fmi.isRelative);
Assert.assertEquals(FileMetaInfo.noDrive, fmi.drive);
Assert.assertEquals(FileMetaInfo.NO_DRIVE, fmi.drive);
Assert.assertEquals("/usr/openvpn", fmi.path);
Assert.assertEquals("hdm", fmi.basename);
Assert.assertEquals(null, fmi.extension);
......@@ -33,7 +33,7 @@ public class MetaInfoUnixTest {
final FileMetaInfo fmi = new FileMetaInfo("/usr/openvpn/hdm.conf");
Assert.assertFalse(fmi.isRelative);
Assert.assertEquals(FileMetaInfo.noDrive, fmi.drive);
Assert.assertEquals(FileMetaInfo.NO_DRIVE, fmi.drive);
Assert.assertEquals("/usr/openvpn", fmi.path);
Assert.assertEquals("hdm", fmi.basename);
Assert.assertEquals("conf", fmi.extension);
......@@ -46,7 +46,7 @@ public class MetaInfoUnixTest {
final FileMetaInfo fmi = new FileMetaInfo("../Desktop/icon");
Assert.assertTrue(fmi.isRelative);
Assert.assertEquals(FileMetaInfo.noDrive, fmi.drive);
Assert.assertEquals(FileMetaInfo.NO_DRIVE, fmi.drive);
Assert.assertEquals("../Desktop", fmi.path);
Assert.assertEquals("icon", fmi.basename);
Assert.assertEquals(null, fmi.extension);
......@@ -59,7 +59,7 @@ public class MetaInfoUnixTest {
final FileMetaInfo fmi = new FileMetaInfo("../../Desktop/icon.gif");
Assert.assertTrue(fmi.isRelative);
Assert.assertEquals(FileMetaInfo.noDrive, fmi.drive);
Assert.assertEquals(FileMetaInfo.NO_DRIVE, fmi.drive);
Assert.assertEquals("../../Desktop", fmi.path);
Assert.assertEquals("icon", fmi.basename);
Assert.assertEquals("gif", fmi.extension);
......
......@@ -46,7 +46,7 @@ public class MetaInfoWindowsTest {
final FileMetaInfo fmi = new FileMetaInfo("..\\Desktop\\icon");
Assert.assertTrue(fmi.isRelative);
Assert.assertEquals(FileMetaInfo.noDrive, fmi.drive);
Assert.assertEquals(FileMetaInfo.NO_DRIVE, fmi.drive);
Assert.assertEquals("..\\Desktop", fmi.path);
Assert.assertEquals("icon", fmi.basename);
Assert.assertEquals(null, fmi.extension);
......@@ -59,7 +59,7 @@ public class MetaInfoWindowsTest {
final FileMetaInfo fmi = new FileMetaInfo("..\\..\\Desktop\\icon.gif");
Assert.assertTrue(fmi.isRelative);
Assert.assertEquals(FileMetaInfo.noDrive, fmi.drive);
Assert.assertEquals(FileMetaInfo.NO_DRIVE, fmi.drive);
Assert.assertEquals("..\\..\\Desktop", fmi.path);
Assert.assertEquals("icon", fmi.basename);
Assert.assertEquals("gif", fmi.extension);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment