1 4 package com.mockobjects.constraint; 5 6 import java.util.EventObject ; 7 8 9 11 public class IsEventFrom 12 implements Constraint 13 { 14 private Class _event_class; 15 private Object _source; 16 17 21 public IsEventFrom( Object source ) { 22 this( EventObject .class, source ); 23 } 24 25 29 public IsEventFrom( Class event_class, Object source ) { 30 _event_class = event_class; 31 _source = source; 32 } 33 34 public boolean eval( Object o ) { 35 if( o instanceof EventObject ) { 36 EventObject ev = (EventObject )o; 37 return _event_class.isInstance(o) && ev.getSource() == _source; 38 39 } else { 40 return false; 41 } 42 } 43 44 public String toString() { 45 return "an event of type " + _event_class.getName() + 46 " from " + _source; 47 } 48 } 49 | Popular Tags |