List of usage examples for weka.core Attribute parseDate
public double parseDate(String string) throws ParseException
From source file:adams.gui.visualization.instances.InstancesTableModel.java
License:Open Source License
/** * Sets the value in the cell at columnIndex and rowIndex to aValue. but only * the value and the value can be changed. Ignores operation if value hasn't * changed./* ww w. ja va 2s.c o m*/ * * @param aValue the new value * @param rowIndex the row index * @param columnIndex the column index * @param notify whether to notify the listeners */ public void setValueAt(Object aValue, int rowIndex, int columnIndex, boolean notify) { int type; int index; String tmp; Instance inst; Attribute att; Object oldValue; boolean different; int offset; offset = 1; if (m_ShowWeightsColumn) offset++; oldValue = getValueAt(rowIndex, columnIndex); different = !("" + oldValue).equals("" + aValue); if (!different) return; if (!m_IgnoreChanges) addUndoPoint(); type = getType(rowIndex, columnIndex); index = columnIndex - offset; inst = m_Data.instance(rowIndex); att = inst.attribute(index); // missing? if (aValue == null) { inst.setValue(index, Utils.missingValue()); } else { tmp = aValue.toString(); switch (type) { case Attribute.DATE: try { att.parseDate(tmp); inst.setValue(index, att.parseDate(tmp)); } catch (Exception e) { // ignore } break; case Attribute.NOMINAL: if (att.indexOfValue(tmp) > -1) inst.setValue(index, att.indexOfValue(tmp)); break; case Attribute.STRING: inst.setValue(index, tmp); break; case Attribute.NUMERIC: try { inst.setValue(index, Double.parseDouble(tmp)); } catch (Exception e) { // ignore } break; case Attribute.RELATIONAL: try { inst.setValue(index, inst.attribute(index).addRelation((Instances) aValue)); } catch (Exception e) { // ignore } break; default: throw new IllegalArgumentException("Unsupported Attribute type: " + type + "!"); } } // notify only if the value has changed! if (notify) notifyListener(new TableModelEvent(this, rowIndex, columnIndex)); }
From source file:meka.gui.dataviewer.DataTableModel.java
License:Open Source License
/** * sets the value in the cell at columnIndex and rowIndex to aValue. but only * the value and the value can be changed * * @param aValue the new value/* ww w . j a va 2s .c o m*/ * @param rowIndex the row index * @param columnIndex the column index * @param notify whether to notify the listeners */ public void setValueAt(Object aValue, int rowIndex, int columnIndex, boolean notify) { int type; int index; String tmp; Instance inst; Attribute att; Object oldValue; if (!m_IgnoreChanges) { addUndoPoint(); } oldValue = getValueAt(rowIndex, columnIndex); type = getType(rowIndex, columnIndex); index = columnIndex - 1; inst = m_Data.instance(rowIndex); att = inst.attribute(index); // missing? if (aValue == null) { inst.setValue(index, Utils.missingValue()); } else { tmp = aValue.toString(); switch (type) { case Attribute.DATE: try { att.parseDate(tmp); inst.setValue(index, att.parseDate(tmp)); } catch (Exception e) { // ignore } break; case Attribute.NOMINAL: if (att.indexOfValue(tmp) > -1) { inst.setValue(index, att.indexOfValue(tmp)); } break; case Attribute.STRING: inst.setValue(index, tmp); break; case Attribute.NUMERIC: try { Double.parseDouble(tmp); inst.setValue(index, Double.parseDouble(tmp)); } catch (Exception e) { // ignore } break; case Attribute.RELATIONAL: try { inst.setValue(index, inst.attribute(index).addRelation((Instances) aValue)); } catch (Exception e) { // ignore } break; default: throw new IllegalArgumentException("Unsupported Attribute type: " + type + "!"); } } // notify only if the value has changed! if (notify && (!("" + oldValue).equals("" + aValue))) { notifyListener(new TableModelEvent(this, rowIndex, columnIndex)); } }