Mercurial > hg4j
comparison src/org/tmatesoft/hg/util/Path.java @ 133:4a948ec83980
core.Path to util.Path as it's not Hg repo dependant
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Wed, 16 Feb 2011 20:59:39 +0100 |
| parents | src/org/tmatesoft/hg/core/Path.java@a3a2e5deb320 |
| children | 8248aae33f7d |
comparison
equal
deleted
inserted
replaced
| 132:6778075cd2b4 | 133:4a948ec83980 |
|---|---|
| 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@hg4j.com | |
| 16 */ | |
| 17 package org.tmatesoft.hg.util; | |
| 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 if (path.indexOf('\\') != -1) { | |
| 73 throw new IllegalArgumentException(); | |
| 74 } | |
| 75 Path rv = new Path(path); | |
| 76 return rv; | |
| 77 } | |
| 78 | |
| 79 /** | |
| 80 * Path filter. | |
| 81 */ | |
| 82 public interface Matcher { | |
| 83 public boolean accept(Path path); | |
| 84 } | |
| 85 } |
