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.apache.nutch.mapreduce.NutchCounter.java
public void increase(Enum<?> counter) { increase(counter.ordinal()); }
From source file:org.apache.nutch.mapreduce.NutchCounter.java
public int get(Enum<?> counter) { return get(counter.ordinal()); }
From source file:hu.bme.mit.trainbenchmark.generator.sql.SqlSerializer.java
private String valueToString(final Object value) { String stringValue;// w ww . ja va 2s. c o m if (value instanceof Boolean) { stringValue = (Boolean) value ? "1" : "0"; } else if (value instanceof String) { // escape string stringValue = "\"" + value + "\""; } else if (value instanceof Enum) { // change enum to ordinal value final Enum<?> enumeration = (Enum<?>) value; stringValue = Integer.toString(enumeration.ordinal()); } else { stringValue = value.toString(); } return stringValue; }
From source file:org.apache.nutch.mapreduce.NutchCounter.java
public void increase(Enum<?> counter, int value) { increase(counter.ordinal(), value); }
From source file:org.apache.nutch.mapreduce.NutchCounter.java
public void setValue(Enum<?> counter, int value) { setValue(counter.ordinal(), value); }
From source file:org.bimserver.shared.pb.ProtocolBuffersConverter.java
private Object convertFieldValue(SField field, Object val) throws ConvertException { if (val instanceof EnumValueDescriptor) { EnumValueDescriptor enumValueDescriptor = (EnumValueDescriptor) val; Class<?> enumClass; try {/*from w w w. j a va2 s. co m*/ enumClass = Class .forName("org.bimserver.interfaces.objects." + enumValueDescriptor.getType().getName()); for (Object v : enumClass.getEnumConstants()) { Enum<?> e = (Enum<?>) v; if (e.ordinal() == enumValueDescriptor.getNumber()) { val = e; break; } } } catch (ClassNotFoundException e) { LOGGER.error("", e); } return val; } else if (field.getType().getInstanceClass() == Date.class) { return new Date((Long) val); } else if (field.getType().getInstanceClass() == DataHandler.class) { ByteString byteString = (ByteString) val; ByteArrayDataSource byteArrayDataSource = new ByteArrayDataSource("test", byteString.toByteArray()); return new DataHandler(byteArrayDataSource); } else if (val instanceof DynamicMessage) { return convertProtocolBuffersMessageToSObject((DynamicMessage) val, null, field.isAggregate() ? field.getGenericType() : field.getType()); } else { return val; } }
From source file:org.netxilia.api.impl.format.EnumerationFormatter.java
private String enumValue(String enumValueProperty, Enum<?> enumItem) { if (enumValueProperty == null || ENUM_VALUE_NAME.equals(enumValueProperty)) { return enumItem.name(); }//from w ww. j a v a 2s .c o m if (ENUM_VALUE_ORDINAL.equals(enumValueProperty)) { return String.valueOf(enumItem.ordinal()); } try { return BeanUtils.getSimpleProperty(enumItem, enumValueProperty); } catch (Exception e) { throw new IllegalArgumentException("Unknown property:" + enumItem.getClass() + "." + enumValueProperty); } }
From source file:com.github.riking.dropcontrol.ItemStringInterpreter.java
@Override public byte interpret(String s) { for (Enum<?> e : values) { if (s.equalsIgnoreCase(e.toString())) { return (byte) e.ordinal(); }/*from w ww.java 2 s .c o m*/ } return 0; }
From source file:org.bimserver.shared.pb.ProtocolBuffersConverter.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public Message convertSObjectToProtocolBuffersObject(SBase object, SClass definedType) throws ConvertException { Builder builder = null;//from ww w . j a v a 2 s .c o m MessageDescriptorContainer messageDescriptor = protocolBuffersMetaData .getMessageDescriptor(definedType.getSimpleName()); if (messageDescriptor == null) { throw new ConvertException("No message descriptor found with name " + definedType.getSimpleName()); } Descriptor definedDescriptor = messageDescriptor.getDescriptor(); try { builder = DynamicMessage.getDefaultInstance(definedDescriptor).newBuilderForType(); } catch (SecurityException e) { throw new ConvertException(e); } catch (IllegalArgumentException e) { throw new ConvertException(e); } SClass sClass = object.getSClass(); SClass superClass = sClass; while (superClass.getSuperClass() != null && superClass.getSuperClass().getInstanceClass() != Object.class) { superClass = superClass.getSuperClass(); } if (sClass != superClass && messageDescriptor.getField("__actual_type") != null) { builder.setField(messageDescriptor.getField("__actual_type"), sClass.getSimpleName()); builder.setField(messageDescriptor.getField("__" + sClass.getSimpleName()), convertSObjectToProtocolBuffersObject(object, sClass)); } for (SField field : definedType.getAllFields()) { try { Object value = object.sGet(field); FieldDescriptor fieldDescriptor = messageDescriptor.getField(field.getName()); if (value != null) { if (value.getClass().isPrimitive() || value.getClass() == String.class || value.getClass() == Long.class || value.getClass() == Double.class || value.getClass() == Integer.class || value.getClass() == Boolean.class) { builder.setField(fieldDescriptor, value); } else if (value.getClass().isEnum()) { Enum eNum = (Enum) value; int ordinal = eNum.ordinal(); EnumValueDescriptor findValueByNumber = fieldDescriptor.getEnumType() .findValueByNumber(ordinal); builder.setField(fieldDescriptor, findValueByNumber); } else if (value.getClass() == Date.class) { builder.setField(fieldDescriptor, ((Date) value).getTime()); } else if (value.getClass() == DataHandler.class) { DataHandler dataHandler = (DataHandler) value; InputStream inputStream = dataHandler.getInputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); IOUtils.copy(inputStream, byteArrayOutputStream); ByteString byteString = ByteString.copyFrom(byteArrayOutputStream.toByteArray()); builder.setField(fieldDescriptor, byteString); } else if (List.class.isAssignableFrom(value.getClass())) { List list = (List) value; List newList = new ArrayList(); for (Object o : list) { if (fieldDescriptor.getJavaType() == JavaType.MESSAGE) { newList.add( convertSObjectToProtocolBuffersObject((SBase) o, field.getGenericType())); } else { newList.add(o); } } builder.setField(fieldDescriptor, newList); } else { LOGGER.error("Unimplemented: " + fieldDescriptor.getName() + ": " + value); } } } catch (SecurityException e) { LOGGER.error("", e); } catch (IllegalArgumentException e) { LOGGER.error("", e); } catch (IOException e) { LOGGER.error("", e); } } return builder.build(); }
From source file:org.batoo.jpa.core.impl.jdbc.BasicColumn.java
/** * Converts the value corresponding to enum or temporal type * //from ww w .j a v a 2s.c om * @param value * the raw value * @return the converted value * * @since $version * @author hceylan */ public Object convertValue(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) { return value; } final Enum<?> enumValue = (Enum<?>) value; if (this.enumType == EnumType.ORDINAL) { return enumValue.ordinal(); } return enumValue.name(); }