jkteater
asked on
Checking a map for a null value
I have a method today that preforms a check to see if a value exist
What has changed
Will now be checked from a map. I understand that if the key is not created there is not a value - so something like
How should I address the logic for
Something Like
value 1 = pmap.get(rds.get(row).rev)
then
//////////////////////////////////////////////////////////////////////////
// prlvalueCheck() //
//////////////////////////////////////////////////////////////////////////
public boolean prlValueCheck() {
boolean prlValue = true;
boolean matrixDest = dscheck;
for (int i = 0; i < rds.size(); i++) {
try {
String value = rds.get(i).rev.getRelatedComponent("IMAN_master_form_rev").getStringProperty("PRL");
String value1 = rds.get(i).valuePRL;
if ((value == null || value.trim().isEmpty()) && matrixDest == true) {
prlValue = false;
break;
}
if ((value == null || value.trim().isEmpty()) && value1.trim().isEmpty()) {
prlValue = false;
break;
}
}
catch (TCException e) {
e.printStackTrace();
}
}
return prlValue;
}// end prlValueCheck()
What has changed
String value1 = rds.get(i).valuePRL;
Will now be checked from a map. I understand that if the key is not created there is not a value - so something like
if(pmap.get(rds.get(row).rev) != null),
could be used in place of String value 1How should I address the logic for
if ((value == null || value.trim().isEmpty()) && value1.trim().isEmpty()) {
Something Like
value 1 = pmap.get(rds.get(row).rev)
then
if ((value == null || value.trim().isEmpty()) && value1 == null)) {
if( value == null || (value.trim().length() == 0 && value1.trim().length() ==0)){
//do something..
}
//do something..
}
ASKER
I need to change this
String value1 = rds.get(i).valuePRL;
To check and see if there is a value for valuePRL in the map. So I assume if there is not a key created, then there is not a value. So I want to change the above to check the map for a key
Something like this - I think
if(pmap.get(rds.get(row).r ev) != null) {
prlMapCheck = true;
}'
Then I need to remove value1.trim().isEmpty() from
String value1 = rds.get(i).valuePRL;
To check and see if there is a value for valuePRL in the map. So I assume if there is not a key created, then there is not a value. So I want to change the above to check the map for a key
Something like this - I think
if(pmap.get(rds.get(row).r
prlMapCheck = true;
}'
Then I need to remove value1.trim().isEmpty() from
if ((value == null || value.trim().isEmpty()) && value1.trim().isEmpty()) {
prlValue = false;
break;
}
and add the value for the map check above.
so what is your question ?
Yes, if there is no key in the map then
map.get(key) will return null for such key
Where do you see the problem?
Yes, if there is no key in the map then
map.get(key) will return null for such key
Where do you see the problem?
ASKER
how would you go about checking the map and then assigning the value in the if logic
So you want to chek if the map has a value associated with certain key, and if it does not you want to add the key -value pair for such key - this is what you want to do?
Please, explain in words what it is that you want to accomplish
Please, explain in words what it is that you want to accomplish
ASKER
right now
String value1 = rds.get(i).valuePRL;
is getting the value for valuePRL from the ArrayList.
Then in the if statement it is checking to see if value1 is empty
I am now using a map to store the value of valuePRL with a key of revision number
String value1 = rds.get(i).valuePRL; <- this needs to be replaced with something checking to see if there is a valuePRL value in the map for the specific key
Once I have a value for valuePRL, I need to replace
value1.trim().isEmpty() in the if statement with something that says value1 is false
String value1 = rds.get(i).valuePRL;
is getting the value for valuePRL from the ArrayList.
Then in the if statement it is checking to see if value1 is empty
I am now using a map to store the value of valuePRL with a key of revision number
String value1 = rds.get(i).valuePRL; <- this needs to be replaced with something checking to see if there is a valuePRL value in the map for the specific key
Once I have a value for valuePRL, I need to replace
value1.trim().isEmpty() in the if statement with something that says value1 is false
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Open in new window