Skip to content

Commit f3c3833

Browse files
committed
me.tongfei.progressbar runs on Java8 only actframework#622
1 parent b71dbf6 commit f3c3833

15 files changed

Lines changed: 867 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# ActFramework Change Log
22

33
**1.8.8**
4+
* `me.tongfei.progressbar` runs on Java8 only #622
45
* Session expiration time shall not be output using `Expires` header #623
56
* Param binding: allow it to ignore missing namespace when there is only one param to bind #618
67
* @On(async = true) not work #611

LICENSE

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
ActFramework is subject to the following license
2+
13
Apache License
24
Version 2.0, January 2004
35
http://www.apache.org/licenses/
@@ -200,3 +202,44 @@ Apache License
200202
See the License for the specific language governing permissions and
201203
limitations under the License.
202204

205+
jBCrypt is subject to the following license:
206+
207+
/*
208+
* Copyright (c) 2006 Damien Miller <[email protected]>
209+
*
210+
* Permission to use, copy, modify, and distribute this software for any
211+
* purpose with or without fee is hereby granted, provided that the above
212+
* copyright notice and this permission notice appear in all copies.
213+
*
214+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
215+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
216+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
217+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
218+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
219+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
220+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
221+
*/
222+
223+
me.tongfei.progressbar is under MIT license
224+
225+
The MIT License (MIT)
226+
227+
Copyright (c) 2015 Tongfei Chen
228+
229+
Permission is hereby granted, free of charge, to any person obtaining a copy
230+
of this software and associated documentation files (the "Software"), to deal
231+
in the Software without restriction, including without limitation the rights
232+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
233+
copies of the Software, and to permit persons to whom the Software is
234+
furnished to do so, subject to the following conditions:
235+
236+
The above copyright notice and this permission notice shall be included in all
237+
copies or substantial portions of the Software.
238+
239+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
240+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
241+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
242+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
243+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
244+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
245+
SOFTWARE.

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,11 @@
319319
<version>${jpa.version}</version>
320320
</dependency>
321321

322-
<dependency>
323-
<groupId>me.tongfei</groupId>
324-
<artifactId>progressbar</artifactId>
325-
<version>${progressbar.version}</version>
326-
</dependency>
322+
<!--<dependency>-->
323+
<!--<groupId>me.tongfei</groupId>-->
324+
<!--<artifactId>progressbar</artifactId>-->
325+
<!--<version>${progressbar.version}</version>-->
326+
<!--</dependency>-->
327327

328328
</dependencies>
329329

src/main/java/fc/cron/CronExpression.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
/*-
1919
* #%L
20-
* ACT Framework
20+
* frode-carlsen/cron
2121
* %%
22-
* Copyright (C) 2014 - 2017 ActFramework
22+
* Copyright (C) 2014 - 2017 frode-carlsen
2323
* %%
2424
* Licensed under the Apache License, Version 2.0 (the "License");
2525
* you may not use this file except in compliance with the License.
@@ -35,6 +35,8 @@
3535
* #L%
3636
*/
3737

38+
import static org.joda.time.DateTimeConstants.DAYS_PER_WEEK;
39+
3840
import org.joda.time.DateTime;
3941
import org.joda.time.LocalDate;
4042
import org.joda.time.MutableDateTime;
@@ -46,8 +48,6 @@
4648
import java.util.regex.Matcher;
4749
import java.util.regex.Pattern;
4850

49-
import static org.joda.time.DateTimeConstants.DAYS_PER_WEEK;
50-
5151
/**
5252
* Parser for unix-like cron expressions: Cron expressions allow specifying combinations of criteria for time
5353
* such as: &quot;Each Monday-Friday at 08:00&quot; or &quot;Every last friday of the month at 01:30&quot;
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
package me.tongfei.progressbar;
2+
3+
/*-
4+
* #%L
5+
* TongFei ProgressBar
6+
* %%
7+
* Copyright (C) 2014 - 2018 Tongfei Chen
8+
* %%
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* #L%
21+
*/
22+
23+
import me.tongfei.progressbar.wrapped.ProgressBarWrappedIterable;
24+
import me.tongfei.progressbar.wrapped.ProgressBarWrappedIterator;
25+
import org.joda.time.LocalDateTime;
26+
27+
import java.io.PrintStream;
28+
import java.util.Iterator;
29+
30+
/**
31+
* A simple console-based progress bar.
32+
* @author Tongfei Chen
33+
*/
34+
public class ProgressBar {
35+
36+
private ProgressState progress;
37+
private ProgressThread target;
38+
private Thread thread;
39+
40+
/**
41+
* Creates a progress bar with the specific task name and initial maximum value.
42+
* @param task Task name
43+
* @param initialMax Initial maximum value
44+
*/
45+
public ProgressBar(String task, long initialMax) {
46+
this(task, initialMax, 1000, System.err, ProgressBarStyle.UNICODE_BLOCK);
47+
}
48+
49+
public ProgressBar(String task, long initialMax, ProgressBarStyle style) {
50+
this(task, initialMax, 1000, System.err, style);
51+
}
52+
53+
public ProgressBar(String task, long initialMax, int updateIntervalMillis) {
54+
this(task, initialMax, updateIntervalMillis, System.err, ProgressBarStyle.UNICODE_BLOCK);
55+
}
56+
57+
/**
58+
* Creates a progress bar with the specific task name, initial maximum value,
59+
* customized update interval (default 1000 ms), the PrintStream to be used, and output style.
60+
* @param task Task name
61+
* @param initialMax Initial maximum value
62+
* @param updateIntervalMillis Update interval (default value 1000 ms)
63+
* @param os Print stream (default value System.err)
64+
* @param style Output style (default value ProgresBarStyle.UNICODE_BLOCK)
65+
*/
66+
public ProgressBar(String task, long initialMax, int updateIntervalMillis, PrintStream os, ProgressBarStyle style) {
67+
this.progress = new ProgressState(task, initialMax);
68+
this.target = new ProgressThread(progress, style, updateIntervalMillis, os);
69+
this.thread = new Thread(target);
70+
}
71+
72+
/**
73+
* Starts this progress bar.
74+
*/
75+
public ProgressBar start() {
76+
progress.startTime = LocalDateTime.now();
77+
thread.start();
78+
return this;
79+
}
80+
81+
/**
82+
* Advances this progress bar by a specific amount.
83+
* @param n Step size
84+
*/
85+
public ProgressBar stepBy(long n) {
86+
progress.stepBy(n);
87+
return this;
88+
}
89+
90+
/**
91+
* Advances this progress bar to the specific progress value.
92+
* @param n New progress value
93+
*/
94+
public ProgressBar stepTo(long n) {
95+
progress.stepTo(n);
96+
return this;
97+
}
98+
99+
/**
100+
* Advances this progress bar by one step.
101+
*/
102+
public ProgressBar step() {
103+
progress.stepBy(1);
104+
return this;
105+
}
106+
107+
/**
108+
* Gives a hint to the maximum value of the progress bar.
109+
* @param n Hint of the maximum value
110+
*/
111+
public ProgressBar maxHint(long n) {
112+
if (n < 0)
113+
progress.setAsIndefinite();
114+
else {
115+
progress.setAsDefinite();
116+
progress.maxHint(n);
117+
}
118+
return this;
119+
}
120+
121+
/**
122+
* Stops this progress bar.
123+
*/
124+
public ProgressBar stop() {
125+
target.kill();
126+
try {
127+
thread.join();
128+
target.consoleStream.print("\n");
129+
target.consoleStream.flush();
130+
}
131+
catch (InterruptedException ex) { }
132+
return this;
133+
}
134+
135+
/**
136+
* Sets the extra message at the end of the progress bar.
137+
* @param msg New message
138+
*/
139+
public ProgressBar setExtraMessage(String msg) {
140+
progress.setExtraMessage(msg);
141+
return this;
142+
}
143+
144+
/**
145+
* Returns the current progress.
146+
*/
147+
public long getCurrent() {
148+
return progress.getCurrent();
149+
}
150+
151+
/**
152+
* Returns the maximum value of this progress bar.
153+
*/
154+
public long getMax() {
155+
return progress.getMax();
156+
}
157+
158+
/**
159+
* Returns the name of this task.
160+
*/
161+
public String getTask() {
162+
return progress.getTask();
163+
}
164+
165+
/**
166+
* Returns the extra message at the end of the progress bar.
167+
*/
168+
public String getExtraMessage() {
169+
return progress.getExtraMessage();
170+
}
171+
172+
/**
173+
* Wraps an iterator so that when iterated, a progress bar is shown to track the traversal progress.
174+
* @param it Underlying iterator
175+
* @param task Task name
176+
*/
177+
public static <T> Iterator<T> wrap(Iterator<T> it, String task) {
178+
return new ProgressBarWrappedIterator<>(it, task, -1); // indefinite progress bar
179+
}
180+
181+
/**
182+
* Wraps an iterable so that when iterated, a progress bar is shown to track the traversal progress.
183+
* <p>
184+
* Sample usage: {@code
185+
* for (T x : ProgressBar.wrap(collection, "Traversal")) { ... }
186+
* }
187+
* </p>
188+
* @param ts Underlying iterable
189+
* @param task Task name
190+
*/
191+
public static <T> Iterable<T> wrap(Iterable<T> ts, String task) {
192+
return new ProgressBarWrappedIterable<>(ts, task);
193+
}
194+
195+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package me.tongfei.progressbar;
2+
3+
/*-
4+
* #%L
5+
* TongFei ProgressBar
6+
* %%
7+
* Copyright (C) 2014 - 2018 Tongfei Chen
8+
* %%
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* #L%
21+
*/
22+
23+
/**
24+
* Represents the display style of a progress bar.
25+
* @author Tongfei Chen
26+
* @since 0.5.1
27+
*/
28+
public enum ProgressBarStyle {
29+
30+
/** Use Unicode block characters to draw the progress bar. */
31+
UNICODE_BLOCK("│", "│", '█', ' ', " ▏▎▍▌▋▊▉"),
32+
33+
/** Use only ASCII characters to draw the progress bar. */
34+
ASCII("[", "]", '=', ' ', ">");
35+
36+
String leftBracket;
37+
String rightBracket;
38+
char block;
39+
char space;
40+
String fractionSymbols;
41+
42+
ProgressBarStyle(String leftBracket, String rightBracket, char block, char space, String fractionSymbols) {
43+
this.leftBracket = leftBracket;
44+
this.rightBracket = rightBracket;
45+
this.block = block;
46+
this.space = space;
47+
this.fractionSymbols = fractionSymbols;
48+
}
49+
50+
}

0 commit comments

Comments
 (0)