List of usage examples for org.apache.thrift TEnum getValue
public int getValue();
From source file:com.linecorp.armeria.common.thrift.text.TTextProtocol.java
License:Apache License
@Override public int readI32() throws TException { Class<?> fieldClass = getCurrentFieldClassIfIs(TEnum.class); if (fieldClass != null) { // Enum fields may be set by string, even though they represent integers. getCurrentContext().read();// ww w .ja va2s . com JsonNode elem = getCurrentContext().getCurrentChild(); if (elem.isInt()) { return TypedParser.INTEGER.readFromJsonElement(elem); } else if (elem.isTextual()) { // All TEnum are enums @SuppressWarnings({ "unchecked", "rawtypes" }) TEnum tEnum = (TEnum) Enum.valueOf((Class<Enum>) fieldClass, TypedParser.STRING.readFromJsonElement(elem)); return tEnum.getValue(); } else { throw new TTransportException( "invalid value type for enum field: " + elem.getNodeType() + " (" + elem + ')'); } } else { return readNameOrValue(TypedParser.INTEGER); } }
From source file:com.siemens.sw360.portal.tags.DisplayEnumSelection.java
License:Open Source License
private void doEnumValues(Iterable<? extends TEnum> enums) throws IOException { JspWriter jspWriter = getJspContext().getOut(); for (TEnum enumItem : enums) { String enumItemDescription = ThriftEnumUtils.enumToString(enumItem); boolean selected = enumItem.equals(this.selected) || enumItem.toString().equals(this.selectedName); String value = useStringValues ? enumItem.toString() : "" + enumItem.getValue(); jspWriter.write(String.format( "<option value=\"%s\" class=\"textlabel stackedLabel\" " + (selected ? "selected=\"selected\" " : "") + ">%s</option>", value, enumItemDescription)); }/*from ww w . j a va 2s .co m*/ }
From source file:org.apache.parquet.thrift.ThriftSchemaConverter.java
License:Apache License
private static ThriftField toThriftField(String name, Field field, ThriftField.Requirement requirement) { ThriftType type;// ww w. j av a 2 s . co m switch (ThriftTypeID.fromByte(field.getType())) { case STOP: case VOID: default: throw new UnsupportedOperationException("can't convert type of " + field); case BOOL: type = new BoolType(); break; case BYTE: type = new ByteType(); break; case DOUBLE: type = new DoubleType(); break; case I16: type = new I16Type(); break; case I32: type = new I32Type(); break; case I64: type = new I64Type(); break; case STRING: type = new StringType(); break; case STRUCT: type = toStructType(field.gettStructDescriptor()); break; case MAP: final Field mapKeyField = field.getMapKeyField(); final Field mapValueField = field.getMapValueField(); type = new ThriftType.MapType(toThriftField(mapKeyField.getName(), mapKeyField, requirement), toThriftField(mapValueField.getName(), mapValueField, requirement)); break; case SET: final Field setElemField = field.getSetElemField(); type = new ThriftType.SetType(toThriftField(name, setElemField, requirement)); break; case LIST: final Field listElemField = field.getListElemField(); type = new ThriftType.ListType(toThriftField(name, listElemField, requirement)); break; case ENUM: Collection<TEnum> enumValues = field.getEnumValues(); List<EnumValue> values = new ArrayList<ThriftType.EnumValue>(); for (TEnum tEnum : enumValues) { values.add(new EnumValue(tEnum.getValue(), tEnum.toString())); } type = new EnumType(values); break; } return new ThriftField(name, field.getId(), requirement, type); }
From source file:org.eclipse.sw360.portal.tags.DisplayEnumSelection.java
License:Open Source License
private void doEnumValues(Iterable<? extends TEnum> enums) throws IOException { JspWriter jspWriter = getJspContext().getOut(); Iterator<? extends TEnum> iterator = enums.iterator(); while (iterator.hasNext()) { TEnum enumItem = iterator.next(); String enumItemDescription = ThriftEnumUtils.enumToString(enumItem); boolean selected = enumItem.equals(this.selected) || enumItem.toString().equals(this.selectedName); String value = useStringValues ? enumItem.toString() : "" + enumItem.getValue(); String result = String.format( "<option value=\"%s\" class=\"textlabel stackedLabel\" " + (selected ? "selected=\"selected\" " : "") + ">%s</option>", value, enumItemDescription); if (inQuotes && iterator.hasNext()) { jspWriter.write("\'" + result + "\' +"); } else if (inQuotes) { jspWriter.write("\'" + result + "\'"); } else {//from ww w .j a v a2 s .c o m jspWriter.write(result); } } }