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

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

Introduction

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

Prototype

public final String to(CaseFormat format, String str) 

Source Link

Document

Converts the specified String str from this format to the specified format .

Usage

From source file:brooklyn.util.text.StringFunctions.java

public static Function<String, String> convertCase(final CaseFormat src, final CaseFormat target) {
    return new Function<String, String>() {
        @Override//from w ww .j  a  v a 2  s  .co m
        public String apply(String input) {
            return src.to(target, input);
        }
    };
}

From source file:fr.vberetti.cassandra.metamodel.generation.TemplateUtil.java

private static String normalize(String raw, CaseFormat destination, boolean lowerCase) {
    if (isBlank(raw)) {
        return raw;
    }//from w  ww .java  2  s  .co  m

    String toNormalize = raw.trim();
    if (toNormalize.contains(" ")) {
        toNormalize = toNormalize.replaceAll(" ", "_");
    }
    if (toNormalize.contains("_") && toNormalize.contains("-")) {
        toNormalize = toNormalize.replaceAll("-", "_");
    }

    CaseFormat original = lowerCase ? UPPER_CAMEL : LOWER_CAMEL;
    if (toNormalize.contains("_")) {
        original = lowerCase ? UPPER_UNDERSCORE : LOWER_UNDERSCORE;
    } else if (toNormalize.contains("-")) {
        original = LOWER_HYPHEN;
    }

    return original.to(destination, toNormalize);
}

From source file:com.cinchapi.common.base.CaseFormats.java

/**
 * Generates all possible case formats for a given set of strings.
 * //from w w  w .  j av  a2  s.com
 * @param strings
 * @return a {@link Set} that contains all possible {@link CaseFormat case
 *         formats} for each of the {@code strings}
 */
public static Map<String, CaseFormat> allVariationsOf(String... strings) {
    Map<String, CaseFormat> formatted = Maps.newLinkedHashMap();
    CaseFormat[] formats = CaseFormat.values();
    for (String string : strings) {
        CaseFormat original = detect(string);
        formatted.put(string, original);
        for (CaseFormat target : Arrays.stream(formats).filter(Predicates.equalTo(original).negate())
                .collect(Collectors.toList())) {
            formatted.put(original.to(target, string), target);
        }
    }
    return formatted;
}

From source file:org.apache.brooklyn.core.config.ConfigKeys.java

/** converts the name of the key from one case-strategy (e.g. lowerCamel) to andother (e.g. lower-hyphen) */
public static <T> ConfigKey<T> convert(ConfigKey<T> key, CaseFormat inputCaseStrategy,
        CaseFormat outputCaseStrategy) {
    return newConfigKeyRenamed(inputCaseStrategy.to(outputCaseStrategy, key.getName()), key);
}

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

static String convertCase(String text, CDCSourceConnectorConfig.CaseFormat inputCaseFormat,
        CDCSourceConnectorConfig.CaseFormat outputCaseFormat) {
    if (Strings.isNullOrEmpty(text)) {
        return "";
    }//  w  w w.j  a  va 2s . com
    if (CDCSourceConnectorConfig.CaseFormat.LOWER == outputCaseFormat) {
        return text.toLowerCase();
    } else if (CDCSourceConnectorConfig.CaseFormat.UPPER == outputCaseFormat) {
        return text.toUpperCase();
    } else if (CDCSourceConnectorConfig.CaseFormat.NONE == outputCaseFormat) {
        return text;
    }

    CaseFormat inputFormat = caseFormat(inputCaseFormat);
    CaseFormat outputFormat = caseFormat(outputCaseFormat);

    return inputFormat.to(outputFormat, text);
}

From source file:org.apache.brooklyn.util.text.StringFunctions.java

/** @deprecated since 0.9.0 kept only to allow conversion of anonymous inner classes */
@SuppressWarnings("unused")
@Deprecated// w ww . ja  va2s  .co m
private static Function<String, String> convertCaseOld(final CaseFormat src, final CaseFormat target) {
    // TODO PERSISTENCE WORKAROUND
    return new Function<String, String>() {
        @Override
        public String apply(String input) {
            return src.to(target, input);
        }
    };
}