1 package com.wikihouse.wildcats0201.jdbcchart.fsutil;
2
3 import java.io.File;
4 import java.util.LinkedList;
5 import java.util.List;
6 import java.util.regex.Matcher;
7 import java.util.regex.Pattern;
8
9 /***
10 * <B>PathSpliterFactory </B>. PathSpliterのFactoryです。
11 *
12 * @author $Author: wildcats $
13 * @version $Revision: 5 $
14 */
15 public final class PathSpliterFactory {
16
17 private PathSpliterFactory() {
18 }
19
20 /***
21 * 生成
22 *
23 * @param pathName
24 * パス名
25 * @return PathSpliter
26 */
27 public static PathSpliter create(String pathName) {
28 return create(PathFactory.create(pathName));
29 }
30
31 /***
32 * 生成
33 *
34 * @param pathName
35 * パス名
36 * @return PathSpliter
37 */
38 public static PathSpliter create(Path path) {
39 return new PathSpliterImpl(path);
40 }
41
42 private static class PathSpliterImpl implements PathSpliter {
43
44 private final Path path;
45
46 public PathSpliterImpl(Path path) {
47 this.path = path;
48 }
49
50 /***
51 * @see com.wikihouse.wildcats0201.jdbcchart.fsutil.PathSpliter#split()
52 */
53 public Path[] split() {
54 String location = path.getPath();
55 Pattern pattern = Pattern.compile("[^:]//" + File.separator);
56 Matcher matcher = pattern.matcher(location);
57 int cursor = 0;
58 List list = new LinkedList();
59 while (matcher.find(cursor)) {
60 cursor = matcher.end();
61 list.add(PathFactory.create(location
62 .substring(0, matcher.end())));
63 }
64 return (Path[]) list.toArray(new Path[list.size()]);
65 }
66
67 }
68
69 }