1 package org.jacorb.notification.queue; 2 3 23 24 import java.util.Comparator ; 25 26 import org.jacorb.notification.interfaces.Message; 27 28 32 33 class QueueUtil 34 { 35 private QueueUtil() 36 { 37 } 39 40 42 static final Message[] MESSAGE_ARRAY_TEMPLATE = new Message[0]; 43 44 static final HeapEntry[] HEAP_ENTRY_ARRAY_TEMPLATE = new HeapEntry[0]; 45 46 static Comparator ASCENDING_TIMEOUT_COMPARATOR = new Comparator () 47 { 48 public int compare(Object left, Object right) 49 { 50 Message _left = toMessage(left); 51 Message _right = toMessage(right); 52 53 if (_left.hasTimeout()) 54 { 55 if (!_right.hasTimeout()) 56 { 57 return -1; 58 } 59 60 return (int) (_left.getTimeout() - _right.getTimeout()); 61 } 62 else if (_right.hasTimeout()) 63 { 64 return 1; 65 } 66 67 return 0; 68 } 69 }; 70 71 static Comparator ASCENDING_AGE_COMPARATOR = new Comparator () 72 { 73 public int compare(Object left, Object right) 74 { 75 HeapEntry _left = (HeapEntry) left; 76 HeapEntry _right = (HeapEntry) right; 77 78 return (int)(_left.order_ - _right.order_); 79 } 80 }; 81 82 static Comparator DESCENDING_AGE_COMPARATOR = new Comparator () 83 { 84 public int compare(Object left, Object right) 85 { 86 return -ASCENDING_AGE_COMPARATOR.compare(left, right); 87 } 88 }; 89 90 static Comparator ASCENDING_PRIORITY_COMPARATOR = new Comparator () 91 { 92 public int compare(Object left, Object right) 93 { 94 Message _right = toMessage(right); 95 96 Message _left = toMessage(left); 97 98 return _left.getPriority() - _right.getPriority(); 99 } 100 }; 101 102 static Comparator DESCENDING_PRIORITY_COMPARATOR = new Comparator () 103 { 104 public int compare(Object left, Object right) 105 { 106 return -ASCENDING_PRIORITY_COMPARATOR.compare(left, right); 107 } 108 }; 109 110 static Message toMessage(Object object) 111 { 112 final Message _message; 113 114 if (object instanceof HeapEntry) 115 { 116 _message = ((HeapEntry) object).event_; 117 } 118 else if (object instanceof Message) 119 { 120 _message = (Message) object; 121 } 122 else 123 { 124 throw new IllegalArgumentException (); 125 } 126 return _message; 127 } 128 } | Popular Tags |