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:com.google.api.codegen.util.Name.java

private static CaseFormat getCamelCaseFormat(String piece) {
    if (Character.isUpperCase(piece.charAt(0))) {
        return CaseFormat.UPPER_CAMEL;
    } else {//from  w  w  w .j  a  va2  s .c om
        return CaseFormat.LOWER_CAMEL;
    }
}

From source file:dynamicrefactoring.domain.Scope.java

/**
 * Obtiene una representacion en formato cadena sin "_" entre palabras y con
 * las palabras en mayusculas del nombre del valor de la enumeracion.
 * /*from w w  w. j a v  a 2 s.c o  m*/
 * @return formato adecuado para impresion del nombre del ambito
 */
@Override
public String toString() {
    return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, super.toString()).replace("_", "");
}

From source file:org.openehr.adl.util.AdlUtils.java

public static String getRmTypeName(@Nonnull Class<?> clazz) {
    return CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, clazz.getSimpleName());
}

From source file:com.google.code.jgntp.internal.message.GntpMessage.java

public void appendHeader(String name, Object value, GntpMessageWriter writer) throws IOException {
    buffer.append(name).append(HEADER_SEPARATOR).append(' ');
    if (value != null) {
        if (value instanceof String) {
            String s = (String) value;
            s = s.replaceAll("\r\n", "\n");
            buffer.append(s);//from   ww w. ja v a  2 s . c  om
        } else if (value instanceof Number) {
            buffer.append(((Number) value).toString());
        } else if (value instanceof Boolean) {
            String s = ((Boolean) value).toString();
            s = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, s);
            buffer.append(s);
        } else if (value instanceof Date) {
            String s = dateFormat.format((Date) value);
            buffer.append(s);
        } else if (value instanceof URI) {
            buffer.append(((URI) value).toString());
        } else if (value instanceof GntpId) {
            buffer.append(value.toString());
        } else if (value instanceof InputStream) {
            byte[] data = ByteStreams.toByteArray((InputStream) value);
            GntpId id = addBinary(data);
            buffer.append(id.toString());
        } else if (value instanceof byte[]) {
            byte[] data = (byte[]) value;
            GntpId id = addBinary(data);
            buffer.append(id.toString());
        } else {
            throw new IllegalArgumentException("Value of header [" + name + "] not supported: " + value);
        }
    }
    writer.writeHeaderLine(buffer.toString());
    buffer.setLength(0);
}

From source file:com.eucalyptus.autoscaling.common.AutoScalingMessageValidation.java

public static String displayName(Field field) {
    HttpParameterMapping httpParameterMapping = Ats.from(field).get(HttpParameterMapping.class);
    return httpParameterMapping != null ? httpParameterMapping.parameter()[0]
            : CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, field.getName());
}

From source file:dk.dma.enumgenerator.Generator.java

/**
 * Converts the specified speed from this speed unit to kilometers per hour. For example, to convert 100 meters per
 * second to kilometers per hour: <code>SpeedUnit.METERS_PER_SECOND.toKilometersPerHour(100)</code>.
 *
 * @param speed/*from ww w.j av  a2 s  . c  o  m*/
 *            the speed to convert
 * @return the converted speed
 */
public CodegenClass generateEnum() {
    CodegenEnum c = new CodegenEnum();
    c.setPackage("dk.dma.enumgenerator.test");
    c.setDefinition("public enum " + unit.name + "Unit");

    for (Val v : unit.vals.values()) {
        String enumName = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, v.name);

        CodegenEnumConstant e = c.newConstant(enumName);
        if (v.description != null) {
            e.javadoc().set(v.description);
        }
        for (Val va : unit.vals.values()) {
            CodegenMethod m = e.newMethod("public double to", va.name, "(", unit.type(), " ", this.v, ")");
            if (v == va) {
                m.add("return ", this.v, ";");
            } else {
                boolean found = false;
                for (Conversion co : unit.conversions) {
                    if (co.from == v && co.to == va) {
                        String ex = co.expression.replace("x", this.v);
                        String val = "return " + ex + ";";
                        m.add(val);
                        found = true;
                    }
                }
                if (!found) {
                    m.throwNewUnsupportedOperationException("NotImplementedYet");
                }
            }
        }

        // 32 c toFahrenheit
        // Celcius
    }

    for (Val v : unit.vals.values()) {
        CodegenMethod m = c.addMethod("public abstract double to", v.name, "(", unit.type(), " ", this.v, ")");
        // 32 c toFahrenheit
        // Celcius
    }

    return c;
}

From source file:ninja.rythm.template.TemplateEngineRythm.java

@Override
@SuppressWarnings("unchecked")
public void invoke(Context context, Result result) {

    Object object = result.getRenderable();

    ResponseStreams responseStreams = context.finalizeHeaders(result);

    Map map;/*from   w  w  w.j a  va 2 s . c  om*/
    // if the object is null we simply render an empty map...
    if (object == null) {
        map = Maps.newHashMap();

    } else if (object instanceof Map) {
        map = (Map) object;

    } else {
        // We are getting an arbitrary Object and put that into
        // the root of rythm

        // If you are rendering something like Results.ok().render(new
        // MyObject())
        // Assume MyObject has a public String name field and
        // a getter getField()
        // You can then access the fields in the template like that:
        // @myObject.getField()
        // You will need to declare the object in the Template file, for eg:
        // @args package.MyObject myObject

        String realClassNameLowerCamelCase = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL,
                object.getClass().getSimpleName());

        map = Maps.newHashMap();
        map.put(realClassNameLowerCamelCase, object);

    }

    // set language from framework. You can access
    // it in the templates as @lang
    Optional<String> language = lang.getLanguage(context, Optional.of(result));
    Map<String, Object> renderArgs = new HashMap<String, Object>();
    if (language.isPresent()) {

        renderArgs.put("lang", language.get());
    }

    // put all entries of the session cookie to the map.
    // You can access the values by their key in the cookie
    // For eg: @session.get("key")
    if (!context.getSessionCookie().isEmpty()) {
        renderArgs.put("session", context.getSessionCookie().getData());
    }

    renderArgs.put("contextPath", context.getContextPath());

    // /////////////////////////////////////////////////////////////////////
    // Convenience method to translate possible flash scope keys.
    // !!! If you want to set messages with placeholders please do that
    // !!! in your controller. We only can set simple messages.
    // Eg. A message like "errorMessage=my name is: {0}" => translate in
    // controller and pass directly.
    // A message like " errorMessage=An error occurred" => use that as
    // errorMessage.
    //
    // get flash values like @flash.get("key")
    // ////////////////////////////////////////////////////////////////////

    Map<String, String> flash = new HashMap<String, String>();

    for (Entry<String, String> entry : context.getFlashCookie().getCurrentFlashCookieData().entrySet()) {

        String messageValue = null;

        Optional<String> messageValueOptional = messages.get(entry.getValue(), context, Optional.of(result));

        if (!messageValueOptional.isPresent()) {
            messageValue = entry.getValue();
        } else {
            messageValue = messageValueOptional.get();
        }

        flash.put(entry.getKey(), messageValue);
    }
    renderArgs.put("flash", flash);

    String templateName = rythmHelper.getRythmTemplateForResult(context.getRoute(), result, FILE_SUFFIX);

    // Specify the data source where the template files come from.
    // Here I set a file directory for it:

    try {
        PrintWriter writer = new PrintWriter(responseStreams.getWriter());

        if (language.isPresent()) {
            // RythmEngine uses ThreadLocal to set the locale, so this
            // setting per request is Thread safe.
            engine.prepare(new Locale(language.get()));
        }
        ITemplate t = engine.getTemplate(templateName, map);
        t.__setRenderArgs(renderArgs);
        String response = t.render();

        if (templateName.equals(response)) {
            handleServerError(context,
                    new Exception("Couldn't locate template " + templateName + " in views."));
        } else {
            writer.println(response);
            writer.flush();
            writer.close();
        }

    } catch (Exception e) {
        handleServerError(context, e);
    }
}

From source file:com.gwtplatform.mvp.processors.bundle.BundleDetails.java

private String sanitizeBundleName(String name) {
    String sanitized = name.trim().replaceAll("[^\\w\\d]", "_");
    return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, sanitized);
}

From source file:org.seedstack.seed.core.internal.ErrorsTool.java

private String formatCamelCase(String value) {
    String result = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, value).replace("_", " ");
    return result.substring(0, 1).toUpperCase() + result.substring(1);
}

From source file:org.jclouds.azure.management.domain.InstanceStatus.java

public static InstanceStatus fromValue(String type) {
    try {//from   ww w .  j  a  v  a  2 s .c  o m
        return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(type, "type")));
    } catch (IllegalArgumentException e) {
        return ROLE_STATE_UNKNOWN;
    }
}