This file contains hidden or 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
| public class ValidatorBuilder { | |
| private Validator v; | |
| public ValidatorBuilder() { | |
| v = new Validator(); | |
| } | |
| public Validator build() { | |
| return v; | |
| } |
This file contains hidden or 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
| class Validator { | |
| private Set<String> validationErrors; | |
| private Map<String[], ValidationRule> validationRules; | |
| private boolean validated = false; | |
| Validator() { | |
| validationRules = new HashMap<String[], ValidationRule>(); | |
| validationErrors = new HashSet<String>(); | |
| } |
This file contains hidden or 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
| interface ValidationRule { | |
| /** | |
| * Return the error message for this validation rule, | |
| * which can be retrieved when validate is false. | |
| * | |
| */ | |
| String getErrorMessage(); | |
| /** | |
| * Execute the logic for this validation rule and return true |
This file contains hidden or 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
| class Validator { | |
| private Set<String> validationErrors; | |
| private Map<String[], ValidationRule> validationRules; | |
| private boolean validated = false; | |
| Validator() { | |
| validationRules = new HashMap<String[], ValidationRule>(); | |
| validationErrors = new HashSet<String>(); | |
| } |
This file contains hidden or 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
| abstract class Member { | |
| def memberId: Int | |
| def firstName: String | |
| def lastName: String | |
| } | |
| class BasicMember(val memberId: Int, val firstName: String, val lastName: String) extends Member | |
| trait BuckooBucks { | |
| var buckooBalance: Int = 1000 |
This file contains hidden or 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
| trait FivePercentBonus extends BuckooBucks { | |
| abstract override def addBucks(amt: Int) = { | |
| if(amt >= 500) { | |
| val bonus = (0.05 * amt) | |
| buckooBalance += amt | |
| } | |
| super.addBucks(amt) | |
| } | |
| } |
This file contains hidden or 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
| public class Person { | |
| static int NEXT_ID = 0; | |
| private String first; | |
| private String last; | |
| private int id; | |
| private Person() {} //prevents instantiation not using "create" |
This file contains hidden or 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
| /* 3. */ object Person { | |
| var nextId: Int = 0; | |
| /* 4. */ def create(first: String, last: String): Person = { | |
| nextId += 1 | |
| new Person(first, last, nextId-1) | |
| } | |
| } |
This file contains hidden or 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
| class Member(val id: String, val programId: Long) | |
| class Program3Member(val memberId: String, val program: String) | |
| object Program3Member { | |
| def unapply(c: Member): Option[Member] = { if(c.programId == 3L) Some(c) else None } | |
| } | |
| val pete = new Member("12345", 9L) | |
| val steve = new Member("67891", 3L) | |
| val janet = new Member("23458", 3L) |
This file contains hidden or 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
| object MemberType extends Enumeration { | |
| type MemberType = Value | |
| val Free, Trial, Pay, Premium = Value | |
| } | |
| object MemberStatus extends Enumeration { | |
| type MemberStatus = Value | |
| val Active, Inactive, Disabled = Value | |
| } | |
OlderNewer