Mercurial > hg4j
comparison src/org/tmatesoft/hg/util/Path.java @ 339:863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 16 Nov 2011 22:42:21 +0100 |
parents | a415fe296a50 |
children | 12f668401613 |
comparison
equal
deleted
inserted
replaced
338:3cfa4d908fc9 | 339:863356c2847e |
---|---|
15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com |
16 */ | 16 */ |
17 package org.tmatesoft.hg.util; | 17 package org.tmatesoft.hg.util; |
18 | 18 |
19 import java.util.Collection; | 19 import java.util.Collection; |
20 import java.util.Iterator; | |
21 import java.util.NoSuchElementException; | |
20 | 22 |
21 /** | 23 /** |
22 * Identify repository files (not String nor io.File). Convenient for pattern matching. Memory-friendly. | 24 * Identify repository files (not String nor io.File). Convenient for pattern matching. Memory-friendly. |
23 * | 25 * |
24 * @author Artem Tikhomirov | 26 * @author Artem Tikhomirov |
59 | 61 |
60 @Override | 62 @Override |
61 public String toString() { | 63 public String toString() { |
62 return path; // CharSequence demands toString() impl | 64 return path; // CharSequence demands toString() impl |
63 } | 65 } |
66 | |
67 public Iterable<String> segments() { | |
68 class SegSeq implements Iterable<String>, Iterator<String> { | |
69 private int pos; // first char to return | |
70 | |
71 public Iterator<String> iterator() { | |
72 reset(); | |
73 return this; | |
74 } | |
75 public boolean hasNext() { | |
76 return pos < path.length(); | |
77 } | |
78 public String next() { | |
79 if (pos >= path.length()) { | |
80 throw new NoSuchElementException(); | |
81 } | |
82 int x = path.indexOf('/', pos); | |
83 if (x == -1) { | |
84 String rv = path.substring(pos); | |
85 pos = path.length(); | |
86 return rv; | |
87 } else { | |
88 String rv = path.substring(pos, x); | |
89 pos = x+1; | |
90 return rv; | |
91 } | |
92 } | |
93 public void remove() { | |
94 throw new UnsupportedOperationException(); | |
95 } | |
96 | |
97 private void reset() { | |
98 pos = 0; | |
99 } | |
100 }; | |
101 return new SegSeq(); | |
102 } | |
64 | 103 |
65 public int compareTo(Path o) { | 104 public int compareTo(Path o) { |
66 return path.compareTo(o.path); | 105 return path.compareTo(o.path); |
67 } | 106 } |
68 | 107 |