/** * Create a new collection listener. * @param num The expected number of results. * @param ignorefailures When set to true failures will be * tolerated and just not be added to the result collection. * @param delegate The delegate result listener. */ public CollectionResultListener(int num, boolean ignorefailures, IResultListener<Collection<E>> delegate) { // synchronized(CollectionResultListener.class) // { // System.out.println("start: "+(++open)); // } this.num = num; this.ignorefailures = ignorefailures; this.delegate = delegate; this.results = new ArrayList<E>(); // System.out.println("CollectionResultListener: "+this+", "+num); if(num==0) notifyDelegate((Exception)NULL); }
/** * Set the expected number of results. * @param num The expected number of results to set. */ public void setNumber(int num) { this.num += num+1; // not = num because -1 for each exception when ignorefailures if(checkNotify((E)NULL, (Exception)NULL)) notifyDelegate(null); }
/** * Called when some result is available. * @param result The result. */ public void resultAvailable(E result) { if(checkNotify(result, (Exception)NULL)) notifyDelegate((Exception)NULL); }
/** * Called when an exception occurred. * @param exception The exception. */ public void exceptionOccurred(Exception exception) { if(checkNotify((E)NULL, exception)) notifyDelegate(exception); }