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

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

本文整理了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

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

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

/**
 * Creates a new instance.
 */
private MergeSource(String path, boolean optional) {
  this.path = validateFilePath(path, "path");
  this.optional = optional;
}

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

/**
 * Normalizes the path according to the following order.
 * <ul>
 *   <li>if the path is {@code null}, empty string or "/", normalize to {@code "/*"}</li>
 *   <li>if the path is a valid file path, return the path as it is</li>
 *   <li>if the path is a valid directory path, append "*" at the end</li>
 * </ul>
 */
private static String normalizePath(String path) {
  if (path == null || path.isEmpty() || "/".equals(path)) {
    return "/*";
  }
  if (isValidFilePath(path)) {
    return path;
  }
  if (isValidDirPath(path)) {
    if (path.endsWith("/")) {
      return path + '*';
    } else {
      return path + "/*";
    }
  }
  return path;
}

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

DefaultChange(String path, ChangeType type, @Nullable T content) {
  this.type = requireNonNull(type, "type");
  if (type.contentType() == JsonNode.class) {
    validateJsonFilePath(path, "path");
  } else {
    validateFilePath(path, "path");
  }
  this.path = path;
  this.content = content;
}

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

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

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

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

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

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

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

mergeSources.forEach(path -> validateJsonFilePath(path.path(), "path"));
    return null;
  future.complete(unsafeCast(mergedEntry));
  return null;
});

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

public static String validateFilePath(String path, String paramName) {
  requireNonNull(path, paramName);
  if (isValidFilePath(path)) {
    return path;
  }
  throw new IllegalArgumentException(
      paramName + ": " + path + " (expected: " + FILE_PATH_PATTERN.pattern() + ')');
}

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

public static boolean isValidDirPath(String path) {
  return isValidDirPath(path, false);
}

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

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

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

@Test
public void testTextPatches() throws PatchFailedException {
  final String oriStr = "1\n2\n3\n4\n5\n6\n7\n8\n9";
  final String newStr = "1a\n2\n3\n4\n5\n6\n7\n8\n9a";
  final String expectedUnifiedDiff = "--- /text_file.txt\n" +
                    "+++ /text_file.txt\n" +
                    "@@ -1,4 +1,4 @@\n" +
                    "-1\n" +
                    "+1a\n" +
                    " 2\n" +
                    " 3\n" +
                    " 4\n" +
                    "@@ -6,4 +6,4 @@\n" +
                    " 6\n" +
                    " 7\n" +
                    " 8\n" +
                    "-9\n" +
                    "+9a";
  final Change<String> change = Change.ofTextPatch("/text_file.txt", oriStr, newStr);
  assertEquals(expectedUnifiedDiff, change.content());
  final Patch<String> patch = DiffUtils.parseUnifiedDiff(Util.stringToLines(change.content()));
  final String patchedStr = String.join("\n", patch.applyTo(Util.stringToLines(oriStr)));
  assertEquals(newStr, patchedStr);
}

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

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

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

private static void assertDirPathValidationSuccess(String path) {
  validateDirPath(path, "path");
}

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

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

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

DefaultChange(String path, ChangeType type, @Nullable T content) {
  this.type = requireNonNull(type, "type");
  if (type.contentType() == JsonNode.class) {
    validateJsonFilePath(path, "path");
  } else {
    validateFilePath(path, "path");
  }
  this.path = path;
  this.content = content;
}

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

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

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

mergeSources.forEach(path -> validateJsonFilePath(path.path(), "path"));
    return null;
  future.complete(unsafeCast(mergedEntry));
  return null;
});

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

public static String validateFilePath(String path, String paramName) {
  requireNonNull(path, paramName);
  if (isValidFilePath(path)) {
    return path;
  }
  throw new IllegalArgumentException(
      paramName + ": " + path + " (expected: " + FILE_PATH_PATTERN.pattern() + ')');
}

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

public static boolean isValidDirPath(String path) {
  return isValidDirPath(path, false);
}

相关文章