1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.utgenome.gwt.utgb.client.bean;
26
27 import com.google.gwt.user.client.rpc.IsSerializable;
28
29 public class DatabaseEntry implements IsSerializable {
30
31 public String path = "";
32 public boolean isFile = false;
33
34 public DatabaseEntry() {
35 }
36
37 private DatabaseEntry(String dbFolder, boolean isFile) {
38 this.path = dbFolder;
39 this.isFile = isFile;
40 }
41
42 public static DatabaseEntry newFolder(String dbFolder) {
43 return new DatabaseEntry(dbFolder == null ? "" : dbFolder, false);
44 }
45
46 public static DatabaseEntry newFile(String dbFile) {
47 return new DatabaseEntry(dbFile == null ? "" : dbFile, true);
48 }
49
50 public String leaf() {
51 int pos = path.lastIndexOf("/");
52 if (pos == -1)
53 return path;
54 else
55 return path.substring(pos + 1);
56 }
57
58 public DatabaseEntry parent() {
59 int pos = path.lastIndexOf("/");
60
61 if (pos == -1)
62 return null;
63
64 return newFolder(path.substring(0, pos));
65 }
66
67 public static String parent(String databaseFolder) {
68 DatabaseEntry p = newFolder(databaseFolder).parent();
69 if (p == null)
70 return null;
71 else
72 return p.path;
73 }
74
75 public static String leaf(String databaseFolder) {
76 return newFolder(databaseFolder).leaf();
77 }
78
79
80
81
82
83
84
85 public String dbPath(String dbName) {
86 return path + "/" + dbName;
87 }
88
89 public boolean isFile() {
90 return isFile;
91 }
92
93 public boolean isFolder() {
94 return !isFile;
95 }
96
97 }