Example usage for com.google.common.base CaseFormat UPPER_UNDERSCORE

List of usage examples for com.google.common.base CaseFormat UPPER_UNDERSCORE

Introduction

In this page you can find the example usage for com.google.common.base CaseFormat UPPER_UNDERSCORE.

Prototype

CaseFormat UPPER_UNDERSCORE

To view the source code for com.google.common.base CaseFormat UPPER_UNDERSCORE.

Click Source Link

Document

Java and C++ constant naming convention, e.g., "UPPER_UNDERSCORE".

Usage

From source file:fr.zcraft.zlib.components.rawtext.RawText.java

static public String getI18nKey(Achievement achievement) {
    String key = ACHIEVEMENTS_NAMES.get(achievement);

    if (key == null) {
        key = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, achievement.name());
        ACHIEVEMENTS_NAMES.put(achievement, key);
    }/*from   www  .  ja  v  a 2 s.c  o m*/

    return key;
}

From source file:io.soliton.protobuf.json.Messages.java

private static Object parseField(Descriptors.FieldDescriptor field, JsonElement value,
        Message.Builder enclosingBuilder) throws Exception {
    switch (field.getType()) {
    case DOUBLE://from   w  w w.j  a v  a 2  s .c  om
        if (!value.isJsonPrimitive()) {
            // fail;
        }
        return value.getAsDouble();
    case FLOAT:
        if (!value.isJsonPrimitive()) {
            // fail;
        }
        return value.getAsFloat();
    case INT64:
    case UINT64:
    case FIXED64:
    case SINT64:
    case SFIXED64:
        if (!value.isJsonPrimitive()) {
            // fail
        }
        return value.getAsLong();
    case INT32:
    case UINT32:
    case FIXED32:
    case SINT32:
    case SFIXED32:
        if (!value.isJsonPrimitive()) {
            // fail
        }
        return value.getAsInt();
    case BOOL:
        if (!value.isJsonPrimitive()) {
            // fail
        }
        return value.getAsBoolean();
    case STRING:
        if (!value.isJsonPrimitive()) {
            // fail
        }
        return value.getAsString();
    case GROUP:
    case MESSAGE:
        if (!value.isJsonObject()) {
            // fail
        }
        return fromJson(enclosingBuilder.newBuilderForField(field), value.getAsJsonObject());
    case BYTES:
        if (!value.isJsonPrimitive()) {
            // fail
        }
        return ByteString.copyFrom(BaseEncoding.base64().decode(value.getAsString()));
    case ENUM:
        if (!value.isJsonPrimitive()) {
            // fail
        }
        String protoEnumValue = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, value.getAsString());
        return field.getEnumType().findValueByName(protoEnumValue);
    }
    return null;
}

From source file:ratpack.server.internal.DefaultServerConfigBuilder.java

@Override
public ServerConfig.Builder env(String prefix) {
    Map<String, String> filteredEnvVars = serverEnvironment.getenv().entrySet().stream()
            .filter(entry -> entry.getKey().startsWith(prefix))
            .collect(Collectors.toMap(entry -> CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL,
                    entry.getKey().replace(prefix, "")), Map.Entry::getValue));
    return props(filteredEnvVars);
}

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

/**
 * @param p the predicate to convert/*from ww w.j av  a  2  s.c o m*/
 * @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: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   ww  w  .  j  a va 2 s.  com*/
            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:org.apache.brooklyn.util.javalang.Enums.java

/** attempts to match the givenValue against the given enum values, first looking for exact matches (against name and toString),
 * then matching ignoring case, /*w  w  w  .  ja va 2s. c  o  m*/
 * then matching with {@link CaseFormat#UPPER_UNDERSCORE} converted to {@link CaseFormat#LOWER_CAMEL},
 * then matching with {@link CaseFormat#LOWER_CAMEL} converted to {@link CaseFormat#UPPER_UNDERSCORE}
 * (including case insensitive matches for the final two)
 **/
public static <T extends Enum<?>> Maybe<T> valueOfIgnoreCase(String contextMessage, T[] enumValues,
        String givenValue) {
    if (givenValue == null)
        return Maybe.absent(new IllegalStateException("Value for " + contextMessage + " must not be null"));
    if (Strings.isBlank(givenValue))
        return Maybe.absent(new IllegalStateException("Value for " + contextMessage + " must not be blank"));

    for (T v : enumValues)
        if (v.name().equals(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (v.toString().equals(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (v.name().equalsIgnoreCase(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (v.toString().equalsIgnoreCase(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, v.name()).equals(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, v.toString()).equals(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, v.name()).equalsIgnoreCase(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, v.toString()).equalsIgnoreCase(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, v.toString()).equalsIgnoreCase(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, v.name()).equals(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, v.toString()).equals(givenValue))
            return Maybe.of(v);
    for (T v : enumValues)
        if (CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, v.name()).equalsIgnoreCase(givenValue))
            return Maybe.of(v);

    return Maybe.absent(new IllegalStateException("Invalid value " + givenValue + " for " + contextMessage));
}

From source file:fr.zcraft.zlib.components.rawtext.RawTextPart.java

private String enumCamel(Enum enumValue) {
    return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, enumValue.toString());
}

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);/*w w  w  .j  a v  a2  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:org.immutables.value.processor.encode.Instantiation.java

private String generateProperName(EncodedElement element) {
    if (element.isImplField()) {
        return names.var;
    }//from   w w w . ja v a  2 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.github.jcustenborder.kafka.connect.utils.config.MarkdownFormatter.java

static String schema(Schema schema) {
    String result;//  ww  w .ja  v a  2s .  co  m
    if (!Strings.isNullOrEmpty(schema.name())) {
        if (Time.LOGICAL_NAME.equals(schema.name())) {
            result = "[Time](https://kafka.apache.org/0102/javadoc/org/apache/kafka/connect/data/Time.html)";
        } else if (Date.LOGICAL_NAME.equals(schema.name())) {
            result = "[Date](https://kafka.apache.org/0102/javadoc/org/apache/kafka/connect/data/Date.html)";
        } else if (Timestamp.LOGICAL_NAME.equals(schema.name())) {
            result = "[Timestamp](https://kafka.apache.org/0102/javadoc/org/apache/kafka/connect/data/Timestamp.html)";
        } else if (Decimal.LOGICAL_NAME.equals(schema.name())) {
            result = "[Decimal](https://kafka.apache.org/0102/javadoc/org/apache/kafka/connect/data/Decimal.html)";
        } else {
            result = String.format("[%s](#%s)", schema.name(), schema.name());
        }
    } else {
        if (Schema.Type.ARRAY == schema.type()) {
            result = String.format("Array of %s", schema(schema.valueSchema()));
        } else if (Schema.Type.MAP == schema.type()) {
            result = String.format("Map of <%s, %s>", schema(schema.keySchema()), schema(schema.valueSchema()));
        } else {
            result = String.format(
                    "[%s](https://kafka.apache.org/0102/javadoc/org/apache/kafka/connect/data/Schema.Type.html#%s)",
                    CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, schema.type().toString()),
                    schema.type());
        }
    }

    return result;
}