Mercurial > jhg
diff 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 |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/util/PathRewrite.java Sun Jan 23 04:06:18 2011 +0100 +++ b/src/org/tmatesoft/hg/util/PathRewrite.java Mon Jan 24 03:14:45 2011 +0100 @@ -16,6 +16,9 @@ */ package org.tmatesoft.hg.util; +import java.util.LinkedList; +import java.util.List; + /** * * @author Artem Tikhomirov @@ -24,4 +27,27 @@ public interface PathRewrite { public String rewrite(String path); + + public class Composite implements PathRewrite { + private List<PathRewrite> chain; + + public Composite(PathRewrite... e) { + LinkedList<PathRewrite> r = new LinkedList<PathRewrite>(); + for (int i = (e == null ? -1 : e.length); i >=0; i--) { + r.addFirst(e[i]); + } + chain = r; + } + public Composite chain(PathRewrite e) { + chain.add(e); + return this; + } + + public String rewrite(String path) { + for (PathRewrite pr : chain) { + path = pr.rewrite(path); + } + return path; + } + } }