优化AnsiColorWrapper

This commit is contained in:
TomXin 2022-08-29 07:05:10 +08:00
parent 146abd3e26
commit ea6fc4e9bb

View File

@ -41,23 +41,23 @@ public class AnsiColorWrapper {
if (bitDepth== AnsiColors.BitDepth.FOUR){ if (bitDepth== AnsiColors.BitDepth.FOUR){
if (foreOrBack == ForeOrBack.FORE){ if (foreOrBack == ForeOrBack.FORE){
for (AnsiColor item : AnsiColor.values()) { for (AnsiColor item : AnsiColor.values()) {
if (StrUtil.equals(item.toString(), StrUtil.toString(code))) { if (StrUtil.equals(item.toString(), StrUtil.toString(this.code))) {
return item; return item;
} }
} }
throw new IllegalArgumentException(StrUtil.format("No matched AnsiColor instance,code={}",code)); throw new IllegalArgumentException(StrUtil.format("No matched AnsiColor instance,code={}",this.code));
} }
for (AnsiBackground item : AnsiBackground.values()) { for (AnsiBackground item : AnsiBackground.values()) {
if (StrUtil.equals(item.toString(), StrUtil.toString(code+10))) { if (StrUtil.equals(item.toString(), StrUtil.toString(this.code+10))) {
return item; return item;
} }
} }
throw new IllegalArgumentException(StrUtil.format("No matched Background instance,code={}",code)); throw new IllegalArgumentException(StrUtil.format("No matched Background instance,code={}",this.code));
} }
if (foreOrBack == ForeOrBack.FORE){ if (foreOrBack == ForeOrBack.FORE){
return Ansi8BitColor.foreground(code); return Ansi8BitColor.foreground(this.code);
} }
return Ansi8BitColor.background(code); return Ansi8BitColor.background(this.code);
} }
@Override @Override
@ -69,11 +69,11 @@ public class AnsiColorWrapper {
return false; return false;
} }
AnsiColorWrapper that = (AnsiColorWrapper) o; AnsiColorWrapper that = (AnsiColorWrapper) o;
return code == that.code && bitDepth == that.bitDepth; return this.code == that.code && this.bitDepth == that.bitDepth;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(code, bitDepth); return Objects.hash(this.code, this.bitDepth);
} }
} }