List of usage examples for java.lang Enum ordinal
int ordinal
To view the source code for java.lang Enum ordinal.
Click Source Link
From source file:org.batoo.jpa.jdbc.AbstractColumn.java
/** * {@inheritDoc}//from w w w . j a v a2 s . c o m * */ @Override public Object convertValue(Connection connection, final Object value) { if (value == null) { return null; } if (this.temporalType != null) { switch (this.temporalType) { case DATE: if (value instanceof java.sql.Date) { return value; } if (value instanceof Date) { return new java.sql.Date(((Date) value).getTime()); } return new java.sql.Date(((Calendar) value).getTimeInMillis()); case TIME: if (value instanceof java.sql.Time) { return value; } if (value instanceof Date) { return new java.sql.Time(((Date) value).getTime()); } return new java.sql.Time(((Calendar) value).getTimeInMillis()); case TIMESTAMP: if (value instanceof java.sql.Timestamp) { return value; } if (value instanceof Date) { return new java.sql.Timestamp(((Date) value).getTime()); } return new java.sql.Timestamp(((Calendar) value).getTimeInMillis()); } } if (this.numberType != null) { return ReflectHelper.convertNumber((Number) value, this.numberType); } if (this.enumType != null) { final Enum<?> enumValue = (Enum<?>) value; if (this.enumType == EnumType.ORDINAL) { return enumValue.ordinal(); } return enumValue.name(); } if (this.lob) { try { if (this.javaType == String.class) { return new SerialClob(((String) value).toCharArray()); } else if (this.javaType == char[].class) { return new SerialClob((char[]) value); } else if (this.javaType == byte[].class) { return new SerialBlob((byte[]) value); } else { final ByteArrayOutputStream os = new ByteArrayOutputStream(); final ObjectOutputStream oos = new ObjectOutputStream(os); try { oos.writeObject(value); } finally { oos.close(); } return new SerialBlob(os.toByteArray()); } } catch (final Exception e) { throw new PersistenceException("Cannot set parameter", e); } } else { return value; } }
From source file:kg.apc.jmeter.config.redis.RedisDataSet.java
/** * Override the setProperty method in order to convert * the original String calcMode property. * This used the locale-dependent display value, so caused * problems when the language was changed. * Note that the calcMode StringProperty is replaced with an IntegerProperty * so the conversion only needs to happen once. */// ww w . jav a 2 s. co m @Override public void setProperty(JMeterProperty property) { if (property instanceof StringProperty) { final String pn = property.getName(); if (pn.equals("getMode")) { final Object objectValue = property.getObjectValue(); try { final BeanInfo beanInfo = Introspector.getBeanInfo(this.getClass()); final ResourceBundle rb = (ResourceBundle) beanInfo.getBeanDescriptor() .getValue(GenericTestBeanCustomizer.RESOURCE_BUNDLE); for (Enum<GetMode> e : GetMode.values()) { final String propName = e.toString(); if (objectValue.equals(rb.getObject(propName))) { final int tmpMode = e.ordinal(); if (log.isDebugEnabled()) { log.debug("Converted " + pn + "=" + objectValue + " to mode=" + tmpMode + " using Locale: " + rb.getLocale()); } super.setProperty(pn, tmpMode); return; } } log.warn("Could not convert " + pn + "=" + objectValue + " using Locale: " + rb.getLocale()); } catch (IntrospectionException e) { log.error("Could not find BeanInfo", e); } } else if (pn.equals("whenExhaustedAction")) { final Object objectValue = property.getObjectValue(); try { final BeanInfo beanInfo = Introspector.getBeanInfo(this.getClass()); final ResourceBundle rb = (ResourceBundle) beanInfo.getBeanDescriptor() .getValue(GenericTestBeanCustomizer.RESOURCE_BUNDLE); for (Enum<WhenExhaustedAction> e : WhenExhaustedAction.values()) { final String propName = e.toString(); if (objectValue.equals(rb.getObject(propName))) { final int tmpMode = e.ordinal(); if (log.isDebugEnabled()) { log.debug("Converted " + pn + "=" + objectValue + " to mode=" + tmpMode + " using Locale: " + rb.getLocale()); } super.setProperty(pn, tmpMode); return; } } log.warn("Could not convert " + pn + "=" + objectValue + " using Locale: " + rb.getLocale()); } catch (IntrospectionException e) { log.error("Could not find BeanInfo", e); } } } super.setProperty(property); }
From source file:kg.apc.jmeter.listener.GraphsGeneratorListener.java
/** * Override the setProperty method in order to convert * the original String calcMode property. * This used the locale-dependent display value, so caused * problems when the language was changed. * Note that the calcMode StringProperty is replaced with an IntegerProperty * so the conversion only needs to happen once. */// w w w . j a v a 2 s . c om @Override public void setProperty(JMeterProperty property) { if (property instanceof StringProperty) { final String pn = property.getName(); if (pn.equals("exportMode")) { final Object objectValue = property.getObjectValue(); try { final BeanInfo beanInfo = Introspector.getBeanInfo(this.getClass()); final ResourceBundle rb = (ResourceBundle) beanInfo.getBeanDescriptor() .getValue(GenericTestBeanCustomizer.RESOURCE_BUNDLE); for (Enum<ExportMode> e : ExportMode.values()) { final String propName = e.toString(); if (objectValue.equals(rb.getObject(propName))) { final int tmpMode = e.ordinal(); if (log.isDebugEnabled()) { log.debug("Converted " + pn + "=" + objectValue + " to mode=" + tmpMode + " using Locale: " + rb.getLocale()); } super.setProperty(pn, tmpMode); return; } } log.warn("Could not convert " + pn + "=" + objectValue + " using Locale: " + rb.getLocale()); } catch (IntrospectionException e) { log.error("Could not find BeanInfo", e); } } } super.setProperty(property); }
From source file:foam.lib.json.Outputter.java
public void outputEnum(Enum<?> value) { // outputNumber(value.ordinal()); writer_.append("{"); writer_.append(beforeKey_());/*from ww w . j av a 2 s. c o m*/ writer_.append("class"); writer_.append(afterKey_()); writer_.append(":"); outputString(value.getClass().getName()); writer_.append(","); writer_.append(beforeKey_()); writer_.append("ordinal"); writer_.append(afterKey_()); writer_.append(":"); outputNumber(value.ordinal()); writer_.append("}"); }
From source file:org.candlepin.swagger.CandlepinSwaggerModelConverter.java
protected void pAddEnumProps(Class<?> propClass, Property property) { final boolean useIndex = pMapper.isEnabled(SerializationFeature.WRITE_ENUMS_USING_INDEX); final boolean useToString = pMapper.isEnabled(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); @SuppressWarnings("unchecked") Class<Enum<?>> enumClass = (Class<Enum<?>>) propClass; for (Enum<?> en : enumClass.getEnumConstants()) { String n;//from w w w . java 2 s . c o m if (useIndex) { n = String.valueOf(en.ordinal()); } else if (useToString) { n = en.toString(); } else { n = pIntr.findEnumValue(en); } if (property instanceof StringProperty) { StringProperty sp = (StringProperty) property; sp._enum(n); } } }
From source file:dataviewer.DataViewer.java
private void btn_refreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_refreshActionPerformed for (Enum e : THREAD.values()) { t[e.ordinal()].stop(); }// w w w. jav a 2s . c om tr_files.setEnabled(true); txt_count.setText(""); fill_tree(); }
From source file:dataviewer.DataViewer.java
/** * Creates new form DataViewer//from w w w .j av a2 s . com */ public DataViewer() { try { for (Enum ee : THREAD.values()) { t[ee.ordinal()] = new Thread(); } initComponents(); DropTarget dropTarget = new DropTarget(tr_files, new DropTargetListenerImpl()); TreeSelectionListener treeSelectionListener = new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { javax.swing.JTree tree = (javax.swing.JTree) e.getSource(); TreePath path = tree.getSelectionPath(); Object[] pnode = (Object[]) path.getPath(); String name = pnode[pnode.length - 1].toString(); String ex = getExtension(name); if (ex.equals(".txt") || ex.equals(".dat") || ex.equals(".csv") || ex.equals(".tsv")) { selected_file = name; } else { selected_file = ""; } } }; tr_files.addTreeSelectionListener(treeSelectionListener); tr_files.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() >= 2) { if (!"".equals(selected_file)) { //count_data(); read_data(); } else { TreePath path = tr_files.getSelectionPath(); if (path.getLastPathComponent().toString().equals(cur_path)) { cur_path = (new File(cur_path)).getParent(); } else { cur_path = cur_path + File.separator + path.getLastPathComponent().toString(); } fill_tree(); } } } }); tr_files.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent evt) { if (evt.getKeyCode() == KeyEvent.VK_BACK_SPACE) { cur_path = (new File(cur_path)).getParent(); fill_tree(); } else if (evt.getKeyCode() == KeyEvent.VK_ENTER) { if (!"".equals(selected_file)) { //count_data(); read_data(); } else { TreePath path = tr_files.getSelectionPath(); if (path.getLastPathComponent().toString().equals(cur_path)) { cur_path = (new File(cur_path)).getParent(); } else { cur_path = cur_path + File.separator + path.getLastPathComponent().toString(); } fill_tree(); } } else if (evt.getKeyCode() == KeyEvent.VK_DELETE) { if (!"".equals(selected_file)) { String name = cur_path + File.separator + selected_file; if ((new File(name)).isFile()) { int dialogResult = JOptionPane.showConfirmDialog(null, "Selected file [" + selected_file + "] will be removed and not recoverable.", "Are you sure?", JOptionPane.YES_NO_OPTION); if (dialogResult == JOptionPane.YES_OPTION) { (new File(name)).delete(); fill_tree(); } } } else { JOptionPane.showMessageDialog(null, "For safety concern, removing folder is not supported.", "Information", JOptionPane.ERROR_MESSAGE); } } } }); tr_files.setCellRenderer(new MyTreeCellRenderer()); p_count.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); //tp_menu.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(ctrl1, "tab_read"); //tp_menu.getActionMap().put("tab_read", (Action) new ActionListenerImpl()); //tp_menu.setMnemonicAt(0, KeyEvent.VK_1); //tp_menu.setMnemonicAt(1, KeyEvent.VK_2); /*InputMap inputMap = tp_menu.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); ActionMap actionMap = tp_menu.getActionMap(); KeyStroke ctrl1 = KeyStroke.getKeyStroke("ctrl 1"); inputMap.put(ctrl1, "tab_read"); actionMap.put("tab_read", new AbstractAction() { @Override public void actionPerformed(ActionEvent arg0) { tp_menu.setSelectedIndex(0); } }); KeyStroke ctrl2 = KeyStroke.getKeyStroke("ctrl 2"); inputMap.put(ctrl2, "tab_analyze"); actionMap.put("tab_analyze", new AbstractAction() { @Override public void actionPerformed(ActionEvent arg0) { tp_menu.setSelectedIndex(1); } });*/ config(); } catch (Exception e) { txt_count.setText(e.getMessage()); } }
From source file:org.efaps.esjp.common.uiform.Field_Base.java
/** * @param _parameter Parameter as passed from the eFaps API * @return Return containing Html Snipplet * @throws EFapsException on error/* ww w.jav a 2s.c o m*/ */ public Return getOptionList4Enum(final Parameter _parameter) throws EFapsException { final List<DropDownPosition> values = new ArrayList<>(); final String enumName = getProperty(_parameter, "Enum"); if (enumName != null) { final boolean orderByOrdinal = "true".equalsIgnoreCase(getProperty(_parameter, "OrderByOrdinal")); try { final Class<?> enumClazz = Class.forName(enumName); if (enumClazz.isEnum()) { final Object[] consts = enumClazz.getEnumConstants(); Integer selected = -1; final Object uiObject = _parameter.get(ParameterValues.UIOBJECT); if (uiObject instanceof IUIValue && ((IUIValue) uiObject).getObject() != null) { selected = (Integer) ((IUIValue) uiObject).getObject(); } else if (containsProperty(_parameter, "DefaultValue")) { final String defaultValue = getProperty(_parameter, "DefaultValue"); for (final Object con : consts) { if (((Enum<?>) con).name().equals(defaultValue)) { selected = ((Enum<?>) con).ordinal(); break; } } } if (org.efaps.admin.ui.field.Field.Display.EDITABLE .equals(((IUIValue) uiObject).getDisplay())) { for (final Object con : consts) { final Enum<?> enumVal = (Enum<?>) con; final Integer ordinal = enumVal.ordinal(); final String label = DBProperties.getProperty(enumName + "." + enumVal.name()); final DropDownPosition pos = new DropDownPosition(ordinal, label, orderByOrdinal ? ordinal : label); values.add(pos); pos.setSelected(ordinal == selected); } Collections.sort(values, new Comparator<DropDownPosition>() { @SuppressWarnings("unchecked") @Override public int compare(final DropDownPosition _o1, final DropDownPosition _o2) { return _o1.getOrderValue().compareTo(_o2.getOrderValue()); } }); } } } catch (final ClassNotFoundException e) { LOG.error("ClassNotFoundException", e); } } final Return ret = new Return(); ret.put(ReturnValues.VALUES, values); return ret; }
From source file:org.apache.geode.internal.InternalDataSerializer.java
private static void writeGemFireEnum(Enum<?> e, DataOutput out) throws IOException { boolean isGemFireObject = isGemfireObject(e); DataSerializer.writePrimitiveByte(isGemFireObject ? GEMFIRE_ENUM : PDX_INLINE_ENUM, out); DataSerializer.writeString(e.getDeclaringClass().getName(), out); DataSerializer.writeString(e.name(), out); if (!isGemFireObject) { InternalDataSerializer.writeArrayLength(e.ordinal(), out); }//from w w w . j av a 2s . c o m }
From source file:tufts.vue.LWComponent.java
String getDescriptionOfSetBits(Class enumType, long bits) { final StringBuilder buf = new StringBuilder(); //buf.append(enumType.getSimpleName()); buf.append(enumType.getSimpleName().substring(0, 2)); buf.append('('); boolean first = true; for (Object eValue : enumType.getEnumConstants()) { final Enum e = (Enum) eValue; if ((bits & (1 << e.ordinal())) != 0) { if (!first) buf.append(','); buf.append(eValue);/*from w ww . ja va 2 s. com*/ //buf.append(':');buf.append(e.ordinal()); first = false; } } buf.append(')'); return buf.toString(); }