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:datamine.storage.idl.generator.TableTestDataGenerator.java

public static String getMetaEnumName(String tableName) {
    return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, tableName) + "Metadata";
}

From source file:fr.obeo.intent.specification.parser.SpecificationUtils.java

private static String getCamelCaseName(NamedElement namedElement) {
    String name = namedElement.getName().replaceAll(" ", "_");
    return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name);
}

From source file:org.apache.airavata.userprofile.core.AbstractThriftSerializer.java

@Override
public void serialize(final T value, final JsonGenerator jgen, final SerializerProvider provider)
        throws IOException, JsonProcessingException {
    jgen.writeStartObject();/*from  w  w w .j a  v a 2 s.  c  o  m*/
    for (final E field : getFieldValues()) {
        if (value.isSet(field)) {
            final Object fieldValue = value.getFieldValue(field);
            if (fieldValue != null) {
                log.debug("Adding field {} to the JSON string...",
                        CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, field.getFieldName()));

                jgen.writeFieldName(
                        CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, field.getFieldName()));
                if (fieldValue instanceof Short) {
                    jgen.writeNumber((Short) fieldValue);
                } else if (fieldValue instanceof Integer) {
                    jgen.writeNumber((Integer) fieldValue);
                } else if (fieldValue instanceof Long) {
                    jgen.writeNumber((Long) fieldValue);
                } else if (fieldValue instanceof Double) {
                    jgen.writeNumber((Double) fieldValue);
                } else if (fieldValue instanceof Float) {
                    jgen.writeNumber((Float) fieldValue);
                } else if (fieldValue instanceof Boolean) {
                    jgen.writeBoolean((Boolean) fieldValue);
                } else if (fieldValue instanceof String) {
                    jgen.writeString(fieldValue.toString());
                } else if (fieldValue instanceof Collection) {
                    log.debug("Array opened for field {}.",
                            CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, field.getFieldName()));
                    jgen.writeStartArray();
                    for (final Object arrayObject : (Collection<?>) fieldValue) {
                        jgen.writeObject(arrayObject);
                    }
                    jgen.writeEndArray();
                    log.debug("Array closed for field {}.",
                            CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, field.getFieldName()));
                } else {
                    jgen.writeObject(fieldValue);
                }
            } else {
                log.debug("Skipping converting field {} to JSON:  value is null!",
                        CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, field.getFieldName()));
            }
        } else {
            log.debug("Skipping converting field {} to JSON:  field has not been set!",
                    CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, field.getFieldName()));
        }
    }
    jgen.writeEndObject();
}

From source file:com.shenit.commons.utils.ShenStrings.java

/**
 * To camel format/*from  w ww.j  a  v  a  2s.com*/
 * @param str
 * @return
 */
public static String camel(String str) {
    if (str.indexOf(DELIMITER_UNDERSCORE) < 0)
        return str;
    return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, str(str));
}

From source file:com.facebook.buck.query.LabelsFunction.java

@Override
public Set<QueryTarget> eval(QueryEnvironment env, ImmutableList<Argument> args,
        ListeningExecutorService executor) throws QueryException, InterruptedException {
    String label = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, args.get(0).getWord());
    Set<QueryTarget> inputs = args.get(1).getExpression().eval(env, executor);
    Set<QueryTarget> result = new LinkedHashSet<>();
    for (QueryTarget input : inputs) {
        result.addAll(env.getTargetsInAttribute(input, label));
    }// w w w .  j av  a  2 s  .c  o  m
    return result;
}

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

private String convert(GroupFieldType type) {
    String javaType = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, type.getGroupName());

    // Note that the STRUCT is always accessed through its interface
    return new StringBuilder().append(javaType).append("Interface").toString();
}

From source file:org.spongepowered.common.registry.provider.BlockPropertyIdProvider.java

public static String getIdAndTryRegistration(IProperty<?> property, Block block, String blockId) {
    BlockPropertyIdProvider instance = getInstance();
    checkNotNull(property, "Property is null! Cannot retrieve a registration for a null property!");
    checkNotNull(block, "Block cannot be null!");
    checkNotNull(blockId, "Block id cannot be null!");
    checkArgument(!blockId.isEmpty(), "Block id cannot be empty!");
    if (instance.isRegistered(property)) {
        return instance.propertyIdMap.get(property);
    } else {/*from  w ww  . ja  va2 s .  co m*/
        final String lowerCasedBlockId = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, blockId);
        final String modId = lowerCasedBlockId.split(":")[0];
        final String propertyName = property.getName();
        final String lastAttemptId = lowerCasedBlockId + "_" + property.getName();
        try { // Seriously, don't look past this try state. just continue on with your day...
              // I warned you...
            final String originalClass = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,
                    block.getClass().getSimpleName());
            Class<?> blockClass = block.getClass();
            while (true) {
                if (blockClass == Object.class) {
                    final String propertyId = modId + ":" + originalClass + "_" + property.getName();
                    LogManager.getLogger("Sponge").warn(
                            "Could not find {} owning class, assigning fallback id: {}", property.getName(),
                            propertyId);
                    instance.register(property, propertyId);
                    return propertyId;
                }
                // Had enough?
                for (Field field : blockClass.getDeclaredFields()) {
                    field.setAccessible(true);

                    final boolean isStatic = Modifier.isStatic(field.getModifiers());
                    final Object o = isStatic ? field.get(null) : field.get(block);

                    if (property != o) {
                        continue;
                    }
                    final String className = field.getDeclaringClass().getSimpleName().replace("Block", "")
                            .replace("block", "");
                    final String classNameId = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,
                            className);
                    final String propertyClassName = isStatic ? classNameId : originalClass;
                    final String combinedId = modId + ":" + propertyClassName + "_"
                            + propertyName.toLowerCase(Locale.ENGLISH);
                    if (instance.idPropertyMap.containsKey(combinedId)) {
                        // in this case, we really do have to fall back on the full block id...
                        if (instance.idPropertyMap.containsKey(lastAttemptId)) {
                            // we really are screwed...
                            throw new IllegalArgumentException(
                                    "Sorry! Someone is trying to re-register a block with the same property instances of"
                                            + "block: " + blockId + " , with property: " + propertyName);
                        } else {
                            instance.register((IProperty<?>) o, lastAttemptId);
                            return lastAttemptId;
                        }
                    }
                    instance.register(((IProperty<?>) o), combinedId);
                    return combinedId;
                }
                blockClass = blockClass.getSuperclass();
            }

        } catch (Exception e) {
            LogManager.getLogger("Sponge").warn("An exception was thrown while trying to resolve the property "
                    + property.getName() + "'s owning class, assigning " + "fallback id: " + lastAttemptId, e);
            instance.register(property, lastAttemptId);
            return lastAttemptId;
        }
    }
}

From source file:com.google.api.codegen.viewmodel.CallingForm.java

/**
 * Returns the {@code String} representation of this enum, but in lower camelcase.
 *
 * @return the lower camelcase name of this enum value
 *//* www .jav  a  2s. c o m*/
public String toLowerCamel() {
    return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, toString());
}

From source file:com.google.template.soy.types.proto.Protos.java

/** Performs camelcase translation. */
private static String computeJsExtensionName(FieldDescriptor field) {
    String name = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, field.getName());
    return field.isRepeated() ? name + "List" : name;
}

From source file:datamine.storage.recordbuffers.idl.generator.RecordMetaWrapperGenerator.java

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