2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2003, The Institute for Genomic Research (TIGR). |
2 |
26 Feb 07 |
jari |
All rights reserved. |
2 |
26 Feb 07 |
jari |
4 |
*/ |
2 |
26 Feb 07 |
jari |
5 |
/* |
2 |
26 Feb 07 |
jari |
* $RCSfile: AbstractAlgorithm.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.3 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2005/03/10 15:46:10 $ |
2 |
26 Feb 07 |
jari |
* $Author: braistedj $ |
2 |
26 Feb 07 |
jari |
* $State: Exp $ |
2 |
26 Feb 07 |
jari |
11 |
*/ |
2 |
26 Feb 07 |
jari |
12 |
package org.tigr.microarray.mev.cluster.algorithm; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
import javax.swing.event.EventListenerList; |
2 |
26 Feb 07 |
jari |
15 |
|
2 |
26 Feb 07 |
jari |
16 |
/** |
2 |
26 Feb 07 |
jari |
* This abstract class provides default implementations for some |
2 |
26 Feb 07 |
jari |
* of the methods in the Algorithm interface. It takes care of the |
2 |
26 Feb 07 |
jari |
* management of listeners and provides some conveniences for |
2 |
26 Feb 07 |
jari |
* generating AlgorithmEvents and dispatching them to the listeners. |
2 |
26 Feb 07 |
jari |
* To create a concrete Algorithm as a subclass of AbstractAlgorithm |
2 |
26 Feb 07 |
jari |
* programmer need only provide implementations for the following two |
2 |
26 Feb 07 |
jari |
* methods: |
2 |
26 Feb 07 |
jari |
* <pre> |
2 |
26 Feb 07 |
jari |
* public AlgorithmData execute(AlgorithmData data) throws AlgorithmException; |
2 |
26 Feb 07 |
jari |
* public void abort(); |
2 |
26 Feb 07 |
jari |
* </pre> |
2 |
26 Feb 07 |
jari |
28 |
* |
2 |
26 Feb 07 |
jari |
* @version 1.0 |
2 |
26 Feb 07 |
jari |
* @author Aleksey D.Rezantsev |
2 |
26 Feb 07 |
jari |
31 |
*/ |
2 |
26 Feb 07 |
jari |
32 |
public abstract class AbstractAlgorithm implements Algorithm { |
2 |
26 Feb 07 |
jari |
33 |
|
2 |
26 Feb 07 |
jari |
/** List of listeners */ |
2 |
26 Feb 07 |
jari |
35 |
private EventListenerList listenerList = new EventListenerList(); |
2 |
26 Feb 07 |
jari |
36 |
|
2 |
26 Feb 07 |
jari |
37 |
/* |
2 |
26 Feb 07 |
jari |
* Returns a string representation of the argument distance metric |
2 |
26 Feb 07 |
jari |
39 |
*/ |
2 |
26 Feb 07 |
jari |
40 |
public static String getDistanceName(int function) { |
2 |
26 Feb 07 |
jari |
41 |
String functionName = ""; |
2 |
26 Feb 07 |
jari |
42 |
|
2 |
26 Feb 07 |
jari |
43 |
switch (function) { |
2 |
26 Feb 07 |
jari |
44 |
case Algorithm.DEFAULT: |
2 |
26 Feb 07 |
jari |
45 |
functionName = "Pearson correlation"; |
2 |
26 Feb 07 |
jari |
46 |
break; |
2 |
26 Feb 07 |
jari |
47 |
case Algorithm.PEARSON: |
2 |
26 Feb 07 |
jari |
48 |
functionName = "Pearson correlation"; |
2 |
26 Feb 07 |
jari |
49 |
break; |
2 |
26 Feb 07 |
jari |
50 |
case Algorithm.COSINE: |
2 |
26 Feb 07 |
jari |
51 |
functionName = "Cosine correlation"; |
2 |
26 Feb 07 |
jari |
52 |
break; |
2 |
26 Feb 07 |
jari |
53 |
case Algorithm.COVARIANCE: |
2 |
26 Feb 07 |
jari |
54 |
functionName = "Covariance"; |
2 |
26 Feb 07 |
jari |
55 |
break; |
2 |
26 Feb 07 |
jari |
56 |
case Algorithm.EUCLIDEAN: |
2 |
26 Feb 07 |
jari |
57 |
functionName = "Euclidean"; |
2 |
26 Feb 07 |
jari |
58 |
break; |
2 |
26 Feb 07 |
jari |
59 |
case Algorithm.DOTPRODUCT: |
2 |
26 Feb 07 |
jari |
60 |
functionName = "Dot product"; |
2 |
26 Feb 07 |
jari |
61 |
break; |
2 |
26 Feb 07 |
jari |
62 |
case Algorithm.PEARSONUNCENTERED: |
2 |
26 Feb 07 |
jari |
63 |
functionName = "Pearson uncentered"; |
2 |
26 Feb 07 |
jari |
64 |
break; |
2 |
26 Feb 07 |
jari |
65 |
case Algorithm.PEARSONSQARED: |
2 |
26 Feb 07 |
jari |
66 |
functionName = "Pearson squared"; |
2 |
26 Feb 07 |
jari |
67 |
break; |
2 |
26 Feb 07 |
jari |
68 |
case Algorithm.MANHATTAN: |
2 |
26 Feb 07 |
jari |
69 |
functionName = "Manhattan"; |
2 |
26 Feb 07 |
jari |
70 |
break; |
2 |
26 Feb 07 |
jari |
71 |
case Algorithm.SPEARMANRANK: |
2 |
26 Feb 07 |
jari |
72 |
functionName = "Spearman rank"; |
2 |
26 Feb 07 |
jari |
73 |
break; |
2 |
26 Feb 07 |
jari |
74 |
case Algorithm.KENDALLSTAU: |
2 |
26 Feb 07 |
jari |
75 |
functionName = "Kendall's Tau"; |
2 |
26 Feb 07 |
jari |
76 |
break; |
2 |
26 Feb 07 |
jari |
77 |
case Algorithm.MUTUALINFORMATION: |
2 |
26 Feb 07 |
jari |
78 |
functionName = "Mutual information"; |
2 |
26 Feb 07 |
jari |
79 |
break; |
2 |
26 Feb 07 |
jari |
80 |
default: |
2 |
26 Feb 07 |
jari |
81 |
functionName = "Undefined"; |
2 |
26 Feb 07 |
jari |
82 |
break; |
2 |
26 Feb 07 |
jari |
83 |
} |
2 |
26 Feb 07 |
jari |
84 |
|
2 |
26 Feb 07 |
jari |
85 |
return functionName; |
2 |
26 Feb 07 |
jari |
86 |
} |
2 |
26 Feb 07 |
jari |
87 |
|
2 |
26 Feb 07 |
jari |
88 |
/** |
2 |
26 Feb 07 |
jari |
* Adds a listener to the list. |
2 |
26 Feb 07 |
jari |
* @param l the <code>AlgorithmListener</code>. |
2 |
26 Feb 07 |
jari |
91 |
*/ |
2 |
26 Feb 07 |
jari |
92 |
public void addAlgorithmListener(AlgorithmListener l) { |
2 |
26 Feb 07 |
jari |
93 |
listenerList.add(AlgorithmListener.class, l); |
2 |
26 Feb 07 |
jari |
94 |
} |
2 |
26 Feb 07 |
jari |
95 |
|
2 |
26 Feb 07 |
jari |
96 |
/** |
2 |
26 Feb 07 |
jari |
* Removes a listener from the list. |
2 |
26 Feb 07 |
jari |
* @param l the <code>AlgorithmListener</code>. |
2 |
26 Feb 07 |
jari |
99 |
*/ |
2 |
26 Feb 07 |
jari |
100 |
public void removeAlgorithmListener(AlgorithmListener l) { |
2 |
26 Feb 07 |
jari |
101 |
listenerList.remove(AlgorithmListener.class, l); |
2 |
26 Feb 07 |
jari |
102 |
} |
2 |
26 Feb 07 |
jari |
103 |
|
2 |
26 Feb 07 |
jari |
104 |
/** |
2 |
26 Feb 07 |
jari |
* Notifies all listeners that the algorithm's event has occured. |
2 |
26 Feb 07 |
jari |
* @param event the <code>AlgorithmEvent</code>. |
2 |
26 Feb 07 |
jari |
107 |
*/ |
2 |
26 Feb 07 |
jari |
108 |
public void fireValueChanged(AlgorithmEvent event) { |
2 |
26 Feb 07 |
jari |
109 |
Object[] listeners = listenerList.getListenerList(); |
2 |
26 Feb 07 |
jari |
110 |
for (int i = listeners.length-2; i>=0; i-=2) { |
2 |
26 Feb 07 |
jari |
111 |
if (listeners[i]==AlgorithmListener.class) { |
2 |
26 Feb 07 |
jari |
112 |
((AlgorithmListener)listeners[i+1]).valueChanged(event); |
2 |
26 Feb 07 |
jari |
113 |
} |
2 |
26 Feb 07 |
jari |
114 |
} |
2 |
26 Feb 07 |
jari |
115 |
} |
2 |
26 Feb 07 |
jari |
116 |
} |