Example usage for com.google.common.base CaseFormat UPPER_UNDERSCORE

List of usage examples for com.google.common.base CaseFormat UPPER_UNDERSCORE

Introduction

In this page you can find the example usage for com.google.common.base CaseFormat UPPER_UNDERSCORE.

Prototype

CaseFormat UPPER_UNDERSCORE

To view the source code for com.google.common.base CaseFormat UPPER_UNDERSCORE.

Click Source Link

Document

Java and C++ constant naming convention, e.g., "UPPER_UNDERSCORE".

Usage

From source file:org.jclouds.cloudstack.domain.TemplateFilter.java

@Override
public String toString() {
    return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name());
}

From source file:com.commonsware.android.staticizer.Staticizer.java

void generate(File input, File outputDir, String packageName) throws IOException {
    Type type = new TypeToken<LinkedHashMap<String, Object>>() {
    }.getType();/* www . j av  a 2s  . c o  m*/
    LinkedHashMap<String, Object> data = new Gson().fromJson(new FileReader(input), type);
    String basename = removeExtension(input.getAbsolutePath());
    TypeSpec.Builder builder = TypeSpec.classBuilder(basename).addModifiers(Modifier.PUBLIC, Modifier.FINAL);

    for (Map.Entry<String, Object> entry : data.entrySet()) {
        String fieldName = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, entry.getKey());
        FieldSpec.Builder field;

        if (entry.getValue() instanceof Float) {
            field = FieldSpec.builder(TypeName.FLOAT, fieldName).initializer("$L", entry.getValue());
        } else if (entry.getValue() instanceof Double) {
            field = FieldSpec.builder(TypeName.DOUBLE, fieldName).initializer("$L", entry.getValue());
        } else if (entry.getValue() instanceof Integer) {
            field = FieldSpec.builder(TypeName.INT, fieldName).initializer("$L", entry.getValue());
        } else if (entry.getValue() instanceof Long) {
            field = FieldSpec.builder(TypeName.LONG, fieldName).initializer("$L", entry.getValue());
        } else if (entry.getValue() instanceof Boolean) {
            field = FieldSpec.builder(TypeName.BOOLEAN, fieldName).initializer("$L", entry.getValue());
        } else {
            field = FieldSpec.builder(String.class, fieldName).initializer("$S", entry.getValue().toString());
        }

        field.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL).build();

        builder.addField(field.build());
    }

    JavaFile.builder(packageName, builder.build()).build().writeTo(outputDir);
}

From source file:paperparcel.AdapterNameGenerator.java

/**
 * Creates a name based on the given {@link TypeName}. Names are constants, so will use
 * {@link CaseFormat#UPPER_UNDERSCORE} formatting.
 *//*from w ww .j a  va  2  s.  c  o m*/
String getName(TypeName typeName) {
    String name = typeToNames.get(typeName);
    if (name != null) {
        return name;
    }
    name = getNameInternal(typeName);
    name = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, name);
    name = adapterNames.getUniqueName(name);
    typeToNames.put(typeName, name);
    return name;
}

From source file:es.sm2.openppm.api.converter.common.SettingGroupDTOConverter.java

/**
 * Convert BD model object into DTO model
 *
 * @param model/*www  .ja  v a2  s.c o  m*/
 * @return
 */
@Override
public SettingGroupDTO toDTO(Class<? extends ApplicationSetting> model) {

    String name = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, model.getSimpleName());

    SettingGroupDTO dto = new SettingGroupDTO(name);
    //        dto.setSettingList(new HashMap<String, String>());
    //
    //        for (ApplicationSetting applicationSetting : model.getEnumConstants()) {
    //            dto.getSettingList().put(applicationSetting.name(), applicationSetting.getDefaultValue());
    //        }

    return dto;
}

From source file:org.raml.v2.internal.utils.Inflector.java

private static CaseFormat detectFormat(String word) {
    boolean allUpper = word.toUpperCase().equals(word);
    boolean allLower = word.toLowerCase().equals(word);
    boolean mixedCase = !allUpper && !allLower;
    boolean firstCapital = word.substring(0, 1).toUpperCase().equals(word.substring(0, 1));
    if (mixedCase) {
        if (firstCapital) {
            return CaseFormat.UPPER_CAMEL;
        }//from w w  w  . ja  v a2 s. c o  m
        return LOWER_CAMEL;
    }
    if (allUpper) {
        return CaseFormat.UPPER_UNDERSCORE;
    }
    return CaseFormat.LOWER_UNDERSCORE;
}

From source file:com.activeandroid.TableInfo.java

public TableInfo(Class<? extends Model> type) {
    mType = type;//  w  w w .  ja v a2 s  .  co  m

    final Table tableAnnotation = type.getAnnotation(Table.class);
    if (tableAnnotation != null) {
        mTableName = tableAnnotation.name();
    } else {
        mTableName = type.getSimpleName();
        CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, mTableName);
    }

    List<Field> fields = new LinkedList<Field>(ReflectionUtils.getDeclaredColumnFields(type));
    //      Collections.reverse(fields);
    //WHY?

    for (Field field : fields) {
        final Column columnAnnotation = field.getAnnotation(Column.class);
        String columnName;
        if (columnAnnotation == null) {
            columnName = field.getName();
            CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, columnName);
        } else {
            columnName = columnAnnotation.name();
        }

        mColumnNames.put(field, columnName);
    }
}

From source file:com.google.template.soy.shared.internal.ImpureFunction.java

private ImpureFunction(int numArgs) {
    this.functionName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
    this.numArgs = numArgs;
}

From source file:com.google.template.soy.shared.internal.NonpluginFunction.java

private NonpluginFunction(int numArgs) {
    this.functionName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
    this.numArgs = numArgs;
}

From source file:org.jclouds.azurecompute.binders.VMImageParamsToXML.java

@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    VMImageParams params = VMImageParams.class.cast(input);

    try {/*from  w ww . ja  va  2 s.c om*/
        XMLBuilder builder = XMLBuilder.create("VMImage", "http://schemas.microsoft.com/windowsazure");
        add(builder, "Name", params.name());
        add(builder, "Label", params.label());
        add(builder, "Description", params.description());
        //OSConfig
        VMImageParams.OSDiskConfigurationParams osDiskConfig = params.osDiskConfiguration();
        if (osDiskConfig != null) {
            String cache = CaseFormat.UPPER_UNDERSCORE.to(UPPER_CAMEL, osDiskConfig.hostCaching().toString());
            XMLBuilder osConfigBuilder = builder.e("OSDiskConfiguration");
            osConfigBuilder.e("HostCaching").t(cache).up().e("OSState").t(osDiskConfig.osState().toString())
                    .up().e("OS").t(osDiskConfig.os().toString()).up().e("MediaLink")
                    .t(osDiskConfig.mediaLink().toASCIIString()).up().up(); //OSDiskConfiguration
        }
        builder.up();
        builder.e("DataDiskConfigurations").up();
        add(builder, "Language", params.language());
        add(builder, "ImageFamily", params.imageFamily());

        RoleSize.Type vmSize = params.recommendedVMSize();
        if (vmSize != null) {
            String vmSizeText = params.recommendedVMSize().getText();
            builder.e("RecommendedVMSize").t(vmSizeText).up();
        }

        add(builder, "Eula", params.eula());
        add(builder, "IconUri", params.iconUri());
        add(builder, "SmallIconUri", params.smallIconUri());
        add(builder, "PrivacyUri", params.privacyUri());

        if (params.showGui() != null) {
            String showGuiText = params.showGui().toString();
            builder.e("ShowGui").t(showGuiText).up();
        }
        builder.up();

        return (R) request.toBuilder().payload(builder.asString()).build();
    } catch (Exception e) {
        throw propagate(e);
    }
}

From source file:com.google.template.soy.shared.internal.BuiltinFunction.java

BuiltinFunction() {
    this.functionName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
}