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

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

Introduction

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

Prototype

CaseFormat UPPER_CAMEL

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

Click Source Link

Document

Java and C++ class naming convention, e.g., "UpperCamel".

Usage

From source file:org.apache.airavata.db.AbstractThriftSerializer.java

@Override
public void serialize(final T value, final JsonGenerator jgen, final SerializerProvider provider)
        throws IOException {
    jgen.writeStartObject();// w w  w.j a  v  a 2  s .  co  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_CAMEL, field.getFieldName()));

                jgen.writeFieldName(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, 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_CAMEL, 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_CAMEL, field.getFieldName()));
                } else {
                    jgen.writeObject(fieldValue);
                }
            } else {
                log.debug("Skipping converting field {} to JSON:  value is null!",
                        CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, field.getFieldName()));
            }
        } else {
            log.debug("Skipping converting field {} to JSON:  field has not been set!",
                    CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, field.getFieldName()));
        }
    }
    jgen.writeEndObject();
}

From source file:com.dopsun.msg4j.tools.JavaGenerator.java

/**
 * AbcXyz to ABC_XYZ
 * 
 * @param name
 * @return
 */
public String nameToConst(String name) {
    return CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, name);
}

From source file:org.sonarqube.wsgenerator.Helper.java

private String rawName(String path) {
    String x = path.replaceFirst("^api\\/", "");
    if (x.contains("_")) {
        return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, x.toLowerCase());
    }//from  w  w  w  . jav a 2  s  .  c o  m
    return capitalizeFirstLetter(x);
}

From source file:com.github.herong.rpc.netty.protobuf.demo3.Demo3ProtobufServerHandler.java

private void invokeHandle(Commands.Command decoded) throws Exception {
    Command.CommandType com = decoded.getType();
    String methodName = "handle" + CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, com.name());

    for (Method method : getClass().getDeclaredMethods()) {
        if (method.getName().equalsIgnoreCase(methodName)) {
            method.setAccessible(true);//www.ja  v a  2s. c o  m
            Class[] types = method.getParameterTypes();
            Class cmdType = types[0];
            Field f = cmdType.getField("cmd");
            GeneratedMessage.GeneratedExtension ext = (GeneratedMessage.GeneratedExtension) f.get(decoded);

            method.invoke(this, decoded.getExtension(ext));
            break;
        }
    }
}

From source file:com.opengamma.strata.collect.named.EnumNames.java

private EnumNames(Class<T> enumType, boolean manualToString) {
    ArgChecker.notNull(enumType, "enumType");
    SortedMap<String, T> map = new TreeMap<>();
    SortedSet<String> formattedSet = new TreeSet<>();
    EnumMap<T, String> formatMap = new EnumMap<>(enumType);
    for (T value : enumType.getEnumConstants()) {
        String formatted = manualToString ? value.toString()
                : CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, value.name());
        map.put(value.name(), value);//  w w w  .ja va2 s.  c om
        map.put(value.name().toUpperCase(Locale.ENGLISH), value);
        map.put(value.name().toLowerCase(Locale.ENGLISH), value);
        map.put(formatted, value);
        map.put(formatted.toUpperCase(Locale.ENGLISH), value);
        map.put(formatted.toLowerCase(Locale.ENGLISH), value);
        formattedSet.add(formatted);
        formatMap.put(value, formatted);
    }
    this.parseMap = ImmutableSortedMap.copyOf(map);
    this.formattedSet = ImmutableSortedSet.copyOf(formattedSet);
    this.formatMap = formatMap;
}

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.smartdeveloperhub.harvesters.it.frontend.util.AbstractCappedContainerHandler.java

@Override
public final ResourceSnapshot create(final ContainerSnapshot container, final DataSet representation,
        final WriteSession session) {
    trace("Requested %s creation from: %n%s", this.artifact, representation);
    throw super.unexpectedFailure("%s creation is not supported",
            CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, this.artifact));
}

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 2s  .c om
    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:io.soliton.protobuf.plugin.ProtoServiceHandler.java

public void handle(ServiceDescriptorProto service) throws IOException {
    ImmutableList.Builder<ServiceHandlerData.Method> methods = ImmutableList.builder();
    for (MethodDescriptorProto method : service.getMethodList()) {
        ServiceHandlerData.Method methodData = new ServiceHandlerData.Method(method.getName(),
                CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, method.getName()),
                types.lookup(method.getInputType()).toString(),
                types.lookup(method.getOutputType()).toString());
        methods.add(methodData);/*from   www .j  a va  2s  .c o  m*/
    }

    String fullName = Joiner.on('.').skipNulls().join(protoPackage, service.getName());

    ServiceHandlerData.Service serviceData = new ServiceHandlerData.Service(service.getName(), fullName,
            methods.build());
    ServiceHandlerData data = new ServiceHandlerData(javaPackage, multipleFiles, serviceData);

    String template = Resources.toString(Resources.getResource(this.getClass(), "service_class.mvel"),
            Charsets.UTF_8);
    String serviceFile = (String) TemplateRuntime.eval(template,
            ImmutableMap.<String, Object>of("handler", data));

    CodeGeneratorResponse.Builder response = CodeGeneratorResponse.newBuilder();
    CodeGeneratorResponse.File.Builder file = CodeGeneratorResponse.File.newBuilder();
    file.setContent(serviceFile);
    file.setName(javaPackage.replace('.', '/') + '/' + service.getName() + ".java");
    if (!multipleFiles) {
        file.setName(javaPackage.replace('.', '/') + '/' + outerClassName + ".java");
        file.setInsertionPoint("outer_class_scope");
    }
    response.addFile(file);
    response.build().writeTo(output);
}