I have Set which contain different type of classes like Class A
, Class B
, Class C
now one class Let us suppose class A have this structure
class A{
String id;
String name;
String password;
get()/Set() methods
}
Now Let us suppose Class A each variable contain Null . How to check If class variables contain null so i will not process this class its all DB operation.
Any idea how to separate those classes which all variables are null ?
Just define a method isClassEligibleForDBOperations()
which returns boolean value and implement it like this.
public boolean isClassEligibleForDBOperations()
{
if(id != null && name != null && password != null)
{
return true;
}
return false;
}
Based on the return type you can implement your logic.
If you are working with JEE6, you can use NOT NULL annotation javax.validation.constraints.NotNull. Otherwise you can implement your own NOT NULL annotation and use it.
Is there any constructor in these classes? As I don't see any and you are asking for class variables I'd guess its static variable. Than you can check really easy:
if(A.variable == null){
// your functions
}
or
@class A
String getVariable(){
return variable;
}
@anywhere
if(A.getVariable() == null){
// your functions
}
And I hope "variable contains Null" means it's content is null
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.