Merging collapsible if statements increases the code's readability.

This commit is contained in:
Ayman Abdel Ghany 2016-01-21 19:13:41 +02:00
parent 71b5211781
commit 5fb03d2751
2 changed files with 27 additions and 36 deletions

View File

@ -127,8 +127,7 @@ class CN_QuantifierSegmenter implements ISegmenter{
}
//缓冲区已经用完还有尚未输出的数词
if(context.isBufferConsumed()){
if(nStart != -1 && nEnd != -1){
if(context.isBufferConsumed() && (nStart != -1 && nEnd != -1)){
//输出数词
outputNumLexeme(context);
//重置头尾指针
@ -136,7 +135,6 @@ class CN_QuantifierSegmenter implements ISegmenter{
nEnd = -1;
}
}
}
/**
* 处理中文量词
@ -216,13 +214,12 @@ class CN_QuantifierSegmenter implements ISegmenter{
//找到一个相邻的数词
if(!context.getOrgLexemes().isEmpty()){
Lexeme l = context.getOrgLexemes().peekLast();
if(Lexeme.TYPE_CNUM == l.getLexemeType() || Lexeme.TYPE_ARABIC == l.getLexemeType()){
if(l.getBegin() + l.getLength() == context.getCursor()){
if((Lexeme.TYPE_CNUM == l.getLexemeType() || Lexeme.TYPE_ARABIC == l.getLexemeType())
&& (l.getBegin() + l.getLength() == context.getCursor())){
return true;
}
}
}
}
return false;
}

View File

@ -155,15 +155,13 @@ class LetterSegmenter implements ISegmenter {
}
//判断缓冲区是否已经读完
if(context.isBufferConsumed()){
if(this.start != -1 && this.end != -1){
if(context.isBufferConsumed() && (this.start != -1 && this.end != -1)){
//缓冲以读完输出词元
Lexeme newLexeme = new Lexeme(context.getBufferOffset() , this.start , this.end - this.start + 1 , Lexeme.TYPE_LETTER);
context.addLexeme(newLexeme);
this.start = -1;
this.end = -1;
}
}
//判断是否锁定缓冲区
if(this.start == -1 && this.end == -1){
@ -203,15 +201,13 @@ class LetterSegmenter implements ISegmenter {
}
//判断缓冲区是否已经读完
if(context.isBufferConsumed()){
if(this.englishStart != -1 && this.englishEnd != -1){
if(context.isBufferConsumed() && (this.englishStart != -1 && this.englishEnd != -1)){
//缓冲以读完输出词元
Lexeme newLexeme = new Lexeme(context.getBufferOffset() , this.englishStart , this.englishEnd - this.englishStart + 1 , Lexeme.TYPE_ENGLISH);
context.addLexeme(newLexeme);
this.englishStart = -1;
this.englishEnd= -1;
}
}
//判断是否锁定缓冲区
if(this.englishStart == -1 && this.englishEnd == -1){
@ -254,15 +250,13 @@ class LetterSegmenter implements ISegmenter {
}
//判断缓冲区是否已经读完
if(context.isBufferConsumed()){
if(this.arabicStart != -1 && this.arabicEnd != -1){
if(context.isBufferConsumed() && (this.arabicStart != -1 && this.arabicEnd != -1)){
//生成已切分的词元
Lexeme newLexeme = new Lexeme(context.getBufferOffset() , this.arabicStart , this.arabicEnd - this.arabicStart + 1 , Lexeme.TYPE_ARABIC);
context.addLexeme(newLexeme);
this.arabicStart = -1;
this.arabicEnd = -1;
}
}
//判断是否锁定缓冲区
if(this.arabicStart == -1 && this.arabicEnd == -1){