📄 filter.java
字号:
ex.printStackTrace(); } finally { m_visual.setText(oldText); m_visual.setStatic(); m_state = IDLE; if (isInterrupted()) { m_trainingSet = null; if (m_log != null) { m_log.logMessage("Filter test set interrupted!"); m_log.statusMessage("OK"); } } block(false); } } }; m_filterThread.setPriority(Thread.MIN_PRIORITY); m_filterThread.start(); block(true); m_filterThread = null; m_state = IDLE; } catch (Exception ex) { ex.printStackTrace(); } } } /** * Accept a data set * * @param e a <code>DataSetEvent</code> value */ public void acceptDataSet(DataSetEvent e) { processTrainingOrDataSourceEvents(e); } /** * Set the visual appearance of this bean * * @param newVisual a <code>BeanVisual</code> value */ public void setVisual(BeanVisual newVisual) { m_visual = newVisual; } /** * Get the visual appearance of this bean * * @return a <code>BeanVisual</code> value */ public BeanVisual getVisual() { return m_visual; } /** * Use the default visual appearance */ public void useDefaultVisual() { m_visual.loadIcons(BeanVisual.ICON_PATH+"DefaultFilter.gif", BeanVisual.ICON_PATH+"DefaultFilter_animated.gif"); } /** * Add a training set listener * * @param tsl a <code>TrainingSetListener</code> value */ public synchronized void addTrainingSetListener(TrainingSetListener tsl) { m_trainingListeners.addElement(tsl); } /** * Remove a training set listener * * @param tsl a <code>TrainingSetListener</code> value */ public synchronized void removeTrainingSetListener(TrainingSetListener tsl) { m_trainingListeners.removeElement(tsl); } /** * Add a test set listener * * @param tsl a <code>TestSetListener</code> value */ public synchronized void addTestSetListener(TestSetListener tsl) { m_testListeners.addElement(tsl); } /** * Remove a test set listener * * @param tsl a <code>TestSetListener</code> value */ public synchronized void removeTestSetListener(TestSetListener tsl) { m_testListeners.removeElement(tsl); } /** * Add a data source listener * * @param dsl a <code>DataSourceListener</code> value */ public synchronized void addDataSourceListener(DataSourceListener dsl) { m_dataListeners.addElement(dsl); } /** * Remove a data source listener * * @param dsl a <code>DataSourceListener</code> value */ public synchronized void removeDataSourceListener(DataSourceListener dsl) { m_dataListeners.remove(dsl); } /** * Add an instance listener * * @param tsl an <code>InstanceListener</code> value */ public synchronized void addInstanceListener(InstanceListener tsl) { m_instanceListeners.addElement(tsl); } /** * Remove an instance listener * * @param tsl an <code>InstanceListener</code> value */ public synchronized void removeInstanceListener(InstanceListener tsl) { m_instanceListeners.removeElement(tsl); } private void notifyDataOrTrainingListeners(EventObject ce) { Vector l; synchronized (this) { l = (ce instanceof TrainingSetEvent) ? (Vector)m_trainingListeners.clone() : (Vector)m_dataListeners.clone(); } if (l.size() > 0) { for(int i = 0; i < l.size(); i++) { if (ce instanceof TrainingSetEvent) { ((TrainingSetListener)l.elementAt(i)). acceptTrainingSet((TrainingSetEvent)ce); } else { ((DataSourceListener)l.elementAt(i)).acceptDataSet((DataSetEvent)ce); } } } } private void notifyTestListeners(TestSetEvent ce) { Vector l; synchronized (this) { l = (Vector)m_testListeners.clone(); } if (l.size() > 0) { for(int i = 0; i < l.size(); i++) { ((TestSetListener)l.elementAt(i)).acceptTestSet(ce); } } } protected void notifyInstanceListeners(InstanceEvent tse) { Vector l; synchronized (this) { l = (Vector)m_instanceListeners.clone(); } if (l.size() > 0) { for(int i = 0; i < l.size(); i++) { // System.err.println("Notifying instance listeners " // +"(Filter)"); ((InstanceListener)l.elementAt(i)).acceptInstance(tse); } } } /** * Returns true if, at this time, * the object will accept a connection with respect to the supplied * event name * * @param eventName the event * @return true if the object will accept a connection */ public boolean connectionAllowed(String eventName) { if (m_listenees.containsKey(eventName)) { return false; } /* reject a test event if we don't have a training or data set event if (eventName.compareTo("testSet") == 0) { if (!m_listenees.containsKey("trainingSet") && !m_listenees.containsKey("dataSet")) { return false; } } */ // will need to reject train/test listener if we have a // data source listener and vis versa if (m_listenees.containsKey("dataSet") && (eventName.compareTo("trainingSet") == 0 || eventName.compareTo("testSet") == 0 || eventName.compareTo("instance") == 0)) { return false; } if ((m_listenees.containsKey("trainingSet") || m_listenees.containsKey("testSet")) && (eventName.compareTo("dataSet") == 0 || eventName.compareTo("instance") == 0)) { return false; } if (m_listenees.containsKey("instance") && (eventName.compareTo("trainingSet") == 0 || eventName.compareTo("testSet") == 0 || eventName.compareTo("dataSet") == 0)) { return false; } // reject an instance event connection if our filter isn't // streamable if (eventName.compareTo("instance") == 0 && !(m_Filter instanceof StreamableFilter)) { return false; } return true; } /** * Notify this object that it has been registered as a listener with * a source with respect to the supplied event name * * @param eventName * @param source the source with which this object has been registered as * a listener */ public synchronized void connectionNotification(String eventName, Object source) { if (connectionAllowed(eventName)) { m_listenees.put(eventName, source); } } /** * Notify this object that it has been deregistered as a listener with * a source with respect to the supplied event name * * @param eventName the event * @param source the source with which this object has been registered as * a listener */ public synchronized void disconnectionNotification(String eventName, Object source) { m_listenees.remove(eventName); } /** * Function used to stop code that calls acceptTrainingSet, acceptTestSet, * or acceptDataSet. This is * needed as filtering is performed inside a separate * thread of execution. * * @param tf a <code>boolean</code> value */ private synchronized void block(boolean tf) { if (tf) { try { // only block if thread is still doing something useful! if (m_filterThread.isAlive() && m_state != IDLE) { wait(); } } catch (InterruptedException ex) { } } else { notifyAll(); } } /** * Stop all action if possible */ public void stop() { // tell all listenees (upstream beans) to stop Enumeration en = m_listenees.keys(); while (en.hasMoreElements()) { Object tempO = m_listenees.get(en.nextElement()); if (tempO instanceof BeanCommon) { System.err.println("Listener is BeanCommon"); ((BeanCommon)tempO).stop(); } } // } /** * Set a logger * * @param logger a <code>Logger</code> value */ public void setLog(Logger logger) { m_log = logger; } /** * Return an enumeration of user requests * * @return an <code>Enumeration</code> value */ public Enumeration enumerateRequests() { Vector newVector = new Vector(0); if (m_filterThread != null) { newVector.addElement("Stop"); } return newVector.elements(); } /** * Perform the named request * * @param request a <code>String</code> value * @exception IllegalArgumentException if an error occurs */ public void performRequest(String request) throws IllegalArgumentException { if (request.compareTo("Stop") == 0) { stop(); } else { throw new IllegalArgumentException(request + " not supported (Filter)"); } } /** * Returns true, if at the current time, the named event could * be generated. Assumes that supplied event names are names of * events that could be generated by this bean. * * @param eventName the name of the event in question * @return true if the named event could be generated at this point in * time */ public boolean eventGeneratable(String eventName) { // can't generate the named even if we are not receiving it as an // input! if (!m_listenees.containsKey(eventName)) { return false; } Object source = m_listenees.get(eventName); if (source instanceof EventConstraints) { if (!((EventConstraints)source).eventGeneratable(eventName)) { return false; } } if (eventName.compareTo("instance") == 0) { if (!(m_Filter instanceof StreamableFilter)) { return false; } } return true; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -