• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

empty-string criterions

 
Robert Bar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

my spec says that:

- null matches any value
- non-null value (lets say A) matches any field value that begins with A.

But what about "" string? It is a non-value value that accidentally matches any field value!

Is it possible to have only null value reserved for matching any field value? Maybe "" can be reserved to match only "" field value? Or maybe it is against the spec?

please, help me )

rob
 
Samuel Ittera
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just worked on this problem a few days ago. It turns out
something.startsWith("") always returns true. So what I did was take the literal requirement to heart.

boolean match = true;

data = read(recNo);

for(int n = 0; n < data.length - 1; n++)
{
if(criteria[n] == null)
continue;
else if (criteria[n].equals(""))
match = false;
else if (!data[n].startsWith(criteria[n))
match = false;
}

// special case for owner field

if(criteria[data.length - 1] == null)
continue;
else if (criteria[data.length - 1].length == 0)
{
if(data.length != 0)
match = false;
}
else if (!data[data.length - 1].startsWith(criteria[n))
match = false;


I do not expect any of the fields in the db to be blank with the exception of the owner field. If anyone has a better aproach, I would be interested.
Hope this helped.
[ August 21, 2006: Message edited by: Samuel Ittera ]
 
Daniel Massie
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a JTextField for the user to enter the search criteria, "" will always be the value when the user does not enter a value for that field. I went with the option of disregarding "" values in my GUI and therefore making it a null when it makes its way to the find method.
 
Robert Bar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Samuel,

are you sure that you take the requirements literally?

Look, the "" value is a non-null value, so it should be treated like any other string, shouldn't it?

regards,
Rob
 
Samuel Ittera
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robert,
All I was trying to convey is "" is not null and therefore it should not be treated as null ( match any ). But anyString.startsWith("") will always return true, so you need to be carefull that just because anyString.startsWith("") is true, it might not be a match.
 
Robert Bar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samuel,

In my interpretation, the statement: "A null value in criteria[n] matches any value" actually doesn't rule out the statement: "Some of non-null values in criteria[n] matches any value". Both statements are logically consistent.

Your interpretation is:

"A null value in criteria[n] matches any value" for that reason "None of non-null values in criteria[n] matches any value".

I think my interpretation doesn't violate the 2nd rule:

"A non-null value in criteria[n] matches corresponding record[n] value that starts with criteria[n]"

and your interpretation violates it (because for you "" is a non-null value that actually matches to nothing).

regards,
Robert
 
Adam Nace
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Samuel Ittera:
Robert,
All I was trying to convey is "" is not null and therefore it should not be treated as null ( match any ). But anyString.startsWith("") will always return true, so you need to be carefull that just because anyString.startsWith("") is true, it might not be a match.


... but doesn't every string start with the empty string "".

for example, what if you do this:



... hmm... looks like every string starts with "" to me........

... it's kinda like saying 1 = 01 = 00001 = 1.0 = 01.00 = etc ...

- Adam
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic