1 package org.openphacts.nextprot.util;
2
3
4
5
6
7
8
9
10
11
12 import java.math.BigDecimal;
13
14 import org.apache.velocity.tools.generic.SafeConfig;
15
16 public class EchoTool extends SafeConfig {
17 private Object hashMark;
18 private int maxColumns;
19 private long progressCount;
20
21
22
23
24 public EchoTool() {
25 super();
26 this.hashMark = new String( "#" );
27 this.maxColumns = 80;
28 this.progressCount = 0L;
29 }
30
31
32
33
34
35
36 public void println( Object x ) {
37 if( x != null )
38 System.out.println( x );
39 }
40
41 private BigDecimal convertNumber( Object x ) {
42 BigDecimal num = null;
43 if( x != null ) {
44 try {
45 num = new BigDecimal( x.toString() );
46 }
47 catch( NumberFormatException nfe ) {
48 num = null;
49 }
50 }
51 return num;
52 }
53
54 private void printHashMark() {
55 if( (progressCount % (long)maxColumns) == 0 )
56 System.out.println();
57 if( hashMark != null )
58 System.out.print( hashMark );
59 }
60
61
62
63
64 public void startProgress() {
65 this.progressCount = 0L;
66 }
67
68
69
70
71
72
73 public void advance( Object amount ) {
74 BigDecimal amt = convertNumber( amount );
75 if( amt != null ) {
76 progressCount+=amt.longValue();
77 printHashMark();
78 }
79 }
80
81
82
83
84 public void advance() {
85 progressCount++;
86 printHashMark();
87 }
88
89
90
91
92
93 public Object getMark() {
94 return hashMark;
95 }
96
97
98
99
100
101 public void setMark(Object newHashMark) {
102 this.hashMark = newHashMark;
103 }
104
105
106
107
108
109 public Object getColumns() {
110 return new Integer(maxColumns);
111 }
112
113
114
115
116
117 public void setColumns(Object newMaxCols) {
118 BigDecimal cols = convertNumber( newMaxCols );
119 if( cols != null )
120 maxColumns = cols.intValue();
121 }
122
123 }