Skip to content

Instantly share code, notes, and snippets.

@codingtim
Last active September 13, 2016 07:14
Show Gist options
  • Save codingtim/9de419c79f3ca3cc814190d9ce692ee7 to your computer and use it in GitHub Desktop.
Save codingtim/9de419c79f3ca3cc814190d9ce692ee7 to your computer and use it in GitHub Desktop.
Target with modeled PublicIdentifier
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.");
}
}
}
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