00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 package com.meapsoft;
00024
00025 import java.io.Serializable;
00026 import java.util.Comparator;
00027
00037 public abstract class ChunkDist implements Serializable, Comparator
00038 {
00039 public Chunk targetChunk = null;
00040 public ChunkDist next;
00041
00042 public int[] featdim;
00043
00044 public ChunkDist()
00045 {
00046 next = null;
00047 featdim = null;
00048 }
00049
00050 public ChunkDist(ChunkDist next)
00051 {
00052 this.next = next;
00053 }
00054
00055 public ChunkDist(int[] fd)
00056 {
00057 this();
00058 featdim = fd;
00059 }
00060
00061 public ChunkDist(ChunkDist next, int[] fd)
00062 {
00063 this.next = next;
00064 featdim = fd;
00065 }
00066
00070 public double distance(Chunk c1, Chunk c2)
00071 {
00072 if(next != null)
00073 return next.distance(c1, c2);
00074 return 0;
00075 }
00076
00082 public void setTarget(Chunk t)
00083 {
00084 targetChunk = t;
00085 }
00086
00090 public int compare(Object o1, Object o2) throws ClassCastException
00091 {
00092 Chunk c1 = (Chunk)o1;
00093 Chunk c2 = (Chunk)o2;
00094
00095
00096 double d1 = distance(c1, targetChunk);
00097 double d2 = distance(c2, targetChunk);
00098
00099 double comp = d1-d2;
00100
00101
00102 if(comp > 0)
00103 return 1;
00104 else if(comp < 0)
00105 return -1;
00106
00107
00108
00109 else if(comp == 0)
00110 return c1.compareTo(c2);
00111
00112
00113 return(0);
00114 }
00115
00116 public boolean equals(Object obj)
00117 {
00118 return this == obj;
00119 }
00120 }