/* (non-Javadoc) * @see org.ribax.swing.ui.TabContainer#loadItemData(java.util.ArrayList, java.lang.String) */ protected void loadItemData(ArrayList<NameValuePair> params, String action) { if (params == null) { params = new ArrayList<NameValuePair>(); } // if there are parameters on this Tab then add them to the parameters for // submission to any web service if (paramSet != null) { ArrayList<NameValuePair> tlist = paramSet.getNameValuePairs(); if (tlist != null) { params.addAll(tlist); } } if (LOG.isDebugEnabled()) { LOG.debug(name + Messages.getString(BUNDLE_NAME, "Tab.19")); // $NON-NLS-1$ } // tell each data Item to load its data using the parameters and action string for (int i = 0; i < dataItems.size(); i++) { DataItem item = (DataItem) dataItems.elementAt(i); if (item == null) { LOG.error(name + Messages.getString(BUNDLE_NAME, "Tab.20") + getTitle()); // $NON-NLS-1$ continue; } item.loadData(params, action); } }
/** * putData Put the item value in the currently opened DataItem * * @param dsData is a DataItem item (properly initiated), having dimensions, type and size * corresponding to opened DataItem */ protected void putData(DataItem dsData) throws NexusException { // Ensures the DataItem has an array value dsData.arrayify(); // Getting data from DataItem Object iData = dsData.getData(); // Converting from string to byte[] if (dsData.getType() == NexusFile.NX_CHAR) iData = ((String) iData).getBytes(); // Converting from boolean[] to byte[] else if (dsData.getType() == NexusFile.NX_BOOLEAN) iData = convertArray(dsData); /* ******** Warning: jnexus API doesn't support NX_INT64 for writing * those lines convert NX_INT64 into NX_FLOAT64, so long to double // Converting from long[] to double[] else if( dsData.getType() == NexusFile.NX_INT64 ) { iData = convertArray(dsData); dsData.setType(NexusFile.NX_FLOAT64); } */ // Putting data into opened DataItem getNexusFile().putdata(iData); }
/* (non-Javadoc) * @see org.ribax.swing.ui.TabContainer#submitItemData(java.util.ArrayList, java.lang.String) */ protected void submitItemData(ArrayList<NameValuePair> params, String action) { if (params == null) { params = new ArrayList<NameValuePair>(); } // collect the selected elements from all the data items on this tab ArrayList<NameValuePair> tlist = getAllElements(); if (tlist != null) { params.addAll(tlist); } // invalidate all the DataItems on this Tab invalidateDataItems(); if (source != null) { // replace the contents of the tab with the data from the source readDescriptionFromURL(url, params, action); loaded = false; // now tell each new data item to load its data loadData(params, action); } else { // tell each data Item to load its data with the collected parameters for (int i = 0; i < dataItems.size(); i++) { DataItem item = (DataItem) dataItems.elementAt(i); item.loadData(params, action); } } }
public String printFormatData(DataItems data) { String ret = ""; StringWriter sw = new StringWriter(); BufferedWriter bw = new BufferedWriter(sw); int numRows = data.getLength(); try { for (int row = 0; row < numRows; row++) { DataItem s = data.getElementAt(row); bw.write(s.toString()); bw.write("\r\n"); } } catch (IOException e) { e.printStackTrace(); } finally { ret = sw.toString(); if (bw != null) try { bw.close(); } catch (Exception ee) { } if (sw != null) try { sw.close(); } catch (Exception ee) { } } return ret; }
private void bindProxiesAndProperties(KrollDict properties, boolean isRootTemplate) { String id = null; Object props = null; DataItem item = null; // Get/generate random bind id if (isRootTemplate) { id = itemID; } else if (properties.containsKey(TiC.PROPERTY_BIND_ID)) { id = TiConvert.toString(properties, TiC.PROPERTY_BIND_ID); } if (id == null) return; if (isRootTemplate) { rootItem = item = new DataItem(TiC.PROPERTY_PROPERTIES); } else { item = new DataItem(id); } dataItems.put(id, item); if (properties.get(TiC.PROPERTY_PROPERTIES) != null) { props = properties.get(TiC.PROPERTY_PROPERTIES); } if (props instanceof HashMap) { item.setDefaultProperties(new KrollDict((HashMap) props)); } }
@Test public void testText() { final DataItem item = new DataItem(); final String val = "abc"; item.setText(val); assertEquals(val, item.getText()); }
/** * convertArray Returns an array of values corresponding to writable type by the HDF library. It * converts automatically the data type into its corresponding type. i.e: if dsData is a boolean * array it converts it into byte array, if it's a byte array it converts it into a bool array... * * @param dsData the data to be converted into * @throws NexusException * @note: conversions are the following: bool => byte, byte => bool */ protected Object convertArray(DataItem dsData) throws NexusException { String sClassName = dsData.getData().getClass().getName(); sClassName = sClassName.substring(sClassName.lastIndexOf('[') + 1); Object oOutput; int[] iShape = detectArrayShape(dsData.getData()); // Converting boolean to byte because Nexus API don't accept it if (sClassName.startsWith("Ljava.lang.Boolean") || sClassName.equals("Z")) oOutput = java.lang.reflect.Array.newInstance(Byte.TYPE, iShape); else if (sClassName.startsWith("Ljava.lang.Byte") || sClassName.equals("B")) oOutput = java.lang.reflect.Array.newInstance(Boolean.TYPE, iShape); /* * ******** Warning: jnexus API doesn't support NX_INT64 for writing * those lines convert NX_INT64 into NX_FLOAT64, so long to double // * Converting long as double because the JAVA Nexus API uses C++ native * methods whom don't support integer 64 bit else if( * sClassName.startsWith("Ljava.lang.Long") || sClassName.equals("J") ) * oOutput = java.lang.reflect.Array.newInstance( Double.class, * dsData.getSize()); */ // Nothing to do else throw new NexusException("No data conversion requested!"); return convertArray(oOutput, dsData.getData()); }
// given DataItem private void getWithDataItem( Word w, MorphItem mi, DataItem item, EntriesItem[] entries, String targetPred, String targetRel, MacroAdder macAdder, Map<String, Double> supertags, Set<String> supertagsFound, SignHash result) { for (int i = 0; i < entries.length; i++) { EntriesItem entry = entries[i]; if (entry.getStem().equals(DEFAULT_VAL)) { getWithEntriesItem( w, mi, item.getStem(), item.getPred(), targetPred, targetRel, entry, macAdder, supertags, supertagsFound, result); } } }
@Test public void testNumber() { final DataItem item = new DataItem(); final double val = 123.456; item.setNumber(val); assertEquals(val, item.getNumber(), 0.000001); }
public void loadData(ArrayList<NameValuePair> params, String action) { if (loaded) { return; } if (LOG.isDebugEnabled()) { LOG.debug(name + Messages.getString(BUNDLE_NAME, "Folder.26")); // $NON-NLS-1$ } // tell the tabs in this folder to load their data for (int i = 0; i < dataItems.size(); i++) { DataItem item = (DataItem) dataItems.elementAt(i); if (item == null) { LOG.error(name + Messages.getString(BUNDLE_NAME, "Folder.27") + getTitle()); // $NON-NLS-1$ continue; } if (LOG.isDebugEnabled()) { LOG.debug( name + Messages.getString(BUNDLE_NAME, "Folder.28") + item.getTitle()); // $NON-NLS-1$ } item.loadData(params, action); } loaded = true; }
/** Deserializes the object from XML */ public DataItem parseItem(XMLStreamReader in) throws IOException, XMLStreamException { DataItem item = new DataItem(); ArrayList<DataField> fieldList = new ArrayList<DataField>(); int tag = in.nextTag(); while (tag > 0) { if (_isFinest) debug(in); if (XMLStreamReader.END_ELEMENT == tag) { item.setFieldList(fieldList); return item; } if (XMLStreamReader.START_ELEMENT == tag && "field".equals(in.getLocalName())) { fieldList.add(parseField(in)); } else if (XMLStreamReader.START_ELEMENT == tag) { log.finer(this + " <" + in.getLocalName() + "> is an unknown tag"); skipToEnd(in, in.getLocalName()); } tag = in.nextTag(); } skipToEnd(in, "item"); return item; }
/** * writeData Write a DataItem on the node pointed by path. * * @param dsData DataItem item to be written * @param paPath path to set datas in current file (can be absolute or local) * @note if path don't exists it will be automatically created */ public void writeData(DataItem dsData, PathNexus paPath) throws NexusException { if (dsData.getData() instanceof PathNexus) { // Write link writeLink((PathNexus) dsData.getData(), paPath); // Return to document root closeAll(); } else { // Create or open DataItem boolean bNeedDataCheck = createDataItem(dsData, paPath, true); // Check data compatiblity if needed if (bNeedDataCheck) { checkDataMatch(dsData); } // Write data putData(dsData); // Write attributes putAttr(dsData); // Return to document root closeAll(); } }
/* (non-Javadoc) * @see org.ribax.swing.ui.TabContainer#refresh(java.util.ArrayList, java.lang.String) */ public void refresh(ArrayList<NameValuePair> params, String action) { if (LOG.isDebugEnabled()) { LOG.debug(name + Messages.getString(BUNDLE_NAME, "Tab.17")); // $NON-NLS-1$ } // invalidate all the DataItems on this Tab invalidateDataItems(); if (source != null) { // replace the contents of the tab with the data from the source readDescriptionFromURL(url, params, action); loaded = false; // now tell each new data item to load its data loadData(params, action); } else { // tell each DataItem in our internal list to refresh for (int i = 0; i < dataItems.size(); i++) { DataItem item = (DataItem) dataItems.elementAt(i); if (item == null) { LOG.error(name + Messages.getString(BUNDLE_NAME, "Tab.18") + getTitle()); // $NON-NLS-1$ continue; } item.refresh(params, action); } } }
/** * checkData Check if given data fits the currently opened DataItem * * @param dsData DataItem properly initiated containing data to compare with current node * @throws NexusException if node and data aren't compatible */ protected void checkDataMatch(DataItem dsData) throws NexusException { // Get infos on DataItem (data type, rank, dimsize) int[] iDimSize = dsData.getSize(); // DataItem dimension's sizes int[] iNodSize = new int[RANK_MAX]; // whole DataItem dimension's sizes int[] iDataInf = new int[2]; // iDataInf[0] = DataItem rank ; // iDataInf[1] = data type openFile(); getNexusFile().getinfo(iNodSize, iDataInf); closeFile(); // Checking type compatibility if (dsData.getType() != iDataInf[1]) { throw new NexusException("Datas and target node do not have compatible type!"); } // Checking rank compatibility if (iDimSize.length > iDataInf[0]) { throw new NexusException("Datas and target node do not have compatible rank!"); } // Checking dimensions sizes compatibility { // The dimensions to check of the opened DataItem are // iDimSize.length // last ones int iDim = (iDataInf[0] - iDimSize.length); for (; iDim < iDataInf[0]; iDim++) { if (iDimSize[iDim + iDimSize.length - iDataInf[0]] != iNodSize[iDim]) throw new NexusException("Datas and target node do not have compatible dimension sizes!"); } } }
@Test public void testHasTag() { DataItem di = new DataItem(MajorType.UNSIGNED_INTEGER); assertFalse(di.hasTag()); di.setTag(new Tag(1)); assertTrue(di.hasTag()); }
/* (non-Javadoc) * @see org.ribax.swing.ui.DataItem#close() */ public void close() { // invalidate all the Tabs in this folder for (int i = 0; i < dataItems.size(); i++) { DataItem item = (DataItem) dataItems.elementAt(i); item.close(); } }
@Test public void testGetTag() { DataItem di = new DataItem(MajorType.UNSIGNED_INTEGER); di.setTag(new Tag(1)); Tag t = di.getTag(); assertEquals(1L, t.getValue()); }
@Test public void testEquals() { DataItem a = new TestDataItem(); DataItem b = new TestDataItem(); assertEquals(a, b); a.setTag(1); assertFalse(a.equals(b)); assertFalse(a.equals(null)); }
@Test public void testRemoveTag() { DataItem di = new DataItem(MajorType.UNSIGNED_INTEGER); di.setTag(new Tag(1)); assertNotNull(di.getTag()); di.removeTag(); assertNull(di.getTag()); }
// 按照时间,sizeWindow和stepWindow将数据分成项集,再调用Itemset2File写入文件 public static String[] movingdivide(DataItems datainput, TaskElement task, boolean FP) throws IOException { int sizeWindow = (int) ((ParamsSM) task.getMiningParams()).getSizeWindow() * 1000; // seconds int stepWindow = (int) ((ParamsSM) task.getMiningParams()).getStepWindow() * 1000; // seconds int len = datainput.getLength(); List<Date> time = datainput.getTime(); List<String> data = datainput.getData(); List<String> DataSets = new ArrayList<String>(); Date win_start_time = time.get(0); Date win_end_time = getDateAfter(win_start_time, sizeWindow); Date win_start_next = getDateAfter(win_start_time, stepWindow); int ind_next = -1; StringBuilder sb = new StringBuilder(); int i = 0; do { DataItem item = datainput.getElementAt(i); i++; Date date = item.getTime(); String val = item.getData(); if (!date.before(win_start_time) && !date.after(win_end_time)) { if (sb.length() != 0) sb.append(" "); sb.append(val + " -1"); if (!date.before(win_start_next) && ind_next == -1) ind_next = i - 1; } else { sb.append(" -2"); DataSets.add(sb.toString()); sb = new StringBuilder(); if (ind_next == -1) { if (!date.before(getDateAfter(win_end_time, stepWindow))) { win_start_time = date; if (sb.length() != 0) sb.append(" "); sb.append(val + " -1"); } else { win_start_time = win_start_next; // getDateAfter(win_start_time, stepWindow); if (sb.length() != 0) sb.append(" "); sb.append(val + " -1"); } } else { i = ind_next; ind_next = -1; win_start_time = win_start_next; } win_end_time = getDateAfter(win_start_time, sizeWindow); win_start_next = getDateAfter(win_start_time, stepWindow); } } while (i < len); sb.append(" -2"); DataSets.add(sb.toString()); return DataSets.toArray(new String[0]); }
public DataItem initDataItem(Item item) { DataItem dataItem = new DataItem(); if (item != null) { dataItem.addField(DataItemField.initField("itemRef", "ItemRef", 10, item.ItemRef())); dataItem.addField(DataItemField.initField("value", "Value", 15, item.value())); dataItem.setItemObject(item); } return dataItem; }
/* (non-Javadoc) * @see org.ribax.swing.ui.DataItem#updateData(java.util.ArrayList, java.lang.String) */ public void updateData(ArrayList<NameValuePair> params, String action) { if (LOG.isDebugEnabled()) { LOG.debug(name + Messages.getString(BUNDLE_NAME, "Folder.25")); // $NON-NLS-1$ } // update all the Tabs in this folder for (int i = 0; i < dataItems.size(); i++) { DataItem item = (DataItem) dataItems.elementAt(i); item.updateData(params, action); } }
private void init() { if (this.values != null) { return; } this.values = new HashMap<String, Object>(this.datas.size()); for (DataItem item : datas) { String key = item.getKey(); Object value = this.getDataType().stringToObject(item.getValue()); this.values.put(key, value); } }
/* (non-Javadoc) * @see org.ribax.swing.ui.DataItem#refresh(java.util.ArrayList, java.lang.String) */ public void refresh(ArrayList<NameValuePair> params, String action) { if (LOG.isDebugEnabled()) { LOG.debug(name + " refresh"); } // refresh each Tab in the tabbed pane for (int i = 0; i < dataItems.size(); i++) { DataItem item = (DataItem) dataItems.elementAt(i); item.refresh(params, action); } }
/** putAttr Write all DataItem's attribute in the currently opened DataItem */ protected void putAttr(DataItem dsData) throws NexusException { HashMap<String, ?> mAttrMap = dsData.getAttributes(); String sAttrName; Object oAttrVal; if (mAttrMap != null) { for (Iterator<String> iter = mAttrMap.keySet().iterator(); iter.hasNext(); ) { sAttrName = (String) iter.next(); oAttrVal = dsData.getAttribute(sAttrName); putAttr(sAttrName, oAttrVal); } } }
/* (non-Javadoc) * @see org.ribax.swing.ui.DataItem#invalidateData() */ public void invalidateData() { if (LOG.isDebugEnabled()) { LOG.debug(name + Messages.getString(BUNDLE_NAME, "Folder.24")); // $NON-NLS-1$ } loaded = false; // invalidate all the Tabs in this folder for (int i = 0; i < dataItems.size(); i++) { DataItem item = (DataItem) dataItems.elementAt(i); item.invalidateData(); } }
public void release() { for (int i = 0; i < dataItems.size(); i++) { DataItem item = dataItems.get(i); if (item != null) { item.release(); } } dataItems.clear(); if (rootItem != null) { rootItem.release(); rootItem = null; } }
/** Tell every DataItem to stop whatever they are doing (like streaming). */ public void stop() { Enumeration<TreeNode> e = rootNode.breadthFirstEnumeration(); DefaultMutableTreeNode node; // tell the root Folder to stop Object nodeInfo = rootNode.getUserObject(); ((DataItem) nodeInfo).close(); // tell all of the root Folder's descendents to stop for (; e.hasMoreElements(); ) { node = (DefaultMutableTreeNode) e.nextElement(); nodeInfo = node.getUserObject(); ((DataItem) nodeInfo).close(); } }
/** Tell every item in the tree that it's data is out of date */ private void invalidateItemTree() { Enumeration<TreeNode> e = rootNode.breadthFirstEnumeration(); DefaultMutableTreeNode node; // invalidate the root object Object nodeInfo = rootNode.getUserObject(); ((DataItem) nodeInfo).invalidateData(); // invalidate all of the root object's descendents for (; e.hasMoreElements(); ) { node = (DefaultMutableTreeNode) e.nextElement(); nodeInfo = node.getUserObject(); ((DataItem) nodeInfo).invalidateData(); } }
public static DataItem fromString(String item) { try { return DataItem.valueOf(item.trim().toUpperCase()); } catch (Exception ex) { // NOSONAR return UNKNOWN; } }