-1

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 ?

JavaBeigner
  • 608
  • 9
  • 28

3 Answers3

1

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.

Prabhaker A
  • 8,317
  • 1
  • 18
  • 24
0

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.

Shahnaz Khan
  • 1,055
  • 1
  • 14
  • 26
0

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

dumbak
  • 404
  • 3
  • 8