Mercurial > jhg
diff src/org/tmatesoft/hg/util/Path.java @ 431:12f668401613
FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 29 Mar 2012 20:54:04 +0200 |
parents | 863356c2847e |
children | 072b5f3ed0c8 |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/util/Path.java Thu Mar 29 18:48:23 2012 +0200 +++ b/src/org/tmatesoft/hg/util/Path.java Thu Mar 29 20:54:04 2012 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 TMate Software Ltd + * Copyright (c) 2011-2012 TMate Software Ltd * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -187,24 +187,36 @@ * Factory for paths */ public interface Source { - Path path(String p); + Path path(CharSequence p); } - + /** * Straightforward {@link Source} implementation that creates new Path instance for each supplied string + * and optionally piping through a converter to get e.g. cached instance */ public static class SimpleSource implements Source { private final PathRewrite normalizer; + private final Convertor<Path> convertor; + + public SimpleSource() { + this(new PathRewrite.Empty(), null); + } public SimpleSource(PathRewrite pathRewrite) { - if (pathRewrite == null) { - throw new IllegalArgumentException(); - } - normalizer = pathRewrite; + this(pathRewrite, null); } - public Path path(String p) { - return Path.create(normalizer.rewrite(p)); + public SimpleSource(PathRewrite pathRewrite, Convertor<Path> pathConvertor) { + normalizer = pathRewrite; + convertor = pathConvertor; + } + + public Path path(CharSequence p) { + Path rv = Path.create(normalizer.rewrite(p)); + if (convertor != null) { + return convertor.mangle(rv); + } + return rv; } } }