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:datamine.storage.idl.generator.java.InterfaceGenerator.java

public static String getDefaultValueGetterName(Field field) {
    return new StringBuilder().append("get")
            .append(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, field.getName()))
            .append("DefaultValue").toString();
}

From source file:org.bonitasoft.web.designer.experimental.parametrizedWidget.ParametrizedWidgetFactory.java

private String inputDisplayLabel(ContractInput contractInput) {
    return CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, contractInput.getName())
            .replaceAll("((?<=[a-z])(?=[A-Z]))|((?<=[A-Z])(?=[A-Z][a-z]))", " ");
}

From source file:datamine.storage.idl.generator.java.InterfaceGenerator.java

public static String getListSizeGetterName(Field field) {
    return new StringBuilder().append("get")
            .append(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, field.getName())).append("Size")
            .toString();// www . j ava 2 s. c o m
}

From source file:org.jraf.androidcontentprovidergenerator.Main.java

private void loadModel(File inputDir) throws IOException, JSONException {
    JSONObject config = getConfig(inputDir);
    String apiModelJavaPackage = config.getString(Json.API_MODEL_JAVA_PACKAGE);

    File[] entityFiles = inputDir.listFiles(new FileFilter() {
        @Override/*w w  w . j a  va  2  s . c  om*/
        public boolean accept(File pathname) {
            return !pathname.getName().startsWith("_") && pathname.getName().endsWith(".json");
        }
    });
    for (File entityFile : entityFiles) {
        if (Config.LOGD) {
            Log.d(TAG, entityFile.getCanonicalPath());
        }
        String entityName = FilenameUtils.getBaseName(entityFile.getCanonicalPath());
        if (Config.LOGD) {
            Log.d(TAG, "entityName=" + entityName);
        }
        Entity entity = new Entity(entityName);
        String fileContents = FileUtils.readFileToString(entityFile);
        JSONObject entityJson = new JSONObject(fileContents);

        // Fields
        JSONArray fieldsJson = entityJson.getJSONArray("fields");
        int len = fieldsJson.length();
        for (int i = 0; i < len; i++) {
            JSONObject fieldJson = fieldsJson.getJSONObject(i);
            if (Config.LOGD) {
                Log.d(TAG, "fieldJson=" + fieldJson);
            }
            String name = fieldJson.getString(Field.Json.NAME);
            String type = fieldJson.getString(Field.Json.TYPE);
            boolean isIndex = fieldJson.optBoolean(Field.Json.INDEX, false);
            boolean isNullable = fieldJson.optBoolean(Field.Json.NULLABLE, true);
            String defaultValue = fieldJson.optString(Field.Json.DEFAULT_VALUE);
            String enumName = fieldJson.optString(Field.Json.ENUM_NAME);
            JSONArray enumValuesJson = fieldJson.optJSONArray(Field.Json.ENUM_VALUES);
            List<EnumValue> enumValues = new ArrayList<EnumValue>();
            if (enumValuesJson != null) {
                int enumLen = enumValuesJson.length();
                for (int j = 0; j < enumLen; j++) {
                    Object enumValue = enumValuesJson.get(j);
                    if (enumValue instanceof String) {
                        // Name only
                        enumValues.add(new EnumValue((String) enumValue, null));
                    } else {
                        // Name and Javadoc
                        JSONObject enumValueJson = (JSONObject) enumValue;
                        String enumValueName = (String) enumValueJson.keys().next();
                        String enumValueJavadoc = enumValueJson.getString(enumValueName);
                        enumValues.add(new EnumValue(enumValueName, enumValueJavadoc));
                    }
                }
            }
            Field field = new Field(name, type, isIndex, isNullable, defaultValue, enumName, enumValues);
            entity.addField(field);
        }

        // API
        JSONObject apiJson = entityJson.optJSONObject("api");
        if (apiJson != null) {
            // Automatic endpoints
            JSONArray autoApiEndpointsJson = apiJson.optJSONArray("autoEndpoints");
            if (autoApiEndpointsJson != null) {
                for (int i = 0; i < autoApiEndpointsJson.length(); i++) {
                    String autoApiEndpointJson = autoApiEndpointsJson.getString(i);
                    ApiParam idParam = new ApiParam("id", Type.fromJsonName("Integer"), "Path");

                    if (autoApiEndpointJson.equals("index")) {
                        entity.addApiMethod(new ApiEndpoint("get" + entity.getNameCamelCase() + "List",
                                "/" + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,
                                        entity.getNameCamelCase()),
                                "GET", new ArrayList<ApiParam>(), false, false,
                                Type.fromJsonName("java.util.List<" + entity.getNameCamelCase() + ">"),
                                "Retrieves a list of " + entity.getNameCamelCase() + " models."));
                    } else if (autoApiEndpointJson.equals("get")) {
                        entity.addApiMethod(new ApiEndpoint("get" + entity.getNameCamelCase(),
                                "/" + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,
                                        entity.getNameCamelCase()) + "/{id}",
                                "GET", new ArrayList<ApiParam>(Arrays.asList(idParam)), false, false,
                                Type.fromJsonName(entity.getNameCamelCase()),
                                "Retrieves an instance of a " + entity.getNameCamelCase() + " model."));
                    } else if (autoApiEndpointJson.equals("post")) {
                        ArrayList<ApiParam> postParams = new ArrayList<ApiParam>();

                        // @TODO, not the right field
                        for (Field field : entity.getFields()) {
                            postParams.add(
                                    new ApiParam(field.getNameCamelCaseLowerCase(), field.getType(), "Field"));
                        }

                        entity.addApiMethod(new ApiEndpoint("post" + entity.getNameCamelCase(),
                                "/" + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,
                                        entity.getNameCamelCase()),
                                "POST", postParams, true, false, Type.fromJsonName(entity.getNameCamelCase()),
                                "Creates a new instance of a " + entity.getNameCamelCase() + " model."));
                    } else if (autoApiEndpointJson.equals("put")) {
                        ArrayList<ApiParam> putParams = new ArrayList<ApiParam>();
                        putParams.add(idParam);

                        // @TODO, not the right field
                        for (Field field : entity.getFields()) {
                            putParams.add(
                                    new ApiParam(field.getNameCamelCaseLowerCase(), field.getType(), "Field"));
                        }

                        entity.addApiMethod(new ApiEndpoint("put" + entity.getNameCamelCase(),
                                "/" + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,
                                        entity.getNameCamelCase()) + "/{id}",
                                "POST", putParams, true, false, Type.fromJsonName(entity.getNameCamelCase()),
                                "Updates an instance of a " + entity.getNameCamelCase() + " model."));
                    } else if (autoApiEndpointJson.equals("delete")) {
                        entity.addApiMethod(new ApiEndpoint("delete" + entity.getNameCamelCase(),
                                "/" + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,
                                        entity.getNameCamelCase()) + "/{id}/delete",
                                "GET", new ArrayList<ApiParam>(Arrays.asList(idParam)), false, false,
                                Type.fromJsonName(entity.getNameCamelCase()),
                                "Deletes an instance of a " + entity.getNameCamelCase() + " model."));
                    }
                }
            }

            // Specific endpoints
            JSONArray apiEndpointsJson = apiJson.optJSONArray("endpoints");
            if (apiEndpointsJson != null) {
                for (int i = 0; i < apiEndpointsJson.length(); i++) {
                    JSONObject apiEndpointJson = apiEndpointsJson.getJSONObject(i);

                    String name = apiEndpointJson.getString(ApiEndpoint.Json.NAME);
                    String method = apiEndpointJson.getString(ApiEndpoint.Json.METHOD);
                    String endpoint = apiEndpointJson.getString(ApiEndpoint.Json.ENDPOINT);
                    String description = apiEndpointJson.getString(ApiEndpoint.Json.DESCRIPTION);
                    boolean isFormUrlEncoded = apiEndpointJson.optBoolean(ApiEndpoint.Json.IS_FORM_URL_ENCODED,
                            false);
                    boolean isMultipart = apiEndpointJson.optBoolean(ApiEndpoint.Json.IS_MULTIPART, false);
                    Type returnType = Type.fromJsonName(
                            apiEndpointJson.optString(ApiEndpoint.Json.RETURN_TYPE, entity.getNameCamelCase()));

                    List<ApiParam> params = new ArrayList<ApiParam>();
                    JSONArray pathParamsJson = apiEndpointJson.optJSONArray(ApiEndpoint.Json.PARAMETERS);
                    if (pathParamsJson != null) {
                        for (int j = 0; j < pathParamsJson.length(); j++) {
                            JSONObject pathParamJson = pathParamsJson.getJSONObject(j);
                            String paramName = pathParamJson.getString(ApiParam.Json.NAME);
                            Type paramType = Type.fromJsonName(pathParamJson.getString(ApiParam.Json.TYPE));
                            String placement = pathParamJson.optString(ApiParam.Json.PLACEMENT, "Path");
                            params.add(new ApiParam(paramName, paramType, placement));
                        }
                    }

                    entity.addApiMethod(new ApiEndpoint(name, endpoint, method, params, isFormUrlEncoded,
                            isMultipart, returnType, description));
                }
            }

            // API Fields
        }

        // Constraints (optional)
        JSONArray constraintsJson = entityJson.optJSONArray("constraints");
        if (constraintsJson != null) {
            len = constraintsJson.length();
            for (int i = 0; i < len; i++) {
                JSONObject constraintJson = constraintsJson.getJSONObject(i);
                if (Config.LOGD) {
                    Log.d(TAG, "constraintJson=" + constraintJson);
                }
                String name = constraintJson.getString(Constraint.Json.NAME);
                String definition = constraintJson.getString(Constraint.Json.DEFINITION);
                Constraint constraint = new Constraint(name, definition);
                entity.addConstraint(constraint);
            }
        }

        Model.get().addEntity(entity);
    }
    // Header (optional)
    File headerFile = new File(inputDir, "header.txt");
    if (headerFile.exists()) {
        String header = FileUtils.readFileToString(headerFile).trim();
        Model.get().setHeader(header);
    }
    if (Config.LOGD) {
        Log.d(TAG, Model.get().toString());
    }
}

From source file:com.b2international.snowowl.snomed.datastore.request.rf2.exporter.Rf2RefSetExporter.java

private String getCombinedRefSetName() {
    switch (refSetType) {
    case CONCRETE_DATA_TYPE:
        return "ConcreteDomainReferenceSet";
    case OWL_AXIOM:
        return "OWLAxiom";
    case OWL_ONTOLOGY:
        return "OWLOntology";
    case MRCM_DOMAIN:
        return "MRCMDomain";
    case MRCM_ATTRIBUTE_DOMAIN:
        return "MRCMAttributeDomain";
    case MRCM_ATTRIBUTE_RANGE:
        return "MRCMAttributeRange";
    case MRCM_MODULE_SCOPE:
        return "MRCMModuleScope";
    case ASSOCIATION: //$FALL-THROUGH$
    case SIMPLE: //$FALL-THROUGH$
    case QUERY: //$FALL-THROUGH$
    case ATTRIBUTE_VALUE: //$FALL-THROUGH$
    case EXTENDED_MAP: //$FALL-THROUGH$
    case SIMPLE_MAP: //$FALL-THROUGH$
    case SIMPLE_MAP_WITH_DESCRIPTION: //$FALL-THROUGH$
    case COMPLEX_MAP: //$FALL-THROUGH$
    case DESCRIPTION_TYPE: //$FALL-THROUGH$
    case MODULE_DEPENDENCY: //$FALL-THROUGH$ 
    case LANGUAGE:
        return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, refSetType.name());
    default:/*from ww w .ja  v a2 s  . c  om*/
        throw new IllegalArgumentException("Unknown SNOMED CT reference set type: " + refSetType);
    }
}

From source file:com.google.cloud.trace.guice.annotation.ManagedTracerSpanInterceptor.java

private String convertJavaName(String name) {
    return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name);
}

From source file:com.querydsl.core.alias.Alias.java

/**
 * Create a new alias proxy of the given type
 *
 * @param cl type of the alias/*from   w  w  w  .  j  av a 2s.c  o  m*/
 * @return alias instance
 */
public static <A> A alias(Class<A> cl) {
    return alias(cl, CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, cl.getSimpleName()));
}

From source file:io.prestosql.operator.aggregation.AggregationUtils.java

public static String generateAggregationName(String baseName, TypeSignature outputType,
        List<TypeSignature> inputTypes) {
    StringBuilder sb = new StringBuilder();
    sb.append(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, outputType.toString()));
    for (TypeSignature inputType : inputTypes) {
        sb.append(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, inputType.toString()));
    }//from w  w w  .  j  a  v a  2s  .c o m
    sb.append(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, baseName.toLowerCase(ENGLISH)));

    return sb.toString();
}

From source file:dagger.internal.codegen.SubcomponentWriter.java

private void writeSubcomponentWithoutBuilder(MethodSpec.Builder componentMethod,
        ExecutableType resolvedMethod) {
    ImmutableList.Builder<CodeBlock> subcomponentConstructorParameters = ImmutableList.builder();
    List<? extends VariableElement> params = subcomponentFactoryMethod.get().methodElement().getParameters();
    List<? extends TypeMirror> paramTypes = resolvedMethod.getParameterTypes();
    for (int i = 0; i < params.size(); i++) {
        VariableElement moduleVariable = params.get(i);
        TypeElement moduleTypeElement = MoreTypes.asTypeElement(paramTypes.get(i));
        ComponentRequirement componentRequirement = ComponentRequirement.forModule(moduleTypeElement.asType());
        TypeName moduleType = TypeName.get(paramTypes.get(i));
        componentMethod.addParameter(moduleType, moduleVariable.getSimpleName().toString());
        if (!componentContributionFields.containsKey(componentRequirement)) {
            String preferredModuleName = CaseFormat.UPPER_CAMEL.to(LOWER_CAMEL,
                    moduleTypeElement.getSimpleName().toString());
            FieldSpec contributionField = componentField(ClassName.get(moduleTypeElement), preferredModuleName)
                    .addModifiers(FINAL).build();
            component.addField(contributionField);

            String actualModuleName = contributionField.name;
            constructor.addParameter(moduleType, actualModuleName)
                    .addStatement("this.$1L = $2T.checkNotNull($1L)", actualModuleName, Preconditions.class);

            MemberSelect moduleSelect = localField(name, actualModuleName);
            componentContributionFields.put(componentRequirement, moduleSelect);
            subcomponentConstructorParameters.add(CodeBlock.of("$L", moduleVariable.getSimpleName()));
        }//from   w  w  w  .  j  a  v a  2s . co  m
    }

    Set<ComponentRequirement> uninitializedModules = difference(graph.componentRequirements(),
            componentContributionFields.keySet());

    for (ComponentRequirement componentRequirement : uninitializedModules) {
        checkState(componentRequirement.kind().equals(ComponentRequirement.Kind.MODULE));
        TypeElement moduleType = componentRequirement.typeElement();
        String preferredModuleName = CaseFormat.UPPER_CAMEL.to(LOWER_CAMEL,
                moduleType.getSimpleName().toString());
        FieldSpec contributionField = componentField(ClassName.get(moduleType), preferredModuleName)
                .addModifiers(FINAL).build();
        component.addField(contributionField);
        String actualModuleName = contributionField.name;
        constructor.addStatement("this.$L = new $T()", actualModuleName, ClassName.get(moduleType));
        MemberSelect moduleSelect = localField(name, actualModuleName);
        componentContributionFields.put(componentRequirement, moduleSelect);
    }

    componentMethod.addStatement("return new $T($L)", name,
            makeParametersCodeBlock(subcomponentConstructorParameters.build()));
}

From source file:org.eclipse.che.api.factory.server.builder.FactoryBuilder.java

/**
 * Validate compatibility of factory parameters.
 *
 * @param object//ww  w  . jav  a2  s.c  om
 *         - object to validate factory parameters
 * @param parent
 *         - parent object
 * @param methodsProvider
 *         - class that provides methods with {@link org.eclipse.che.api.core.factory.FactoryParameter}
 *         annotations
 * @param allowedMethodsProvider
 *         - class that provides allowed methods
 * @param version
 *         - version of factory
 * @param parentName
 *         - parent parameter queryParameterName
 * @throws org.eclipse.che.api.core.ConflictException
 */
void validateCompatibility(Object object, Object parent, Class methodsProvider, Class allowedMethodsProvider,
        Version version, String parentName, boolean isUpdate) throws ConflictException {
    // validate source
    if (SourceStorageDto.class.equals(methodsProvider) && !hasSubprojectInPath(parent)) {
        sourceStorageParametersValidator.validate((SourceStorage) object, version);
    }

    // get all methods recursively
    for (Method method : methodsProvider.getMethods()) {
        FactoryParameter factoryParameter = method.getAnnotation(FactoryParameter.class);
        // is it factory parameter

        if (factoryParameter == null) {
            continue;
        }
        String fullName = (parentName.isEmpty() ? "" : (parentName + ".")) + CaseFormat.UPPER_CAMEL
                .to(CaseFormat.LOWER_CAMEL, method.getName().startsWith("is") ? method.getName().substring(2)
                        : method.getName().substring(3).toLowerCase());
        // check that field is set
        Object parameterValue;
        try {
            parameterValue = method.invoke(object);
        } catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException e) {
            // should never happen
            LOG.error(e.getLocalizedMessage(), e);
            throw new ConflictException(FactoryConstants.INVALID_PARAMETER_MESSAGE);
        }

        // if value is null or empty collection or default value for primitives
        if (ValueHelper.isEmpty(parameterValue)) {
            // field must not be a mandatory, unless it's ignored or deprecated or doesn't suit to the version
            if (Obligation.MANDATORY.equals(factoryParameter.obligation())
                    && factoryParameter.deprecatedSince().compareTo(version) > 0
                    && factoryParameter.ignoredSince().compareTo(version) > 0
                    && method.getDeclaringClass().isAssignableFrom(allowedMethodsProvider)) {
                throw new ConflictException(
                        String.format(FactoryConstants.MISSING_MANDATORY_MESSAGE, method.getName()));
            }
        } else if (!method.getDeclaringClass().isAssignableFrom(allowedMethodsProvider)) {
            throw new ConflictException(
                    String.format(FactoryConstants.PARAMETRIZED_INVALID_PARAMETER_MESSAGE, fullName, version));
        } else {
            // is parameter deprecated
            if (factoryParameter.deprecatedSince().compareTo(version) <= 0
                    || (!isUpdate && factoryParameter.setByServer())) {
                throw new ConflictException(String
                        .format(FactoryConstants.PARAMETRIZED_INVALID_PARAMETER_MESSAGE, fullName, version));
            }

            // use recursion if parameter is DTO object
            if (method.getReturnType().isAnnotationPresent(DTO.class)) {
                // validate inner objects such Git ot ProjectAttributes
                validateCompatibility(parameterValue, object, method.getReturnType(), method.getReturnType(),
                        version, fullName, isUpdate);
            } else if (Map.class.isAssignableFrom(method.getReturnType())) {
                Type tp = ((ParameterizedType) method.getGenericReturnType()).getActualTypeArguments()[1];

                Class secMapParamClass = (tp instanceof ParameterizedType)
                        ? (Class) ((ParameterizedType) tp).getRawType()
                        : (Class) tp;
                if (!String.class.equals(secMapParamClass) && !List.class.equals(secMapParamClass)) {
                    if (secMapParamClass.isAnnotationPresent(DTO.class)) {
                        Map<Object, Object> map = (Map) parameterValue;
                        for (Map.Entry<Object, Object> entry : map.entrySet()) {
                            validateCompatibility(entry.getValue(), object, secMapParamClass, secMapParamClass,
                                    version, fullName + "." + entry.getKey(), isUpdate);
                        }
                    } else {
                        throw new RuntimeException("This type of fields is not supported by factory.");
                    }
                }
            } else if (List.class.isAssignableFrom(method.getReturnType())) {
                Type tp = ((ParameterizedType) method.getGenericReturnType()).getActualTypeArguments()[0];

                Class secListParamClass = (tp instanceof ParameterizedType)
                        ? (Class) ((ParameterizedType) tp).getRawType()
                        : (Class) tp;
                if (!String.class.equals(secListParamClass) && !List.class.equals(secListParamClass)) {
                    if (secListParamClass.isAnnotationPresent(DTO.class)) {
                        List<Object> list = (List) parameterValue;
                        for (Object entry : list) {
                            validateCompatibility(entry, object, secListParamClass, secListParamClass, version,
                                    fullName, isUpdate);
                        }
                    } else {
                        throw new RuntimeException("This type of fields is not supported by factory.");
                    }
                }
            }
        }
    }
}