Last active
September 13, 2016 07:14
-
-
Save codingtim/9de419c79f3ca3cc814190d9ce692ee7 to your computer and use it in GitHub Desktop.
Target with modeled PublicIdentifier
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 PublicIdentifier { | |
private static final Pattern ALLOWED_REGEX = Pattern.compile("[a-zA-Z\\-_]*"); | |
private String value; | |
public PublicIdentifier(String value) { | |
validate(value); | |
this.value = value; | |
} | |
private void validate(String value) { | |
if(value == null || value.trim().isEmpty()) { | |
throw new IllegalArgumentException("Public identifier should not be empty."); | |
} | |
if(!ALLOWED_REGEX.matcher(value).matches()) { | |
throw new IllegalArgumentException("Public identifier should only contains valid characters."); | |
} | |
} | |
} |
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 Target { | |
private Code code; | |
private Name name; | |
private PublicIdentifier publicIdentifier; | |
public Target(Code code, Name name, PublicIdentifier publicIdentifier) { | |
this.code = code; | |
this.name = name; | |
this.publicIdentifier = publicIdentifier; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment