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

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

Introduction

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

Prototype

CaseFormat LOWER_CAMEL

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

Click Source Link

Document

Java variable naming convention, e.g., "lowerCamel".

Usage

From source file:gobblin.converter.avro.FlattenNestedKeyConverter.java

@Override
public Schema convertSchema(Schema inputSchema, WorkUnitState workUnit) throws SchemaConversionException {
    // Clear previous state
    fieldNameMap.clear();//from w w  w .  j a  v a  2s.c o  m

    Config config = ConfigUtils.propertiesToConfig(workUnit.getProperties())
            .getConfig(getClass().getSimpleName());
    List<String> nestedKeys = ConfigUtils.getStringList(config, FIELDS_TO_FLATTEN);

    List<Field> fields = new ArrayList<>();
    // Clone the existing fields
    for (Field field : inputSchema.getFields()) {
        fields.add(new Field(field.name(), field.schema(), field.doc(), field.defaultVal(), field.order()));
    }

    // Convert each of nested keys into a top level field
    for (String key : nestedKeys) {
        if (!key.contains(FIELD_LOCATION_DELIMITER)) {
            continue;
        }

        String nestedKey = key.trim();
        // Create camel-cased name
        String hyphenizedKey = nestedKey.replace(FIELD_LOCATION_DELIMITER, "-");
        String name = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, hyphenizedKey);
        if (fieldNameMap.containsKey(name)) {
            // Duplicate
            continue;
        }
        fieldNameMap.put(name, nestedKey);

        // Find the field
        Optional<Field> optional = AvroUtils.getField(inputSchema, nestedKey);
        if (!optional.isPresent()) {
            throw new SchemaConversionException("Unable to get field with location: " + nestedKey);
        }
        Field field = optional.get();

        // Make a copy under a new name
        Field copy = new Field(name, field.schema(), field.doc(), field.defaultVal(), field.order());
        fields.add(copy);
    }

    Schema outputSchema = Schema.createRecord(inputSchema.getName(), inputSchema.getDoc(),
            inputSchema.getNamespace(), inputSchema.isError());
    outputSchema.setFields(fields);
    return outputSchema;
}

From source file:com.github.jcustenborder.kafka.connect.cdc.SchemaGenerator.java

private static CaseFormat caseFormat(CDCSourceConnectorConfig.CaseFormat inputCaseFormat) {
    CaseFormat inputFormat;//from  w w w . j a va2  s.  co m
    switch (inputCaseFormat) {
    case LOWER_CAMEL:
        inputFormat = CaseFormat.LOWER_CAMEL;
        break;
    case LOWER_HYPHEN:
        inputFormat = CaseFormat.LOWER_HYPHEN;
        break;
    case LOWER_UNDERSCORE:
        inputFormat = CaseFormat.LOWER_UNDERSCORE;
        break;
    case UPPER_CAMEL:
        inputFormat = CaseFormat.UPPER_CAMEL;
        break;
    case UPPER_UNDERSCORE:
        inputFormat = CaseFormat.UPPER_UNDERSCORE;
        break;
    default:
        throw new UnsupportedOperationException(
                String.format("'%s' is not a supported case format.", inputCaseFormat));
    }
    return inputFormat;
}

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  v  a2  s .  c om*/
        return CaseFormat.LOWER_CAMEL;
    }
}

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);//ww  w. j  a  va 2  s  .c o m
        } 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:com.google.template.soy.internal.proto.Field.java

private static String computeSoyName(FieldDescriptor field) {
    return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, field.getName()) + fieldSuffix(field);
}

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  ww  w. j a va2  s  .  c o  m*/
    // 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:iterator.view.Details.java

public void setDetails() {
    StringBuilder html = new StringBuilder("<html>");
    String name = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL,
            Optional.fromNullable(ifs.getName()).or(IFS.UNTITLED));
    String words = CharMatcher.JAVA_LETTER_OR_DIGIT.negate().replaceFrom(name, ' ');
    html.append("<a name=\"top\"></a>").append(String.format("<h1 id=\"title\">IFS %s</h1>", words));

    if (ifs.isEmpty()) {
        html.append("<h2>Empty</h2>");
    } else {/*w w w .  j a  v  a  2 s  . c o m*/
        int i = 0;
        int columns = (int) Math.floor((float) getWidth() / 350f);
        html.append("<table>");
        for (Transform t : Ordering.from(IFS.IDENTITY).immutableSortedCopy(ifs)) {
            if (i % columns == 0 && i != 0)
                html.append("</tr>");
            if (i % columns == 0)
                html.append("<tr>");
            html.append("<td>").append("<table class=\"ifs\" width=\"250px\">");

            double[] matrix = new double[6];
            t.getTransform().getMatrix(matrix);

            Color c = Color.WHITE;
            if (controller.isColour()) {
                if (controller.hasPalette()) {
                    c = controller.getColours().get(i % controller.getPaletteSize());
                } else {
                    c = Color.getHSBColor((float) i / (float) ifs.size(), 0.8f, 0.8f);
                }
            }

            String transform = String.format(
                    "<tr class=\"transform\">" + "<td class=\"id\">%02d</td>"
                            + "<td class=\"bracketl\" rowspan=\"2\">&nbsp;</td>"
                            + "<td class=\"matrixr1\" align=\"right\">%.3f</td>"
                            + "<td class=\"matrixr1\" align=\"right\">%.3f</td>"
                            + "<td class=\"matrixr1\" align=\"right\">%.3f</td>"
                            + "<td class=\"bracketr\" rowspan=\"2\">&nbsp;</td>" + "</tr>"
                            + "<tr class=\"transform\">" + "<td class=\"info\">%.1f%%"
                            + "<div style=\"width: 15px; height: 10px; border: 1px solid %s; "
                            + "background: #%02x%02x%02x; padding: 0; margin: 0;\">&nbsp;</div>" + "</td>"
                            + "<td class=\"matrixr2\" align=\"right\">%.3f</td>"
                            + "<td class=\"matrixr2\" align=\"right\">%.3f</td>"
                            + "<td class=\"matrixr2\" align=\"right\">%.3f</td>" + "</tr>"
                            + "<tr class=\"space\"><td colspan=\"6\">&nbsp;</td></tr>",
                    t.getId(), matrix[0], matrix[1], matrix[2], 100d * t.getDeterminant() / ifs.getWeight(),
                    controller.isColour() ? "black" : "white", c.getRed(), c.getGreen(), c.getBlue(), matrix[3],
                    matrix[4], matrix[5]);
            html.append(transform).append("</table>").append("</td>");

            i++;
        }
        html.append("</tr>").append("</table>");
    }

    html.append("</html>");
    setText(html.toString());

    repaint();

    scrollToReference("top");
}

From source file:org.apache.gobblin.converter.avro.FlattenNestedKeyConverter.java

@Override
public Schema convertSchema(Schema inputSchema, WorkUnitState workUnit) throws SchemaConversionException {
    // Clear previous state
    fieldNameMap.clear();/*from  w w  w  . j  a va 2  s. c om*/

    Config config = ConfigUtils.propertiesToConfig(workUnit.getProperties())
            .getConfig(getClass().getSimpleName());
    List<String> nestedKeys = ConfigUtils.getStringList(config, FIELDS_TO_FLATTEN);
    // No keys need flatten
    if (nestedKeys == null || nestedKeys.size() == 0) {
        return inputSchema;
    }

    List<Field> fields = new ArrayList<>();
    // Clone the existing fields
    for (Field field : inputSchema.getFields()) {
        fields.add(new Field(field.name(), field.schema(), field.doc(), field.defaultValue(), field.order()));
    }

    // Convert each of nested keys into a top level field
    for (String key : nestedKeys) {
        if (!key.contains(FIELD_LOCATION_DELIMITER)) {
            continue;
        }

        String nestedKey = key.trim();
        // Create camel-cased name
        String hyphenizedKey = nestedKey.replace(FIELD_LOCATION_DELIMITER, "-");
        String name = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, hyphenizedKey);
        if (fieldNameMap.containsKey(name)) {
            // Duplicate
            continue;
        }
        fieldNameMap.put(name, nestedKey);

        // Find the field
        Optional<Field> optional = AvroUtils.getField(inputSchema, nestedKey);
        if (!optional.isPresent()) {
            throw new SchemaConversionException("Unable to get field with location: " + nestedKey);
        }
        Field field = optional.get();

        // Make a copy under a new name
        Field copy = new Field(name, field.schema(), field.doc(), field.defaultValue(), field.order());
        fields.add(copy);
    }

    Schema outputSchema = Schema.createRecord(inputSchema.getName(), inputSchema.getDoc(),
            inputSchema.getNamespace(), inputSchema.isError());
    outputSchema.setFields(fields);
    return outputSchema;
}

From source file:org.talend.components.service.rest.impl.ControllersConfiguration.java

/**
 * Initialise Web binders to be able to use {@link PropertyTrigger} in camel case in {@link PathVariable}.
 *///w ww.j  av  a 2  s .  com
@InitBinder
protected void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(PropertyTrigger.class, new PropertyEditorSupport() {

        @Override
        public void setAsText(String text) throws IllegalArgumentException {
            String upperUnderscoreCased = CaseFormat.LOWER_CAMEL.converterTo(CaseFormat.UPPER_UNDERSCORE)
                    .convert(text);
            PropertyTrigger propertyTrigger = PropertyTrigger.valueOf(upperUnderscoreCased);
            setValue(propertyTrigger);
        }
    });
    binder.registerCustomEditor(DefinitionType.class, new DefinitionTypeConverter());
    binder.registerCustomEditor(ConnectorTypology.class, new ConnectorTypologyConverter());
}