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.embulk.cli.EmbulkNew.java

private String getDisplayName(final String name) {
    final String[] nameSplit = name.split("_");
    final ArrayList<String> nameComposition = new ArrayList<String>();
    for (String namePart : nameSplit) {
        nameComposition.add(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, namePart));
    }//from w ww .  j  a  v a2s .  c o m
    return Joiner.on(" ").join(nameComposition);
}

From source file:com.axelor.web.service.RestService.java

@GET
@Path("{id}/{field}/download")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@SuppressWarnings("all")
public javax.ws.rs.core.Response download(@PathParam("id") Long id, @PathParam("field") String field,
        @QueryParam("image") boolean isImage) throws IOException {

    boolean isAttachment = MetaFile.class.getName().equals(getModel());

    Class klass = getResource().getModel();
    Mapper mapper = Mapper.of(klass);//from  w  w w  . ja v a 2  s.c o m
    Model bean = JPA.find(klass, id);

    if (isAttachment) {
        final String fileName = (String) mapper.get(bean, "fileName");
        final String filePath = (String) mapper.get(bean, "filePath");
        final File inputFile = FileUtils.getFile(uploadPath, filePath);
        if (!inputFile.exists()) {
            return javax.ws.rs.core.Response.status(Status.NOT_FOUND).build();
        }
        return javax.ws.rs.core.Response.ok(new StreamingOutput() {

            @Override
            public void write(OutputStream output) throws IOException, WebApplicationException {
                uploadSave(new FileInputStream(inputFile), output);
            }
        }).header("Content-Disposition", "attachment; filename=\"" + fileName + "\"").build();
    }

    String fileName = getModel() + "_" + field;
    Object data = mapper.get(bean, field);

    if (isImage) {
        String base64 = BLANK_IMAGE;
        if (data instanceof byte[]) {
            base64 = new String((byte[]) data);
        }
        try {
            base64 = base64.substring(base64.indexOf(";base64,") + 8);
            data = DatatypeConverter.parseBase64Binary(base64);
        } catch (Exception e) {
        }
        return javax.ws.rs.core.Response.ok(data).build();
    }

    fileName = fileName.replaceAll("\\s", "") + "_" + id;
    fileName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, fileName);

    if (data == null) {
        return javax.ws.rs.core.Response.noContent().build();
    }

    return javax.ws.rs.core.Response.ok(data)
            .header("Content-Disposition", "attachment; filename=\"" + fileName + "\"").build();
}

From source file:org.apache.metron.parsers.regex.RegularExpressionsParser.java

private void convertCamelCaseToUnderScore(Map<String, Object> json) {
    Map<String, String> oldKeyNewKeyMap = new HashMap<>();
    for (Map.Entry<String, Object> entry : json.entrySet()) {
        if (capitalLettersPattern.matcher(entry.getKey()).matches()) {
            oldKeyNewKeyMap.put(entry.getKey(),
                    CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, entry.getKey()));
        }//w w  w .ja  v  a  2 s  .c  o m
    }
    oldKeyNewKeyMap.forEach((oldKey, newKey) -> json.put(newKey, json.remove(oldKey)));
}

From source file:com.gmail.sretof.db.jdbc.processor.CamelBeanProcessor.java

/**
 * The positions in the returned array represent column numbers. The values
 * stored at each position represent the index in the
 * <code>PropertyDescriptor[]</code> for the bean property that matches the
 * column name. If no bean property was found for a column, the position is
 * set to <code>PROPERTY_NOT_FOUND</code>.
 * /* w  w  w .j a  va 2  s. com*/
 * @param rsmd
 *            The <code>ResultSetMetaData</code> containing column
 *            information.
 * 
 * @param props
 *            The bean property descriptors.
 * 
 * @throws SQLException
 *             if a database access error occurs
 * 
 * @return An int[] with column index to property index mappings. The 0th
 *         element is meaningless because JDBC column indexing starts at 1.
 */
protected int[] mapColumnsToProperties(ResultSetMetaData rsmd, PropertyDescriptor[] props) throws SQLException {
    int cols = rsmd.getColumnCount();
    int[] columnToProperty = new int[cols + 1];
    Arrays.fill(columnToProperty, PROPERTY_NOT_FOUND);

    for (int col = 1; col <= cols; col++) {
        String columnName = rsmd.getColumnLabel(col);
        if (null == columnName || 0 == columnName.length()) {
            columnName = rsmd.getColumnName(col);
        }
        columnName = columnName.toLowerCase();
        String propertyName = columnToPropertyOverrides.get(columnName);
        if (propertyName == null) {
            propertyName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, columnName);// ?
        }
        for (int i = 0; i < props.length; i++) {
            String prop = props[i].getName();
            if (propertyName.equalsIgnoreCase(prop)) {
                columnToProperty[col] = i;
                break;
            }
        }
    }
    return columnToProperty;
}

From source file:io.soliton.shapeshifter.NamedSchema.java

/**
 * Returns the external name of a given field of this schema.
 *
 * @param name the name of the field to look up
 *///from   www  .j  a  v a 2  s .co m
public String getPropertyName(String name) {
    Preconditions.checkArgument(has(name));
    if (substitutions.containsKey(name)) {
        name = substitutions.get(name);
    }
    return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name);
}

From source file:com.twitter.elephanttwin.retrieval.BlockIndexedFileInputFormat.java

/**
 * return the right method name based on the input column name.<br>
 *  Works with both Thrift and Protocol classes.
 *///from  w w w  .  j  a va 2 s.co m
public static String getCamelCaseMethodName(String columnName, Class<?> c) {
    if (TBase.class.isAssignableFrom(c))
        return "get" + columnName.substring(0, 1).toUpperCase() + columnName.substring(1);
    else if (Message.class.isAssignableFrom(c)) {
        return "get" + CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, columnName);
    }
    throw new RuntimeException("only Thrift and Protocol Buffer value classes are supported");
}

From source file:com.attribyte.relay.wp.WPSupplier.java

/**
 * Gets the key for replicated metadata - converting based on 'metaNameCaseFormat', if
 * configured.//from   w w  w . ja  va2 s . co  m
 * @param key The metadata key.
 * @return The key with conversion applied.
 */
private String metaKey(final String key) {
    return metaNameCaseFormat == null ? key : CaseFormat.LOWER_UNDERSCORE.to(metaNameCaseFormat, key);
}