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:com.axelor.csv.script.PrepareCsv.java

/**
 * Method to generate csv files/*from  ww  w.j  av a 2  s  . c  o m*/
 * @param xmlDir 
 * @param csvDir
 */
public void prepareCsv(String xmlDir, String csvDir) {
    List<String> ignoreType = Arrays.asList("one-to-one", "many-to-many", "one-to-many");
    try {
        if (xmlDir != null && csvDir != null) {
            File xDir = new File(xmlDir);
            File cDir = new File(csvDir);
            List<String[]> blankData = new ArrayList<String[]>();
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            if (xDir.isDirectory() && cDir.isDirectory()) {
                for (File xf : xDir.listFiles()) {
                    LOG.info("Processing XML: " + xf.getName());
                    List<String> fieldList = new ArrayList<String>();
                    Document doc = dBuilder.parse(xf);
                    NodeList nList = doc.getElementsByTagName("module");
                    String module = nList.item(0).getAttributes().getNamedItem("name").getNodeValue();
                    nList = doc.getElementsByTagName("entity");
                    if (nList != null) {
                        NodeList fields = nList.item(0).getChildNodes();
                        Integer count = 0;
                        String csvFileName = module + "_" + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL,
                                xf.getName().replace(".xml", ".csv"));
                        while (count < fields.getLength()) {
                            Node field = fields.item(count);
                            NamedNodeMap attrs = field.getAttributes();
                            String type = field.getNodeName();
                            if (attrs != null && attrs.getNamedItem("name") != null
                                    && !ignoreType.contains(type)) {
                                String fieldName = attrs.getNamedItem("name").getNodeValue();
                                if (type.equals("many-to-one")) {
                                    String[] objName = attrs.getNamedItem("ref").getNodeValue().split("\\.");
                                    String refName = objName[objName.length - 1];
                                    String nameColumn = getNameColumn(xmlDir + "/" + refName + ".xml");
                                    if (nameColumn != null)
                                        fieldList.add(fieldName + "." + nameColumn);
                                    else {
                                        fieldList.add(fieldName);
                                        LOG.error("No name column found for " + refName + ", field '"
                                                + attrs.getNamedItem("name").getNodeValue() + "'");
                                    }
                                } else
                                    fieldList.add(fieldName);
                            }

                            count++;
                        }
                        CsvTool.csvWriter(csvDir, csvFileName, ';', StringUtils.join(fieldList, ",").split(","),
                                blankData);
                        LOG.info("CSV file prepared: " + csvFileName);
                    }
                }

            } else
                LOG.error("XML and CSV paths must be directory");
        } else
            LOG.error("Please input XML and CSV directory path");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.google.errorprone.bugpatterns.DateFormatConstant.java

@Override
public Description matchVariable(VariableTree tree, VisitorState state) {
    if (tree.getInitializer() == null) {
        return NO_MATCH;
    }//ww w .ja  va2s .c  om
    VarSymbol sym = ASTHelpers.getSymbol(tree);
    if (sym == null || sym.getKind() != ElementKind.FIELD) {
        return NO_MATCH;
    }
    String name = sym.getSimpleName().toString();
    if (!(sym.isStatic() && sym.getModifiers().contains(Modifier.FINAL))) {
        return NO_MATCH;
    }
    if (!name.equals(Ascii.toUpperCase(name))) {
        return NO_MATCH;
    }
    if (!isSubtype(getType(tree), state.getTypeFromString("java.text.DateFormat"), state)) {
        return NO_MATCH;
    }
    SuggestedFix rename = renameVariable(tree,
            CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, tree.getName().toString()), state);
    return buildDescription(tree).addFix(threadLocalFix(tree, state, sym, rename)).addFix(rename).build();
}

From source file:com.google.template.soy.passes.ResolvePackageRelativeCssNamesVisitor.java

private static String toCamelCase(String packageName) {
    String packageNameWithDashes = packageName.replace('.', '-');
    return CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, packageNameWithDashes);
}

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

@Override
public T deserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    final T instance = newInstance();
    final ObjectMapper mapper = (ObjectMapper) jp.getCodec();
    final ObjectNode rootNode = mapper.readTree(jp);
    final Iterator<Map.Entry<String, JsonNode>> iterator = rootNode.fields();

    while (iterator.hasNext()) {
        final Map.Entry<String, JsonNode> currentField = iterator.next();
        try {/* w  w w  .  j av  a2s  . c om*/
            /*
             * If the current node is not a null value, process it.  Otherwise,
             * skip it.  Jackson will treat the null as a 0 for primitive
             * number types, which in turn will make Thrift think the field
             * has been set. Also we ignore the MongoDB specific _id field
             */
            if (!currentField.getKey().equalsIgnoreCase("_id")
                    && currentField.getValue().getNodeType() != JsonNodeType.NULL) {
                final E field = getField(
                        CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, currentField.getKey()));
                final JsonParser parser = currentField.getValue().traverse();
                parser.setCodec(mapper);
                final Object value = mapper.readValue(parser, generateValueType(instance, field));
                if (value != null) {
                    log.debug(String.format("Field %s produced value %s of type %s.", currentField.getKey(),
                            value, value.getClass().getName()));
                    instance.setFieldValue(field, value);
                } else {
                    log.debug("Field {} contains a null value.  Skipping...", currentField.getKey());
                }
            } else {
                log.debug("Field {} contains a null value.  Skipping...", currentField.getKey());
            }
        } catch (final NoSuchFieldException | IllegalArgumentException e) {
            log.error("Unable to de-serialize field '{}'.", currentField.getKey(), e);
            ctxt.mappingException(e.getMessage());
        }
    }

    try {
        // Validate that the instance contains all required fields.
        validate(instance);
    } catch (final TException e) {
        log.error(String.format("Unable to deserialize JSON '%s' to type '%s'.", jp.getValueAsString(),
                instance.getClass().getName(), e));
        ctxt.mappingException(e.getMessage());
    }

    return instance;
}

From source file:fr.putnami.pwt.core.error.client.widget.SimpleErrorDisplayer.java

private String getMessage(Throwable error, String suffix, String defaultMessage) {
    if (this.constants == null) {
        return defaultMessage;
    }//w w w  .  ja  va2 s.com
    try {
        String className = error.getClass().getSimpleName();
        if (error instanceof CommandException) {
            className = ((CommandException) error).getCauseSimpleClassName();
        }
        String methodName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, className) + suffix;
        return this.constants.getString(methodName);
    } catch (MissingResourceException exc) {
        return defaultMessage;
    }
}

From source file:dagger.android.processor.ContributesAndroidInjectorGenerator.java

private void generate(AndroidInjectorDescriptor descriptor) {
    ClassName moduleName = descriptor.enclosingModule().topLevelClassName()
            .peerClass(Joiner.on('_').join(descriptor.enclosingModule().simpleNames()) + "_"
                    + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, descriptor.methodName()));

    String baseName = descriptor.injectedType().simpleName();
    ClassName subcomponentName = moduleName.nestedClass(baseName + "Subcomponent");
    ClassName subcomponentBuilderName = subcomponentName.nestedClass("Builder");

    TypeSpec module = TypeSpec.classBuilder(moduleName).addModifiers(PUBLIC, ABSTRACT)
            .addAnnotation(AnnotationSpec.builder(Module.class)
                    .addMember("subcomponents", "$T.class", subcomponentName).build())
            .addMethod(bindAndroidInjectorFactory(descriptor, subcomponentBuilderName))
            .addType(subcomponent(descriptor, subcomponentName, subcomponentBuilderName))
            .addMethod(MethodSpec.constructorBuilder().addModifiers(PRIVATE).build()).build();
    try {/*from ww  w  .j  av a 2 s .co  m*/
        JavaFile.builder(moduleName.packageName(), module).skipJavaLangImports(true).build().writeTo(filer);
    } catch (IOException e) {
        throw new AssertionError(e);
    }
}

From source file:com.google.errorprone.bugpatterns.ConstantField.java

private Description checkImmutable(VariableTree tree, VisitorState state, Symbol.VarSymbol sym, String name) {
    Type type = sym.type;/*from   w  ww.jav  a2s  .  c  o m*/
    if (type == null) {
        return Description.NO_MATCH;
    }
    switch (name) {
    case "serialVersionUID":
        // mandated by the Serializable API
        return Description.NO_MATCH;
    default:
        break;
    }
    if (name.toUpperCase().equals(name)) {
        return Description.NO_MATCH;
    }
    if (state.getTypes().unboxedTypeOrType(type).isPrimitive()
            || ASTHelpers.isSameType(type, state.getSymtab().stringType, state)
            || type.tsym.getKind() == ElementKind.ENUM) {
        String constName = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, name);
        if (constName.startsWith("K_")) {
            constName = constName.substring("K_".length());
        }
        return buildDescription(tree)
                .setMessage(String.format("%ss are immutable, field should be named '%s'",
                        sym.type.tsym.getSimpleName(), constName))
                .addFix(SuggestedFixes.renameVariable(tree, constName, state)).build();
    }
    return Description.NO_MATCH;
}

From source file:fr.putnami.pwt.core.editor.client.helper.MessageHelper.java

public String getMessageKey(Path path, String suffix) {
    if (path == null || path.isEmpty()) {
        return null;
    }/* w w  w .  jav  a2s.  co  m*/

    String labelKey = path.toString().replaceAll("\\.", "_").replaceAll("\\[", "").replaceAll("]", "")
            .toUpperCase();

    labelKey = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, String.valueOf(labelKey));
    if (!Strings.isNullOrEmpty(suffix)) {
        labelKey += suffix.substring(0, 1).toUpperCase() + suffix.substring(1);
    }
    return labelKey;
}

From source file:com.tactfactory.harmony.platform.android.updater.EntityImplementationAndroid.java

/**
 * Generate the necessary getters and setters for the class.
 * @param fileString The stringbuffer containing the class java code
 * @param classMeta The Metadata containing the infos on the java class
 *///from   w  w  w. j  a  v  a2  s  .  c o m
private final void generateGetterAndSetters(final SourceFileManipulator manipulator,
        final EntityMetadata classMeta) {

    final Collection<FieldMetadata> fields = classMeta.getFields().values();
    final boolean childClass = MetadataUtils.inheritsFromEntity(classMeta, ApplicationMetadata.INSTANCE);
    for (final FieldMetadata field : fields) {
        final boolean isInheritedId = childClass && classMeta.getIds().containsKey(field.getName());
        if (!field.isInternal() && !isInheritedId) {
            // Getter
            if (!this.alreadyImplementsGet(field, classMeta)) {
                ConsoleUtils.displayDebug("Add implements getter of " + field.getName(),
                        " => get" + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, field.getName()));

                manipulator.generateFieldAccessor(field, "itemGetter.java");
            }

            // Setter
            if (!this.alreadyImplementsSet(field, classMeta)) {
                ConsoleUtils.displayDebug("Add implements setter of " + field.getName(),
                        " => set" + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, field.getName()));

                manipulator.generateFieldAccessor(field, "itemSetter.java");
            }
        }
    }

    manipulator.addImport(classMeta, "ArrayList", "java.util.ArrayList");

    manipulator.addImport(classMeta, "List", "java.util.List");
}

From source file:ninja.utils.SwissKnife.java

/**
 * Returns the lower class name. Eg. A class named MyObject will become
 * "myObject"./* www  . ja  v  a  2 s. c  om*/
 *
 * @param object Object for which to return the lowerCamelCaseName
 * @return the lowerCamelCaseName of the Object
 */
public static String getRealClassNameLowerCamelCase(Object object) {

    return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, object.getClass().getSimpleName());

}