01: /*
02: * Created on Jul 28, 2005
03: */
04: package uk.org.ponder.rsf.util;
05:
06: import uk.org.ponder.stringutil.CharWrap;
07:
08: /**
09: * @author Antranig Basman (antranig@caret.cam.ac.uk)
10: *
11: */
12: public class SplitID {
13: public static final String WILDCARD_COMPONENT = "*";
14: public static final char SEPARATOR = ':';
15: public String prefix;
16: public String suffix;
17:
18: public SplitID(String id) {
19: int colpos = id.indexOf(SEPARATOR);
20: if (colpos == -1) {
21: prefix = id;
22: } else {
23: prefix = id.substring(0, colpos);
24: suffix = id.substring(colpos + 1);
25: }
26: }
27:
28: public String toString() {
29: CharWrap togo = new CharWrap(prefix.length() + suffix.length()
30: + 1);
31: togo.append(prefix);
32: if (suffix != null) {
33: togo.append(SEPARATOR).append(suffix);
34: }
35: return togo.toString();
36: }
37:
38: public static boolean isSplit(String id) {
39: return id.indexOf(SEPARATOR) != -1;
40: }
41:
42: public static String getSuffix(String id) {
43: int colpos = id.indexOf(SEPARATOR);
44: return (colpos == -1) ? null : id.substring(colpos + 1);
45: }
46:
47: /** Returns the "raw" prefix of the ID - i.e. the part before the colon
48: * if one appears, or the entire ID if none.
49: */
50: public static String getPrefix(String id) {
51: int colpos = id.indexOf(SEPARATOR);
52: return colpos == -1 ? id : id.substring(0, colpos);
53: }
54:
55: /** Returns the "repetitive" prefix of the ID - i.e. the prefix including
56: * colon if one appears, or null if none.
57: */
58: public static String getPrefixColon(String id) {
59: int colpos = id.indexOf(SEPARATOR);
60: return colpos == -1 ? null : id.substring(0, colpos + 1);
61: }
62: }
|