5 public class BackupFilenameParts
19 public BackupFilenameParts(File file, String base, String template, int digits)
21 this(file.getName(), base, template, digits);
24 public BackupFilenameParts(String filename, String base, String template,
27 this.isBackupFile = false;
29 int numcharstart = template.indexOf(BackupFiles.NUM_PLACEHOLDER);
31 String templateStart = template;
32 String templateEnd = "";
33 if (numcharstart > -1)
35 templateStart = template.substring(0, numcharstart);
36 templateEnd = template.substring(
37 numcharstart + BackupFiles.NUM_PLACEHOLDER.length());
38 digits = suggesteddigits;
41 // calculate minimum length of a backup filename
42 int minlength = base.length() + template.length()
43 - BackupFiles.NUM_PLACEHOLDER.length() + digits ;
45 if (!(filename.startsWith(base) && filename.length() >= minlength))
51 int startLength = base.length() + templateStart.length();
52 int endLength = templateEnd.length();
53 String numString = numcharstart > -1?filename.substring(startLength,
54 filename.length() - endLength):"";
56 if (filename.length() >= startLength + digits + endLength
57 && filename.startsWith(base + templateStart)
58 && filename.endsWith(templateEnd)
59 && numString.matches("[0-9]*"))
62 this.templateStart = templateStart;
63 this.num = numString.length() > 0?Integer.parseInt(numString):0;
65 this.templateEnd = templateEnd;
66 this.isBackupFile = true;
71 public boolean isBackupFile()
73 return this.isBackupFile;