Mercurial > jhg
annotate src/org/tmatesoft/hg/util/PathRewrite.java @ 142:37a34044e6bd
More reasonable use of path normalizer and path.source
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> | 
|---|---|
| date | Thu, 17 Feb 2011 05:06:07 +0100 | 
| parents | 8248aae33f7d | 
| children | a415fe296a50 | 
| rev | line source | 
|---|---|
| 64 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 1 /* | 
| 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 2 * Copyright (c) 2011 TMate Software Ltd | 
| 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 3 * | 
| 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 4 * This program is free software; you can redistribute it and/or modify | 
| 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 5 * it under the terms of the GNU General Public License as published by | 
| 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 6 * the Free Software Foundation; version 2 of the License. | 
| 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 7 * | 
| 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 8 * This program is distributed in the hope that it will be useful, | 
| 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 11 * GNU General Public License for more details. | 
| 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 12 * | 
| 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 13 * For information on how to redistribute this software under | 
| 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 14 * the terms of a license other than GNU General Public License | 
| 102 
a3a2e5deb320
Updated contact address to support@hg4j.com
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
93diff
changeset | 15 * contact TMate Software at support@hg4j.com | 
| 64 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 16 */ | 
| 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 17 package org.tmatesoft.hg.util; | 
| 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 18 | 
| 74 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 19 import java.util.LinkedList; | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 20 import java.util.List; | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 21 | 
| 64 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 22 /** | 
| 142 
37a34044e6bd
More reasonable use of path normalizer and path.source
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
141diff
changeset | 23 * File names often need transformations, like Windows-style path to Unix or human-readable data file name to storage location. | 
| 
37a34044e6bd
More reasonable use of path normalizer and path.source
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
141diff
changeset | 24 * | 
| 64 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 25 * @author Artem Tikhomirov | 
| 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 26 * @author TMate Software Ltd. | 
| 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 27 */ | 
| 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 28 public interface PathRewrite { | 
| 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 29 | 
| 141 
8248aae33f7d
Adopt FileIterator moving towards WCStatusCollector parameterizing. Improved path handling, move 'em around
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
102diff
changeset | 30 // XXX think over CharSequence use instead of String | 
| 64 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 31 public String rewrite(String path); | 
| 93 
d55d4eedfc57
Switch to Path instead of String in filenames returned by various status operations
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
74diff
changeset | 32 | 
| 
d55d4eedfc57
Switch to Path instead of String in filenames returned by various status operations
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
74diff
changeset | 33 public static class Empty implements PathRewrite { | 
| 
d55d4eedfc57
Switch to Path instead of String in filenames returned by various status operations
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
74diff
changeset | 34 public String rewrite(String path) { | 
| 
d55d4eedfc57
Switch to Path instead of String in filenames returned by various status operations
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
74diff
changeset | 35 return path; | 
| 
d55d4eedfc57
Switch to Path instead of String in filenames returned by various status operations
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
74diff
changeset | 36 } | 
| 
d55d4eedfc57
Switch to Path instead of String in filenames returned by various status operations
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
74diff
changeset | 37 } | 
| 74 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 38 | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 39 public class Composite implements PathRewrite { | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 40 private List<PathRewrite> chain; | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 41 | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 42 public Composite(PathRewrite... e) { | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 43 LinkedList<PathRewrite> r = new LinkedList<PathRewrite>(); | 
| 142 
37a34044e6bd
More reasonable use of path normalizer and path.source
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
141diff
changeset | 44 for (int i = 0; e != null && i < e.length; i++) { | 
| 
37a34044e6bd
More reasonable use of path normalizer and path.source
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
141diff
changeset | 45 r.addLast(e[i]); | 
| 74 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 46 } | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 47 chain = r; | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 48 } | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 49 public Composite chain(PathRewrite e) { | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 50 chain.add(e); | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 51 return this; | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 52 } | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 53 | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 54 public String rewrite(String path) { | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 55 for (PathRewrite pr : chain) { | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 56 path = pr.rewrite(path); | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 57 } | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 58 return path; | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 59 } | 
| 
6f1b88693d48
Complete refactoring to org.tmatesoft
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: 
64diff
changeset | 60 } | 
| 64 
19e9e220bf68
Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
 Artem Tikhomirov <tikhomirov.artem@gmail.com> parents: diff
changeset | 61 } | 
