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:es.sm2.openppm.api.converter.common.SettingGroupDTOConverter.java

/**
 * Conver DTO model into BD model/* w  w w. j a  va 2s . co  m*/
 *
 * @param modelDTO
 * @return
 */
@Override
public Class<? extends ApplicationSetting> toModel(SettingGroupDTO modelDTO) {

    Class<? extends ApplicationSetting> applicationSetting = null;

    if (modelDTO != null && ValidateUtil.isNotNull(modelDTO.getName())) {

        String name = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, modelDTO.getName());

        Set<Class<? extends ApplicationSetting>> applicationSettingList = CacheStatic
                .getApplicationSettingList();

        Iterator<Class<? extends ApplicationSetting>> iterator = applicationSettingList.iterator();
        while (applicationSetting == null && iterator.hasNext()) {
            Class<? extends ApplicationSetting> setting = iterator.next();

            if (setting.getSimpleName().equals(name)) {
                applicationSetting = setting;
            }
        }
    }

    return applicationSetting;
}

From source file:org.jclouds.s3.domain.CannedAccessPolicy.java

/**
 * @param capHeader// w  w  w . j  a v  a2  s .  com
 * The value of the x-amz-acl HTTP Header returned by S3 when an
 * object has a canned access policy.
 * 
 * @return
 * the canned access policy object corresponding to the header value,
 * or null if the given header value does not represent a valid canned 
 * policy.
 */
public static CannedAccessPolicy fromHeader(String capHeader) {
    return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, capHeader));
}

From source file:org.apache.brooklyn.util.javalang.coerce.EnumTypeCoercions.java

public static <E extends Enum<E>> Maybe<E> tryCoerce(String input, Class<E> targetType) {
    if (input == null)
        return null;
    if (targetType == null)
        return Maybe.absent("Null enum type");
    if (!targetType.isEnum())
        return Maybe.absent("Type '" + targetType + "' is not an enum");

    List<String> options = ImmutableList.of(input,
            CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, input),
            CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_UNDERSCORE, input),
            CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, input),
            CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, input));
    for (String value : options) {
        try {/*from   ww  w.  j a va 2s.  c o m*/
            return Maybe.of(Enum.valueOf(targetType, value));
        } catch (IllegalArgumentException iae) {
            continue;
        }
    }
    Maybe<E> result = Enums.valueOfIgnoreCase(targetType, input);
    if (result.isPresent())
        return result;
    return Maybe.absent(new ClassCoercionException(
            "Invalid value '" + input + "' for " + JavaClassNames.simpleClassName(targetType)
                    + "; expected one of " + Arrays.asList(Enums.values(targetType))));
}

From source file:com.opengamma.basics.value.ValueAdjustmentType.java

/**
 * Obtains the type from a unique name./*from   ww  w.j  a  v  a  2 s. c  om*/
 * 
 * @param uniqueName  the unique name
 * @return the type
 * @throws IllegalArgumentException if the name is not known
 */
@FromString
public static ValueAdjustmentType of(String uniqueName) {
    ArgChecker.notNull(uniqueName, "uniqueName");
    return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, uniqueName));
}

From source file:com.google.errorprone.bugpatterns.SimpleDateFormatConstant.java

@Override
public Description matchVariable(VariableTree tree, VisitorState state) {
    if (tree.getInitializer() == null) {
        return NO_MATCH;
    }/*from ww w. j  a v  a 2  s  .c  om*/
    VarSymbol sym = ASTHelpers.getSymbol(tree);
    if (sym == null || sym.getKind() != ElementKind.FIELD) {
        return NO_MATCH;
    }
    String name = sym.getSimpleName().toString();
    if (!(sym.isStatic() && sym.getModifiers().contains(Modifier.FINAL))) {
        return NO_MATCH;
    }
    if (!name.equals(name.toUpperCase())) {
        return NO_MATCH;
    }
    if (!isSameType(getType(tree), state.getTypeFromString("java.text.SimpleDateFormat"), state)) {
        return NO_MATCH;
    }
    return buildDescription(tree).addFix(threadLocalFix(tree, state, sym))
            .addFix(renameVariable(tree,
                    CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, tree.getName().toString()), state))
            .build();
}

From source file:com.google.errorprone.bugpatterns.DateFormatConstant.java

@Override
public Description matchVariable(VariableTree tree, VisitorState state) {
    if (tree.getInitializer() == null) {
        return NO_MATCH;
    }//from   w w  w. j a v a  2s .c om
    VarSymbol sym = ASTHelpers.getSymbol(tree);
    if (sym == null || sym.getKind() != ElementKind.FIELD) {
        return NO_MATCH;
    }
    String name = sym.getSimpleName().toString();
    if (!(sym.isStatic() && sym.getModifiers().contains(Modifier.FINAL))) {
        return NO_MATCH;
    }
    if (!name.equals(Ascii.toUpperCase(name))) {
        return NO_MATCH;
    }
    if (!isSubtype(getType(tree), state.getTypeFromString("java.text.DateFormat"), state)) {
        return NO_MATCH;
    }
    SuggestedFix rename = renameVariable(tree,
            CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, tree.getName().toString()), state);
    return buildDescription(tree).addFix(threadLocalFix(tree, state, sym, rename)).addFix(rename).build();
}

From source file:brooklyn.entity.basic.Lifecycle.java

/**
 * Creates a {@link Lifecycle} from a text representation.
 *
 * This accepts the text representations output by the {@link #value()} method for each entry.
 *
 * @see #value()/*from w ww . ja  v  a2s .c  o m*/
 */
public static Lifecycle fromValue(String v) {
    try {
        return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, v));
    } catch (IllegalArgumentException iae) {
        return ON_FIRE;
    }
}

From source file:com.bbva.kltt.apirest.core.generator.output.language.OutputLanguageNaming.java

@Override
public String getCamelCaseName(final String name) {
    String nameToFormat = ConstantsCommon.STRING_EMPTY;
    if (name != null) {
        //Converting the spaces and hyphens to underscores
        nameToFormat = name.replaceAll("[ -]", ConstantsCommon.STRING_UNDERSCORE);
    }//from ww w.jav  a 2 s.co m

    return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, nameToFormat);
}

From source file:fr.putnami.pwt.core.editor.client.helper.MessageHelper.java

public String getMessageKey(Path path, String suffix) {
    if (path == null || path.isEmpty()) {
        return null;
    }//from   w  w  w. j  av a2  s. co m

    String labelKey = path.toString().replaceAll("\\.", "_").replaceAll("\\[", "").replaceAll("]", "")
            .toUpperCase();

    labelKey = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, String.valueOf(labelKey));
    if (!Strings.isNullOrEmpty(suffix)) {
        labelKey += suffix.substring(0, 1).toUpperCase() + suffix.substring(1);
    }
    return labelKey;
}

From source file:org.apache.airavata.db.AbstractThriftDeserializer.java

@Override
public T deserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    final T instance = newInstance();
    final ObjectMapper mapper = (ObjectMapper) jp.getCodec();
    final ObjectNode rootNode = mapper.readTree(jp);
    final Iterator<Map.Entry<String, JsonNode>> iterator = rootNode.fields();

    while (iterator.hasNext()) {
        final Map.Entry<String, JsonNode> currentField = iterator.next();
        try {/*from  w w  w  . j  a va  2  s.  c  o m*/
            /*
             * If the current node is not a null value, process it.  Otherwise,
             * skip it.  Jackson will treat the null as a 0 for primitive
             * number types, which in turn will make Thrift think the field
             * has been set. Also we ignore the MongoDB specific _id field
             */
            if (!currentField.getKey().equalsIgnoreCase("_id")
                    && currentField.getValue().getNodeType() != JsonNodeType.NULL) {
                final E field = getField(
                        CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, currentField.getKey()));
                final JsonParser parser = currentField.getValue().traverse();
                parser.setCodec(mapper);
                final Object value = mapper.readValue(parser, generateValueType(instance, field));
                if (value != null) {
                    log.debug(String.format("Field %s produced value %s of type %s.", currentField.getKey(),
                            value, value.getClass().getName()));
                    instance.setFieldValue(field, value);
                } else {
                    log.debug("Field {} contains a null value.  Skipping...", currentField.getKey());
                }
            } else {
                log.debug("Field {} contains a null value.  Skipping...", currentField.getKey());
            }
        } catch (final NoSuchFieldException | IllegalArgumentException e) {
            log.error("Unable to de-serialize field '{}'.", currentField.getKey(), e);
            ctxt.mappingException(e.getMessage());
        }
    }

    try {
        // Validate that the instance contains all required fields.
        validate(instance);
    } catch (final TException e) {
        log.error(String.format("Unable to deserialize JSON '%s' to type '%s'.", jp.getValueAsString(),
                instance.getClass().getName(), e));
        ctxt.mappingException(e.getMessage());
    }

    return instance;
}