Skip to content

Commit

Permalink
delete third variable
Browse files Browse the repository at this point in the history
  • Loading branch information
BtcContributor committed Feb 23, 2021
1 parent c46a990 commit 4926d31
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,11 @@ private void addInputsPane() {
depositTxHex.setPrefWidth(800);
depositTxLegacy.setAllowIndeterminate(false);
depositTxLegacy.setSelected(false);
depositTxHex.setValidator(new LengthValidator(HEX_HASH_LENGTH));
depositTxHex.setValidator(new LengthValidator(HEX_HASH_LENGTH, HEX_HASH_LENGTH));
buyerAddressString.setValidator(new LengthValidator(20, 80));
sellerAddressString.setValidator(new LengthValidator(20, 80));
buyerPubKeyAsHex.setValidator(new LengthValidator(HEX_PUBKEY_LENGTH));
sellerPubKeyAsHex.setValidator(new LengthValidator(HEX_PUBKEY_LENGTH));
buyerPubKeyAsHex.setValidator(new LengthValidator(HEX_PUBKEY_LENGTH, HEX_PUBKEY_LENGTH));
sellerPubKeyAsHex.setValidator(new LengthValidator(HEX_PUBKEY_LENGTH, HEX_PUBKEY_LENGTH));
}

private void addImportPane() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@
public class LengthValidator extends InputValidator {
private int minLength;
private int maxLength;
private int fixedLength;

public LengthValidator() {
this(0, Integer.MAX_VALUE);
}

public LengthValidator(int fixed) {
this.fixedLength = fixed;
}

public LengthValidator(int min, int max) {
this.minLength = min;
this.maxLength = max;
Expand All @@ -26,9 +21,9 @@ public ValidationResult validate(String input) {
ValidationResult result = new ValidationResult(true);
int length = (input == null) ? 0 : input.length();

if (this.minLength == 0 && this.maxLength == 0) {
if (length != this.fixedLength)
result = new ValidationResult(false, Res.get("validation.fixedLength", this.fixedLength));
if (this.minLength == this.maxLength) {
if (length != this.minLength)
result = new ValidationResult(false, Res.get("validation.fixedLength", this.minLength));
} else
if (length < this.minLength || length > this.maxLength)
result = new ValidationResult(false, Res.get("validation.length", this.minLength, this.maxLength));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,5 @@ public void validate() throws Exception {
assertFalse(validator2.validate("").isValid); // too short
assertFalse(validator2.validate(null).isValid); // too short
assertFalse(validator2.validate("123456789").isValid); // too long

LengthValidator validator3 = new LengthValidator(2);

assertTrue(validator3.validate("12").isValid); // equal

assertFalse(validator3.validate("1").isValid); // not equal, too short
assertFalse(validator3.validate("123").isValid); // not equal, too long
assertFalse(validator3.validate("").isValid); // not equal
assertFalse(validator3.validate(null).isValid); // not equal

}
}

0 comments on commit 4926d31

Please sign in to comment.