Mercurial > jhg
comparison src/org/tmatesoft/hg/core/Path.java @ 64:19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 21 Jan 2011 05:56:43 +0100 |
parents | |
children | c677e1593919 |
comparison
equal
deleted
inserted
replaced
63:a47530a2ea12 | 64:19e9e220bf68 |
---|---|
1 /* | |
2 * Copyright (c) 2011 TMate Software Ltd | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * For information on how to redistribute this software under | |
14 * the terms of a license other than GNU General Public License | |
15 * contact TMate Software at support@svnkit.com | |
16 */ | |
17 package org.tmatesoft.hg.core; | |
18 | |
19 /** | |
20 * Identify repository files (not String nor io.File). Convenient for pattern matching. Memory-friendly. | |
21 * | |
22 * @author Artem Tikhomirov | |
23 * @author TMate Software Ltd. | |
24 */ | |
25 public final class Path implements CharSequence, Comparable<Path>/*Cloneable? - although clone for paths make no sense*/{ | |
26 // private String[] segments; | |
27 // private int flags; // dir, unparsed | |
28 private String path; | |
29 | |
30 /*package-local*/Path(String p) { | |
31 path = p; | |
32 } | |
33 | |
34 public int length() { | |
35 return path.length(); | |
36 } | |
37 | |
38 public char charAt(int index) { | |
39 return path.charAt(index); | |
40 } | |
41 | |
42 public CharSequence subSequence(int start, int end) { | |
43 // new Path if start-end matches boundaries of any subpath | |
44 return path.substring(start, end); | |
45 } | |
46 | |
47 @Override | |
48 public String toString() { | |
49 return path; // CharSequence demands toString() impl | |
50 } | |
51 | |
52 public int compareTo(Path o) { | |
53 return path.compareTo(o.path); | |
54 } | |
55 | |
56 @Override | |
57 public boolean equals(Object obj) { | |
58 if (obj != null && getClass() == obj.getClass()) { | |
59 return this == obj || path.equals(((Path) obj).path); | |
60 } | |
61 return false; | |
62 } | |
63 @Override | |
64 public int hashCode() { | |
65 return path.hashCode(); | |
66 } | |
67 | |
68 public static Path create(String path) { | |
69 if (path == null) { | |
70 throw new IllegalArgumentException(); | |
71 } | |
72 Path rv = new Path(path); | |
73 return rv; | |
74 } | |
75 public interface Matcher { | |
76 public boolean accept(Path path); | |
77 } | |
78 } |