All pastes #979486 Raw Edit

Unnamed

public java v1 · immutable
·published 2008-04-10 12:16 UTC
rendered paste body
// $Id: objinst.java,v 1.2 2000/12/24 22:04:57 doug Exp $// http://www.bagley.org/~doug/shootout/// Collection class code is from my friend Phil Chu, Thanks Phil!//** This copy courtesy of http://www.kano.net/javabench///**  Added Timer() codeimport java.io.*;import java.util.*;import java.text.*;class Toggle {    boolean state = true;    public Toggle(boolean start_state) {	this.state = start_state;    }    public boolean value() {	return(this.state);    }    public Toggle activate() {	this.state = !this.state;	return(this);    }}class NthToggle extends Toggle {    int count_max = 0;    int counter = 0;    public NthToggle(boolean start_state, int max_counter) {	super(start_state);	this.count_max = max_counter;	this.counter = 0;    }    public Toggle activate() {	this.counter += 1;	if (this.counter >= this.count_max) {	    this.state = !this.state;	    this.counter = 0;	}	return(this);    }}public class objinst {    public static void main(String args[]) throws IOException {	int n = Integer.parseInt(args[0]);    long start = System.currentTimeMillis();  	Toggle toggle1 = new Toggle(true);	for (int i=0; i<5; i++) {	    System.out.println((toggle1.activate().value()) ? "true" : "false");	}	for (int i=0; i<n; i++) {	    Toggle toggle = new Toggle(true);	}	System.out.println("");		NthToggle ntoggle1 = new NthToggle(true, 3);	for (int i=0; i<8; i++) {	    System.out.println((ntoggle1.activate().value()) ? "true" : "false");	}	for (int i=0; i<n; i++) {	    NthToggle toggle = new NthToggle(true, 3);	}    long end = System.currentTimeMillis();     System.out.println("Time: " + (end - start) + " ms");     }}