小编Ern*_*nio的帖子

使用java流查找第一个免费"索引"

我需要在我的文件系统中找到第一个免费索引,其中包含名称流作为源.

考虑列表:["New2","New4","New0","New1",......]第一个未使用的索引将是3.

int index = 0;
try (IntStream indexes = names.stream()
    .filter(name -> name.startsWith("New"))
    .mapToInt(Integer::parseInt)
    .distinct()
    .sorted())
{
    // I was thinking about making possible indexes stream, removing existig ones from try-with-resource block, and getting .min().
    IntStream.rangeClosed(0, 10)... // Idk what to do.
}
Run Code Online (Sandbox Code Playgroud)

我要求别人帮我找到正确的语法,或提出更好的解决方案.

java java-8 java-stream

4
推荐指数
1
解决办法
231
查看次数

为什么动态调整字符串大小会导致崩溃?

考虑代码:

char *word = NULL;                                      // Pointer at buffered string.
int size = 0;                                           // Size of buffered string.
int index = 0;                                          // Write index.

char c;                                                 // Next character read from file.

FILE *file = fopen(fileDir, "r");
if (file)
{
    while ((c = getc(file)) != EOF)
    {
        printf("Current index: %d, size: %d, Word: %s\n", index, size, word);
        if (isValidChar(c))
        {
            appendChar(c, &word, &size, &index);
        }
        else if (word) // Any non-valid char is end of word. If (pointer) …
Run Code Online (Sandbox Code Playgroud)

c string pointers realloc

2
推荐指数
1
解决办法
73
查看次数

我可以动态加载 HTML 字符串作为组件模板并在 Angular 7 中完全编译它吗?

所以我读了这个: https: //angular.io/guide/dynamic-component-loader

我正在尝试从 i18n 数据库加载产品描述页面。让我们定义 REST 服务器,例如请求:

{ product: "stick", lang: "en" }
Run Code Online (Sandbox Code Playgroud)

将返回:

{ content:
   "<div class="wrap">
        <h1>English translation title</h1>
        <span>Some text</span>
        <app-image-component some-component-bindings="..."></app-image-component>
    </div>"
  css:
   ".wrap { rules }"
}
Run Code Online (Sandbox Code Playgroud)

我的问题:

  • (基于教程链接)我知道 Angular 允许提取数据对象并将它们插入到预定义的 html 模板中。是否允许插入整个模板(整个 HTML,而不仅仅是数据值)?
  • 也允许自定义CSS吗?我知道 css (或 sass)被编译成 Angular 特定的“thingy” - 这可以在加载时完成吗?内联CSS怎么样?
  • 如果第一个是可能的 - 它也会编译角度事物(应用程序定义的组件,例如app-image-component示例中的组件)?

目标是赋予(应用程序)管理员将产品内容页面组合在一起的权力,这些页面可以使用填充数据的预定义组件。

我想做的事情是否得到了良好的支持,还是会非常复杂(有一些奇怪的技巧)?

angular angular7

2
推荐指数
1
解决办法
2569
查看次数

所有双向关系都可以是 LAZY 吗?

我将 Spring 与 JPA (Hibernate) 一起使用。

当我从许多网站学习有关关系的内容时(实现它们的方法很少),也有关于获取类型的讨论,但我在这里提出的问题从未得到完全解答。

我想知道是否存在双向关系不能偷懒的情况?单向有时也不能偷懒吗?

Box举例来说:假设一个 中有多个es Warehouse。鉴于这是 ManyToOne 关系(如上所述,实现它的方法很少,为了这个例子,我们假设Warehouse是拥有方) - 它可以在两端都是惰性的(你可以 loadBox和 lazily Warehouse,但加载Warehouse不会加载所有Boxes 它)有,只有当你真正得到它们时)?

这样的代码片段看起来怎么样——我是否只是用 JPA 的 LAZY 注释两端,或者其他一些,也许是 Hibernate 特定的东西?

java hibernate jpa

1
推荐指数
1
解决办法
1135
查看次数

异常和错误以错误的顺序打印

程序用于将程序参数解析为几何形状.

  • 圆(C):1 arg [radius]
  • 五角大楼(P):1 arg [side]
  • Square,Rhombus,Rect(Q):5 args [a,b,c,d,angleA](程序根据args选择生成哪一个)

我的问题是在控制台中打印异常/错误的顺序.

public static void main(String[] args)
{
    if (args.length > 0)
    {
        int readerIndex = 0; // currently read argument

        for (char symbol : args[readerIndex++].toCharArray())
        {
            ShapeType type = null; // Enum for C, P or Q.
            int toRead = 0; // How many args should we read.
            int read = 0; // How many we alredy read.

            try
            {
                type = ShapeType.bySymbol(symbol); // C, P or Q.
                toRead = …
Run Code Online (Sandbox Code Playgroud)

java exception try-catch

0
推荐指数
1
解决办法
56
查看次数