annotate src/org/tmatesoft/hg/internal/Filter.java @ 355:f2c11fe7f3e9

Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 06 Dec 2011 12:57:21 +0100
parents a37ce7145c3f
children
rev   line source
112
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2011 TMate Software Ltd
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
130
7567f4a42fe5 Correct contact address
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 115
diff changeset
15 * contact TMate Software at support@hg4j.com
112
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.internal;
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import java.nio.ByteBuffer;
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import org.tmatesoft.hg.repo.HgRepository;
133
4a948ec83980 core.Path to util.Path as it's not Hg repo dependant
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 130
diff changeset
22 import org.tmatesoft.hg.util.Path;
112
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 /**
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 *
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 * @author Artem Tikhomirov
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 * @author TMate Software Ltd.
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 */
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 public interface Filter {
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30
355
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
31 /**
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
32 * Filters data and returns a new buffer with data or an original buffer.
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
33 * Original buffer may not be fully consumed, #compact() might be operation to perform
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
34 * @param src
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
35 * @return a buffer ready to be read
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
36 */
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
37 //
112
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 ByteBuffer filter(ByteBuffer src);
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39
355
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
40 /*
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
41 * Factory doesn't look into data (i.e. could't do a preview), works solely with path
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
42 */
112
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 interface Factory {
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
44 void initialize(HgRepository hgRepo);
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 113
diff changeset
45 // may return null if for a given path and/or options this filter doesn't make any sense
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 113
diff changeset
46 Filter create(Path path, Options opts);
113
67ae317408c9 Filter implementation for newline translation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 112
diff changeset
47 }
67ae317408c9 Filter implementation for newline translation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 112
diff changeset
48
67ae317408c9 Filter implementation for newline translation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 112
diff changeset
49 enum Direction {
67ae317408c9 Filter implementation for newline translation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 112
diff changeset
50 FromRepo, ToRepo
67ae317408c9 Filter implementation for newline translation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 112
diff changeset
51 }
67ae317408c9 Filter implementation for newline translation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 112
diff changeset
52
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 113
diff changeset
53 public class Options {
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 113
diff changeset
54
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 113
diff changeset
55 private final Direction direction;
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 113
diff changeset
56 public Options(Direction dir) {
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 113
diff changeset
57 direction = dir;
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 113
diff changeset
58 }
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 113
diff changeset
59
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 113
diff changeset
60 Direction getDirection() {
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 113
diff changeset
61 return direction;
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 113
diff changeset
62 }
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 113
diff changeset
63
112
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 }
d488c7638b87 Prototype Filter support with keyword filter as a playground
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 }