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

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

Introduction

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

Prototype

CaseFormat LOWER_UNDERSCORE

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

Click Source Link

Document

C++ variable naming convention, e.g., "lower_underscore".

Usage

From source file:org.apache.beam.runners.core.construction.PipelineOptionsTranslation.java

/** Converts the provided {@link PipelineOptions} to a {@link Struct}. */
public static Struct toProto(PipelineOptions options) {
    Struct.Builder builder = Struct.newBuilder();

    try {//from  w  ww.  j  a v a2  s.com
        // TODO: Officially define URNs for options and their scheme.
        TreeNode treeNode = MAPPER.valueToTree(options);
        TreeNode rootOptions = treeNode.get("options");
        Iterator<String> optionsKeys = rootOptions.fieldNames();
        Map<String, TreeNode> optionsUsingUrns = new HashMap<>();
        while (optionsKeys.hasNext()) {
            String optionKey = optionsKeys.next();
            TreeNode optionValue = rootOptions.get(optionKey);
            optionsUsingUrns.put(
                    "beam:option:" + CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, optionKey) + ":v1",
                    optionValue);
        }

        // The JSON format of a Protobuf Struct is the JSON object that is equivalent to that struct
        // (with values encoded in a standard json-codeable manner). See Beam PR 3719 for more.
        JsonFormat.parser().merge(MAPPER.writeValueAsString(optionsUsingUrns), builder);
        return builder.build();
    } catch (IOException e) {
        throw new RuntimeException("Failed to convert PipelineOptions to Protocol", e);
    }
}

From source file:com.github.ko2ic.plugin.eclipse.taggen.common.domain.valueobject.NameRuleString.java

public String phraseConstantName() {
    String value = str;//from   w  w  w .ja v  a2  s. co  m
    if (Character.isUpperCase(str.charAt(0))) {
        if (!str.contains("_")) {
            value = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, str);
        }
    } else {
        if (str.contains("_")) {
            value = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_UNDERSCORE, str);
        } else {
            value = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, str);
        }
    }
    return value;
}

From source file:org.syncany.plugins.transfer.TransferPluginUtil.java

/**
 * Determines the {@link TransferSettings} class for a given
 * {@link TransferPlugin} class.//from ww w. j av a  2s.  com
 */
public static Class<? extends TransferSettings> getTransferSettingsClass(
        Class<? extends TransferPlugin> transferPluginClass) {
    String pluginNameIdentifier = TransferPluginUtil.getPluginPackageName(transferPluginClass);

    if (pluginNameIdentifier == null) {
        throw new RuntimeException("There are no valid transfer settings attached to that plugin ("
                + transferPluginClass.getName() + ")");
    } else {
        try {
            String pluginPackageIdentifier = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,
                    pluginNameIdentifier);
            String transferSettingsClassName = MessageFormat.format(PLUGIN_TRANSFER_SETTINGS_CLASS_NAME,
                    pluginPackageIdentifier, pluginNameIdentifier);

            return Class.forName(transferSettingsClassName).asSubclass(TransferSettings.class);
        } catch (Exception e) {
            throw new RuntimeException("Cannot find matching transfer settings class for plugin ("
                    + transferPluginClass.getName() + ")");
        }
    }
}

From source file:org.jclouds.joyent.cloudapi.v6_5.reference.Metadata.java

public String key() {
    return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_UNDERSCORE, name());
}

From source file:com.thinkbiganalytics.nifi.feedmgr.NifiEnvironmentProperties.java

/**
 * return the environment property in the format that can be used with NiFi
 *
 * @param envProperty the property from the application.properties
 * @return the formatted property to work with NiFi
 *//* w  ww  .j  a  v  a 2s  .  co m*/
private static String environmentPropertyToNifi(String envProperty) {
    String name = envProperty.replaceAll("_", " ");
    name = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name);
    return name;
}

From source file:io.soliton.protobuf.plugin.ProtoFileHandler.java

@VisibleForTesting
static String inferOuterClassName(FileDescriptorProto file) {
    String fileName = file.getName();
    if (fileName.endsWith(".proto")) {
        fileName = fileName.substring(0, fileName.length() - ".proto".length());
    }/* w ww .j  a v  a2  s .  com*/
    fileName = Iterables.getLast(Splitter.on('/').split(fileName));
    fileName = fileName.replace('-', '_');
    fileName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, fileName);
    return Character.toUpperCase(fileName.charAt(0)) + fileName.substring(1);
}

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 ww .  ja v a  2s  .c o  m*/
        return LOWER_CAMEL;
    }
    if (allUpper) {
        return CaseFormat.UPPER_UNDERSCORE;
    }
    return CaseFormat.LOWER_UNDERSCORE;
}

From source file:com.groupon.jenkins.buildtype.install_packages.template.DotCiTemplate.java

private String getName() {
    String className = getClass().getSimpleName();
    return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, className);
}

From source file:fm.pattern.tokamak.server.validation.UniqueValueValidator.java

public boolean isValid(PersistentEntity entity, ConstraintValidatorContext constraint) {
    final String value = (String) Reflection.get(entity, property);
    if (isBlank(value)) {
        return true;
    }//  ww  w  .  j a va2  s.com

    String columnName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, property);

    String query = "select count(id) from " + getTableName(entity) + " where " + columnName
            + " = :value and id != :id";
    Query q = repository.query(query).setParameter("value", value).setParameter("id", entity.getId());

    return repository.count(q) == 0;
}

From source file:datamine.storage.idl.generator.TableTestDataGenerator.java

public static String getTestDataClassName(String tableName) {
    return new StringBuilder().append(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, tableName))
            .append("TestData").toString();
}