forked from AY2324S1-CS2103T-T13-0/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request AY2324S1-CS2103T-T13-0#92 from rocketninja7/model
Add modular credit
- Loading branch information
Showing
2 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
src/main/java/seedu/address/model/module/ModularCredit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package seedu.address.model.module; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.util.AppUtil.checkArgument; | ||
|
||
public class ModularCredit { | ||
public static final String MESSAGE_CONSTRAINTS = "Modular credits should be a non-negative integer."; | ||
|
||
public static final String VALIDATION_REGEX = "^[\\p{Digit}]+$"; | ||
|
||
private int modularCredit; | ||
|
||
/** | ||
* Constructs a {@code ModularCredit}. | ||
* | ||
* @param modularCredit A valid modular credit. | ||
*/ | ||
public ModularCredit(String modularCredit) { | ||
requireNonNull(modularCredit); | ||
checkArgument(isValidModularCredit(modularCredit), MESSAGE_CONSTRAINTS); | ||
this.modularCredit = Integer.parseInt(modularCredit); | ||
} | ||
|
||
/** | ||
* Returns if a given string is a valid email. | ||
*/ | ||
public static boolean isValidModularCredit(String test) { | ||
return test.matches(VALIDATION_REGEX); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.valueOf(modularCredit); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof ModularCredit)) { | ||
return false; | ||
} | ||
|
||
ModularCredit otherModularCredit = (ModularCredit) other; | ||
return modularCredit == otherModularCredit.modularCredit; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return modularCredit; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters