• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

UB find method - OR or AND

 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Roberto Perillo
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 497
2
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 497
2
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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 ?
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Danger, 10,000 volts, very electic .... tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic