@KFStep(category="Tools", toolTipText="Sort instances in ascending or descending order") public class Sorter extends javax.swing.JPanel implements BeanCommon, Visible, java.io.Serializable, DataSource, DataSourceListener, TrainingSetListener, TestSetListener, InstanceListener, EventConstraints, StructureProducer, EnvironmentHandler
| Modifier and Type | Class and Description |
|---|---|
protected static class |
Sorter.InstanceHolder
Inner class that holds instances and the index of the temp file that holds
them (if operating in incremental mode)
|
protected static class |
Sorter.SortComparator
Comparator that applies the sort rules
|
protected static class |
Sorter.SortRule
Implements a sorting rule based on a single attribute
|
javax.swing.JPanel.AccessibleJPaneljavax.swing.JComponent.AccessibleJComponent| Modifier and Type | Field and Description |
|---|---|
protected java.util.List<java.io.File> |
m_bufferFiles
List of sorted temp files for incremental operation
|
protected java.lang.String |
m_bufferSize
Size of the in-memory buffer
|
protected int |
m_bufferSizeI
Size of the in-memory buffer after resolving any environment vars
|
protected boolean |
m_busy
True if we are busy
|
protected java.lang.String |
m_connectionType
The type of the incoming connection
|
protected java.util.ArrayList<DataSourceListener> |
m_dataListeners
Downstream steps listening to batch data events
|
protected Environment |
m_env
Environment variables
|
protected InstanceEvent |
m_ie
For printing status updates in incremental mode
|
protected java.util.List<Sorter.InstanceHolder> |
m_incrementalBuffer
In memory buffer for incremental operation
|
protected java.util.ArrayList<InstanceListener> |
m_instanceListeners
Downstream steps listening to instance events
|
protected java.lang.Object |
m_listenee
Step talking to us
|
protected Logger |
m_log
Logging
|
protected Sorter.SortComparator |
m_sortComparator
Comparator that applies the sort rules
|
protected java.lang.String |
m_sortDetails
Holds the internal textual description of the sort definitions
|
protected java.util.concurrent.atomic.AtomicBoolean |
m_stopRequested
True if a stop has been requested
|
protected int |
m_streamCounter |
protected java.util.Map<java.lang.String,java.lang.Integer> |
m_stringAttIndexes
Holds indexes of string attributes, keyed by attribute name
|
protected java.lang.String |
m_tempDirectory
The directory to hold the temp files - if not set the system tmp directory
is used
|
protected BeanVisual |
m_visual
Default visual for data sources
|
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW| Constructor and Description |
|---|
Sorter()
Constructs a new Sorter
|
| Modifier and Type | Method and Description |
|---|---|
void |
acceptDataSet(DataSetEvent e)
Accept and process a data set event
|
void |
acceptInstance(InstanceEvent e)
Accept and process an instance event
|
void |
acceptTestSet(TestSetEvent e)
Accept and process a test set event
|
void |
acceptTrainingSet(TrainingSetEvent e)
Accept and process a training set event
|
void |
addDataSourceListener(DataSourceListener dsl)
Add a datasource listener
|
void |
addInstanceListener(InstanceListener dsl)
Add an instance listener
|
boolean |
connectionAllowed(java.beans.EventSetDescriptor esd)
Returns true if, at this time, the object will accept a connection via the
named event
|
boolean |
connectionAllowed(java.lang.String eventName)
Returns true if, at this time, the object will accept a connection via the
named event
|
void |
connectionNotification(java.lang.String eventName,
java.lang.Object source)
Notify this object that it has been registered as a listener with a source
for receiving events described by the named event This object is
responsible for recording this fact.
|
void |
disconnectionNotification(java.lang.String eventName,
java.lang.Object source)
Notify this object that it has been deregistered as a listener with a
source for named event.
|
protected void |
emitBufferedInstances()
Performs the merge stage of the merge sort by opening all temp files and
interleaving the instances.
|
boolean |
eventGeneratable(java.lang.String eventName)
Returns true if, at the current time, the named event could be generated.
|
java.lang.String |
getBufferSize()
Get the size of the in-memory buffer
|
Instances |
getConnectedFormat()
Returns the structure of the incoming instances (if any)
|
java.lang.String |
getCustomName()
Get the custom (descriptive) name for this bean (if one has been set)
|
java.lang.String |
getSortDetails()
Get the sort rules to use
|
Instances |
getStructure(java.lang.String eventName)
Get the structure of the output encapsulated in the named event.
|
java.lang.String |
getTempDirectory()
Get the directory to use for temporary files during incremental operation
|
BeanVisual |
getVisual()
Get the visual representation
|
java.lang.String |
globalInfo()
Help information suitable for displaying in the GUI.
|
protected void |
init(Instances structure) |
boolean |
isBusy()
Returns true if. at this time, the bean is busy with some (i.e. perhaps a
worker thread is performing some calculation).
|
void |
removeDataSourceListener(DataSourceListener dsl)
Remove a datasource listener
|
void |
removeInstanceListener(InstanceListener dsl)
Remove an instance listener
|
void |
setBufferSize(java.lang.String buffSize)
Set the size of the in-memory buffer
|
void |
setCustomName(java.lang.String name)
Set a custom (descriptive) name for this bean
|
void |
setEnvironment(Environment env)
Set environment variables to use
|
void |
setLog(Logger logger)
Set a logger
|
void |
setSortDetails(java.lang.String sortDetails)
Set the sort rules to use
|
void |
setTempDirectory(java.lang.String tempDir)
Set the directory to use for temporary files during incremental operation
|
void |
setVisual(BeanVisual newVisual)
Set a new visual representation
|
protected void |
sortBuffer(boolean write)
Sorts the in-memory buffer
|
protected java.lang.String |
statusMessagePrefix() |
void |
stop()
Stop any processing that the bean might be doing.
|
protected void |
stopWithErrorMessage(java.lang.String error,
java.lang.Exception ex)
Stops the step (and upstream ones) and then prints an error message and
optional exception message
|
void |
useDefaultVisual()
Use the default visual representation
|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIaddAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateadd, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeaction, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleprotected transient Logger m_log
protected java.lang.Object m_listenee
protected java.lang.String m_connectionType
protected InstanceEvent m_ie
protected boolean m_busy
protected java.util.concurrent.atomic.AtomicBoolean m_stopRequested
protected java.lang.String m_sortDetails
protected transient Environment m_env
protected transient Sorter.SortComparator m_sortComparator
protected transient java.util.List<Sorter.InstanceHolder> m_incrementalBuffer
protected transient java.util.List<java.io.File> m_bufferFiles
protected java.lang.String m_bufferSize
protected int m_bufferSizeI
protected java.util.Map<java.lang.String,java.lang.Integer> m_stringAttIndexes
protected java.lang.String m_tempDirectory
protected transient int m_streamCounter
protected BeanVisual m_visual
protected java.util.ArrayList<DataSourceListener> m_dataListeners
protected java.util.ArrayList<InstanceListener> m_instanceListeners
public java.lang.String globalInfo()
public boolean eventGeneratable(java.lang.String eventName)
eventGeneratable in interface EventConstraintseventName - the name of the event in questionpublic void acceptInstance(InstanceEvent e)
acceptInstance in interface InstanceListenere - an InstanceEvent valueprotected void emitBufferedInstances()
protected void sortBuffer(boolean write)
throws java.lang.Exception
write - whether to write the sorted buffer to a temp filejava.lang.Exception - if a problem occurspublic void acceptTestSet(TestSetEvent e)
acceptTestSet in interface TestSetListenere - a TestSetEvent valuepublic void acceptTrainingSet(TrainingSetEvent e)
acceptTrainingSet in interface TrainingSetListenere - a TrainingSetEvent valueprotected void init(Instances structure)
public java.lang.String getBufferSize()
public void setBufferSize(java.lang.String buffSize)
buffSize - the size of the in-memory bufferpublic void setTempDirectory(java.lang.String tempDir)
tempDir - the temp dir to usepublic java.lang.String getTempDirectory()
public void setSortDetails(java.lang.String sortDetails)
sortDetails - the sort rules in internal string representationpublic java.lang.String getSortDetails()
public void acceptDataSet(DataSetEvent e)
acceptDataSet in interface DataSourceListenere - a DataSetEvent valuepublic void addDataSourceListener(DataSourceListener dsl)
addDataSourceListener in interface DataSourcedsl - the datasource listener to addpublic void removeDataSourceListener(DataSourceListener dsl)
removeDataSourceListener in interface DataSourcedsl - the datasource listener to removepublic void addInstanceListener(InstanceListener dsl)
addInstanceListener in interface DataSourcedsl - the instance listener to addpublic void removeInstanceListener(InstanceListener dsl)
removeInstanceListener in interface DataSourcedsl - the instance listener to removepublic void useDefaultVisual()
useDefaultVisual in interface Visiblepublic void setVisual(BeanVisual newVisual)
public BeanVisual getVisual()
public void setCustomName(java.lang.String name)
setCustomName in interface BeanCommonname - the name to usepublic java.lang.String getCustomName()
getCustomName in interface BeanCommonpublic void stop()
stop in interface BeanCommonprotected void stopWithErrorMessage(java.lang.String error,
java.lang.Exception ex)
error - the error message to printex - the optional exceptionpublic boolean isBusy()
isBusy in interface BeanCommonpublic void setLog(Logger logger)
setLog in interface BeanCommonlogger - a weka.gui.Logger valuepublic boolean connectionAllowed(java.beans.EventSetDescriptor esd)
connectionAllowed in interface BeanCommonesd - the EventSetDescriptor for the event in questionpublic boolean connectionAllowed(java.lang.String eventName)
connectionAllowed in interface BeanCommoneventName - the name of the eventpublic void connectionNotification(java.lang.String eventName,
java.lang.Object source)
connectionNotification in interface BeanCommoneventName - the eventsource - the source with which this object has been registered as a
listenerpublic void disconnectionNotification(java.lang.String eventName,
java.lang.Object source)
disconnectionNotification in interface BeanCommoneventName - the eventsource - the source with which this object has been registered as a
listenerprotected java.lang.String statusMessagePrefix()
public Instances getStructure(java.lang.String eventName)
getStructure in interface StructureProducereventName - the name of the output event that encapsulates the
requested output.public Instances getConnectedFormat()
Instances valuepublic void setEnvironment(Environment env)
setEnvironment in interface EnvironmentHandlerenv - the environment variables to
use