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:com.google.api.codegen.util.Name.java

private String toCamel(CaseFormat caseFormat) {
    StringBuffer buffer = new StringBuffer();
    boolean firstPiece = true;
    for (NamePiece namePiece : namePieces) {
        if (firstPiece && caseFormat.equals(CaseFormat.LOWER_CAMEL)) {
            buffer.append(namePiece.caseFormat.to(CaseFormat.LOWER_CAMEL, namePiece.identifier));
        } else {/*from  w  w  w  .  j  av a  2  s.  c  o m*/
            CaseFormat toCaseFormat = CaseFormat.UPPER_CAMEL;
            if (namePiece.casingMode.equals(CasingMode.UPPER_CAMEL_TO_SQUASHED_UPPERCASE)) {
                toCaseFormat = CaseFormat.UPPER_UNDERSCORE;
            }
            buffer.append(namePiece.caseFormat.to(toCaseFormat, namePiece.identifier));
        }
        firstPiece = false;
    }
    return buffer.toString();
}

From source file:eu.supersede.dynadapt.aom.dsl.resources.constants.AbstractUMLPackageConstant.java

protected static String toConstantName(String name) {
    return CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, name).replaceAll("__", "_");
}

From source file:org.gaul.s3proxy.S3ErrorCode.java

private S3ErrorCode(int httpStatusCode, String message) {
    this.errorCode = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
    this.httpStatusCode = httpStatusCode;
    this.message = requireNonNull(message);
}

From source file:com.palantir.typescript.text.reconciler.PresentationReconciler.java

private static Color getForegroundColor(TokenClass classification) {
    String camelClassificationName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL,
            classification.name());//from www . j a v  a 2s . co m
    String preferenceName = "syntaxColoring." + camelClassificationName + ".color";
    String colorString = TypeScriptPlugin.getDefault().getPreferenceStore().getString(preferenceName);

    if (!colorString.isEmpty()) {
        RGB rgb = StringConverter.asRGB(colorString);

        return COLORS.getUnchecked(rgb);
    }

    return null;
}

From source file:com.jedi.metadata.DatabaseMetadataUtil.java

public static CustomTypeInfo getCustomType(Connection connection, String owner, String typeName)
        throws SQLException {
    CustomTypeInfo customTypeInfo = null;
    String sql = "SELECT OWNER," + "       TYPE_NAME," + "       TYPECODE," + "       TYPE_OID"
            + "  FROM ALL_TYPES" + " WHERE OWNER = '" + owner + "' AND TYPE_NAME = '" + typeName + "'";
    Statement statement = connection.createStatement();
    ResultSet resultSet = statement.executeQuery(sql);
    resultSet.next();//w w  w. j  ava2s  .  c o  m
    customTypeInfo = new CustomTypeInfo();
    customTypeInfo.setOwner(resultSet.getString("OWNER"));
    customTypeInfo.setName(resultSet.getString("TYPE_NAME"));
    String objectType = resultSet.getString("TYPECODE");
    customTypeInfo.setObjectType(objectType);
    customTypeInfo.setIsCollection("COLLECTION".equals(objectType));
    if (customTypeInfo.isIsCollection()) {
        sql = "SELECT COLL_TYPE, ELEM_TYPE_OWNER, ELEM_TYPE_NAME" + "  FROM ALL_COLL_TYPES"
                + " WHERE ELEM_TYPE_OWNER = '" + owner + "'" + "       AND TYPE_NAME = '" + typeName + "'";
        statement = connection.createStatement();
        resultSet = statement.executeQuery(sql);
        resultSet.next();
        customTypeInfo.setCollectionType(resultSet.getString("COLL_TYPE"));
        typeName = resultSet.getString("ELEM_TYPE_NAME");
        customTypeInfo.setCollectionElementType(typeName);
        owner = resultSet.getString("ELEM_TYPE_OWNER");
        customTypeInfo.setCollectionElementTypeOwner(owner);
    }

    sql = "SELECT OWNER," + "         ATTR_NAME," + "         ATTR_TYPE_OWNER," + "         ATTR_TYPE_NAME,"
            + "         LENGTH," + "         PRECISION," + "         SCALE," + "         ATTR_NO"
            + "    FROM ALL_TYPE_ATTRS" + "   WHERE OWNER = '" + owner + "' AND TYPE_NAME = '" + typeName + "'"
            + "ORDER BY ATTR_NO";
    statement = connection.createStatement();
    resultSet = statement.executeQuery(sql);
    while (resultSet.next()) {
        CustomTypeArgumentInfo customTypeArgumentInfo = new CustomTypeArgumentInfo();
        String argumentName = resultSet.getString("ATTR_NAME");
        customTypeArgumentInfo.setName(argumentName);
        customTypeArgumentInfo.setOwner(resultSet.getString("OWNER"));
        String dataType = resultSet.getString("ATTR_TYPE_NAME");
        if (dataType != null && !dataType.isEmpty()) {
            dataType = dataType.toUpperCase();
            customTypeArgumentInfo.setDataType(dataType);
        }

        String dataTypeOwner = resultSet.getString("ATTR_TYPE_OWNER");
        customTypeArgumentInfo.setDataTypeOwner(dataTypeOwner);
        customTypeArgumentInfo.setPosition(resultSet.getInt("ATTR_NO"));
        customTypeArgumentInfo.setLength(resultSet.getInt("LENGTH"));
        customTypeArgumentInfo.setPrecision(resultSet.getInt("PRECISION"));
        customTypeArgumentInfo.setScale(resultSet.getInt("SCALE"));

        if (dataTypeOwner != null && !dataTypeOwner.isEmpty()) {
            customTypeArgumentInfo.setIsCustomObject(true);
        }

        customTypeInfo.getArguments().add(customTypeArgumentInfo);

        if (argumentName != null && !argumentName.isEmpty()) {
            argumentName = argumentName.toUpperCase();
            if (argumentName.startsWith("P_")) {
                argumentName = argumentName.substring(2);
            }
            String fieldName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, argumentName);
            customTypeArgumentInfo.setFieldName(fieldName);

            String javaType = getJavaType(dataType);
            customTypeArgumentInfo.setFieldType(javaType);

        }
    }

    return customTypeInfo;
}

From source file:org.rakam.client.builder.document.SlateDocumentGenerator.java

private MarkdownBuilder generateApiTags(MarkdownBuilder markdownBuilder) {
    if (!swagger.getTags().isEmpty()) {
        Map<String, Tag> tags = swagger.getTags().stream()
                .collect(Collectors.toMap(t -> t.getName().toLowerCase(), Function.identity()));
        Set<String> nonOrderedTags = new HashSet<>(tags.keySet());
        nonOrderedTags.removeAll(tagsOrder);
        Stream.concat(tagsOrder.stream(), nonOrderedTags.stream()).forEachOrdered(tagName -> {
            Tag tag = tags.get(tagName.toLowerCase());
            if (tag == null) {
                LOGGER.warn("tag not found:" + tagName);
            } else {
                String name = tag.getName();
                String description = tag.getDescription();
                markdownBuilder.documentTitle(
                        CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name.replaceAll("-", " ")))
                        .newLine().textLine(description).newLine();
                processOperation(markdownBuilder, name);
            }/*from  w w w . ja  v a  2  s .  c  o m*/
        });
        markdownBuilder.newLine();
    }
    return markdownBuilder;
}

From source file:org.ballerinalang.composer.service.workspace.rest.datamodel.BLangFileRestService.java

public static JsonElement generateJSON(Node node, Map<String, Node> anonStructs)
        throws InvocationTargetException, IllegalAccessException {
    if (node == null) {
        return JsonNull.INSTANCE;
    }/*w  ww .j  av  a  2s .  c  om*/
    Set<Method> methods = ClassUtils.getAllInterfaces(node.getClass()).stream()
            .flatMap(aClass -> Arrays.stream(aClass.getMethods())).collect(Collectors.toSet());
    JsonObject nodeJson = new JsonObject();

    JsonArray wsJsonArray = new JsonArray();
    Set<Whitespace> ws = node.getWS();
    if (ws != null && !ws.isEmpty()) {
        for (Whitespace whitespace : ws) {
            JsonObject wsJson = new JsonObject();
            wsJson.addProperty("ws", whitespace.getWs());
            wsJson.addProperty("i", whitespace.getIndex());
            wsJson.addProperty("text", whitespace.getPrevious());
            wsJson.addProperty("static", whitespace.isStatic());
            wsJsonArray.add(wsJson);
        }
        nodeJson.add("ws", wsJsonArray);
    }
    Diagnostic.DiagnosticPosition position = node.getPosition();
    if (position != null) {
        JsonObject positionJson = new JsonObject();
        positionJson.addProperty("startColumn", position.getStartColumn());
        positionJson.addProperty("startLine", position.getStartLine());
        positionJson.addProperty("endColumn", position.getEndColumn());
        positionJson.addProperty("endLine", position.getEndLine());
        nodeJson.add("position", positionJson);
    }

    /* Virtual props */

    JsonArray type = getType(node);
    if (type != null) {
        nodeJson.add(SYMBOL_TYPE, type);
    }
    if (node.getKind() == NodeKind.INVOCATION) {
        assert node instanceof BLangInvocation : node.getClass();
        BLangInvocation invocation = (BLangInvocation) node;
        if (invocation.symbol != null && invocation.symbol.kind != null) {
            nodeJson.addProperty(INVOCATION_TYPE, invocation.symbol.kind.toString());
        }
    }

    for (Method m : methods) {
        String name = m.getName();

        if (name.equals("getWS") || name.equals("getPosition")) {
            continue;
        }

        String jsonName;
        if (name.startsWith("get")) {
            jsonName = toJsonName(name, 3);
        } else if (name.startsWith("is")) {
            jsonName = toJsonName(name, 2);
        } else {
            continue;
        }

        Object prop = m.invoke(node);

        /* Literal class - This class is escaped in backend to address cases like "ss\"" and 8.0 and null */
        if (node.getKind() == NodeKind.LITERAL && "value".equals(jsonName)) {
            if (prop instanceof String) {
                nodeJson.addProperty(jsonName, '"' + StringEscapeUtils.escapeJava((String) prop) + '"');
                nodeJson.addProperty(UNESCAPED_VALUE, String.valueOf(prop));
            } else {
                nodeJson.addProperty(jsonName, String.valueOf(prop));
            }
            continue;
        }

        if (node.getKind() == NodeKind.USER_DEFINED_TYPE && jsonName.equals("typeName")) {
            IdentifierNode typeNode = (IdentifierNode) prop;
            Node structNode;
            if (typeNode.getValue().startsWith("$anonStruct$")
                    && (structNode = anonStructs.remove(typeNode.getValue())) != null) {
                JsonObject anonStruct = generateJSON(structNode, anonStructs).getAsJsonObject();
                anonStruct.addProperty("anonStruct", true);
                nodeJson.add("anonStruct", anonStruct);
                continue;
            }
        }

        if (prop instanceof List && jsonName.equals("types")) {
            // Currently we don't need any Symbols for the UI. So skipping for now.
            continue;
        }

        /* Node classes */
        if (prop instanceof Node) {
            nodeJson.add(jsonName, generateJSON((Node) prop, anonStructs));
        } else if (prop instanceof List) {
            List listProp = (List) prop;
            JsonArray listPropJson = new JsonArray();
            nodeJson.add(jsonName, listPropJson);
            for (Object listPropItem : listProp) {
                if (listPropItem instanceof Node) {
                    /* Remove top level anon func and struct */
                    if (node.getKind() == NodeKind.COMPILATION_UNIT) {
                        if (listPropItem instanceof BLangStruct && ((BLangStruct) listPropItem).isAnonymous) {
                            anonStructs.put(((BLangStruct) listPropItem).getName().getValue(),
                                    ((BLangStruct) listPropItem));
                            continue;
                        }
                        if (listPropItem instanceof BLangFunction
                                && (((BLangFunction) listPropItem)).name.value.startsWith("$lambda$")) {
                            continue;
                        }
                    }
                    listPropJson.add(generateJSON((Node) listPropItem, anonStructs));
                } else {
                    logger.debug("Can't serialize " + jsonName + ", has a an array of " + listPropItem);
                }
            }

            /* Runtime model classes */
        } else if (prop instanceof Set && jsonName.equals("flags")) {
            Set flags = (Set) prop;
            for (Flag flag : Flag.values()) {
                nodeJson.addProperty(StringUtils.lowerCase(flag.toString()), flags.contains(flag));
            }
        } else if (prop instanceof Set) {
            // TODO : limit this else if to getInputs getOutputs of transform.
            Set vars = (Set) prop;
            JsonArray listVarJson = new JsonArray();
            nodeJson.add(jsonName, listVarJson);
            for (Object obj : vars) {
                listVarJson.add(obj.toString());
            }
        } else if (prop instanceof NodeKind) {
            String kindName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, prop.toString());
            nodeJson.addProperty(jsonName, kindName);
        } else if (prop instanceof OperatorKind) {
            nodeJson.addProperty(jsonName, prop.toString());

            /* Generic classes */
        } else if (prop instanceof String) {
            nodeJson.addProperty(jsonName, (String) prop);
        } else if (prop instanceof Number) {
            nodeJson.addProperty(jsonName, (Number) prop);
        } else if (prop instanceof Boolean) {
            nodeJson.addProperty(jsonName, (Boolean) prop);
        } else if (prop instanceof Enum) {
            nodeJson.addProperty(jsonName, StringUtils.lowerCase(((Enum) prop).name()));
        } else if (prop != null) {
            nodeJson.addProperty(jsonName, prop.toString());
            String message = "Node " + node.getClass().getSimpleName() + " contains unknown type prop: "
                    + jsonName + " of type " + prop.getClass();
            logger.error(message);
        }
    }
    return nodeJson;
}

From source file:com.aitorvs.autoparcel.internal.codegen.AutoParcelProcessor.java

private ImmutableMap<TypeMirror, FieldSpec> getTypeAdapters(ImmutableList<Property> properties) {
    Map<TypeMirror, FieldSpec> typeAdapters = new LinkedHashMap<>();
    NameAllocator nameAllocator = new NameAllocator();
    nameAllocator.newName("CREATOR");
    for (Property property : properties) {
        if (property.typeAdapter != null && !typeAdapters.containsKey(property.typeAdapter)) {
            ClassName typeName = (ClassName) TypeName.get(property.typeAdapter);
            String name = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, typeName.simpleName());
            name = nameAllocator.newName(name, typeName);

            typeAdapters.put(property.typeAdapter,
                    FieldSpec.builder(typeName, NameAllocator.toJavaIdentifier(name), PRIVATE, STATIC, FINAL)
                            .initializer("new $T()", typeName).build());
        }//from   w w w.  ja  v  a2  s  .  c  o m
    }
    return ImmutableMap.copyOf(typeAdapters);
}

From source file:com.attribyte.relay.wp.WPSupplier.java

@Override
public void init(final Properties props, final Optional<ByteString> savedState, final Logger logger)
        throws Exception {

    if (isInit.compareAndSet(false, true)) {

        this.logger = logger;

        logger.info("Initializing WP supplier...");

        final long siteId = Long.parseLong(props.getProperty("siteId", "0"));
        if (siteId < 1L) {
            throw new Exception("A 'siteId' must be specified");
        }/*from w  w  w . j a  v a2 s  . com*/

        final Set<String> cachedTaxonomies = ImmutableSet.of(TAG_TAXONOMY, CATEGORY_TAXONOMY);
        final Duration taxonomyCacheTimeout = Duration.ofMinutes(30); //TODO: Configure
        final Duration userCacheTimeout = Duration.ofMinutes(30); //TODO: Configure
        initPools(props, logger);
        this.db = new DB(defaultConnectionPool, siteId, cachedTaxonomies, taxonomyCacheTimeout,
                userCacheTimeout);

        Properties siteProps = new InitUtil("site.", props, false).getProperties();
        Site overrideSite = new Site(siteProps);
        this.site = this.db.selectSite().overrideWith(overrideSite);

        logger.info(
                String.format("Initialized site %d - %s", this.site.id, Strings.nullToEmpty(this.site.title)));

        if (savedState.isPresent()) {
            startMeta = PostMeta.fromBytes(savedState.get());
        } else {
            startMeta = PostMeta.ZERO;
        }

        this.selectSleepMillis = Integer.parseInt(props.getProperty("selectSleepMillis", "30000"));

        this.selectAll = props.getProperty("selectAll", "false").equalsIgnoreCase("true");
        if (this.selectAll) {
            this.stopId = this.db.selectMaxPostId();
        } else {
            this.stopId = 0L;
        }

        String supplyIdsFileStr = props.getProperty("supplyIdsFile", "");
        if (!supplyIdsFileStr.isEmpty()) {
            this.selectAll = true;
            File supplyIdsFile = new File(supplyIdsFileStr);
            logger.info(String.format("Using 'supplyIdsFile', '%s'", supplyIdsFile.getAbsolutePath()));
            this.supplyIds = Lists.newArrayListWithExpectedSize(1024);
            List<String> lines = Files.readLines(supplyIdsFile, Charsets.UTF_8);
            for (String line : lines) {
                line = line.trim();
                if (line.isEmpty() || line.startsWith("#")) {
                    continue;
                }
                Long id = Longs.tryParse(line);
                if (id != null) {
                    this.supplyIds.add(id);
                    logger.info(String.format("Adding supplied id, '%d'", id));
                }
            }

        } else {
            this.supplyIds = null;
        }

        this.maxSelected = Integer.parseInt(props.getProperty("maxSelected", "500"));

        String allowedStatusStr = props.getProperty("allowedStatus", "").trim();
        if (!allowedStatusStr.isEmpty()) {
            if (allowedStatusStr.equalsIgnoreCase("all")) {
                this.allowedStatus = ALL_STATUS;
            } else {
                this.allowedStatus = ImmutableSet
                        .copyOf(Splitter.on(',').omitEmptyStrings().splitToList(allowedStatusStr).stream()
                                .map(Post.Status::fromString).collect(Collectors.toSet()));
            }
        } else {
            this.allowedStatus = DEFAULT_ALLOWED_STATUS;
        }

        String allowedTypesStr = props.getProperty("allowedTypes", "").trim();
        if (!allowedStatusStr.isEmpty()) {
            this.allowedTypes = ImmutableSet
                    .copyOf(Splitter.on(',').omitEmptyStrings().splitToList(allowedTypesStr)).stream()
                    .map(Post.Type::fromString).collect(Collectors.toSet());
        } else {
            this.allowedTypes = DEFAULT_ALLOWED_TYPES;
        }

        String allowedPostMetaStr = props.getProperty("allowedPostMeta", "").trim();
        if (!allowedPostMetaStr.isEmpty()) {
            this.allowedPostMeta = ImmutableSet
                    .copyOf(Splitter.on(',').omitEmptyStrings().splitToList(allowedPostMetaStr));
        } else {
            this.allowedPostMeta = ImmutableSet.of();
        }

        String allowedImageMetaStr = props.getProperty("allowedImageMeta", "").trim();
        if (!allowedImageMetaStr.isEmpty()) {
            this.allowedImageMeta = ImmutableSet
                    .copyOf(Splitter.on(',').omitEmptyStrings().splitToList(allowedImageMetaStr));
        } else {
            this.allowedImageMeta = ImmutableSet.of();
        }

        String allowedUserMetaStr = props.getProperty("allowedUserMeta", "").trim();
        if (!allowedUserMetaStr.isEmpty()) {
            this.allowedUserMeta = ImmutableSet
                    .copyOf(Splitter.on(',').omitEmptyStrings().splitToList(allowedUserMetaStr));
        } else {
            this.allowedUserMeta = ImmutableSet.of();
        }

        String metaNameCaseFormat = props.getProperty("metaNameCaseFormat", "").trim().toLowerCase();
        switch (metaNameCaseFormat) {
        case "lower_camel":
            this.metaNameCaseFormat = CaseFormat.LOWER_CAMEL;
            break;
        case "lower_hyphen":
            this.metaNameCaseFormat = CaseFormat.LOWER_HYPHEN;
            break;
        case "upper_camel":
            this.metaNameCaseFormat = CaseFormat.UPPER_CAMEL;
            break;
        case "upper_underscore":
            this.metaNameCaseFormat = CaseFormat.UPPER_UNDERSCORE;
            break;
        default:
            this.metaNameCaseFormat = null;
        }

        this.excerptOutputField = props.getProperty("excerptOutputField", "summary").toLowerCase().trim();

        this.stopOnLostMessage = props.getProperty("stopOnLostMessage", "false").equalsIgnoreCase("true");

        this.logReplicationMessage = props.getProperty("logReplicationMessage", "false")
                .equalsIgnoreCase("true");

        this.originId = props.getProperty("originId", "");

        Properties dusterProps = new InitUtil("duster.", props, false).getProperties();
        if (dusterProps.size() > 0) {
            this.httpClient = new JettyClient();
            this.httpClient.init("http.", props, logger);
            this.dusterClient = new DusterClient(dusterProps, httpClient, logger);
            logger.info("Duster is enabled...");
        } else {
            logger.info("Duster is disabled...");
        }

        if (!props.getProperty("contentTransformer", "").trim().isEmpty()) {
            this.contentTransformer = (ContentTransformer) (Class
                    .forName(props.getProperty("contentTransformer")).newInstance());
            this.contentTransformer.init(props);
        } else if (props.getProperty("cleanShortcodes", "true").equalsIgnoreCase("true")) {
            this.contentTransformer = new ShortcodeCleaner();
        }

        if (!props.getProperty("postTransformer", "").trim().isEmpty()) {
            this.postTransformer = (PostTransformer) (Class.forName(props.getProperty("postTransformer"))
                    .newInstance());
            this.postTransformer.init(props);
        } else {
            this.postTransformer = null;
        }

        if (!props.getProperty("postFilter", "").trim().isEmpty()) {
            this.postFilter = (PostFilter) (Class.forName(props.getProperty("postFilter")).newInstance());
            this.postFilter.init(props);
        } else {
            this.postFilter = null;
        }

        String dbDir = props.getProperty("metadb.dir", "").trim();
        if (dbDir.isEmpty()) {
            this.metaDB = null;
        } else {
            logger.info(String.format("Initializing meta db, '%s'...", dbDir));
            File metaDir = new File(dbDir);
            if (!metaDir.exists()) {
                throw new Exception(String.format("The 'metadb.dir' must exist ('%s')", dbDir));
            }
            this.metaDB = new PostMetaDB(metaDir);
        }

        Long modifiedOffsetHours = Longs.tryParse(props.getProperty("modifiedOffsetHours", "0"));
        this.modifiedOffsetMillis = modifiedOffsetHours != null ? modifiedOffsetHours * 3600 * 1000L : 0L;
        if (this.modifiedOffsetMillis != 0L) {
            logger.info(String.format("Set modified select offset to %d millis", this.modifiedOffsetMillis));
        }

        this.replicateScheduledState = props.getProperty("replicateScheduledState", "true")
                .equalsIgnoreCase("true");
        this.replicatePendingState = props.getProperty("replicatePendingState", "false")
                .equalsIgnoreCase("true");

        logger.info("Initialized WP supplier...");

    }
}

From source file:org.openehr.adl.am.AmObjectFactory.java

public static Class<? extends RmObject> getRmClass(@Nonnull String rmTypeName) throws ClassNotFoundException {
    int genericsTypeIndex = rmTypeName.indexOf('<');
    String name = genericsTypeIndex == -1 ? rmTypeName : rmTypeName.substring(0, genericsTypeIndex);
    String className = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name);
    //noinspection unchecked
    return (Class<RmObject>) Class.forName(RM_PACKAGE_NAME + '.' + className);
}