public void testSettingGettingGroupWithCustomFields() throws FieldNotFound { final String settingValue = "SETTING_VALUE"; final Quote.NoLegs grp = buildGroupWithCustomFields(settingValue); final StringField accessorField = new StringField(9001); // Custom tag is // 9001 final StringField gotField = grp.getField(accessorField); // We assume that checksum equality s enough - DV assertEquals( "GettingValue is not the same the SettingValue", settingValue, gotField.getValue()); }
public String getInstanceName() { if (instanceNameField != null) { return instanceNameField.getValue(); } else { return null; } }
public void testSettingGettingNestedGroupWithCustomFields() throws FieldNotFound { final String settingValue = "SETTING_VALUE"; // The root group final quickfix.fix44.QuoteRequest.NoRelatedSym gNoRelatedSym = buildNestedGroupWithCustomFields(settingValue); // Getting part final quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs getgrp = new quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs(); gNoRelatedSym.getGroup(1, getgrp); final StringField accessorField = new StringField(9001); // Custom Field final StringField gotFieldStd = getgrp.getField(accessorField); assertEquals( "GettingValue is not the same the SettingValue", settingValue, gotFieldStd.getValue()); }
public void testSettingGettingGroupWithCustomAndStandardFields() throws FieldNotFound { final String settingValue = "SETTING_VALUE"; final Quote.NoLegs grp = buildGroupWithCustomAndStandardFields(settingValue); final StringField accessorField = new StringField(9001); // Custom tag is // 9001 final StringField gotField = grp.getField(accessorField); final LegSymbol accessorFieldStd = new LegSymbol(); // Standard Field final LegSymbol gotFieldStd = (LegSymbol) grp.getField(accessorFieldStd); assertEquals( "GettingValue is not the same the SettingValue", settingValue, gotField.getValue()); assertEquals( "GettingValue is not the same the SettingValue", settingValue, gotFieldStd.getValue()); }
// Testing group re-usability when setting values public void testSettingGettingGroupByReusingGroup() throws FieldNotFound { // The root group final quickfix.fix44.QuoteRequest.NoRelatedSym gNoRelatedSym = new quickfix.fix44.QuoteRequest.NoRelatedSym(); // Create the initial group final quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs nestedgroup = new quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs(); final String notOverridenFieldValue = "Value1.1"; nestedgroup.setField(new LegSymbol(notOverridenFieldValue)); nestedgroup.setField(new StringField(9001, "Value1.2")); gNoRelatedSym.addGroup(nestedgroup); // Create the second group by re-using the same group and changing one value of only one field final String overridenFieldValue = "Value2.2"; nestedgroup.setField(new StringField(9001, overridenFieldValue)); gNoRelatedSym.addGroup(nestedgroup); // Getting part final quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs getgrp = new quickfix.fix44.QuoteRequest.NoRelatedSym.NoLegs(); gNoRelatedSym.getGroup(2, getgrp); final StringField accessorField = new StringField(9001); // Custom Field final StringField gotField = getgrp.getField(accessorField); final LegSymbol accessorFieldStd = new LegSymbol(); // Standard Field final LegSymbol gotFieldStd = (LegSymbol) getgrp.getField(accessorFieldStd); // Ensures that the field overriden has been set correctly assertEquals( "GettingValue is not the same the SettingValue", overridenFieldValue, gotField.getValue()); // Ensures that the field not overriden has been set correctly assertEquals( "GettingValue is not the same the SettingValue", notOverridenFieldValue, gotFieldStd.getValue()); }
private static String value(StringField f) { return f != null ? f.getValue() : NOT_SET; }
public static void writeHeapFile( ArrayList<Tuple> tuples, File outFile, int npagebytes, Type[] typeAr) throws IOException { int nrecbytes = 0; for (int i = 0; i < typeAr.length; i++) { nrecbytes += typeAr[i].getLen(); } int maxNumRecordsInAPage = (npagebytes * 8) / (nrecbytes * 8 + 1); // floor comes // for free // per record, we need one bit; there are nrecords per page, so we need // nrecords bits, i.e., ((nrecords/32)+1) integers. int nheaderbytes = (maxNumRecordsInAPage / 8); if (nheaderbytes * 8 < maxNumRecordsInAPage) nheaderbytes++; // ceiling int nheaderbits = nheaderbytes * 8; FileOutputStream os = new FileOutputStream(outFile); int npages = 0; int numRecordInCurrPage = 0; int totalRecordCount = 0; ByteArrayOutputStream headerBAOS = new ByteArrayOutputStream(nheaderbytes); DataOutputStream headerStream = new DataOutputStream(headerBAOS); ByteArrayOutputStream pageBAOS = new ByteArrayOutputStream(npagebytes); DataOutputStream pageStream = new DataOutputStream(pageBAOS); for (Tuple t : tuples) { int fieldNo = 0; numRecordInCurrPage++; totalRecordCount++; Iterator<Field> it = t.fields(); while (it.hasNext()) { Field f = it.next(); if (typeAr[fieldNo] == Type.INT_TYPE) { IntField i = (IntField) f; pageStream.writeInt(i.getValue()); } else if (typeAr[fieldNo] == Type.STRING_TYPE) { StringField sf = (StringField) f; String s = sf.getValue(); int overflow = Type.STRING_LEN - s.length(); if (overflow < 0) { String news = s.substring(0, Type.STRING_LEN); s = news; } pageStream.writeInt(s.length()); pageStream.writeBytes(s); while (overflow-- > 0) pageStream.write((byte) 0); } fieldNo++; } // if we wrote a full page of records, or if we're done altogether, // write out the header of the page. // // in the header, write a 1 for bits that correspond to records // we've // written and 0 for empty slots. // // when we're done, also flush the page to disk, but only if it has // records on it. however, if this file is empty, do flush an empty // page to disk. if (numRecordInCurrPage >= maxNumRecordsInAPage || totalRecordCount == tuples.size() && numRecordInCurrPage > 0 || totalRecordCount == tuples.size() && npages == 0) { int i = 0; byte headerbyte = 0; for (i = 0; i < nheaderbits; i++) { if (i < numRecordInCurrPage) headerbyte |= (1 << (i % 8)); if (((i + 1) % 8) == 0) { headerStream.writeByte(headerbyte); headerbyte = 0; } } if (i % 8 > 0) headerStream.writeByte(headerbyte); // pad the rest of the page with zeroes for (i = 0; i < (npagebytes - (numRecordInCurrPage * nrecbytes + nheaderbytes)); i++) pageStream.writeByte(0); // write header and body to file headerStream.flush(); headerBAOS.writeTo(os); pageStream.flush(); pageBAOS.writeTo(os); // reset header and body for next page headerBAOS = new ByteArrayOutputStream(nheaderbytes); headerStream = new DataOutputStream(headerBAOS); pageBAOS = new ByteArrayOutputStream(npagebytes); pageStream = new DataOutputStream(pageBAOS); numRecordInCurrPage = 0; npages++; } } os.close(); }
/** Free Method. */ public void free() { m_recSpecialFunction = null; // QueryConverter closed this super.free(); }
/** Initialize class fields. */ public void init( Record record, String strName, int iDataLength, String strDesc, Object strDefault) { m_recSpecialFunction = null; super.init(record, strName, iDataLength, strDesc, strDefault); }
public BundleOptionsFrame(String displayName, String instanceName, List<OptionGroup> options) { setResizable(false); this.displayName = displayName; content = (JComponent) getContentPane(); content.setLayout(new GridBagLayout()); final BundleOptionsFrame frame = this; // Close button Action closeAction = new AbstractAction("Close") { @Override public void actionPerformed(ActionEvent e) { frame.setVisible(false); } }; JButton close_button = new JButton(closeAction); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = currentRow++; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(2, 2, 2, 2); content.add(close_button, c); // Escape key binding JComponent root = frame.getRootPane(); root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "close"); root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke("ctrl W"), "close"); root.getActionMap().put("close", closeAction); if (instanceName != null) { // Predicate name StringOption opt = new StringOption(); opt.setDisplayName("Predicate name"); opt.setDefault(instanceName); instanceNameField = new StringField(opt); instanceNameField.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { updateTitle(); } }); addField(instanceNameField); JTextField tf = (JTextField) instanceNameField.getComponent(); tf.selectAll(); tf.requestFocusInWindow(); } else { // We're a codec; no instance name instanceNameField = null; } updateTitle(); // Options ExampleField example = null; for (OptionGroup group : options) { addSeparator(group.getDisplayName()); for (Option option : group.getOptions()) { OptionField field; if (option instanceof BooleanOption) { field = new BooleanField((BooleanOption) option); } else if (option instanceof StringOption) { field = new StringField((StringOption) option); } else if (option instanceof NumberOption) { field = new NumberField((NumberOption) option); } else if (option instanceof ChoiceOption) { field = new ChoiceField((ChoiceOption) option); } else if (option instanceof ExampleOption) { if (example != null) { throw new IllegalArgumentException("Cannot display more than one ExampleOption"); } example = new ExampleField((ExampleOption) option); field = example; } else { throw new IllegalArgumentException("Unknown option type"); } addField(field); optionFields.add(field); } } this.exampleField = example; pack(); }