Mercurial > jhg
comparison src/org/tmatesoft/hg/util/PathRewrite.java @ 74:6f1b88693d48
Complete refactoring to org.tmatesoft
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Mon, 24 Jan 2011 03:14:45 +0100 |
| parents | 19e9e220bf68 |
| children | d55d4eedfc57 |
comparison
equal
deleted
inserted
replaced
| 73:0d279bcc4442 | 74:6f1b88693d48 |
|---|---|
| 14 * the terms of a license other than GNU General Public License | 14 * the terms of a license other than GNU General Public License |
| 15 * contact TMate Software at support@svnkit.com | 15 * contact TMate Software at support@svnkit.com |
| 16 */ | 16 */ |
| 17 package org.tmatesoft.hg.util; | 17 package org.tmatesoft.hg.util; |
| 18 | 18 |
| 19 import java.util.LinkedList; | |
| 20 import java.util.List; | |
| 21 | |
| 19 /** | 22 /** |
| 20 * | 23 * |
| 21 * @author Artem Tikhomirov | 24 * @author Artem Tikhomirov |
| 22 * @author TMate Software Ltd. | 25 * @author TMate Software Ltd. |
| 23 */ | 26 */ |
| 24 public interface PathRewrite { | 27 public interface PathRewrite { |
| 25 | 28 |
| 26 public String rewrite(String path); | 29 public String rewrite(String path); |
| 30 | |
| 31 public class Composite implements PathRewrite { | |
| 32 private List<PathRewrite> chain; | |
| 33 | |
| 34 public Composite(PathRewrite... e) { | |
| 35 LinkedList<PathRewrite> r = new LinkedList<PathRewrite>(); | |
| 36 for (int i = (e == null ? -1 : e.length); i >=0; i--) { | |
| 37 r.addFirst(e[i]); | |
| 38 } | |
| 39 chain = r; | |
| 40 } | |
| 41 public Composite chain(PathRewrite e) { | |
| 42 chain.add(e); | |
| 43 return this; | |
| 44 } | |
| 45 | |
| 46 public String rewrite(String path) { | |
| 47 for (PathRewrite pr : chain) { | |
| 48 path = pr.rewrite(path); | |
| 49 } | |
| 50 return path; | |
| 51 } | |
| 52 } | |
| 27 } | 53 } |
