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.openehr.adl.rm.RmBeanReflector.java

private static String getAttributeForField(@Nonnull String fieldName) {
    return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, fieldName);
}

From source file:com.google.api.tools.framework.model.FieldSelector.java

/**
 * Returns the HTTP parameter name of this selector. This is the sequence of proto field names
 * lower-cameled and joined by '.'.// w w  w  .  j  a  v  a2s  .c  om
 */
public String getParamName() {
    if (paramName != null) {
        return paramName;
    }
    return paramName = Joiner.on('.').join(FluentIterable.from(fields).transform(new Function<Field, String>() {
        @Override
        public String apply(Field field) {
            return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, field.getSimpleName());
        }
    }));
}

From source file:dao.versions.neo4j.Neo4jVersionHistoryDagFactory.java

/**
 * Truncate the DAG to only have a certain number of levels, removing everything before that.
 *
 * @param dag the DAG to truncate//from  ww w.j a v  a2 s  . c o m
 * @param numLevels the number of levels to keep
 */
@Override
public void truncate(VersionHistoryDag dag, int numLevels, Class<? extends Item> itemType)
        throws GroundException {

    int keptLevels = 1;
    List<Long> lastLevel = new ArrayList<>();
    List<Long> previousLevel = dag.getLeaves();

    while (keptLevels <= numLevels) {
        List<Long> currentLevel = new ArrayList<>();

        previousLevel.forEach(id -> currentLevel.addAll(dag.getParent(id)));

        lastLevel = previousLevel;
        previousLevel = currentLevel;

        keptLevels++;
    }

    List<Long> deleteQueue = previousLevel;
    Set<Long> deleted = new HashSet<>();

    for (long id : lastLevel) {
        this.addEdge(dag, dag.getItemId(), id, dag.getItemId());
    }

    List<DbDataContainer> predicates = new ArrayList<>();

    while (deleteQueue.size() > 0) {
        long id = deleteQueue.get(0);

        String[] splits = itemType.getName().split("\\.");
        String className = splits[splits.length - 1];
        String tableNamePrefix = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, className);

        if (itemType.equals(Structure.class)) {
            predicates.add(new DbDataContainer("structure_version_id", GroundType.LONG, id));
            this.dbClient.deleteNode(predicates, "structure_version_attribute");
            predicates.clear();
        }

        if (itemType.getName().toLowerCase().contains("graph")) {
            predicates.add(new DbDataContainer(tableNamePrefix + "_version_id", GroundType.LONG, id));
            this.dbClient.deleteNode(predicates, tableNamePrefix + "_version_edge");
            predicates.clear();
        }

        predicates.add(new DbDataContainer("id", GroundType.LONG, id));

        this.dbClient.deleteNode(predicates, className + "Version");

        deleteQueue.remove(0);
        List<Long> parents = dag.getParent(id);

        predicates.clear();
        predicates.add(new DbDataContainer("rich_version_id", GroundType.LONG, id));
        this.dbClient.deleteNode(predicates, "RichVersionTag");
        deleted.add(id);

        parents.forEach(parentId -> {
            if (!deleted.contains(parentId)) {
                deleteQueue.add(parentId);
            }
        });
    }
}

From source file:com.ning.billing.recurly.model.push.Notification.java

/**
 * Detect notification type based on the xml root name.
 *
 * @param payload//from w w  w . j  ava2 s .co m
 * @return notification type or null if root name is not found or if there
 *         is no type corresponding to the root name
 */
public static Type detect(final String payload) {
    final Matcher m = ROOT_NAME.matcher(payload);
    if (m.find() && m.groupCount() >= 1) {
        final String root = m.group(1);
        try {
            return Type.valueOf(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, root));
        } catch (IllegalArgumentException e) {
            log.warn("Enable to detect notification type, no type for {}", root);
            return null;
        }
    }
    log.warn("Enable to detect notification type");
    return null;
}

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

private String getLowerCamelUnderscoreSimpleName() {
    return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, this.cls.getSimpleName());
}

From source file:org.syncany.plugins.transfer.TransferPluginUtil.java

private static String getPluginPackageName(Class<?> clazz) {
    Matcher matcher = PLUGIN_PACKAGE_NAME_PATTERN.matcher(clazz.getPackage().getName());

    if (matcher.matches()) {
        String pluginPackageName = matcher.group(1);
        return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, pluginPackageName);
    }/* w w  w.  jav a  2 s  .  co  m*/

    return null;
}

From source file:com.google.api.codegen.transformer.php.PhpGapicSamplesTransformer.java

private List<ViewModel> generateSamples(GapicInterfaceContext context) {
    ImmutableList.Builder<ViewModel> viewModels = new ImmutableList.Builder<>();
    SurfaceNamer namer = context.getNamer();
    SampleFileRegistry generatedSamples = new SampleFileRegistry();

    List<OptionalArrayMethodView> allmethods = methodGenerator.generateApiMethods(context);
    DynamicLangSampleView.Builder sampleClassBuilder = DynamicLangSampleView.newBuilder();
    for (OptionalArrayMethodView method : allmethods) {
        String subPath = pathMapper.getSamplesOutputPath(context.getInterfaceModel().getFullName(),
                context.getProductConfig(), method.name());
        for (MethodSampleView methodSample : method.samples()) {
            String callingForm = methodSample.callingForm().toLowerCamel();
            String valueSet = methodSample.valueSet().id();
            String className = namer.getApiSampleClassName(
                    CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, method.name()), callingForm,
                    valueSet);/*ww  w .  j a v  a2  s .  c  o m*/
            String sampleOutputPath = subPath + File.separator + namer.getApiSampleFileName(className);
            String autoloadPath = "__DIR__ . '"
                    + Strings.repeat("/..",
                            (int) sampleOutputPath.chars().filter(c -> c == File.separatorChar).count())
                    + "/vendor/autoload.php'";
            generatedSamples.addFile(sampleOutputPath, method.name(), callingForm, valueSet,
                    methodSample.regionTag());
            viewModels.add(sampleClassBuilder.templateFileName(STANDALONE_SAMPLE_TEMPLATE_FILENAME)
                    .fileHeader(fileHeaderTransformer.generateFileHeader(context)).outputPath(sampleOutputPath)
                    .className(className)
                    .libraryMethod(method.toBuilder().samples(Collections.singletonList(methodSample)).build())
                    .gapicPackageName(namer.getGapicPackageName(packageConfig.packageName()))
                    .extraInfo(PhpSampleExtraInfo.newBuilder().autoloadPath(autoloadPath)
                            .hasDefaultServiceScopes(context.getInterfaceConfig().hasDefaultServiceScopes())
                            .hasDefaultServiceAddress(context.getInterfaceConfig().hasDefaultServiceAddress())
                            .build())
                    .build());
        }
    }
    return viewModels.build();
}

From source file:dao.versions.cassandra.CassandraVersionHistoryDagFactory.java

/**
 * Truncate the DAG to only have a certain number of levels, removing everything before that.
 *
 * @param dag the DAG to truncate//w  w  w  .j a v a  2s  .  c om
 * @param numLevels the number of levels to keep
 */
@Override
public void truncate(VersionHistoryDag dag, int numLevels, Class<? extends Item> itemType)
        throws GroundException {

    int keptLevels = 1;
    List<Long> previousLevel = dag.getLeaves();
    List<Long> lastLevel = new ArrayList<>();
    while (keptLevels <= numLevels) {
        List<Long> currentLevel = new ArrayList<>();

        previousLevel.forEach(id -> currentLevel.addAll(dag.getParent(id)));

        lastLevel = previousLevel;
        previousLevel = currentLevel;

        keptLevels++;
    }

    List<Long> deleteQueue = new ArrayList<>(new HashSet<>(previousLevel));
    Set<Long> deleted = new HashSet<>();

    List<DbDataContainer> predicates = new ArrayList<>();
    for (long id : lastLevel) {
        this.versionSuccessorFactory.deleteFromDestination(id, dag.getItemId());
        this.addEdge(dag, 0, id, dag.getItemId());
    }

    while (deleteQueue.size() > 0) {
        long id = deleteQueue.get(0);

        if (id != 0) {
            String[] splits = itemType.getName().split("\\.");
            String tableNamePrefix = splits[splits.length - 1];
            tableNamePrefix = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, tableNamePrefix);

            if (itemType.equals(Structure.class)) {
                predicates.add(new DbDataContainer("structure_version_id", GroundType.LONG, id));
                this.dbClient.delete(predicates, "structure_version_attribute");
                predicates.clear();
            }

            if (itemType.getName().toLowerCase().contains("graph")) {
                predicates.add(new DbDataContainer(tableNamePrefix + "_version_id", GroundType.LONG, id));
                this.dbClient.delete(predicates, tableNamePrefix + "_version_edge");
                predicates.clear();
            }

            predicates.add(new DbDataContainer("id", GroundType.LONG, id));
            this.dbClient.delete(predicates, tableNamePrefix + "_version");

            if (!itemType.equals(Structure.class)) {
                this.dbClient.delete(predicates, "rich_version");
            }

            this.dbClient.delete(predicates, "version");

            predicates.clear();
            predicates.add(new DbDataContainer("rich_version_id", GroundType.LONG, id));
            this.dbClient.delete(predicates, "rich_version_tag");

            this.versionSuccessorFactory.deleteFromDestination(id, dag.getItemId());

            deleted.add(id);

            List<Long> parents = dag.getParent(id);

            parents.forEach(parentId -> {
                if (!deleted.contains(parentId)) {
                    deleteQueue.add(parentId);
                }
            });

            predicates.clear();
        }

        deleteQueue.remove(0);
    }
}

From source file:com.google.api.tools.framework.aspects.documentation.model.DocumentationUtil.java

/**
 * Given a string, searches for unqualified references to message fields and to method names and
 * converts them from RPC-style to REST-style. Field names are converted from lower_underscore to
 * lowerCamel. Method names are converted from VerbCollection-style to collection.verb style.
 * No work is done for qualified references; in such a case, an explicit markdown link with the
 * proper display text should be used in the proto comment (e.g.,
 * [foo_bar][Path.To.Message.foo_bar], which will be converted to
 * [fooBar][Path.To.Message.foo_bar] by rpcToRest).
 *//* w  w w .j  av a 2  s  . co  m*/
public static String rpcToRest(SymbolTable symbolTable, String description) {
    StringBuffer sb = new StringBuffer();
    Matcher m = WORD.matcher(description);
    while (m.find()) {

        // Convert field names
        if (symbolTable.containsFieldName(m.group(0))) {
            m.appendReplacement(sb, CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, m.group(0)));

            // Convert method names
        } else if (symbolTable.lookupMethodSimpleName(m.group(0)) != null) {
            RestMethod restMethod = RestMethod
                    .getPrimaryRestMethod(symbolTable.lookupMethodSimpleName(m.group(0)).get(0));
            if (restMethod == null) {
                m.appendReplacement(sb, m.group(0));
            } else {
                m.appendReplacement(sb,
                        restMethod.getSimpleRestCollectionName() + "." + restMethod.getRestMethodName());
            }

        } else {
            m.appendReplacement(sb, m.group(0));
        }
    }
    m.appendTail(sb);
    return sb.toString();
}

From source file:org.dbunitng.beans.BeanMetaData.java

/**
 * ?//from w ww .j  a  v  a2  s. c om
 * 
 * @param name
 *            ??
 * @param setter
 *            Setter
 */
protected void addPropertyWithSetter(String name, Method setter) {
    String lowerName = name.toLowerCase();
    BeanProperty property = propertyMap.get(lowerName);
    Class<?> type = setter.getParameterTypes()[0];
    if (property == null) {
        property = new BeanProperty(name, type, null, null, setter);
        propertyMap.put(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name), property);
    } else {
        property.setSetter(setter);
    }
}