當前位置: 首頁>>代碼示例>>Java>>正文


Java CaseFormat類代碼示例

本文整理匯總了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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:21,代碼來源:Naming.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:27,代碼來源:Accessors.java

示例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);
    }

}
 
開發者ID:pandboy,項目名稱:pingguopai,代碼行數:27,代碼來源:CodeGenerator.java

示例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()));
        }
    }
}
 
開發者ID:TeamPneumatic,項目名稱:pnc-repressurized,代碼行數:17,代碼來源:GuiProgrammer.java

示例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);
    }
}
 
開發者ID:ansell,項目名稱:rdf4j-schema-generator,代碼行數:18,代碼來源:RDF4JSchemaGeneratorCore.java

示例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\""));
}
 
開發者ID:ansell,項目名稱:rdf4j-schema-generator,代碼行數:23,代碼來源:SchemaGeneratorTest.java

示例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\""));
}
 
開發者ID:ansell,項目名稱:rdf4j-schema-generator,代碼行數:23,代碼來源:SchemaGeneratorTest.java

示例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\""));
}
 
開發者ID:ansell,項目名稱:rdf4j-schema-generator,代碼行數:23,代碼來源:SchemaGeneratorTest.java

示例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();
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:26,代碼來源:BerichtStamgegevenWriter.java

示例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;
}
 
開發者ID:ryandavis84,項目名稱:swagger-java-diff-cli,代碼行數:22,代碼來源:RuleParserV1.java

示例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);
}
 
開發者ID:foodora,項目名稱:android-auto-mapper,代碼行數:18,代碼來源:AutoMappperProcessor.java

示例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));
}
 
開發者ID:antology,項目名稱:a6y-server,代碼行數:19,代碼來源:Clazz.java

示例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);
}
 
開發者ID:setheclark,項目名稱:auto-value-json,代碼行數:18,代碼來源:AutoValueJsonExtension.java

示例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();
}
 
開發者ID:elasticjob,項目名稱:elastic-job-cloud,代碼行數:20,代碼來源:JobEventRdbSearch.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:12,代碼來源:Naming.java


注:本文中的com.google.common.base.CaseFormat類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。