How to tell how many times a method has executed?

Hi, all
I've got a main class (Model.java) that repeatedly calls a step() method in a sub class (Ocean.java). I want Ocean.java to execute its step() method following one set of rules for the first time it is called by Model.java, and a different set of rules for all executions 2++. I was just going to use an if/else in Ocean.java's step() method to make it switch based on a boolean haveIExecutedThisStepOnce, or something like that. Is there some way to tell Ocean.java how many times it has executed the step() method? I'm using the RePast code libraries; Model.java uses a method called getTickCount(). It returns a double value of number of times Model.java's step() method has been executed, in which Model.java tells Ocean.java to execute its step() method. Should I pry that getTickCount() value out of Model.java and get it over to Ocean.java's step() method--and if so, how? Or, is there a better way to do this that I'm not aware of?

Why do you think that this field has to be public?
Arguably if there's some functionality that is tightly associated with this counted method, then it should be part of the same class.
Alternatively, think about the counting variable. It should be with the thing that uses it.
So if class A wants to invoke class B method c once, do something else, and then invoke c some more, then that counting is really more an aspect of A than of B, and in that case the state should be in A. In that case the field really counts the number of times that A has invoked B.c, not the number of times that B.c has been invoked overall. Maybe that's what you want.
On the other hand if you really want to count the number of times that B.c has been invoked overall, then it's an aspect of B (or more likely an instance of B). In that case, rather than expose the counting state and the counted method, it would probably be better to create a new method d(). d() would invoke c(), doing something extra depending on the counting state. Make c() private. Like this:
class B {
  private boolean c_has_been_called = false;
  public void d() {
    c();
    if (!c_has_been_called) {
      doWhateverYouNeedInThisCase();
      c_has_been_called = true;
  private void c() {
    // and c() does whatever it normally does
}

Similar Messages

  • Counting how many times my app has been opened

    I want to be able to count how many times a user has opened my application, and so every time the application launches, this number is added by one.
    Does anyone know how I store a long-time variable like this that will still need to be available across different runs of the application? I imagine this value would be stored in the application's preference file in Library, but I don't know how to do this.
    Can any of you please lend me some advice/code to achieve this (I am using Objective-C)?
    Thanks in advance,
    Ricky.

    Hi.
    It has been a while - but I finally got around to slapping some code together. I have successfully created and retrieved the value from the preference file, but for some reason, adding 1 to my value each run is not working. It only adds by one after each BUILD. So I have to rebuild it every time I want it to increment. See my code below;
    [NSUserDefaults init];
    int numberOfTimes;
    numberOfTimes = [[NSUserDefaults standardUserDefaults] integerForKey:@"used"];
    numberOfTimes = numberOfTimes++; //It is that that is not working.
    [[NSUserDefaults standardUserDefaults] setInteger:numberOfTimes forKey:@"used"];
    NSLog (@"%d", [[NSUserDefaults standardUserDefaults] integerForKey:@"used"]);
    I can't seem to stop anything wrong, but then again it is late.
    Do any of you see any errors here?
    Thanks,
    Ricky.

  • HT4059 Being new to iBook publishing I need to know if stats are available to determine how many times my iBook has been downloaded. Can anyone help please? Mr Ignorant

    Being new to iBook publishing I need to know if stats are available to determine how many times my iBook has been downloaded. Can anyone help please? I need to persuade someone that this really is worthwhile. Mr Ignorant.

    The only people who can possibly assist you with this is Apple Customer Relations, call your local Apple contact number and ask for Customer Relations then explain your situation clearly and politely (be firm but don't rant).
    You might want to investiage what the local laws are regarding defective goods and 'fit for use' definitions on warranties etc. Consumer Protection can be a useful tool to use or bargain with if needed ...

  • I have entered the passcode wrong many time my iphone has been disabeld how can i open it

    i have entered the passcode wrong many time my iphone has been disabeld how can i open it

    you will have to wait until you can try again,
    i believe the only way if you don't know the passcode is to factory reset through itunes which you will lose everything from your phone if it hasn't been backed up

  • Finding query access frequency or how many times a query has been executed?

    Dear Experts
    I need to find the total number of access frequency of individual queries that are requested by the users say at a particular time.
    Say there are 20 distinct queries requested in the time difference of 3 hours. All of the 20 queries or some of the queries may be requested for more than 2/3 times at that time by other users. By the way say query Q1 is requested 5 times at that so its query access frequency or how many times this query is executed is 5.
    From where and how can I can find this counting of query access frequency or how many times a query has been executed at particular time or a session?
    Normally we know the there SQL history dynamic performance views or if it can be possible to query the Shared pool library cache for SQL area it may be possible to find the total number of execution time for a query. But how to find that if anyone knows, please help me about this.
    Regards-
    Engr. A.N.M. Bazlur Rashid
    OCP DBA

    That's one of the stats reported by statspack - assuming that your query does sufficient work to meet the thresholds for the standard report. Executions is of course one of the columns of v$sql so you might just wish to sample that yourself. Finally if you are on 11g and the sql you are interested is relatively low resource intensive and you are licensed for AWR then you can use the slightly madly named "colored sql" feature that ensures that a specific statement will always be sampled for AWR.
    Niall Litchfield
    http://www.orawin.info/

  • How to keep track of how many times a link has been clicked?

    How to keep track of how many times a link has been clicked or accessed? Do I need to use database for this?

    Hi
    Proably something like this can work,
    1> Have a servlet/bean invoked when the link is linked
    2> have a static variable in that servlet/bean wich gets incremented before the control is passed to another desired page..
    The problem with this approach is that care has to be taken that the servlet/bean is not re-instalised, in case of which the static variable will also be instalised and the data would be lost.
    The best thing is to store the count in the database.
    Regards
    Arathi.

  • How many times a program has been run?

    Is there a transaction or table or something that tracks how many times a program has been run?   The number of times the program has been run plus using the programs' attributes for last changed would help me a lot.  We need this for an archiving study to determine of the client has set up the configuration correctly since they went live and have been executing the correct programs.  Thanks and mucho rewards if someone has an answer.  FYI - I have done a forum search and could find nothing on this topic.  I have looked at the tables TADIR and no help, as well as transaction STAT.

    I know ST03N transaction can be used extensively to determine how the programs were executed or even to know who all are using a particular transaction...
    I tried to find if we can find the number of executions of a program through this transaction, I could not find myself...
    try if you can find it through this tcode.
    Phani

  • How to find out how many times an album has been burned to cd

    how to find out how many times an album has been burned to cd

    You can't.
    and the restriction (lwhich limits burning a specific playlist to audio CD) applies only to a specific playlist with DRM songs.

  • How do you find out how many times an app has been downloade

    Wondering where I can find out how many times an app from the app store has been downloaded?

    Are you asking if you can find out how many times an app has been downloaded from the app store? Or you asking if you can find how many times you have downloaded the app? If the former, you could try asking the developer. If the latter, none that I know of.

  • Cycle counting - How many times an item has been counted?

    Hallo Gurus,
    do you know if there's a way to know how many times an item has been counted during the year?
    Thank you very much indeed.
                Mick

    Hi Mick,
    Check the below links. Hope they will help you.
    http://help.sap.com/saphelp_snc70/helpdata/EN/4c/c1b4b55b912a4ae10000000a42189b/content.htm
    http://help.sap.com/saphelp_46c/helpdata/en/4d/2b8e3d43ad11d189410000e829fbbd/content.htm
    Regards,
    Shilpa

  • HT4927 This may take a long time, depending on the size of the library. How long is a long time? Mine has been rebuilding now for over 24hrs?

    "This may take a long time, depending on the size of the library". How long is a long time? Mine has been rebuilding now for over 24hrs?

    "This may take a long time, depending on the size of the library"
    How big is your library?
    OT

  • How to check the last time a package has been compiled?

    How to check the last time a package has been compiled from sqlplus?

    LAST_DDL_TIME column in DBA_OBJECTS.

  • How to tell how much toner in hPlaserjet CP1525nw

    how to tell how much toner in hP laserjet CP1525nw

    Hello lwwpbw, and welcome to the HP Forums, I hope you enjoy your experience!
    I saw from your post that you are looking to find the levels of toner within your printer. I'd love to help with that today!
    I have a document I would suggest using, containing the steps to check your toner levels: HP LaserJet Printers - Checking Toner Levels.
    This document may also be helpful to you: HP LaserJet Pro CP1525n and CP1525nw Color Printers - Managing Print Cartridges.
    Good luck and please let me know the results of your troubleshooting steps. Thank you for posting on the HP Forums!
    Please click “Accept as Solution " if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos, Thumbs Up" on the right to say “Thanks" for helping!
    Jamieson
    I work on behalf of HP
    "Remember, I'm pulling for you, we're all in this together!" - Red Green.

  • And disconected the plug many times, but nothing has worked. I'm in Brazil and bought the phone

    My iPhone 4 is interpreting that the headset is conected even if it isnt. I've already reset it, conected and disconected the plug many times, but nothing has worked. I'm in Brazil and bought the phone in Canada. Does it have a garantee? Is there anything I'm missing in adjusting my iPhone?

    It may not be your computer telling you this, it is probably the company providing the shows to you over the Internet. If that is the case, no setting on your computer can change it because the media company is going by your network address (IP address), which is where your Internet modem (cable or DSL) connects to the outside Internet. If the location of your Internet connection appears to be outside the US (even if it is mistake), media companies that distribute shows under contracts with geographical restrictions may lock you out.
    If you use a service like a VPN service, you may have the ability to use IP addresses from other countries so that you can appear to be connecting from there. But it takes some setting up.

  • How do I keep track of how many times a method is called inside anthr clas?

    I am writing code for a program that solves a Knight's Tour. A Knight's Tour is a path a Knight Chess piece can take around the board starting at any spot, touching every square once, and only once. I have to write 2 classes and one is provided. The provided class is encrypted and written by our professor. All I know that it does is simulates the game using the two classes I write and provides a print out and prompts to ask the user which square they want to move to next.
    The square class I have to write consists of a constructor that makes a square object that keeps track of its color (white/black) and its status (whether it has been visited, is occupied by the knight, or is free and has not be visited).
    The GameBoard class I have to write is what I am having problems with. I am writing a method that determines how many squares have been visited. The previous mentioned class that my professor wrote for me contains a method moveKnight();. The way the program works is that every time moveKnight() is called a square's status is changed to occupied and therefore visited later. moveKnight() will only work if the move requested by the user is a valid move.
    SO! My main problem (sorry for all the explaining, just trying to give you all the information) is that I don't know how to keep track of how many times moveKnight() is called by the program. If i can figure this out it should be simple. I'm new to java but i believe...
    if(moveKnight() is called)
    {count++;} //count is a member variable already initialized
    return count;
    the moveKnight() is called section within the if() statement is what I am unclear how to do. Please help.
    Thanks, Veritas

    in your case you want 'count' to be a class attribute rather than a local variable. But yes, incrementing it each time that the method is called will serve your purpose.

Maybe you are looking for

  • Using ipod as a flash drive

    Yes, it's the same as a Flash Drive, and can be used to store anything you want. say i put a paper for class on it and i wana upload it on school computers do i have to load my ipod on the computers and take my usb or what?

  • Syncing from iphone back to macbook?

    The hard drive 'died' on my Macbook just before the 3 years warranty was up so now have a new hard drive but lost all information and files (though tried with expert help - could not recover any). Now I would at least like to sync all the info/music/

  • Photo Stream of last n months album auto update?

    I need (aka really appreciated the convenience of) the ability to automatically share the most recently imported photos with another user on my machine. I've tried a photo stream of the  "Last ☐ Months" smart album that is available in iPhoto's prefe

  • Oracle Forms n Reports 11g Release 2 HA solution

    I want to know is it possible to start Administration server on machine 2 ? if yes then how Steps followed from this link http://docs.oracle.com/cd/E27559_01/doc.1112/e28391/classic.htm : 1. Weblogic 10.3.6 installation along with Oracle forms and re

  • Mission Control Bug

    Hi, I found a bug on Mission Control. I think i will explain good.. sorry about my language. I have two applications: - Adobe Flash - Cornerstone I assign "Desktop 2" to Adobe Flash. I assign "Desktop 3" to Cornerstone (SVN Client) When i go to "Desk