本文整理汇总了Java中com.google.common.base.CaseFormat类的典型用法代码示例。如果您正苦于以下问题:Java CaseFormat类的具体用法?Java CaseFormat怎么用?Java CaseFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CaseFormat类属于com.google.common.base包,在下文中一共展示了CaseFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: detect
import com.google.common.base.CaseFormat; //导入依赖的package包/类
@Override
public String detect(String identifier) {
if (identifier.length() <= lengthsOfPrefixAndSuffix) {
return NOT_DETECTED;
}
boolean prefixMatches = prefix.isEmpty() ||
(identifier.startsWith(prefix) && Ascii.isUpperCase(identifier.charAt(prefix.length())));
boolean suffixMatches = suffix.isEmpty() || identifier.endsWith(suffix);
if (prefixMatches && suffixMatches) {
String detected = identifier.substring(prefix.length(), identifier.length() - suffix.length());
return prefix.isEmpty()
? detected
: CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, detected);
}
return NOT_DETECTED;
}
示例2: resolveAccessorWithBeanAccessor
import com.google.common.base.CaseFormat; //导入依赖的package包/类
@Nullable
private BoundAccessor resolveAccessorWithBeanAccessor(TypeMirror targetType, String attribute) {
@Nullable BoundAccessor accessor = resolveAccessor(targetType, attribute);
if (accessor != null) {
return accessor;
}
String capitalizedName = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, attribute);
accessor = resolveAccessor(targetType, "get" + capitalizedName);
if (accessor != null) {
return accessor;
}
accessor = resolveAccessor(targetType, "is" + capitalizedName);
if (accessor != null) {
return accessor;
}
accessor = resolveAccessor(targetType, "$$" + attribute);
if (accessor != null) {
return accessor;
}
return accessor;
}
示例3: genController
import com.google.common.base.CaseFormat; //导入依赖的package包/类
public static void genController(String tableName, String modelName) {
try {
freemarker.template.Configuration cfg = getConfiguration();
Map<String, Object> data = new HashMap<>();
data.put("date", DATE);
data.put("author", AUTHOR);
String modelNameUpperCamel = StringUtils.isEmpty(modelName) ? tableNameConvertUpperCamel(tableName) : modelName;
data.put("baseRequestMapping", modelNameConvertMappingPath(modelNameUpperCamel));
data.put("modelNameUpperCamel", modelNameUpperCamel);
data.put("modelNameLowerCamel", CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, modelNameUpperCamel));
data.put("basePackage", BASE_PACKAGE);
File file = new File(PROJECT_PATH + JAVA_PATH + PACKAGE_PATH_CONTROLLER + modelNameUpperCamel + "Controller.java");
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
//cfg.getTemplate("controller-restful.ftl").process(data, new FileWriter(file));
cfg.getTemplate("controller.ftl").process(data, new FileWriter(file));
System.out.println(modelNameUpperCamel + "Controller.java 生成成功");
} catch (Exception e) {
throw new RuntimeException("生成Controller失败", e);
}
}
示例4: onIGWAction
import com.google.common.base.CaseFormat; //导入依赖的package包/类
@Optional.Method(modid = ModIds.IGWMOD)
private void onIGWAction() {
int x = lastMouseX;
int y = lastMouseY;
IProgWidget hoveredWidget = programmerUnit.getHoveredWidget(x, y);
if(hoveredWidget != null) {
WikiRegistry.getWikiHooks().showWikiGui("pneumaticcraft:progwidget/" + CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, hoveredWidget.getWidgetString()));
}
for(IProgWidget widget : visibleSpawnWidgets) {
if(widget != draggingWidget && x - guiLeft >= widget.getX() && y - guiTop >= widget.getY() && x - guiLeft <= widget.getX() + widget.getWidth() / 2 && y - guiTop <= widget.getY() + widget.getHeight() / 2) {
WikiRegistry.getWikiHooks().showWikiGui("pneumaticcraft:progwidget/" + CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, widget.getWidgetString()));
}
}
}
示例5: doCaseFormatting
import com.google.common.base.CaseFormat; //导入依赖的package包/类
private String doCaseFormatting(String key, CaseFormat targetFormat) {
if (targetFormat == null) {
return key;
} else {
CaseFormat originalFormat = CaseFormat.LOWER_CAMEL;
if (Character.isUpperCase(key.charAt(0)) && key.contains("_")) {
originalFormat = CaseFormat.UPPER_UNDERSCORE;
} else if (Character.isUpperCase(key.charAt(0))) {
originalFormat = CaseFormat.UPPER_CAMEL;
} else if (key.contains("_")) {
originalFormat = CaseFormat.LOWER_UNDERSCORE;
} else if (key.contains("-")) {
originalFormat = CaseFormat.LOWER_HYPHEN;
}
return originalFormat.to(targetFormat, key);
}
}
示例6: testUpperUnderscoreCase
import com.google.common.base.CaseFormat; //导入依赖的package包/类
/**
* Test method for {@link com.github.ansell.rdf4j.schemagenerator.RDF4JSchemaGeneratorCore#generate(java.nio.file.Path)}.
*/
@Test
public final void testUpperUnderscoreCase() throws Exception {
Path outputPath = testDir.resolve("output");
Files.createDirectories(outputPath);
RDF4JSchemaGeneratorCore testBuilder = new RDF4JSchemaGeneratorCore(inputPath.toAbsolutePath().toString(), format);
testBuilder.setConstantCase(CaseFormat.UPPER_UNDERSCORE);
Path javaFilePath = outputPath.resolve("Test.java");
testBuilder.generate(javaFilePath);
assertTrue("Java file was not found", Files.exists(javaFilePath));
assertTrue("Java file was empty", Files.size(javaFilePath) > 0);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Files.copy(javaFilePath, out);
String result = new String(out.toByteArray(), StandardCharsets.UTF_8);
assertTrue("Did not find expected key case", result.contains("PROPERTY_LOCALISED4 = "));
assertTrue("Did not find original URI", result.contains("\"http://example.com/ns/ontology#propertyLocalised4\""));
}
示例7: testUpperUnderscoreCaseString
import com.google.common.base.CaseFormat; //导入依赖的package包/类
/**
* Test method for {@link com.github.ansell.rdf4j.schemagenerator.RDF4JSchemaGeneratorCore#generate(java.nio.file.Path)}.
*/
@Test
public final void testUpperUnderscoreCaseString() throws Exception {
Path outputPath = testDir.resolve("output");
Files.createDirectories(outputPath);
RDF4JSchemaGeneratorCore testBuilder = new RDF4JSchemaGeneratorCore(inputPath.toAbsolutePath().toString(), format);
testBuilder.setStringConstantCase(CaseFormat.UPPER_UNDERSCORE);
Path javaFilePath = outputPath.resolve("Test.java");
testBuilder.generate(javaFilePath);
assertTrue("Java file was not found", Files.exists(javaFilePath));
assertTrue("Java file was empty", Files.size(javaFilePath) > 0);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Files.copy(javaFilePath, out);
String result = new String(out.toByteArray(), StandardCharsets.UTF_8);
assertTrue("Did not find expected key case", result.contains("PROPERTY_LOCALISED4 = "));
assertTrue("Did not find original URI", result.contains("\"http://example.com/ns/ontology#propertyLocalised4\""));
}
示例8: testUpperUnderscoreCaseLocalName
import com.google.common.base.CaseFormat; //导入依赖的package包/类
/**
* Test method for {@link com.github.ansell.rdf4j.schemagenerator.RDF4JSchemaGeneratorCore#generate(java.nio.file.Path)}.
*/
@Test
public final void testUpperUnderscoreCaseLocalName() throws Exception {
Path outputPath = testDir.resolve("output");
Files.createDirectories(outputPath);
RDF4JSchemaGeneratorCore testBuilder = new RDF4JSchemaGeneratorCore(inputPath.toAbsolutePath().toString(), format);
testBuilder.setLocalNameStringConstantCase(CaseFormat.UPPER_UNDERSCORE);
Path javaFilePath = outputPath.resolve("Test.java");
testBuilder.generate(javaFilePath);
assertTrue("Java file was not found", Files.exists(javaFilePath));
assertTrue("Java file was empty", Files.size(javaFilePath) > 0);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Files.copy(javaFilePath, out);
String result = new String(out.toByteArray(), StandardCharsets.UTF_8);
assertTrue("Did not find expected key case", result.contains("PROPERTY_LOCALISED4 = "));
assertTrue("Did not find original URI", result.contains("\"http://example.com/ns/ontology#propertyLocalised4\""));
}
示例9: write
import com.google.common.base.CaseFormat; //导入依赖的package包/类
/**
* @param berichtStamgegevens stamgegevens
* @param writer de writer
*/
public static void write(final BerichtStamgegevens berichtStamgegevens, BerichtWriter writer) {
if (berichtStamgegevens.getStamtabelGegevens() == null) {
return;
}
final String lowerCamelCaseNaam = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, berichtStamgegevens
.getStamtabelGegevens().getStamgegevenTabel().getNaam());
writer.startElement(lowerCamelCaseNaam + StamtabelGegevens.TABEL_POSTFIX);
for (Map<String, Object> stringObjectMap : berichtStamgegevens.getStamtabelGegevens().getStamgegevens()) {
//xml stamgegeven tabel
writer.startElement(lowerCamelCaseNaam);
writer.attribute("objecttype", berichtStamgegevens.getStamtabelGegevens().getStamgegevenTabel().getNaam());
//elementen
for (AttribuutElement attribuutElement : berichtStamgegevens.getStamtabelGegevens().getStamgegevenTabel()
.getStamgegevenAttributenInBericht()) {
schrijfStamgegevenWaarde(writer, stringObjectMap, attribuutElement);
}
writer.endElement();
}
writer.endElement();
}
示例10: parseCustomRules
import com.google.common.base.CaseFormat; //导入依赖的package包/类
public Map<String, Rule> parseCustomRules(String fileName) throws IOException {
Map<String, Rule> rules = gatherRules();
if (null != fileName) {
File file = new File(fileName);
ObjectMapper objectMapper = new ObjectMapper();
TypeReference<HashMap<String, Boolean>> typeReference
= new TypeReference<HashMap<String, Boolean>>() {
};
Map<String, Boolean> customRules = objectMapper.readValue(file, typeReference);
for (Map.Entry<String, Boolean> entry : customRules.entrySet()) {
if (rules.containsKey(entry.getKey().toLowerCase())) {
Rule rule = rules.get(entry.getKey());
rule.setBreakingChange(entry.getValue());
rules.put(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, rule.getRuleName()), rule);
LOGGER.info("Submited Rule " + rule.getRuleName() + " to " + entry.getValue());
}
}
}
return rules;
}
示例11: getTypeAdapters
import com.google.common.base.CaseFormat; //导入依赖的package包/类
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());
}
}
return ImmutableMap.copyOf(typeAdapters);
}
示例12: Clazz
import com.google.common.base.CaseFormat; //导入依赖的package包/类
Clazz(Database database, org.antology.db.Node clazzNode) throws IOException {
this.database = database;
this.name = clazzNode.getProperty("name").getString();
this.schema = new Schema(clazzNode.getProperty("schema"));
this.actions = new HashMap<>();
org.antology.db.Node actionsNode = clazzNode.getProperty("actions");
for (org.antology.db.Node actionNode : actionsNode.getElements()) {
actions.put(actionNode.getProperty("name").getString(), new Action(this, actionNode));
}
// Load objects
String file = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name) + ".objects.json";
this.objects = new org.antology.db.json.Node(
new File(((org.antology.db.json.Database) database).getPath() + "/" + file));
}
示例13: getTypeAdapters
import com.google.common.base.CaseFormat; //导入依赖的package包/类
private ImmutableMap<TypeMirror, FieldSpec> getTypeAdapters(List<JsonProperty> properties,
NameAllocator nameAllocator) {
Map<TypeMirror, FieldSpec> typeAdapters = new LinkedHashMap<>();
for (JsonProperty 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());
}
}
return ImmutableMap.copyOf(typeAdapters);
}
示例14: buildWhere
import com.google.common.base.CaseFormat; //导入依赖的package包/类
private String buildWhere(final String tableName, final Collection<String> tableFields, final Condition condition) {
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append(" WHERE 1=1");
if (null != condition.getFields() && !condition.getFields().isEmpty()) {
for (Map.Entry<String, Object> entry : condition.getFields().entrySet()) {
String lowerUnderscore = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, entry.getKey());
if (null != entry.getValue() && tableFields.contains(lowerUnderscore)) {
sqlBuilder.append(" AND ").append(lowerUnderscore).append("=?");
}
}
}
if (null != condition.getStartTime()) {
sqlBuilder.append(" AND ").append(getTableTimeField(tableName)).append(">=?");
}
if (null != condition.getEndTime()) {
sqlBuilder.append(" AND ").append(getTableTimeField(tableName)).append("<=?");
}
return sqlBuilder.toString();
}
示例15: apply
import com.google.common.base.CaseFormat; //导入依赖的package包/类
public String apply(String input) {
if (!input.isEmpty()) {
if (this == CAPITALIZED && !Ascii.isUpperCase(input.charAt(0))) {
return CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, input);
}
if (this == LOWERIZED && !Ascii.isLowerCase(input.charAt(0))) {
return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, input);
}
}
return input;
}