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:dao.versions.postgres.PostgresVersionHistoryDagFactory.java

/**
 * Truncate the DAG to only have a certain number of levels, removing everything before that.
 *
 * TODO: refactor to move specific logic into those classes.
 *
 * @param dag the DAG to truncate//from   ww  w.ja  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 = 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.versionSuccessorFactory.deleteFromDestination(id, dag.getItemId());

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

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

            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:brooklyn.entity.container.docker.DockerContainerImpl.java

@Override
public void init() {
    LOG.info("Starting Docker container id {}", getId());
    super.init();

    AtomicInteger counter = config().get(DOCKER_INFRASTRUCTURE)
            .getAttribute(DockerInfrastructure.DOCKER_CONTAINER_COUNTER);
    String dockerContainerName = config().get(DOCKER_CONTAINER_NAME);
    String dockerContainerNameFormat = config().get(DOCKER_CONTAINER_NAME_FORMAT);
    if (Strings.isBlank(dockerContainerName) && Strings.isNonBlank(dockerContainerNameFormat)) {
        dockerContainerName = format(dockerContainerNameFormat, getId(), counter.incrementAndGet());
    }// w  w  w . j a v  a  2s .com
    if (Strings.isNonBlank(dockerContainerName)) {
        dockerContainerName = CharMatcher.BREAKING_WHITESPACE.trimAndCollapseFrom(dockerContainerName, '-');
        setDisplayName(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, dockerContainerName));
        setAttribute(DOCKER_CONTAINER_NAME, dockerContainerName);
    }

    ConfigToAttributes.apply(this, DOCKER_INFRASTRUCTURE);
    ConfigToAttributes.apply(this, DOCKER_HOST);
    ConfigToAttributes.apply(this, ENTITY);
}

From source file:org.gbif.occurrence.query.HumanFilterBuilder.java

/**
 * @param p the predicate to convert/*w  w  w .  ja v  a  2s  . com*/
 * @return a list of anded parameters with multiple values to be combined with OR
 * @throws IllegalStateException if more complex predicates than the portal handles are supplied
 */
public synchronized String humanFilterString(Predicate p) {
    if (p == null) {
        return "All data";
    }
    humanFilter(p);
    StringBuilder sb = new StringBuilder();
    for (Map.Entry<OccurrenceSearchParameter, LinkedList<String>> entry : filter.entrySet()) {
        if (sb.length() > 0) {
            sb.append(" \n");
        }
        sb.append(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, entry.getKey().name()));
        sb.append(": ");
        boolean delimit = false;
        for (String val : entry.getValue()) {
            if (delimit) {
                sb.append(" or ");
            } else {
                delimit = true;
            }
            sb.append(val);
        }
    }
    return sb.toString();
}

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

public static String getInterfaceName(String tableName) {
    return new StringBuilder().append(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, tableName))
            .append("Interface").toString();
}

From source file:org.ballerinalang.composer.tools.ModelGenerator.java

public static JsonObject getContext() {

    // Set alias for the classes
    alias.put("ImportNode", "ImportPackageNode");
    alias.put("ArrayLiteralExprNode", "ArrayLiteralNode");
    alias.put("BinaryExprNode", "BinaryExpressionNode");
    alias.put("BracedTupleExprNode", "BracedOrTupleExpression");
    alias.put("TypeInitExprNode", "TypeInitNode");
    alias.put("FieldBasedAccessExprNode", "FieldBasedAccessNode");
    alias.put("IndexBasedAccessExprNode", "IndexBasedAccessNode");
    alias.put("IntRangeExprNode", "IntRangeExpression");
    alias.put("LambdaNode", "LambdaFunctionNode");
    alias.put("SimpleVariableRefNode", "SimpleVariableReferenceNode");
    alias.put("TernaryExprNode", "TernaryExpressionNode");
    alias.put("AwaitExprNode", "AwaitExpressionNode");
    alias.put("TypeCastExprNode", "TypeCastNode");
    alias.put("TypeConversionExprNode", "TypeConversionNode");
    alias.put("UnaryExprNode", "UnaryExpressionNode");
    alias.put("RestArgsExprNode", "RestArgsNode");
    alias.put("NamedArgsExprNode", "NamedArgNode");
    alias.put("MatchExpressionPatternClauseNode", "MatchExpressionNode");
    alias.put("MatchPatternClauseNode", "MatchStatementPatternNode");
    alias.put("TryNode", "TryCatchFinallyNode");
    alias.put("VariableDefNode", "VariableDefinitionNode");
    alias.put("UnionTypeNodeNode", "UnionTypeNode");
    alias.put("TupleTypeNodeNode", "TupleTypeNode");
    alias.put("EndpointTypeNode", "UserDefinedTypeNode");
    alias.put("StreamingQueryNode", "StreamingQueryStatementNode");
    alias.put("WithinNode", "WithinClause");
    alias.put("PatternClauseNode", "PatternClause");
    alias.put("ElvisExprNode", "ElvisExpressionNode");
    alias.put("CheckExprNode", "CheckedExpressionNode");
    alias.put("RecordLiteralExprNode", "RecordLiteralNode");
    alias.put("TypeDefinitionNode", "TypeDefinition");

    alias.put("EnumeratorNode", "");
    alias.put("RecordLiteralKeyValueNode", "");
    alias.put("TableNode", "");
    alias.put("XmlnsNode", "");
    alias.put("IsAssignableExprNode", "");
    alias.put("XmlQnameNode", "");
    alias.put("XmlAttributeNode", "");
    alias.put("XmlAttributeAccessExprNode", "");
    alias.put("XmlQuotedStringNode", "");
    alias.put("XmlElementLiteralNode", "");
    alias.put("XmlTextLiteralNode", "");
    alias.put("XmlCommentLiteralNode", "");
    alias.put("XmlPiLiteralNode", "");
    alias.put("XmlSequenceLiteralNode", "");
    alias.put("TableQueryExpressionNode", "");
    alias.put("NextNode", "");
    alias.put("TransformNode", "");
    alias.put("StreamNode", "");
    alias.put("FiniteTypeNodeNode", "");
    alias.put("BuiltInRefTypeNode", "");
    alias.put("StreamingInputNode", "");
    alias.put("JoinStreamingInputNode", "");
    alias.put("TableQueryNode", "");
    alias.put("SetAssignmentClauseNode", "");
    alias.put("SetNode", "");
    alias.put("QueryNode", "");
    alias.put("StreamingQueryDeclarationNode", "");

    List<Class<?>> list = ModelGenerator.find("org.ballerinalang.model.tree");

    NodeKind[] nodeKinds = NodeKind.class.getEnumConstants();
    JsonObject nodes = new JsonObject();
    for (NodeKind node : nodeKinds) {
        String nodeKind = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, node.toString());
        String nodeClassName = nodeKind + "Node";
        try {/*from  w w w . j a v a  2  s  .  c o  m*/
            String actualClassName = (alias.get(nodeClassName) != null) ? alias.get(nodeClassName)
                    : nodeClassName;
            Class<?> clazz = list.stream()
                    .filter(nodeClass -> nodeClass.getSimpleName().equals(actualClassName)).findFirst().get();

            JsonObject nodeObj = new JsonObject();
            nodeObj.addProperty("kind", nodeKind);
            nodeObj.addProperty("name", nodeClassName);
            nodeObj.addProperty("fileName", CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, nodeClassName));
            JsonArray attr = new JsonArray();
            JsonArray bools = new JsonArray();
            JsonArray imports = new JsonArray();
            List<String> parents = Arrays.asList(clazz.getInterfaces()).stream()
                    .map(parent -> parent.getSimpleName()).collect(Collectors.toList());

            // tag object with supper type
            if (parents.contains("StatementNode")) {
                nodeObj.addProperty("isStatement", true);
                JsonObject imp = new JsonObject();
                imp.addProperty("returnType", "StatementNode");
                imp.addProperty("returnTypeFile", "statement-node");
                imports.add(imp);
            } else {
                nodeObj.addProperty("isStatement", false);
            }

            if (parents.contains("ExpressionNode")) {
                nodeObj.addProperty("isExpression", true);
                JsonObject imp = new JsonObject();
                imp.addProperty("returnType", "ExpressionNode");
                imp.addProperty("returnTypeFile", "expression-node");
                imports.add(imp);
            } else {
                nodeObj.addProperty("isExpression", false);
            }

            if (!parents.contains("StatementNode") && !parents.contains("ExpressionNode")) {
                JsonObject imp = new JsonObject();
                imp.addProperty("returnType", "Node");
                imp.addProperty("returnTypeFile", "node");
                imports.add(imp);
            }

            Method[] methods = clazz.getMethods();
            for (Method m : methods) {
                String methodName = m.getName();
                if ("getKind".equals(methodName) || "getWS".equals(methodName)
                        || "getPosition".equals(methodName)) {
                    continue;
                }
                if (methodName.startsWith("get")) {
                    JsonObject attribute = new JsonObject();
                    JsonObject imp = new JsonObject();
                    attribute.addProperty("property", toJsonName(m.getName(), 3));
                    attribute.addProperty("methodSuffix", m.getName().substring(3));
                    attribute.addProperty("list", List.class.isAssignableFrom(m.getReturnType()));
                    attribute.addProperty("isNode", Node.class.isAssignableFrom(m.getReturnType()));
                    if (Node.class.isAssignableFrom(m.getReturnType())) {
                        String returnClass = m.getReturnType().getSimpleName();
                        if (alias.containsValue(m.getReturnType().getSimpleName())) {
                            returnClass = getKindForAliasClass(m.getReturnType().getSimpleName());
                        }
                        imp.addProperty("returnType", returnClass);
                        attribute.addProperty("returnType", returnClass);
                        imp.addProperty("returnTypeFile",
                                CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, returnClass));
                        if (!imports.contains(imp)) {
                            imports.add(imp);
                        }
                    }
                    attr.add(attribute);
                }
                if (methodName.startsWith("is")) {
                    JsonObject attribute = new JsonObject();
                    JsonObject imp = new JsonObject();
                    attribute.addProperty("property", toJsonName(m.getName(), 2));
                    attribute.addProperty("methodSuffix", m.getName().substring(2));
                    attribute.addProperty("list", List.class.isAssignableFrom(m.getReturnType()));
                    attribute.addProperty("isNode", Node.class.isAssignableFrom(m.getReturnType()));
                    if (Node.class.isAssignableFrom(m.getReturnType())) {
                        String returnClass = m.getReturnType().getSimpleName();
                        if (alias.containsValue(m.getReturnType().getSimpleName())) {
                            returnClass = getKindForAliasClass(m.getReturnType().getSimpleName());
                        }
                        imp.addProperty("returnType", returnClass);
                        attribute.addProperty("returnType", returnClass);
                        imp.addProperty("returnTypeFile",
                                CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, returnClass));
                        if (!imports.contains(imp)) {
                            imports.add(imp);
                        }
                    }
                    bools.add(attribute);
                }
            }
            nodeObj.add("attributes", attr);
            nodeObj.add("bools", bools);
            nodeObj.add("imports", imports);
            nodes.add(nodeClassName, nodeObj);
        } catch (NoSuchElementException e) {
            out.println("alias.put(\"" + nodeClassName + "\", \"\");");
        }
    }
    out.println(nodes);
    return nodes;
}

From source file:com.bjond.utilities.MiscUtils.java

/**
 *  <code>fromCamelCaseToLowerHyphen</code> method will convert
 *
 * CamelCase to camel-case (lower hyphen). Works only for ASCII equivalents which is 
 * good enough for keywords and internal strings etcetera
 *
 * @param in a <code>String</code> value
 * @return a <code>String</code> value
 *//* w  ww .ja v  a 2s  . c  om*/

public static String fromCamelCaseToLowerHyphen(@NotNull(message = "in must not be null.") final String in) {
    return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, in);
}

From source file:ninja.pebble.template.TemplateEnginePebble.java

/**
 * Getting an arbitrary Object, put that into the root of the template
 * properties map/*  w w  w  .j a  va2s .c  om*/
 *
 * If you are rendering something like Results.ok().render(new MyObject())
 * Assume MyObject has a public String name field.
 *
 * You can then access the fields in the template like that:
 * {myObject.publicField}
 *
 */
private Map createTemplatePropertiesMapAndInsert(Object renderableResult) {

    String realClassNameLowerCamelCase = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL,
            renderableResult.getClass().getSimpleName());

    Map map = Maps.newHashMap();
    map.put(realClassNameLowerCamelCase, renderableResult);

    return map;
}

From source file:org.knight.examples.guava.strings.StringsExamples.java

private void caseFormat() {
    String s1 = "CamelNamingRule";
    //return camel-naming-rule
    log("convert to LOWER_HYPHEN: " + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, s1));

    String s2 = "HYPHEN-Naming-Rule";
    //use Converter interface to convert hyphen style to underscore style
    //the source format does not conform to the assumed format
    //so the behavior of this method is undefined
    //this Converter.convert() actually calls CaseFormat.to() method in the last step
    log("convert to LOWER_UNDERSCORE: "
            + CaseFormat.LOWER_HYPHEN.converterTo(CaseFormat.LOWER_UNDERSCORE).convert(s2));
}

From source file:com.torodb.packaging.config.util.DescriptionFactoryWrapper.java

private void document(JsonPointer propPointer, BeanProperty prop) {
    JavaType type = prop.getType();/*from   w  w  w  .j a  v  a  2 s . c  om*/

    if (hasDescription(prop) && !isPrimitive(type) && !type.isEnumType() && !type.isMapLikeType()) {
        console.println("");
    } else if (isPrimitive(type) || type.isEnumType()) {
        printTabs();
        console.print(propPointer.toString());
        console.print("=");
    } else if (type.isMapLikeType()) {
        printTabs();
        console.print(propPointer.append(JsonPointer.compile("/<string>")).toString());
        console.print("=");
        type = type.getContentType();
    }

    if (isPrimitive(type)) {
        console.print("<");
        console.print(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, type.getRawClass().getSimpleName()));
        console.print(">");
    } else if (type.isEnumType()) {
        console.print("<enum:string>");
    }

    if (hasDescription(prop) && !isPrimitive(type) && !type.isEnumType()) {
        printTabs();
    }

    printDescription(prop);

    if (hasDescription(prop) || isPrimitive(type) || type.isEnumType()) {
        console.println("");
    }

    if (hasDescription(prop) && !isPrimitive(type) && !type.isEnumType()) {
        console.println("");
    }

    if (type.isEnumType()) {
        for (Field enumField : type.getRawClass().getDeclaredFields()) {
            if (!enumField.isEnumConstant()) {
                continue;
            }

            printTabs();
            console.print(" - ");
            console.print(enumField.getName());

            Description enumConstantConfigProperty = enumField.getAnnotation(Description.class);
            if (enumConstantConfigProperty != null && enumConstantConfigProperty.value() != null) {
                console.print(" # ");
                console.print(resourceBundle.getString(enumConstantConfigProperty.value()));
            }

            console.println("");
        }
    }
}

From source file:com.torodb.config.util.DescriptionFactoryWrapper.java

private void document(JsonPointer propPointer, BeanProperty prop) {
    JavaType type = prop.getType();//from w  w  w.  ja  v  a  2  s .  c o m

    if (hasDescription(prop) && !isPrimitive(type) && !type.isEnumType() && !type.isMapLikeType()) {
        console.println("");
    } else if (isPrimitive(type) || type.isEnumType()) {
        printTabs();
        console.print(propPointer.toString());
        console.print("=");
    } else if (type.isMapLikeType()) {
        printTabs();
        console.print(propPointer.append(JsonPointer.compile("/<string>")).toString());
        console.print("=");
        type = type.getContentType();
    }

    if (isPrimitive(type)) {
        console.print("<");
        console.print(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, type.getRawClass().getSimpleName()));
        console.print(">");
    } else if (type.isEnumType()) {
        console.print("<enum:string>");
    }

    if (hasDescription(prop) && !isPrimitive(type) && !type.isEnumType()) {
        printTabs();
    }

    printDescription(prop);

    if (hasDescription(prop) || isPrimitive(type) || type.isEnumType()) {
        console.println("");
    }

    if (hasDescription(prop) && !isPrimitive(type) && !type.isEnumType()) {
        console.println("");
    }

    if (type.isEnumType()) {
        for (Field enumField : type.getRawClass().getDeclaredFields()) {
            if (!enumField.isEnumConstant()) {
                continue;
            }

            printTabs();
            console.print(" - ");
            console.print(enumField.getName());

            Description enumConstantConfigProperty = enumField.getAnnotation(Description.class);
            if (enumConstantConfigProperty != null && enumConstantConfigProperty.value() != null) {
                console.print(" # ");
                console.print(enumConstantConfigProperty.value());
            }

            console.println("");
        }
    }
}