Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

do something every 1000 records or so

Thread view: 
Jo - 15 May 2007 10:17 GMT
Ok, this could be a perfect exam question, but it isn't and i need a
good solution

in a function i get 2 int parameters : begin end
they represent the number of records affected , I have to print to a
log at the start of this and then every 1000 records or so, the code
looks something like this:

public Vector findRecords(int beginRange, int endRange)
        throws UierException
    {
        if beginRange == 0 || "some condition so it prints every 1000
records"  {
               logIt(" Range affected" + beginRange + " to " +
endRange);

.....

I would really appreciate the help
oh and by the way, the range varies, it could be 20, 40, 120, or
whatever, so the condition has to check that between beginRange and
endRange is more that 1000x

i m not sure I m explaining the problem properly, so if its not clear
please ask. also there might be an incredibly easy solution, but i
just cant see it :(
Thanks in advance for the help

jo
Richard Senior - 15 May 2007 10:36 GMT
> Ok, this could be a perfect exam question, but it isn't and i need a
> good solution

I'll believe you.

> if beginRange == 0 || "some condition so it prints every 1000 records"  {

I think you need the modulo (%) operator. This gives the remainder of an
integer division, which will, of course be zero every n records when you
modulo by n. For example 25 % 25 == 0, 50 % 25 == 0, 51 % 25 == 1 and so on.

Signature

Regards,

Richard

Jo - 15 May 2007 12:09 GMT
On May 15, 10:36 am, Richard Senior <nos...@r-senior.demon.co.uk>
wrote:
> > Ok, this could be a perfect exam question, but it isn't and i need a
> > good solution
[quoted text clipped - 11 lines]
>
> Richard

hi there:
the problem is that i dont have an exact brake, ie if i do a module on
1050 i ll get 1, and some mod
but what happens when i get 1090? i ll get 1 again, so how do i make
it print only the first time ?
Richard Senior - 15 May 2007 14:33 GMT
> the problem is that i dont have an exact brake, ie if i do a module on
> 1050 i ll get 1, and some mod
> but what happens when i get 1090? i ll get 1 again, so how do i make
> it print only the first time ?

I don't understand.

Isn't this essentially what you want?

public class Modulo {

    private static final int START = 1;
    private static final int FINISH = 50;
    private static final int INTERVAL = 5;

    public static void main(String[] args) {
        for (int i = START; i <= FINISH; i++) {
            if (i == START || i % INTERVAL == 0) {
                System.out.print(i);
            }
            else {
                System.out.print(".");
            }
        }
    }

}

Signature

Regards,

Richard

Jo - 15 May 2007 16:15 GMT
Thanks for your reply but no,
have a look at the original code on the fucntion, that function is
called for example with parameters

findRecords(0,39)
findRecords(40,120)
findRecords(121,200)
....

or

findRecords(0, 60)
findRecords(61, 120)
findRecords(121, 180)
...

what i need to implement is that if  between beginRange and endRange
there is a 000 number then i run the line

logIt(" Range affected" + beginRange + " to " + endRange);

Where logit is a custom function that writes to a log in my app.

I hope is a bit more clear now

Thanks jo

On May 15, 2:33 pm, Richard Senior <nos...@r-senior.demon.co.uk>
wrote:
> > the problem is that i dont have an exact brake, ie if i do a module on
> > 1050 i ll get 1, and some mod
[quoted text clipped - 28 lines]
>
> Richard
Richard Senior - 15 May 2007 16:53 GMT
> Thanks for your reply but no,
> have a look at the original code on the fucntion, that function is
> called for example with parameters
>
> findRecords(40,120)

Within this call to findRecords(), is there a loop that looks at record
40, 41, 42, 43 ... and so on, up to 120?

> what i need to implement is that if  between beginRange and endRange
> there is a 000 number then i run the line
>
> logIt(" Range affected" + beginRange + " to " + endRange);
>
> Where logit is a custom function that writes to a log in my app.

And do you want to call your logIt() function when you have found or
processed 1000 records, 2000 records, etc.?

Signature

Regards,

Richard

Jo - 15 May 2007 17:23 GMT
On May 15, 4:53 pm, Richard Senior <nos...@r-senior.demon.co.uk>
wrote:
> > Thanks for your reply but no,
> > have a look at the original code on the fucntion, that function is
[quoted text clipped - 4 lines]
> Within this call to findRecords(), is there a loop that looks at record
> 40, 41, 42, 43 ... and so on, up to 120?

No,  this queries a db in that range

> > what i need to implement is that if  between beginRange and endRange
> > there is a 000 number then i run the line
[quoted text clipped - 5 lines]
> And do you want to call your logIt() function when you have found or
> processed 1000 records, 2000 records, etc.?

yes, exactly

> --
> Regards,
>
> Richard
Richard Senior - 15 May 2007 17:32 GMT
>> And do you want to call your logIt() function when you have found or
>> processed 1000 records, 2000 records, etc.?
>
> yes, exactly

So, make a loop with a counter and use the modulo operator like I showed
you. I'm not going to write it for you.

Signature

Regards,

Richard

Z. - 15 May 2007 17:37 GMT
> findRecords(0,39)
> findRecords(40,120)
[quoted text clipped - 8 lines]
> what i need to implement is that if  between beginRange and endRange
> there is a 000 number then i run the line

private int LOGEVERY = 1000;
...

if ((beginRange == 0) ||
    (endRange / LOGEVERY) > (beginRange / LOGEVERY))
   logIt ("Range affected" + beginRange + " to " + endRange);
Jo - 16 May 2007 09:29 GMT
> > findRecords(0,39)
> > findRecords(40,120)
[quoted text clipped - 15 lines]
>      (endRange / LOGEVERY) > (beginRange / LOGEVERY))
>     logIt ("Range affected" + beginRange + " to " + endRange);
hey Z, yes thats nearly there,  actually ((startRange/1000) !=
(endRange/1000)) is what worked
but thatnks a million for your help

Jo


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.