01: /*
02: * SubstringModifier.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.db.importer.modifier;
13:
14: import java.util.HashMap;
15: import java.util.Map;
16: import workbench.db.ColumnIdentifier;
17:
18: /**
19: *
20: * @author support@sql-workbench.net
21: */
22: public class SubstringModifier implements ImportValueModifier {
23: public Map<ColumnIdentifier, ColumnValueSubstring> limits = new HashMap<ColumnIdentifier, ColumnValueSubstring>();
24:
25: public SubstringModifier() {
26: }
27:
28: public int getSize() {
29: return limits.size();
30: }
31:
32: /**
33: * Define substring limits for a column.
34: * An existing mapping for that column will be overwritten.
35: *
36: * @param col the column for which to apply the substring
37: * @param start the start of the substring
38: * @param end the end of the substring
39: */
40: public void addDefinition(ColumnIdentifier col, int start, int end) {
41: ColumnValueSubstring s = new ColumnValueSubstring(start, end);
42: this .limits.put(col.createCopy(), s);
43: }
44:
45: public String modifyValue(ColumnIdentifier col, String value) {
46: ColumnValueSubstring s = this .limits.get(col);
47: if (s != null) {
48: return s.getSubstring(value);
49: }
50: return value;
51: }
52:
53: /**
54: * For testing purposes to allow access to the actual "modifier"
55: */
56: public ColumnValueSubstring getSubstring(ColumnIdentifier col) {
57: return this.limits.get(col);
58: }
59:
60: }
|