Mercurial > jhg
comparison hg4j/src/main/java/org/tmatesoft/hg/util/PathRewrite.java @ 213:6ec4af642ba8 gradle
Project uses Gradle for build - actual changes
author | Alexander Kitaev <kitaev@gmail.com> |
---|---|
date | Tue, 10 May 2011 10:52:53 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
212:edb2e2829352 | 213:6ec4af642ba8 |
---|---|
1 /* | |
2 * Copyright (c) 2011 TMate Software Ltd | |
3 * | |
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 | |
6 * the Free Software Foundation; version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * For information on how to redistribute this software under | |
14 * the terms of a license other than GNU General Public License | |
15 * contact TMate Software at support@hg4j.com | |
16 */ | |
17 package org.tmatesoft.hg.util; | |
18 | |
19 import java.util.LinkedList; | |
20 import java.util.List; | |
21 | |
22 /** | |
23 * File names often need transformations, like Windows-style path to Unix or human-readable data file name to storage location. | |
24 * | |
25 * @author Artem Tikhomirov | |
26 * @author TMate Software Ltd. | |
27 */ | |
28 public interface PathRewrite { | |
29 | |
30 // XXX think over CharSequence use instead of String | |
31 public String rewrite(String path); | |
32 | |
33 public static class Empty implements PathRewrite { | |
34 public String rewrite(String path) { | |
35 return path; | |
36 } | |
37 } | |
38 | |
39 public class Composite implements PathRewrite { | |
40 private List<PathRewrite> chain; | |
41 | |
42 public Composite(PathRewrite... e) { | |
43 LinkedList<PathRewrite> r = new LinkedList<PathRewrite>(); | |
44 for (int i = 0; e != null && i < e.length; i++) { | |
45 r.addLast(e[i]); | |
46 } | |
47 chain = r; | |
48 } | |
49 public Composite chain(PathRewrite e) { | |
50 chain.add(e); | |
51 return this; | |
52 } | |
53 | |
54 public String rewrite(String path) { | |
55 for (PathRewrite pr : chain) { | |
56 path = pr.rewrite(path); | |
57 } | |
58 return path; | |
59 } | |
60 } | |
61 } |