do something every 1000 records or so

J

Jo

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
 
R

Richard Senior

Jo said:
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.
 
J

Jo

I'll believe you.


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.

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 ?
 
R

Richard Senior

Jo said:
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(".");
}
}
}

}
 
J

Jo

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


Jo said:
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(".");
}
}
}

}
 
R

Richard Senior

Jo said:
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.?
 
J

Jo

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
And do you want to call your logIt() function when you have found or
processed 1000 records, 2000 records, etc.?

yes, exactly

 
Z

Z.

Jo said:
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

private int LOGEVERY = 1000;
....

if ((beginRange == 0) ||
(endRange / LOGEVERY) > (beginRange / LOGEVERY))
logIt ("Range affected" + beginRange + " to " + endRange);
 
J

Jo

private int LOGEVERY = 1000;
...

if ((beginRange == 0) ||
(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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top