KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.jgap.*;
13 import org.jgap.util.*;
14 import java.io.*;
15
16 /**
17  * Default implementation for initializing Chromosomes.
18  *
19  * @author Klaus Meffert
20  * @since 2.6
21  */

22 public class DefaultInitializer
23     implements IInitializer, ICloneable, Serializable {
24   /** String containing the CVS revision. Read out via reflection!*/
25   private static final String JavaDoc CVS_REVISION = "$Revision: 1.8 $";
26
27   public boolean isHandlerFor(final Object JavaDoc a_obj, final Class JavaDoc a_class) {
28     if (IChromosome.class.isAssignableFrom(a_class)) {
29       return true;
30     }
31     else {
32       if (a_obj != null && IInitializer.class.isAssignableFrom(a_class)) {
33         IInitializer initer = (IInitializer) a_obj;
34         return initer.isHandlerFor(null, a_class);
35       }
36       else {
37         return false;
38       }
39     }
40   }
41
42   public Object JavaDoc perform(final Object JavaDoc a_obj, final Class JavaDoc a_class,
43                         final Object JavaDoc a_params)
44       throws Exception JavaDoc {
45     if (IInitializer.class.isAssignableFrom(a_class)) {
46       return ( (IInitializer) a_obj).perform(null, a_class, a_params);
47     }
48     else {
49       throw new IllegalArgumentException JavaDoc("DefaultInitializer not suited for"
50           + " class"
51           + a_class.getName()
52           + " !");
53     }
54   }
55
56   /**
57    * @return deep clone of this instance
58    *
59    * @author Klaus Meffert
60    * @since 3.2
61    */

62   public Object JavaDoc clone() {
63     return new DefaultInitializer();
64   }
65 }
66
Popular Tags