[Schmitzm-commits] r193 - trunk/src/schmitzm/io
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Jul 6 12:40:00 CEST 2009
Author: alfonx
Date: 2009-07-06 12:40:00 +0200 (Mon, 06 Jul 2009)
New Revision: 193
Modified:
trunk/src/schmitzm/io/IOUtil.java
Log:
* Refactored
public static String getBaseFileName(File file) {
int extIdx = getFileExtIdx(file);
to
public static String getBaseFilePath(File file) {
int extIdx = getFileExtIdx(file);
because not only the name (as in File.getName() ) was returned, but the File.getPath() without the postfix. As i did refactoring, all references in Atlas, ISDSS, XULU and schmitzm should be changed to getBaseFilePath automatically.
* Created a method getBaseFileName(File file) that really just return the filename without it's extension.
Modified: trunk/src/schmitzm/io/IOUtil.java
===================================================================
--- trunk/src/schmitzm/io/IOUtil.java 2009-07-03 16:28:15 UTC (rev 192)
+++ trunk/src/schmitzm/io/IOUtil.java 2009-07-06 10:40:00 UTC (rev 193)
@@ -79,13 +79,20 @@
* @param file Datei
*/
public static int getFileExtIdx(File file) {
- String fileName = file.getAbsolutePath();
+ return getFileExtIdx(file.getAbsolutePath());
+ }
- int lastPointIdx = fileName.lastIndexOf('.');
- int lastSepIdx = fileName.lastIndexOf(File.separatorChar);
- if ( lastPointIdx < lastSepIdx )
- return -1;
- return lastPointIdx;
+ /**
+ * Liefert den Index des Dateinames, an der die Dateinamen-Erweiterung
+ * (inkl. Punkt) beginnt.
+ * @param file Datei
+ */
+ public static int getFileExtIdx(String pathOrName) {
+ int lastPointIdx = pathOrName.lastIndexOf('.');
+ int lastSepIdx = pathOrName.lastIndexOf(File.separatorChar);
+ if ( lastPointIdx < lastSepIdx )
+ return -1;
+ return lastPointIdx;
}
/**
@@ -136,7 +143,7 @@
* @return neues {@link File}-Objekt
*/
public static File changeFileExt(File file, String newExt) {
- String baseName = getBaseFileName(file);
+ String baseName = getBaseFilePath(file);
return new File( baseName+"."+newExt );
}
@@ -209,10 +216,13 @@
/**
- * Liefert den Namen ohne Erweiterung (z.B. ohne ".exe") einer Datei.
+ * Liefert den Pfad ohne Erweiterung (z.B. ohne ".exe") einer Datei.
+ *
* @param file Datei
+ *
+ * @see #getBaseFileName(File)
*/
- public static String getBaseFileName(File file) {
+ public static String getBaseFilePath(File file) {
int extIdx = getFileExtIdx(file);
if ( extIdx < 0 )
return file.getAbsolutePath();
@@ -220,6 +230,20 @@
}
/**
+ * Liefert den Dateinamen ohne Erweiterung (z.B. ohne ".exe") einer Datei.
+ *
+ * @param file Datei
+ *
+ * @see #getBaseFilePath(File)
+ */
+ public static String getBaseFileName(File file) {
+ int extIdx = getFileExtIdx( file.getName() );
+ if ( extIdx < 0 )
+ return file.getName();
+ return file.getName().substring(0,extIdx);
+ }
+
+ /**
* Liefert das oberste Verzeichnis zu einer Datei (Haupt-Verzeichnis).
* @param file Datei
*/
More information about the Schmitzm-commits
mailing list