comparison hg4j/src/test/java/org/tmatesoft/hg/test/ManifestOutputParser.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.test;
18
19 import java.util.LinkedHashMap;
20 import java.util.Map;
21 import java.util.regex.Matcher;
22 import java.util.regex.Pattern;
23
24 import org.tmatesoft.hg.core.Nodeid;
25 import org.tmatesoft.hg.util.Path;
26
27
28 /**
29 *
30 * @author Artem Tikhomirov
31 * @author TMate Software Ltd.
32 */
33 public class ManifestOutputParser implements OutputParser {
34
35 private final Pattern pattern;
36 private final LinkedHashMap<Path, Nodeid> result = new LinkedHashMap<Path, Nodeid>();
37
38 public ManifestOutputParser() {
39 pattern = Pattern.compile("^([a-f0-9]{40}) (\\d{3}) (.+)$", Pattern.MULTILINE);
40 }
41
42 public void reset() {
43 result.clear();
44 }
45
46 public Map<Path, Nodeid> getResult() {
47 return result;
48 }
49
50 public void parse(CharSequence seq) {
51 Matcher m = pattern.matcher(seq);
52 while (m.find()) {
53 result.put(Path.create(m.group(3)), Nodeid.fromAscii(m.group(1).getBytes(), 0, 40));
54 }
55 }
56 }