wood burning stoves*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes UB find method - OR or AND Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "UB find method - OR or AND" Watch "UB find method - OR or AND" New topic
Author

UB find method - OR or AND

K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2419
    
    7

Hi all for the find method (public int[] find(String[] criteria) throws RecordNotFoundException), I wanted to know it is using "OR" or "AND" logic. Currently, I got the "OR" logic sorted out.
Suppose I have input array:
String[] strAry = {null, "New York", null "N", null, null, null};
And suppose there are 30 records in the file; 3 that start with New York, among these 2 are N for the 4th field; 25 records with N for 4th field. Using my logic, I first get 3 for New York then 25 for N totaling 28 items. I'm using a list then convert this list to array.

Using AND logic, I should get only 2 items. Using OR logic I should get 25 items.
[ January 01, 2009: Message edited by: K. Tsang ]

K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2265
    
    3

Partner, for this method, you do not use any of them. Here's what has to be done: you get the String array, and check if field[n] starts with criteria[n]. If so, this record is included in the list of results (its number is kept in an int array, which will be the list of valid results).

Take a look here. I think it will help you!


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2419
    
    7

Thanks. I have a better understanding.

One more question. My GUI specs say:

It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user.


So I can search for 1) name only, 2) location only or 3) name and location together. Is it right? (1) and (2) is OR logic making (3) AND logic. What happens if I want to search by other fields? Or simply Sun just care about these 2 fields.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2419
    
    7

I have made my find() method to cater the following conditions:
{"Pal", null, null, null, null, null, null}
{"Pal", "Who", null, null, null, null, null}
{null, null, null, null, null, null, null}

On to the next method
John Grabowsky
Greenhorn

Joined: Dec 30, 2008
Posts: 26
Dear K. Tsang,

as i understood the db-interface comment AND logic applies here and only 2 fields are used by the client for selecting. The db-interface requires more functionality than used by client. Any way, you can include all such things to your choices.txt. A deeper question is, whether to expose the db-interface to the client. Im going to make a small business logic between the db-interface and an interface of my choice and expose the latter to the client (by RMI). All transforms between the clients needs and the db-interface -- among them these we discussed above -- can be done there. What about that?


John<br />SCJP 5, 97%
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2265
    
    3

So I can search for 1) name only, 2) location only or 3) name and location together. Is it right? (1) and (2) is OR logic making (3) AND logic. What happens if I want to search by other fields? Or simply Sun just care about these 2 fields.

Yeah, that's correct. As I said in the post I sent you, the find method considers records where field[n] starts with criteria[n]. And I filter that in my business/services layer, to verify if the hotel name and/or location provided in the GUI equals the hotel name and/or location returned in the results. So, for now, you can just consider these two fields. For instance, here's the search method of my business/services layer that my GUI uses:

Where mode is an int constant defined in a class where I kept this and other constants.
[ January 02, 2009: Message edited by: Roberto Perillo ]
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2419
    
    7

Thanks Bob. I implemented my find method a bit differently, not using a map per se. And mine in fact can cater more than 2 fields.

Whether the client or server calls these methods, I will worry that when I get to the client/server. haha
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

Hi Roberto !!!

Partner, for this method, you do not use any of them. Here's what has to be done: you get the String array, and check if field[n] starts with criteria[n]. If so, this record is included in the list of results (its number is kept in an int array, which will be the list of valid results).


If the record comes with some null before some data ? I mean

# Record
# ======
#
# NAME LOCATION SIZE SMOKING RATE DATE OWNER
# SCJD Forum1 Javaranch 9999 Y $99.9 2008/12/08 12345678
# SCJD Forum2 SunSite 9999 Y $99.9 2008/12/08 12345678
#
# String array
# ============
#
# null, null, 99, null, null, null, null

The inicial field of array are null...so....Do i need confirm the next field ? because assignment said "A null value in criteria[n] matches any field value".
So.....I really dont know....I'm thinking...if the some first field are null...it already match...so you dont need continue tests another....
I'm confused...

By the way.....There are any team in brazilian soccer that can stop mine ? TIMÃOOOO EOOOOO

Regards...


Fernando Franzini - Java Blog
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2419
    
    7

Fernando Franzini wrote:If the record comes with some null before some data ? I mean

# Record
# ======
#
# NAME LOCATION SIZE SMOKING RATE DATE OWNER
# SCJD Forum1 Javaranch 9999 Y $99.9 2008/12/08 12345678
# SCJD Forum2 SunSite 9999 Y $99.9 2008/12/08 12345678
#
# String array
# ============
#
# null, null, 99, null, null, null, null

The inicial field of array are null...so....Do i need confirm the next field ? because assignment said "A null value in criteria[n] matches any field value".
So.....I really dont know....I'm thinking...if the some first field are null...it already match...so you dont need continue tests another....
I'm confused...

By the way.....There are any team in brazilian soccer that can stop mine ? TIMÃOOOO EOOOOO

Regards...


Hi Fernando, think of it this way: the specs only cares about the name and location fields. So in the search GUI you should only need to have the name and location for the end user to choose. This means it's not possible to have the [null, null, 99, null, null, null, nul] string array - in fact this means returning all records or whatever your interpretation is for null values.

As Roberto and I mentioned, each field needs to be checked - well at least the first 2 fields. Suppose you ONLY checks the first field for null then you will have problem. Why? What would happen for [null, "SomeLocation", null, null, null, null, null]? This is location only. You original impression only cater for name only.

To recap:
name only eg ["SomeName", null, null, null, null, null, null]
location only eg [null, "SomeLocation", null, null, null, null, null]
name AND location eg ["SomeName", "SomeLocation", null, null, null, null, null]

Therefore you must check at least the first "2" fields of the array. Hint use lists.
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2


To recap:
name only eg ["SomeName", null, null, null, null, null, null]
location only eg [null, "SomeLocation", null, null, null, null, null]
name AND location eg ["SomeName", "SomeLocation", null, null, null, null, null]


Did you do that way ?? I mean.....only considering name and location.....and despising other values inside array....even having somenthing diferente of null ?
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5282
    
  13

Hi Fernando,

About this topic they were already a lot of other discussions/threads in this forum and i don't like to repeat myself, so i'm just gonna point you to these threads and I think you will find a lot of valuable information and answers to all your questions:
- thread 1
- thread 2

If you still have a question after reading through these threads, just let us know

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
 
 
subject: UB find method - OR or AND