Mercurial > jhg
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 430:d280759c2a3f | 431:12f668401613 |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 TMate Software Ltd | 2 * Copyright (c) 2011-2012 TMate Software Ltd |
| 3 * | 3 * |
| 4 * This program is free software; you can redistribute it and/or modify | 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 | 5 * it under the terms of the GNU General Public License as published by |
| 6 * the Free Software Foundation; version 2 of the License. | 6 * the Free Software Foundation; version 2 of the License. |
| 7 * | 7 * |
| 185 | 185 |
| 186 /** | 186 /** |
| 187 * Factory for paths | 187 * Factory for paths |
| 188 */ | 188 */ |
| 189 public interface Source { | 189 public interface Source { |
| 190 Path path(String p); | 190 Path path(CharSequence p); |
| 191 } | 191 } |
| 192 | 192 |
| 193 /** | 193 /** |
| 194 * Straightforward {@link Source} implementation that creates new Path instance for each supplied string | 194 * Straightforward {@link Source} implementation that creates new Path instance for each supplied string |
| 195 * and optionally piping through a converter to get e.g. cached instance | |
| 195 */ | 196 */ |
| 196 public static class SimpleSource implements Source { | 197 public static class SimpleSource implements Source { |
| 197 private final PathRewrite normalizer; | 198 private final PathRewrite normalizer; |
| 199 private final Convertor<Path> convertor; | |
| 200 | |
| 201 public SimpleSource() { | |
| 202 this(new PathRewrite.Empty(), null); | |
| 203 } | |
| 198 | 204 |
| 199 public SimpleSource(PathRewrite pathRewrite) { | 205 public SimpleSource(PathRewrite pathRewrite) { |
| 200 if (pathRewrite == null) { | 206 this(pathRewrite, null); |
| 201 throw new IllegalArgumentException(); | 207 } |
| 202 } | 208 |
| 209 public SimpleSource(PathRewrite pathRewrite, Convertor<Path> pathConvertor) { | |
| 203 normalizer = pathRewrite; | 210 normalizer = pathRewrite; |
| 204 } | 211 convertor = pathConvertor; |
| 205 | 212 } |
| 206 public Path path(String p) { | 213 |
| 207 return Path.create(normalizer.rewrite(p)); | 214 public Path path(CharSequence p) { |
| 215 Path rv = Path.create(normalizer.rewrite(p)); | |
| 216 if (convertor != null) { | |
| 217 return convertor.mangle(rv); | |
| 218 } | |
| 219 return rv; | |
| 208 } | 220 } |
| 209 } | 221 } |
| 210 } | 222 } |
