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:brooklyn.entity.basic.Lifecycle.java

/**
 * The text representation of the {@link #name()}.
 *
 * This is formatted as lower case characters, with hyphens instead of spaces.
 *//*  ww  w  .j a  va 2  s. com*/
public String value() {
    return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name());
}

From source file:org.jclouds.tools.ant.taskdefs.compute.ComputeTask.java

/**
 * makes a connection to the compute service and invokes
 *///w w  w.ja  v a 2 s.c o  m
public void execute() throws BuildException {
    ComputeServiceContext context = computeMap.get(HttpUtils.createUri(provider));

    try {
        for (String action : Splitter.on(',').split(actions)) {
            Action act = Action.valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, action));
            try {
                invokeActionOnService(act, context.getComputeService());
            } catch (RunNodesException e) {
                throw new BuildException(e);
            } catch (IOException e) {
                throw new BuildException(e);
            }
        }
    } finally {
        context.close();
    }
}

From source file:dynamicrefactoring.domain.Scope.java

/**
 * Obtiene una representacion en formato cadena sin "_" entre palabras y con
 * las palabras en mayusculas del nombre del valor de la enumeracion.
 * //from  ww w.  j a  v a  2s  . co  m
 * @return formato adecuado para impresion del nombre del ambito
 */
@Override
public String toString() {
    return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, super.toString()).replace("_", "");
}

From source file:org.openehr.adl.util.AdlUtils.java

public static String getRmTypeName(@Nonnull Class<?> clazz) {
    return CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, clazz.getSimpleName());
}

From source file:dk.dma.enumgenerator.Generator.java

/**
 * Converts the specified speed from this speed unit to kilometers per hour. For example, to convert 100 meters per
 * second to kilometers per hour: <code>SpeedUnit.METERS_PER_SECOND.toKilometersPerHour(100)</code>.
 *
 * @param speed//w ww.j  a  v a  2s . com
 *            the speed to convert
 * @return the converted speed
 */
public CodegenClass generateEnum() {
    CodegenEnum c = new CodegenEnum();
    c.setPackage("dk.dma.enumgenerator.test");
    c.setDefinition("public enum " + unit.name + "Unit");

    for (Val v : unit.vals.values()) {
        String enumName = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, v.name);

        CodegenEnumConstant e = c.newConstant(enumName);
        if (v.description != null) {
            e.javadoc().set(v.description);
        }
        for (Val va : unit.vals.values()) {
            CodegenMethod m = e.newMethod("public double to", va.name, "(", unit.type(), " ", this.v, ")");
            if (v == va) {
                m.add("return ", this.v, ";");
            } else {
                boolean found = false;
                for (Conversion co : unit.conversions) {
                    if (co.from == v && co.to == va) {
                        String ex = co.expression.replace("x", this.v);
                        String val = "return " + ex + ";";
                        m.add(val);
                        found = true;
                    }
                }
                if (!found) {
                    m.throwNewUnsupportedOperationException("NotImplementedYet");
                }
            }
        }

        // 32 c toFahrenheit
        // Celcius
    }

    for (Val v : unit.vals.values()) {
        CodegenMethod m = c.addMethod("public abstract double to", v.name, "(", unit.type(), " ", this.v, ")");
        // 32 c toFahrenheit
        // Celcius
    }

    return c;
}

From source file:org.jclouds.azure.management.domain.InstanceStatus.java

public static InstanceStatus fromValue(String type) {
    try {//from   www.jav a 2  s .c o m
        return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(type, "type")));
    } catch (IllegalArgumentException e) {
        return ROLE_STATE_UNKNOWN;
    }
}

From source file:org.talend.components.service.rest.impl.ControllersConfiguration.java

/**
 * Initialise Web binders to be able to use {@link PropertyTrigger} in camel case in {@link PathVariable}.
 *//*from w w w  .j  a v a 2  s  .  c o m*/
@InitBinder
protected void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(PropertyTrigger.class, new PropertyEditorSupport() {

        @Override
        public void setAsText(String text) throws IllegalArgumentException {
            String upperUnderscoreCased = CaseFormat.LOWER_CAMEL.converterTo(CaseFormat.UPPER_UNDERSCORE)
                    .convert(text);
            PropertyTrigger propertyTrigger = PropertyTrigger.valueOf(upperUnderscoreCased);
            setValue(propertyTrigger);
        }
    });
    binder.registerCustomEditor(DefinitionType.class, new DefinitionTypeConverter());
    binder.registerCustomEditor(ConnectorTypology.class, new ConnectorTypologyConverter());
}

From source file:com.github.jcustenborder.kafka.connect.cdc.SchemaGenerator.java

private static CaseFormat caseFormat(CDCSourceConnectorConfig.CaseFormat inputCaseFormat) {
    CaseFormat inputFormat;//from w  w  w .  j av a  2  s . c o m
    switch (inputCaseFormat) {
    case LOWER_CAMEL:
        inputFormat = CaseFormat.LOWER_CAMEL;
        break;
    case LOWER_HYPHEN:
        inputFormat = CaseFormat.LOWER_HYPHEN;
        break;
    case LOWER_UNDERSCORE:
        inputFormat = CaseFormat.LOWER_UNDERSCORE;
        break;
    case UPPER_CAMEL:
        inputFormat = CaseFormat.UPPER_CAMEL;
        break;
    case UPPER_UNDERSCORE:
        inputFormat = CaseFormat.UPPER_UNDERSCORE;
        break;
    default:
        throw new UnsupportedOperationException(
                String.format("'%s' is not a supported case format.", inputCaseFormat));
    }
    return inputFormat;
}

From source file:org.ow2.proactive.scheduling.api.graphql.fetchers.JobDataFetcher.java

@Override
protected Stream<Job> dataMapping(Stream<JobData> dataStream) {
    return dataStream.map(jobData -> Job.builder()
            .dataManagement(DataManagement.builder().globalSpaceUrl(jobData.getGlobalSpace())
                    .inputSpaceUrl(jobData.getInputSpace()).outputSpaceUrl(jobData.getOutputSpace())
                    .userSpaceUrl(jobData.getUserSpace()).build())
            .description(jobData.getDescription()).finishedTime(jobData.getFinishedTime())
            .genericInformation(jobData.getGenericInformation()).id(jobData.getId())
            .inErrorTime(jobData.getInErrorTime()).lastUpdatedTime(jobData.getLastUpdatedTime())
            .maxNumberOfExecution(jobData.getMaxNumberOfExecution()).name(jobData.getJobName())
            .numberOfFailedTasks(jobData.getNumberOfFailedTasks())
            .numberOfFaultyTasks(jobData.getNumberOfFaultyTasks())
            .numberOfFinishedTasks(jobData.getNumberOfFinishedTasks())
            .numberOfInErrorTasks(jobData.getNumberOfInErrorTasks())
            .numberOfPendingTasks(jobData.getNumberOfPendingTasks())
            .numberOfRunningTasks(jobData.getNumberOfRunningTasks())
            .onTaskError(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, jobData.getOnTaskErrorString()))
            .owner(jobData.getOwner()).priority(jobData.getPriority().name())
            .projectName(jobData.getProjectName()).removedTime(jobData.getRemovedTime())
            .status(jobData.getStatus().name()).startTime(jobData.getStartTime())
            .submittedTime(jobData.getSubmittedTime()).totalNumberOfTasks(jobData.getTotalNumberOfTasks())
            // TODO Currently map the JobVariable object to a simple string (its value).
            // Need to map the whole object later
            .variables(getVariables(jobData)).build());
}

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

public static JsonObject getContext() {
    // Set alias for the classes
    alias.put("ImportNode", "ImportPackageNode");
    alias.put("RecordLiteralKeyValueNode", "RecordKeyValueNode");
    alias.put("XmlnsNode", "XMLNSDeclarationNode");
    alias.put("ArrayLiteralExprNode", "ArrayLiteralNode");
    alias.put("BinaryExprNode", "BinaryExpressionNode");
    alias.put("ConnectorInitExprNode", "ConnectorInitNode");
    alias.put("FieldBasedAccessExprNode", "FieldBasedAccessNode");
    alias.put("IndexBasedAccessExprNode", "IndexBasedAccessNode");
    alias.put("LambdaNode", "LambdaFunctionNode");
    alias.put("RecordLiteralExprNode", "RecordLiteralNode");
    alias.put("SimpleVariableRefNode", "SimpleVariableReferenceNode");
    alias.put("TernaryExprNode", "TernaryExpressionNode");
    alias.put("TypeCastExprNode", "TypeCastNode");
    alias.put("TypeConversionExprNode", "TypeConversionNode");
    alias.put("UnaryExprNode", "UnaryExpressionNode");
    alias.put("XmlAttributeNode", "XMLAttributeNode");
    alias.put("XmlCommentLiteralNode", "XMLCommentLiteralNode");
    alias.put("XmlElementLiteralNode", "XMLElementLiteralNode");
    alias.put("XmlPiLiteralNode", "XMLProcessingInstructionLiteralNode");
    alias.put("XmlQnameNode", "XMLQNameNode");
    alias.put("XmlQuotedStringNode", "XMLQuotedStringNode");
    alias.put("XmlTextLiteralNode", "XMLTextLiteralNode");
    alias.put("TryNode", "TryCatchFinallyNode");
    alias.put("VariableDefNode", "VariableDefinitionNode");
    alias.put("BuiltInRefTypeNode", "BuiltInReferenceTypeNode");
    alias.put("EnumeratorNode", "EnumNode");

    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 www.j av  a2s . 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;
}