comparison src/org/tmatesoft/hg/util/Path.java @ 705:b4242b7e7dfe

Merge command: implement conflict resolution alternatives
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 15 Aug 2013 18:43:50 +0200
parents 5d8798772cca
children
comparison
equal deleted inserted replaced
704:7743a9c10bfa 705:b4242b7e7dfe
212 * and optionally piping through a converter to get e.g. cached instance 212 * and optionally piping through a converter to get e.g. cached instance
213 */ 213 */
214 public static class SimpleSource implements Source { 214 public static class SimpleSource implements Source {
215 private final PathRewrite normalizer; 215 private final PathRewrite normalizer;
216 private final Convertor<Path> convertor; 216 private final Convertor<Path> convertor;
217 private final Path.Source delegate;
217 218
218 public SimpleSource() { 219 public SimpleSource() {
219 this(new PathRewrite.Empty(), null); 220 this(new PathRewrite.Empty(), null);
220 } 221 }
221 222
222 public SimpleSource(PathRewrite pathRewrite) { 223 public SimpleSource(PathRewrite pathRewrite) {
223 this(pathRewrite, null); 224 this(pathRewrite, null);
224 } 225 }
225 226
226 public SimpleSource(PathRewrite pathRewrite, Convertor<Path> pathConvertor) { 227 public SimpleSource(PathRewrite pathRewrite, Convertor<Path> pathConvertor) {
228 assert pathRewrite != null;
227 normalizer = pathRewrite; 229 normalizer = pathRewrite;
228 convertor = pathConvertor; 230 convertor = pathConvertor;
231 delegate = null;
232 }
233
234 public SimpleSource(Path.Source actual, Convertor<Path> pathConvertor) {
235 assert actual != null;
236 normalizer = null;
237 delegate = actual;
238 convertor = pathConvertor;
229 } 239 }
230 240
231 public Path path(CharSequence p) { 241 public Path path(CharSequence p) {
232 Path rv = Path.create(normalizer.rewrite(p)); 242 // in fact, it's nicer to have sequence of sources, and a bunch of small
243 // Source implementations each responsible for specific aspect, like Convertor
244 // or delegation to another Source. However, these classes are just too small
245 // to justify their existence
246 Path rv;
247 if (delegate != null) {
248 rv = delegate.path(p);
249 } else {
250 rv = Path.create(normalizer.rewrite(p));
251 }
233 if (convertor != null) { 252 if (convertor != null) {
234 return convertor.mangle(rv); 253 return convertor.mangle(rv);
235 } 254 }
236 return rv; 255 return rv;
237 } 256 }