5 public class BackupFilenameParts
19 public BackupFilenameParts(File file, String base, String template,
22 this(file.getName(), base, template, digits);
25 public BackupFilenameParts(String filename, String base, String template,
28 this.isBackupFile = false;
30 int numcharstart = template.indexOf(BackupFiles.NUM_PLACEHOLDER);
32 String templateStart = template;
33 String templateEnd = "";
34 if (numcharstart > -1)
36 templateStart = template.substring(0, numcharstart);
37 templateEnd = template.substring(
38 numcharstart + BackupFiles.NUM_PLACEHOLDER.length());
39 digits = suggesteddigits;
42 // calculate minimum length of a backup filename
43 int minlength = base.length() + template.length()
44 - BackupFiles.NUM_PLACEHOLDER.length() + digits;
46 if (!(filename.startsWith(base) && filename.length() >= minlength))
52 int startLength = base.length() + templateStart.length();
53 int endLength = templateEnd.length();
54 String numString = numcharstart > -1
55 ? filename.substring(startLength, filename.length() - endLength)
58 if (filename.length() >= startLength + digits + endLength
59 && filename.startsWith(base + templateStart)
60 && filename.endsWith(templateEnd)
61 && numString.matches("[0-9]*"))
64 this.templateStart = templateStart;
65 this.num = numString.length() > 0 ? Integer.parseInt(numString) : 0;
67 this.templateEnd = templateEnd;
68 this.isBackupFile = true;
73 public boolean isBackupFile()
75 return this.isBackupFile;