Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bassel Dib
Library
Commits
c630c8d8
Commit
c630c8d8
authored
11 months ago
by
Bassel Dib
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
3abde8a5
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/org/example/MetaValidator.java
+62
-0
62 additions, 0 deletions
src/main/java/org/example/MetaValidator.java
with
62 additions
and
0 deletions
src/main/java/org/example/MetaValidator.java
0 → 100644
+
62
−
0
View file @
c630c8d8
package
org.example
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Method
;
import
java.util.Arrays
;
import
java.util.stream.Stream
;
public
class
MetaValidator
{
public
MetaValidator
(){
}
/* get Field names from all the classes, concatenate them to one array and iterate
to check if a name violate the 20 rule or starts with uppercase-> return false */
public
static
boolean
ValidateFieldsNames
(){
Book
book
=
new
Book
();
Article
article
=
new
Article
();
boolean
checker
=
false
;
// checker of violation
Field
[]
fieldsBook
=
book
.
getClass
().
getDeclaredFields
();
Field
[]
fieldsArticle
=
article
.
getClass
().
getDeclaredFields
();
Field
[]
both
=
Stream
.
concat
(
Arrays
.
stream
(
fieldsBook
),
// concatenate Fields of both classes
Arrays
.
stream
(
fieldsArticle
))
.
toArray
(
Field
[]::
new
);
for
(
Field
f
:
both
)
{
if
(
f
.
getName
().
length
()
>
20
||
Character
.
isUpperCase
(
f
.
getName
().
charAt
(
0
)))
{
System
.
out
.
println
(
"Field \""
+
f
.
getName
()
+
"\" has more than 20 characters or dose not start with lower-case"
);
checker
=
true
;
}
}
if
(
checker
)
return
false
;
return
true
;
}
/* check if Methods start with lowercase or have more than 40 characters like implementation above */
public
static
boolean
ValidateMethodsNames
(){
Book
book
=
new
Book
();
Article
article
=
new
Article
();
boolean
checker
=
false
;
Method
[]
methodsBook
=
book
.
getClass
().
getDeclaredMethods
();
Method
[]
methodsArticle
=
article
.
getClass
().
getDeclaredMethods
();
Method
[]
both
=
Stream
.
concat
(
Arrays
.
stream
(
methodsBook
),
Arrays
.
stream
(
methodsArticle
))
.
toArray
(
Method
[]::
new
);
for
(
Method
f
:
both
)
{
if
(
f
.
getName
().
length
()
>
40
||
Character
.
isUpperCase
(
f
.
getName
().
charAt
(
0
)))
{
System
.
out
.
println
(
"Method \""
+
f
.
getName
()
+
"\" has more than 40 characters or dose not start with lower-case"
);
checker
=
true
;
}
}
if
(
checker
)
return
false
;
return
true
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment