KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > impl > StockRandomGenerator


1 /*
2  * This file is part of JGAP.
3  *
4  * JGAP offers a dual license model containing the LGPL as well as the MPL.
5  *
6  * For licencing information please see the file license.txt included with JGAP
7  * or have a look at the top of class org.jgap.Chromosome which representatively
8  * includes the JGAP license policy applicable for any file delivered with JGAP.
9  */

10 package org.jgap.impl;
11
12 import java.io.*;
13 import java.util.*;
14
15 import org.jgap.*;
16 import org.jgap.util.*;
17
18 /**
19  * The stock random generator uses the java.util.Random class to
20  * provide a simple implementation of the RandomGenerator interface.
21  * No actual code is provided here.
22  *
23  * @author Neil Rotstan
24  * @author Klaus Meffert
25  * @since 1.0
26  */

27 public class StockRandomGenerator
28     extends Random
29     implements RandomGenerator, ICloneable, Comparable JavaDoc {
30   /** String containing the CVS revision. Read out via reflection!*/
31   private final static String JavaDoc CVS_REVISION = "$Revision: 1.7 $";
32
33   /**
34    * When deserializing, initialize the seed because otherwise we could get
35    * duplicate evolution results when doing distributed computing!
36    *
37    * @param a_inputStream the ObjectInputStream provided for deserialzation
38    *
39    * @throws IOException
40    * @throws ClassNotFoundException
41    *
42    * @author Klaus Meffert
43    * @since 3.01
44    */

45   private void readObject(ObjectInputStream a_inputStream)
46       throws IOException, ClassNotFoundException JavaDoc {
47     //always perform the default de-serialization first
48
a_inputStream.defaultReadObject();
49     setSeed(System.currentTimeMillis());
50   }
51
52   /**
53    * @return deep clone of this instance
54    *
55    * @author Klaus Meffert
56    * @since 3.2
57    */

58   public Object JavaDoc clone() {
59     StockRandomGenerator result = new StockRandomGenerator();
60     result.setSeed(System.currentTimeMillis());
61     return result;
62   }
63
64   /**
65    * @param a_other sic
66    * @return as always
67    *
68    * @author Klaus Meffert
69    * @since 3.2
70    */

71   public int compareTo(Object JavaDoc a_other) {
72     if (a_other.getClass().equals(getClass())) {
73       return 0;
74     }
75     else {
76       return getClass().getName().compareTo(a_other.getClass().getName());
77     }
78   }
79 }
80
Popular Tags