1 package org.jacorb.notification; 2 3 22 23 import org.jacorb.notification.filter.EventTypeIdentifier; 24 import org.omg.CosNotification.EventType; 25 26 30 31 public class EventTypeWrapper implements EventTypeIdentifier, Comparable ![JavaDoc](../../../../cmn/javadoc.gif) 32 { 33 private final EventType eventType_; 34 private final String constraintKey_; 35 36 public static final EventType EVENT_TYPE_ALL = new EventType("", "%ALL"); 37 38 public static final EventType[] EMPTY_EVENT_TYPE_ARRAY = new EventType[0]; 39 40 public EventTypeWrapper(EventType eventType) 41 { 42 eventType_ = eventType; 43 44 constraintKey_ = 45 AbstractMessage.calcConstraintKey( eventType.domain_name, eventType.type_name ); 46 } 47 48 public EventType getEventType() 49 { 50 return eventType_; 51 } 52 53 public String toString() 54 { 55 return toString(eventType_); 56 } 57 58 public boolean equals(Object other) 59 { 60 try { 61 return equals(eventType_, ((EventTypeWrapper)other).eventType_); 62 } catch (ClassCastException e) 63 { 64 return super.equals(other); 65 } 66 } 67 68 public int hashCode() 69 { 70 return toString().hashCode(); 71 } 72 73 public int compareTo(Object o) 74 { 75 try 76 { 77 EventTypeWrapper _other = (EventTypeWrapper) o; 78 79 int _compare = eventType_.domain_name 80 .compareTo(_other.eventType_.domain_name); 81 82 if (_compare == 0) 83 { 84 _compare = eventType_.type_name 85 .compareTo(_other.eventType_.type_name); 86 } 87 88 return _compare; 89 90 } catch (ClassCastException e) 91 { 92 throw new IllegalArgumentException (); 93 } 94 } 95 96 98 public static String toString(EventType et) 99 { 100 StringBuffer buffer = new StringBuffer (); 101 appendEventTypeToBuffer(et, buffer); 102 return buffer.toString(); 103 } 104 105 private static void appendEventTypeToBuffer(EventType et, StringBuffer buffer) 106 { 107 buffer.append(et.domain_name); 108 buffer.append("/"); 109 buffer.append(et.type_name); 110 } 111 112 public static String toString(EventType[] ets) 113 { 114 StringBuffer b = new StringBuffer ("["); 115 116 for (int x = 0; x < ets.length; ++x) 117 { 118 appendEventTypeToBuffer(ets[x], b); 119 120 if (x < ets.length - 1) 121 { 122 b.append(", "); 123 } 124 } 125 126 b.append("]"); 127 128 return b.toString(); 129 } 130 131 public static boolean equals(EventType left, EventType right) 132 { 133 return left.domain_name.equals(right.domain_name) && left.type_name.equals(right.type_name); 134 } 135 136 public String getConstraintKey() 137 { 138 return constraintKey_; 139 } 140 } | Popular Tags |