1 10 11 12 package org.mmbase.applications.community.modules; 13 14 import org.mmbase.util.*; 15 import org.mmbase.module.core.*; 16 import java.util.Vector ; 17 18 27 public class CompareMessages implements CompareInterface { 28 29 public final static String UP = "UP"; 30 public final static String DOWN = "DOWN"; 31 32 private Vector fields; 33 private Vector sortDirs; 34 35 public CompareMessages(Vector fields) { 36 this.fields = fields; 37 sortDirs = new Vector (fields.size()); 38 for (int i = 0; i < fields.size(); i++) { 39 sortDirs.add(UP); 40 } 41 } 42 43 47 public CompareMessages(Vector fields, Vector sortDirs) { 48 this.fields = fields; 49 this.sortDirs = sortDirs; 50 for (int i = sortDirs.size(); i < fields.size(); i++) { 51 sortDirs.add(UP); 52 } 53 } 54 55 59 public int compare(Object thisone, Object other) { 60 MMObjectNode n1 = (MMObjectNode)thisone; 61 MMObjectNode n2 = (MMObjectNode)other; 62 Object o1, o2; 63 int result; 64 int fieldnr = 0; 65 do { 66 o1 = n1.getValue((String )fields.elementAt(fieldnr)); 67 o2 = n2.getValue((String )fields.elementAt(fieldnr)); 68 if (o1 instanceof Integer ) { 69 if (((String )sortDirs.elementAt(fieldnr)).equals(UP)) 70 result = (((Integer )o1).compareTo((Integer )o2)); 71 else 72 result = -(((Integer )o1).compareTo((Integer )o2)); 73 } else if (o1 instanceof String ) { 74 if (((String )sortDirs.elementAt(fieldnr)).equals(UP)) 75 result = (((String )o1).compareToIgnoreCase((String )o2)); 76 else 77 result = -(((String )o1).compareToIgnoreCase((String )o2)); 78 } else { 79 result = 0; 80 } 81 fieldnr++; 82 } while ((result == 0) && (fieldnr < fields.size())); 83 return result; 84 } 85 } 86 | Popular Tags |