1111
1212public class StructuresUtil {
1313
14- private static final Pattern IdentifierNamePattern = Pattern .compile ("^[A-Za-z_][A-Za-z0-9_]*$" );
14+ private static final Pattern StructureNamePattern = Pattern .compile ("^[A-Za-z_][A-Za-z0-9_]*$" );
1515 private static final Pattern StructureApplicationPattern = Pattern .compile ("^[A-Za-z][A-Za-z0-9._-]*$" );
1616 private static final Pattern StructureProjectIdPattern = Pattern .compile ("^[a-z][a-z0-9._-]*$" );
1717
@@ -51,8 +51,10 @@ public static void validateStructure(Structure structure){
5151 * @throws IllegalArgumentException will be thrown if the structure name is invalid
5252 */
5353 public static void validateStructureName (String structureName ){
54- if (structureName == null
55- || !IdentifierNamePattern .matcher (structureName ).matches ()){
54+ if (structureName == null ){
55+ throw new IllegalArgumentException ("Structure name must not be null" );
56+ }
57+ if (!StructureNamePattern .matcher (structureName ).matches ()){
5658 throw new IllegalArgumentException ("Structure Name Invalid, first character must be a " +
5759 "letter, number or underscore. And contain only letters, numbers or underscores. Got " + structureName );
5860 }
@@ -64,17 +66,21 @@ public static void validateStructureName(String structureName){
6466 * @param applicationId to validate
6567 * @throws IllegalArgumentException will be thrown if the structure application is invalid
6668 */
67- public static void validateApplicationId (String applicationId ){
68- if (applicationId == null
69- || !StructureApplicationPattern .matcher (applicationId ).matches ()){
69+ public static void validateApplicationId (String applicationId ) {
70+ if (applicationId == null ) {
71+ throw new IllegalArgumentException ("Application Id must not be null" );
72+ }
73+ if (!StructureApplicationPattern .matcher (applicationId ).matches ()){
7074 throw new IllegalArgumentException ("Structure Application Id Invalid, first character must be a " +
7175 "letter. And contain only letters, numbers, periods, underscores or dashes. Got " + applicationId );
7276 }
7377 }
7478
7579 public static void validateProjectId (String projectId ){
76- if (projectId == null
77- || !StructureProjectIdPattern .matcher (projectId ).matches ()){
80+ if (projectId == null ){
81+ throw new IllegalArgumentException ("Project Id must not be null" );
82+ }
83+ if (!StructureProjectIdPattern .matcher (projectId ).matches ()){
7884 throw new IllegalArgumentException ("Structure Project Id Invalid, first character must be a " +
7985 "letter. And contain only letters, numbers, periods, underscores or dashes. Got " + projectId );
8086 }
@@ -87,9 +93,13 @@ public static void validateProjectId(String projectId){
8793 * @throws IllegalArgumentException will be thrown if the property name is invalid
8894 */
8995 public static void validatePropertyName (String propertyName ){
90- if (propertyName == null
91- || propertyName .length () > 255
92- || !IdentifierNamePattern .matcher (propertyName ).matches ()){
96+ if (propertyName == null ){
97+ throw new IllegalArgumentException ("Property Name must not be null" );
98+ }
99+ if (propertyName .length () > 255 ){
100+ throw new IllegalArgumentException ("Property Name cannot have more than 255 characters" );
101+ }
102+ if (!StructureNamePattern .matcher (propertyName ).matches ()){
93103 throw new IllegalArgumentException ("Property Name Invalid, first character must be a " +
94104 "letter, number or underscore. And contain only letters, numbers or underscores. Got " + propertyName );
95105 }
0 commit comments