com.linecorp.centraldogma.internal.Util类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(222)

本文整理了Java中com.linecorp.centraldogma.internal.Util类的一些代码示例,展示了Util类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util类的具体详情如下:
包路径:com.linecorp.centraldogma.internal.Util
类名称:Util

Util介绍

[英]This class borrowed some of its methods from a [NetUtil class](https://github.com/netty/netty/blob/4.1/common
/src/main/java/io/netty/util/NetUtil.java) which was part of Netty project.
[中]这个类从一个{$0$}借用了一些方法,这个{$0$}是Netty项目的一部分。

代码示例

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server

  1. /**
  2. * Returns a raw session instance which is casted to {@code T} type.
  3. *
  4. * @throws NullPointerException if the {@code rawSession} is {@code null}
  5. * @throws ClassCastException if the {@code rawSession} cannot be casted to {@code T}
  6. */
  7. <T> T castRawSession() {
  8. return Util.unsafeCast(requireNonNull(rawSession, "rawSession"));
  9. }

代码示例来源:origin: line/centraldogma

  1. /**
  2. * Creates a new instance.
  3. */
  4. private MergeSource(String path, boolean optional) {
  5. this.path = validateFilePath(path, "path");
  6. this.optional = optional;
  7. }

代码示例来源:origin: line/centraldogma

  1. /**
  2. * Normalizes the path according to the following order.
  3. * <ul>
  4. * <li>if the path is {@code null}, empty string or "/", normalize to {@code "/*"}</li>
  5. * <li>if the path is a valid file path, return the path as it is</li>
  6. * <li>if the path is a valid directory path, append "*" at the end</li>
  7. * </ul>
  8. */
  9. private static String normalizePath(String path) {
  10. if (path == null || path.isEmpty() || "/".equals(path)) {
  11. return "/*";
  12. }
  13. if (isValidFilePath(path)) {
  14. return path;
  15. }
  16. if (isValidDirPath(path)) {
  17. if (path.endsWith("/")) {
  18. return path + '*';
  19. } else {
  20. return path + "/*";
  21. }
  22. }
  23. return path;
  24. }

代码示例来源:origin: line/centraldogma

  1. DefaultChange(String path, ChangeType type, @Nullable T content) {
  2. this.type = requireNonNull(type, "type");
  3. if (type.contentType() == JsonNode.class) {
  4. validateJsonFilePath(path, "path");
  5. } else {
  6. validateFilePath(path, "path");
  7. }
  8. this.path = path;
  9. this.content = content;
  10. }

代码示例来源:origin: line/centraldogma

  1. @JsonCreator
  2. JsonPathQuery(@JsonProperty("path") String path,
  3. @JsonProperty("expressions") Iterable<String> jsonPaths) {
  4. this.path = validateJsonFilePath(path, "path");
  5. Streams.stream(requireNonNull(jsonPaths, "jsonPaths"))
  6. .forEach(jsonPath -> Util.validateJsonPath(jsonPath, "jsonPath"));
  7. this.jsonPaths = ImmutableList.copyOf(jsonPaths);
  8. }

代码示例来源:origin: line/centraldogma

  1. /**
  2. * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_TEXT_PATCH}.
  3. *
  4. * @param path the path of the file
  5. * @param oldText the old content of the file
  6. * @param newText the new content of the file
  7. */
  8. static Change<String> ofTextPatch(String path, @Nullable String oldText, String newText) {
  9. validateFilePath(path, "path");
  10. requireNonNull(newText, "newText");
  11. final List<String> oldLineList = oldText == null ? Collections.emptyList()
  12. : Util.stringToLines(oldText);
  13. final List<String> newLineList = Util.stringToLines(newText);
  14. final Patch<String> patch = DiffUtils.diff(oldLineList, newLineList);
  15. final List<String> unifiedDiff = DiffUtils.generateUnifiedDiff(path, path, oldLineList, patch, 3);
  16. return new DefaultChange<>(path, ChangeType.APPLY_TEXT_PATCH, String.join("\n", unifiedDiff));
  17. }

代码示例来源:origin: line/centraldogma

  1. /**
  2. * Returns the simplified name of the specified type.
  3. */
  4. public static String simpleTypeName(Class<?> clazz) {
  5. return simpleTypeName(clazz, false);
  6. }

代码示例来源:origin: line/centraldogma

  1. mergeSources.forEach(path -> validateJsonFilePath(path.path(), "path"));
  2. return null;
  3. future.complete(unsafeCast(mergedEntry));
  4. return null;
  5. });

代码示例来源:origin: line/centraldogma

  1. public static String validateFilePath(String path, String paramName) {
  2. requireNonNull(path, paramName);
  3. if (isValidFilePath(path)) {
  4. return path;
  5. }
  6. throw new IllegalArgumentException(
  7. paramName + ": " + path + " (expected: " + FILE_PATH_PATTERN.pattern() + ')');
  8. }

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common

  1. public static boolean isValidDirPath(String path) {
  2. return isValidDirPath(path, false);
  3. }

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common-shaded

  1. JsonPathQuery(String path, String... jsonPaths) {
  2. requireNonNull(jsonPaths, "jsonPaths");
  3. this.path = validateJsonFilePath(path, "path");
  4. this.jsonPaths = Stream.of(jsonPaths).peek(JsonPathQuery::validateJsonPath).collect(toImmutableList());
  5. }

代码示例来源:origin: line/centraldogma

  1. @Test
  2. public void testTextPatches() throws PatchFailedException {
  3. final String oriStr = "1\n2\n3\n4\n5\n6\n7\n8\n9";
  4. final String newStr = "1a\n2\n3\n4\n5\n6\n7\n8\n9a";
  5. final String expectedUnifiedDiff = "--- /text_file.txt\n" +
  6. "+++ /text_file.txt\n" +
  7. "@@ -1,4 +1,4 @@\n" +
  8. "-1\n" +
  9. "+1a\n" +
  10. " 2\n" +
  11. " 3\n" +
  12. " 4\n" +
  13. "@@ -6,4 +6,4 @@\n" +
  14. " 6\n" +
  15. " 7\n" +
  16. " 8\n" +
  17. "-9\n" +
  18. "+9a";
  19. final Change<String> change = Change.ofTextPatch("/text_file.txt", oriStr, newStr);
  20. assertEquals(expectedUnifiedDiff, change.content());
  21. final Patch<String> patch = DiffUtils.parseUnifiedDiff(Util.stringToLines(change.content()));
  22. final String patchedStr = String.join("\n", patch.applyTo(Util.stringToLines(oriStr)));
  23. assertEquals(newStr, patchedStr);
  24. }

代码示例来源:origin: line/centraldogma

  1. public static String emailToUsername(String emailAddr, String paramName) {
  2. validateEmailAddress(emailAddr, paramName);
  3. return emailAddr.substring(0, emailAddr.indexOf('@'));
  4. }

代码示例来源:origin: line/centraldogma

  1. private static void assertDirPathValidationSuccess(String path) {
  2. validateDirPath(path, "path");
  3. }

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common

  1. /**
  2. * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_TEXT_PATCH}.
  3. *
  4. * @param path the path of the file
  5. * @param oldText the old content of the file
  6. * @param newText the new content of the file
  7. */
  8. static Change<String> ofTextPatch(String path, @Nullable String oldText, String newText) {
  9. validateFilePath(path, "path");
  10. requireNonNull(newText, "newText");
  11. final List<String> oldLineList = oldText == null ? Collections.emptyList()
  12. : Util.stringToLines(oldText);
  13. final List<String> newLineList = Util.stringToLines(newText);
  14. final Patch<String> patch = DiffUtils.diff(oldLineList, newLineList);
  15. final List<String> unifiedDiff = DiffUtils.generateUnifiedDiff(path, path, oldLineList, patch, 3);
  16. return new DefaultChange<>(path, ChangeType.APPLY_TEXT_PATCH, String.join("\n", unifiedDiff));
  17. }

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common

  1. DefaultChange(String path, ChangeType type, @Nullable T content) {
  2. this.type = requireNonNull(type, "type");
  3. if (type.contentType() == JsonNode.class) {
  4. validateJsonFilePath(path, "path");
  5. } else {
  6. validateFilePath(path, "path");
  7. }
  8. this.path = path;
  9. this.content = content;
  10. }

代码示例来源:origin: line/centraldogma

  1. FindOption(String name, T defaultValue) {
  2. this.name = name;
  3. this.defaultValue = defaultValue;
  4. fullName = Util.simpleTypeName(FindOption.class) + '.' + name;
  5. }

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server

  1. mergeSources.forEach(path -> validateJsonFilePath(path.path(), "path"));
  2. return null;
  3. future.complete(unsafeCast(mergedEntry));
  4. return null;
  5. });

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common

  1. public static String validateFilePath(String path, String paramName) {
  2. requireNonNull(path, paramName);
  3. if (isValidFilePath(path)) {
  4. return path;
  5. }
  6. throw new IllegalArgumentException(
  7. paramName + ": " + path + " (expected: " + FILE_PATH_PATTERN.pattern() + ')');
  8. }

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common-shaded

  1. public static boolean isValidDirPath(String path) {
  2. return isValidDirPath(path, false);
  3. }

相关文章