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.google.template.soy.pysrc.internal.GeneratePySanitizeEscapingDirectiveCode.java

@Override
protected void generateHelperFunction(StringBuilder outputCode, DirectiveDigest digest) {
    String name = digest.getDirectiveName();
    String fnName = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name);
    outputCode.append("\ndef ").append(fnName).append("_helper(value):\n").append("  value = str(value)\n");
    if (digest.getFilterName() != null) {
        String filterName = digest.getFilterName();
        outputCode.append("  if not _FILTER_FOR_").append(filterName).append(".search(value):\n");
        // TODO(dcphillips): Raising a debugging assertion error could be useful.
        outputCode.append("    return '").append(digest.getInnocuousOutput()).append("'\n").append("\n");
    }//  w w w  . j  a v a 2s  . co  m

    if (digest.getNonAsciiPrefix() != null) {
        // TODO: We can add a second replace of all non-ascii codepoints below.
        throw new UnsupportedOperationException("Non ASCII prefix escapers not implemented yet.");
    }
    if (digest.getEscapesName() != null) {
        String escapeMapName = digest.getEscapesName();
        String matcherName = digest.getMatcherName();
        outputCode.append("  return _MATCHER_FOR_").append(matcherName).append(".sub(\n")
                .append("      _REPLACER_FOR_").append(escapeMapName).append(", value)\n");
    } else {
        outputCode.append("  return value\n");
    }
    outputCode.append("\n");
}

From source file:com.netflix.spinnaker.clouddriver.ecs.provider.agent.AbstractEcsCachingAgent.java

CacheResult buildCacheResult(String authoritativeKeyName, List<T> items, ProviderCache providerCache) {
    String prettyKeyName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, authoritativeKeyName);

    Map<String, Collection<CacheData>> dataMap = generateFreshData(items);

    //Old keys can come from different account/region, filter them to the current account/region.
    Set<String> oldKeys = providerCache.getAll(authoritativeKeyName).stream().map(CacheData::getId)
            .filter(key -> keyAccountRegionFilter(authoritativeKeyName, key)).collect(Collectors.toSet());

    Map<String, Collection<String>> evictions = computeEvictableData(dataMap.get(authoritativeKeyName),
            oldKeys);/*from  w  ww .  j a  v a  2 s  .c  o m*/
    evictions = addExtraEvictions(evictions);
    log.info("Evicting " + evictions.size() + " " + prettyKeyName + (evictions.size() > 1 ? "s" : "") + " in "
            + getAgentType());

    return new DefaultCacheResult(dataMap, evictions);
}

From source file:com.github.jcustenborder.kafka.connect.utils.templates.model.Example.java

private ObjectNode connectorJson() {
    ObjectNode node = ObjectMapperFactory.INSTANCE.createObjectNode();
    String connectorName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, this.className.getSimpleName())
            + "1";
    node.put("name", connectorName);

    ObjectNode config = ObjectMapperFactory.INSTANCE.createObjectNode();
    node.set("config", config);
    config.put("connector.class", this.className.getName());
    config.put("tasks.max", "1");
    if (SinkConnector.class.isAssignableFrom(this.className)) {
        config.put("topics", "topic1,topic2,topic3");
    }/*  w  w w  . j  av  a 2 s  .co  m*/
    for (Map.Entry<String, String> kvp : this.config.entrySet()) {
        config.put(kvp.getKey(), kvp.getValue());
    }
    if (null != this.transformations && !transformations.isEmpty()) {
        Set<String> transformKeys = this.transformations.keySet();
        config.put("transforms", Joiner.on(',').join(transformKeys));
        for (String transformKey : transformKeys) {
            Map<String, String> transformSettings = this.transformations.get(transformKey);
            for (Map.Entry<String, String> kvp : transformSettings.entrySet()) {
                final String key = String.format("transforms.%s.%s", transformKey, kvp.getKey());
                config.put(key, kvp.getValue());
            }
        }
    }

    return node;
}

From source file:com.tactfactory.harmony.generator.BundleGenerator.java

/**
 * Generate Bundle metadata./*  w  w  w .  j  a  va2 s. c o m*/
 * @param bundleOwnerName Owner name
 * @param bundleName Bundle name
 * @param bundleNameSpace Bundle namespace
 */
private void generateMeta(final String bundleOwnerName, final String bundleName, final String bundleNameSpace) {

    final String tplPath = this.getAdapter().getMetaBundleTemplatePath() + "/TemplateMetadata.java";
    final String genPath = this.getAdapter().getMetaBundlePath(bundleOwnerName, bundleNameSpace, bundleName)
            + "/" + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, bundleName) + "Metadata.java";

    this.makeSource(tplPath, genPath, false);
}

From source file:org.immutables.value.processor.encode.Instantiation.java

private String generateProperName(EncodedElement element) {
    if (element.isImplField()) {
        return names.var;
    }/*w w w.ja va2  s  .c  o m*/

    if (element.isExpose()) {
        return names.get;
    }

    if (element.standardNaming() != StandardNaming.NONE) {
        switch (element.standardNaming()) {
        case GET:
            return names.get;
        case INIT:
            return names.init;
        case ADD:
            return names.add();
        case ADD_ALL:
            return names.addAll();
        case PUT:
            return names.put();
        case PUT_ALL:
            return names.putAll();
        case WITH:
            return names.with;
        default:
        }
    }

    if (isDefaultUnspecifiedValue(element)) {
        if (element.isCopy()) {
            return names.with;
        }
        if (element.isInit()) {
            return names.init;
        }
    }

    if (element.isStaticField() && element.isFinal()) {
        String base = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, rawName());
        return element.naming().apply(base);
    }

    return names.apply(element.naming(), element.depluralize());
}

From source file:com.tactfactory.harmony.platform.winphone.WinphoneProjectAdapter.java

@Override
public List<IUpdater> getDatabaseFiles() {
    List<IUpdater> result = new ArrayList<IUpdater>();

    String applicationName = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL,
            this.adapter.getApplicationMetadata().getName());

    String templatePath = this.adapter.getTemplateSourceDataPath();
    String filePath = this.adapter.getSourcePath() + this.adapter.getData() + "/";

    result.add(new SourceFile(templatePath + "Base/ApplicationSqlAdapterBase.cs",
            String.format("%sBase/SqlAdapterBase.cs", filePath), true));

    result.add(new ProjectUpdater(FileType.Compile, "Data/" + "Base/SqlAdapterBase.cs"));

    result.add(new SourceFile(templatePath + "Base/ApplicationSqlOpenHelperBase.cs",
            String.format("%sBase/%sSqlOpenHelperBase.cs", filePath, applicationName), true));

    result.add(new ProjectUpdater(FileType.Compile,
            "Data/" + String.format("Base/%sSqlOpenHelperBase.cs", applicationName)));

    result.add(new SourceFile(templatePath + "ApplicationSqlAdapter.cs",
            String.format("%sSqlAdapter.cs", filePath), false));

    result.add(new ProjectUpdater(FileType.Compile, "Data/" + "SqlAdapter.cs"));

    result.add(new SourceFile(templatePath + "ApplicationSqlOpenHelper.cs",
            String.format("%s%sSqlOpenHelper.cs", filePath, applicationName), false));

    result.add(new ProjectUpdater(FileType.Compile,
            "Data/" + String.format("%sSqlOpenHelper.cs", applicationName)));

    return result;
}

From source file:proto.src.main.java.com.google.gson.protobuf.ProtoTypeAdapter.java

/**
 * Creates a new {@link ProtoTypeAdapter} builder, defaulting enum serialization to
 * {@link EnumSerialization#NAME} and converting field serialization from
 * {@link CaseFormat#LOWER_UNDERSCORE} to {@link CaseFormat#LOWER_CAMEL}.
 *///  ww  w  .j  a v a  2s.  com
public static Builder newBuilder() {
    return new Builder(EnumSerialization.NAME, CaseFormat.LOWER_UNDERSCORE, CaseFormat.LOWER_CAMEL);
}

From source file:org.apache.calcite.jdbc.MetaImpl.java

static ColumnMetaData.StructType fieldMetaData(Class clazz) {
    final List<ColumnMetaData> list = new ArrayList<ColumnMetaData>();
    for (Field field : clazz.getFields()) {
        if (Modifier.isPublic(field.getModifiers()) && !Modifier.isStatic(field.getModifiers())) {
            list.add(columnMetaData(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, field.getName()),
                    list.size() + 1, field.getType()));
        }/*from w w w.  ja va 2  s.  c o m*/
    }
    return ColumnMetaData.struct(list);
}

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

/**
 * Validate compatibility of factory parameters.
 *
 * @param object/*  ww  w.j a v a 2s. c o m*/
 *         - object to validate factory parameters
 * @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.ApiException
 */
void validateCompatibility(Object object, Class methodsProvider, Class allowedMethodsProvider, Version version,
        String parentName) throws ApiException {
    // get all methods recursively
    for (Method method : methodsProvider.getMethods()) {
        FactoryParameter factoryParameter = method.getAnnotation(FactoryParameter.class);
        // is it factory parameter
        if (factoryParameter != null) {
            String fullName = (parentName.isEmpty() ? "" : (parentName + ".")) + CaseFormat.UPPER_CAMEL
                    .to(CaseFormat.LOWER_CAMEL, 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(FactoryConstants.MISSING_MANDATORY_MESSAGE);
                }
            } 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) {
                    throw new ConflictException(String.format(
                            FactoryConstants.PARAMETRIZED_INVALID_PARAMETER_MESSAGE, fullName, version));
                }

                if (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, method.getReturnType(), method.getReturnType(),
                            version, fullName);
                } else if (Map.class.isAssignableFrom(method.getReturnType())) {
                    Type tp = ((ParameterizedType) method.getGenericReturnType()).getActualTypeArguments()[1];

                    Class secMapParamClass;
                    if (tp instanceof ParameterizedType) {
                        secMapParamClass = (Class) ((ParameterizedType) tp).getRawType();
                    } else {
                        secMapParamClass = (Class) tp;
                    }
                    if (String.class.equals(secMapParamClass)) {
                        if (ImportSourceDescriptor.class.equals(methodsProvider)) {
                            sourceProjectParametersValidator.validate((ImportSourceDescriptor) object, version);
                        }
                    } else if (List.class.equals(secMapParamClass)) {
                        // do nothing
                    } else {
                        if (secMapParamClass.isAnnotationPresent(DTO.class)) {
                            Map<Object, Object> map = (Map) parameterValue;
                            for (Map.Entry<Object, Object> entry : map.entrySet()) {
                                validateCompatibility(entry.getValue(), secMapParamClass, secMapParamClass,
                                        version, fullName + "." + entry.getKey());
                            }
                        } else {
                            throw new RuntimeException("This type of fields is not supported by factory.");
                        }
                    }
                }
            }
        }
    }
}

From source file:org.dozer.util.ProtoUtils.java

public static String toCamelCase(String name) {
    return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name);
}