Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf04de65

Browse files
committed
feat: added support for aborting
1 parent23ccec2 commitf04de65

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Licensed to the Indoqa Software Design und Beratung GmbH (Indoqa) under
3+
* one or more contributor license agreements. See the NOTICE file distributed
4+
* with this work for additional information regarding copyright ownership.
5+
* Indoqa licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
packagecom.indoqa.fsa.character;
18+
19+
publicclassAbortedExceptionextendsRuntimeException {
20+
21+
privatestaticfinallongserialVersionUID =1L;
22+
}

‎src/main/java/com/indoqa/fsa/character/CharAcceptorBuilder.java‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
importjava.text.NumberFormat;
2323
importjava.util.*;
2424
importjava.util.Map.Entry;
25+
importjava.util.function.BooleanSupplier;
2526
importjava.util.function.Consumer;
2627

2728
importcom.indoqa.fsa.AcceptorBuilder;
@@ -42,6 +43,7 @@ public class CharAcceptorBuilder implements AcceptorBuilder {
4243
privateReplacementsreplacements;
4344

4445
privateConsumer<String>messageConsumer;
46+
privateBooleanSupplierabortSupplier;
4547

4648
privatebooleanminified;
4749
privatebooleanremapped;
@@ -138,6 +140,10 @@ public CharAcceptor build() {
138140
returnnewCharAcceptor(data,this.caseSensitive);
139141
}
140142

143+
publicvoidsetAbortSupplier(BooleanSupplierabortSupplier) {
144+
this.abortSupplier =abortSupplier;
145+
}
146+
141147
publicvoidsetMessageConsumer(Consumer<String>messageConsumer) {
142148
this.messageConsumer =messageConsumer;
143149
}
@@ -292,9 +298,12 @@ private char[] buildData() {
292298
continue;
293299
}
294300

301+
this.checkAborted();
302+
295303
System.arraycopy(node,0,data,offset,node.length);
296304
offset +=node.length;
297305
}
306+
298307
returndata;
299308
}
300309

@@ -327,6 +336,12 @@ private Map<String, List<NodeReference>> buildGroups() {
327336
returnresult;
328337
}
329338

339+
privatevoidcheckAborted() {
340+
if (this.abortSupplier !=null &&this.abortSupplier.getAsBoolean()) {
341+
thrownewAbortedException();
342+
}
343+
}
344+
330345
privatevoidfindEndNodeReplacements() {
331346
for (inti =0;i <this.nodeCount;i++) {
332347
if (this.nodes[i] ==null ||this.nodes[i].length !=0) {
@@ -395,6 +410,8 @@ private void minify() {
395410
this.replacements.clear();
396411

397412
for (StringeachChangedGroup :changedGroups) {
413+
this.checkAborted();
414+
398415
List<NodeReference>group =groups.get(eachChangedGroup);
399416
if (group ==null) {
400417
continue;
@@ -474,6 +491,8 @@ private void serialize(DataOutputStream outputStream) throws IOException {
474491
continue;
475492
}
476493

494+
this.checkAborted();
495+
477496
for (chareachChar :node) {
478497
outputStream.writeChar(eachChar);
479498
}

‎src/main/java/com/indoqa/fsa/character/CharTransducerBuilder.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
importjava.util.ArrayList;
2323
importjava.util.Arrays;
2424
importjava.util.List;
25+
importjava.util.function.BooleanSupplier;
2526
importjava.util.function.Consumer;
2627

2728
importcom.indoqa.fsa.TransducerBuilder;
@@ -105,6 +106,10 @@ public CharTransducer build() {
105106
returnnewCharTransducer(charAcceptor,DEFAULT_SEPARATOR);
106107
}
107108

109+
publicvoidsetAbortSupplier(BooleanSupplierabortSupplier) {
110+
this.acceptorBuilder.setAbortSupplier(abortSupplier);
111+
}
112+
108113
publicvoidsetMessageConsumer(Consumer<String>messageConsumer) {
109114
this.acceptorBuilder.setMessageConsumer(messageConsumer);
110115
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp