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:Main.java
private static <T extends Enum<T>> int enumSetToBitwise(EnumSet<T> enumSet) { int bitwise = 0; for (Enum<T> enumValue : enumSet) { bitwise += (int) Math.pow(2, enumValue.ordinal()); }/*w ww .j a va 2 s . c om*/ return bitwise; }
From source file:de.iteratec.iteraplan.businesslogic.exchange.common.vbb.impl.util.VisualVariableHelper.java
private static EClassifier getEEnum(EPackage vvEPackage, Class<? extends Enum<?>> enumClass) { if (vvEPackage.getEClassifier(enumClass.getSimpleName()) == null) { EEnum result = EcoreFactory.eINSTANCE.createEEnum(); result.setName(enumClass.getSimpleName()); result.setInstanceClass(enumClass); for (Enum<?> enumValue : enumClass.getEnumConstants()) { EEnumLiteral lit = EcoreFactory.eINSTANCE.createEEnumLiteral(); lit.setValue(enumValue.ordinal()); lit.setName(enumValue.name()); result.getELiterals().add(lit); }//ww w.jav a2s . co m vvEPackage.getEClassifiers().add(result); } return vvEPackage.getEClassifier(enumClass.getSimpleName()); }
From source file:org.batoo.jpa.jdbc.ValueConverter.java
/** * convert java objects to jdbc friendly * /*from w w w.j av a 2s. c o m*/ * @param value * jdbc raw value * @param javaType * type of value * @param temporalType * temporal type * @param enumType * enum type * @param lob * is Lob * @return jdbc friendly value * @since 2.0.1 */ public static Object toJdbc(Object value, Class<?> javaType, TemporalType temporalType, EnumType enumType, boolean lob) { if (value == null) { return null; } if (temporalType != null) { switch (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 (Number.class.isAssignableFrom(javaType)) { return ReflectHelper.convertNumber((Number) value, javaType); } if (enumType != null) { final Enum<?> enumValue = (Enum<?>) value; if (enumType == EnumType.ORDINAL) { return enumValue.ordinal(); } return enumValue.name(); } if (lob) { try { if (javaType == String.class) { return new SerialClob(((String) value).toCharArray()); } else if (javaType == char[].class) { return new SerialClob((char[]) value); } else if (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:org.evosuite.regression.ObjectFields.java
private static double getElementaryValue(Enum<?> p) { return p.ordinal(); }
From source file:com.hazelcast.simulator.worker.tasks.AbstractWorkerWithMultipleProbes.java
@Override public void bind(PropertyBinding binding) { Set<O> operations = operationSelectorBuilder.getOperations(); workerProbes = new Probe[INITIAL_PROBE_ARRAY_LENGTH]; for (Enum operation : operations) { int ordinal = operation.ordinal(); if (ordinal >= workerProbes.length) { Probe[] newProbes = new Probe[2 * (ordinal + 1)]; System.arraycopy(workerProbes, 0, newProbes, 0, workerProbes.length); this.workerProbes = newProbes; }/* w ww. ja v a 2 s .c o m*/ String probeName = capitalizeFully(operation.name(), '_').replace("_", "") + "Probe"; Probe probe = binding.getOrCreateProbe(probeName, false); workerProbes[ordinal] = probe; } }
From source file:org.appverse.web.framework.backend.frontfacade.json.controllers.EnumSerializer.java
@Override public void serialize(Enum<?> t, JsonGenerator jg, SerializerProvider sp) throws IOException, JsonGenerationException { jg.writeNumber(t.ordinal()); }
From source file:org.datalorax.populace.core.populate.mutator.change.ChangeEnumMutator.java
private Object changeEnum(final Enum currentValue) { final Object[] allValues = currentValue.getDeclaringClass().getEnumConstants(); final int newOrdinal = (currentValue.ordinal() + 1) % allValues.length; return allValues[newOrdinal]; }
From source file:gov.nih.nci.caarray.plugins.illumina.AbstractCsvDesignHelper.java
/** * init headerIndex by looking at the order of the headers row. *///from w ww .ja va2 s. c o m @SuppressWarnings("unchecked") void initHeaderIndex(List<String> headerValues) { EnumSet<? extends Enum> headers = EnumSet.allOf(headerEnumClass); headerIndex = new int[headers.size()]; for (int i = 0; i < headerValues.size(); i++) { Enum h = Enum.valueOf(headerEnumClass, headerValues.get(i).toUpperCase(Locale.getDefault())); headerIndex[h.ordinal()] = i; } }
From source file:hu.bme.mit.trainbenchmark.generator.sql.SQLGenerator.java
private String valueToString(final Object value) { String stringValue;// w w w. j a v a2s. c om 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.tango.server.attribute.ReflectAttributeBehavior.java
private AttributeValue buildAttributeValue(final Object value) throws DevFailed { AttributeValue result = null;/*from www . jav a 2 s . c o m*/ if (value == null) { result = new AttributeValue(null); } else if (value instanceof AttributeValue) { result = (AttributeValue) value; } else if (value instanceof DeviceState) { final DeviceState state = (DeviceState) value; result = new AttributeValue(state.getDevState()); } else if (value instanceof DeviceState[]) { final DeviceState[] in = (DeviceState[]) value; final DevState[] devStates = new DevState[in.length]; for (int i = 0; i < in.length; i++) { devStates[i] = in[i].getDevState(); } result = new AttributeValue(devStates); } else if (value instanceof Enum) { final Enum<?> enumValue = (Enum<?>) value; result = new AttributeValue((short) enumValue.ordinal()); } else { result = new AttributeValue(value); } return result; }