View Javadoc

1   package com.insanityengine.ghia.util;
2   
3   /***
4    *
5    * <P>
6    * Convenient stdlib type stuff
7    * </P>
8    *
9    * $Header: /usr/local/cvsroot/ghia/src/java/com/insanityengine/ghia/util/Stdlib.java,v 1.5 2005/03/19 17:50:02 brian Exp $
10   *
11   * @author BrianHammond
12   *
13   */
14  
15  public class Stdlib {
16  
17  	public final static Object NULL = null;
18  	public final static long RAND_MAX = 2147483647;
19  
20  	/***
21  	 *  cheap version of System.out.println
22  	 *
23  	 *
24  	 */
25  	public static void sout( Object o ) { System.out.println( o ); }
26  
27  	/***
28  	 *  inspired by the classic c function of the same name...
29  	 *  @return what you would expect
30  	 */
31  	public static long atol( String s ) {
32  		try { return Long.valueOf( s ).longValue(); } 
33  		catch ( Exception e ) { return 0; }
34  	}
35  
36  	/***
37  	 *  inspired by the classic c function of the same name...
38  	 *  @return what you would expect
39  	 */
40  	public static int atoi( String s ) {
41  		try { return Integer.valueOf( s ).intValue(); } 
42  		catch ( Exception e ) { return 0; }
43  	}
44  
45  	/***
46  	 *  inspired by the classic c function of the same name...
47  	 *  @return what you would expect if you expect a float
48  	 */
49  	public static float atof( String s ) {
50  		try { return Float.valueOf( s ).floatValue(); } 
51  		catch ( Exception e ) { return 0; }
52  	}
53  	
54  	/***
55  	 *  inspired by the classic c function of the same name...
56  	 *  @return what you would expect
57  	 */
58  	public static double atod( String s ) {
59  		try { return Double.valueOf( s ).doubleValue(); } 
60  		catch ( Exception e ) { return 0; }
61  	}
62  
63  	/***
64  	 *  inspired by the classic c function of the same name...
65  	 *  @return what you would expect
66  	 */
67  	public static long rand() {
68  		return ( long ) ( Math.random() * RAND_MAX );
69  	}
70  
71  	/***
72  	 *  inspired by the classic c function of the same name...
73  	 *  @return what you would expect
74  	 */
75  	public static int irand() {
76  		return ( int ) rand();
77  	}
78  
79  	/***
80  	 * public static toString( String[] strz ) {
81  	 * @param x
82  	 * @return x
83  	 */
84  	public static String toString( String[] strz ) {
85  		StringBuffer sb = new StringBuffer();
86  		for ( int i = 0 ; i < strz.length ; i++ ) {
87  			if ( 0 != i ) sb.append( ", " );
88  			sb.append( "\"" ).append( strz[ i ] ).append( "\"" );
89  		}
90  		return sb.toString();
91  	}
92  
93  };
94  
95  /***
96   * 
97   * $Log: Stdlib.java,v $
98   * Revision 1.5  2005/03/19 17:50:02  brian
99   * repackaging
100  *
101  * Revision 1.4  2004/09/22 03:03:08  brian
102  * added cheesy irand method
103  *
104  * Revision 1.3  2004/09/01 17:40:57  brian
105  * atof returns float atod returns double, screwy, aint it?
106  *
107  * Revision 1.2  2004/09/01 14:10:12  brian
108  * fixed typo in package name
109  *
110  * Revision 1.1  2004/09/01 14:06:32  brian
111  * from moogl
112  *
113  *
114  */