Nice TWiki > Doc > CodeExamples > MethcallIntermediateExample (r1.1) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }
/* Please try the NoviceExamples before the BeginnerExamples
To compile:
   nicec --classpath .. --sourcepath .. -a methcall.jar methcall_intermediate
To run:
   java -jar methcall.jar 10
*/


import methcall_intermediate.*; // Java Toggle class

class NToggle extends Toggle {
    int toggleTrigger = 0;
    int count = 0;
}


activate(t@NToggle){ 
    t.count++;
    if (t.count >= t.toggleTrigger){
        t.state = !t.state;
        t.count = 0;
    }
    return t; }


void main(String[] args){
    int n =  nTimes(args);

    let val = true;
    let toggle = new Toggle(true);
    for(int i=0; i<n; i++) {
       val = toggle.activate().value();
    }
    println(val);

    val = true;
    let ntoggle = new NToggle(true, toggleTrigger: 3);
    for(int i=0; i<n; i++) {
       val = ntoggle.activate().value();
    }
    println(val);
}


int nTimes(String[] s){
    try { return Integer.parseInt(s[0]); }
    catch (Exception e){ return 1; } }


/* Notes - language
Compare with Java at the "Win32 Language Shootout"

*/
-- IsaacGouy - 30 Aug 2003

Topic MethcallIntermediateExample . { Edit | Attach | Ref-By | Printable | Diffs | r1.4 | > | r1.3 | > | r1.2 | More }
Revision r1.1 - 30 Aug 2003 - 14:43 GMT - IsaacGouy
Parents: WebHome > CodeExamples
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback.