Project

General

Profile

« Previous | Next » 

Revision 1520

Added by Jing Tao over 21 years ago

Implement Comparator interface.

View differences:

src/edu/ucsb/nceas/metacat/SubTree.java
28 28

  
29 29
package edu.ucsb.nceas.metacat;
30 30

  
31
import java.util.Comparator;
31 32
import java.util.Stack;
32 33
import java.sql.PreparedStatement;
33 34
import java.sql.SQLException;
......
37 38
/**
38 39
 * A Class that represents an XML Subtree
39 40
 */
40
public class SubTree
41
public class SubTree implements Comparator
41 42
{
42 43
  private String docId = null;
43 44
  private String subTreeId = null;
......
231 232
   
232 233
    }//getSubtreeNodeList
233 234
    
234
    public static void main (String agus)
235
    {
236
      
237
    }
235
   /** methods from Comparator interface */
236
   public int compare(Object o1, Object o2)
237
   {
238
     SubTree tree1 = (SubTree) o1;
239
     SubTree tree2 = (SubTree) o2;
240
     if (tree1.getStartNodeId() > tree2.getStartNodeId())
241
     {
242
       return 1;
243
     }
244
     else if (tree1.getStartNodeId() < tree2.getStartNodeId())
245
     {
246
       return -1;
247
     }
248
     else
249
     {
250
       return 0;
251
     }
252
     
253
   }//cpmpare
254
   
255
   /** method from Comparator interface */
256
   public boolean equals(Object obj)
257
   {
258
     SubTree tree = (SubTree)obj;
259
     if (startNodeId == tree.getStartNodeId())
260
     {
261
       return true;
262
     }
263
     else
264
     {
265
       return false;
266
     }
267
   }
268
   
238 269
}

Also available in: Unified diff