小编wan*_*Dev的帖子

运行 javafx 应用程序、Netbeans 11、java 12、javafx 13 的问题

尝试运行一个简单的 hello world 示例,但出现以下错误,我不明白:

Graphics Device initialization failed for :  d3d, sw
Error initializing QuantumRenderer: no suitable pipeline found
java.lang.RuntimeException: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
Run Code Online (Sandbox Code Playgroud)

如何解决?我是否需要一些尚未包含的库、插件、配置?

这是我的 pom:尝试使用 Java 9,10,11,12 和 JavaFX 12 & 13 并得到相同的错误。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany</groupId>
<artifactId>mavenproject3</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.release>11</maven.compiler.release>
    <javafx.version>13</javafx.version>
</properties>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <release>${maven.compiler.release}</release>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>0.0.4</version>
            <configuration>
                <mainClass>com.mycompany.mavenproject3.MainApp</mainClass>
                <executable>C:\Program Files\Java\jdk-12\bin\java</executable>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency> …
Run Code Online (Sandbox Code Playgroud)

java netbeans javafx maven

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

在 Intellij Idea Terminal 中为常用命令创建缩写

我看到一些开发人员在 Intellij IDEA 终端中使用命令的缩写(可能它可以在任何终端中完成,只是在 Intellij 中看到它)并且想知道它是如何完成的。例如代替

~/IdeaProjects/MyProject someBranch > mvn clean install
Run Code Online (Sandbox Code Playgroud)

他们只用

~/IdeaProjects/MyProject someBranch > mci
Run Code Online (Sandbox Code Playgroud)

我看过一些如何在 shell 中定义变量的教程,但我不确定定义变量是上述工作的方式,也不确定如何在 Intellij 中做到这一点。知道它是如何实现的吗?不确定我应该用什么搜索词来谷歌。

java terminal intellij-idea

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

如何从重载的可变参数构造函数调用对象的基本构造函数?

我有一个简单的类,其中包含所有可用字段的构造函数,我想添加一个带有可变参数的重载构造函数,以允许创建对象,即使某些字段未知。

class FooClass {
    int id;
    String first;
    String second;
    String third;

    FooClass(final int id, final String first, final String second, final String third) {
        this.id = id;
        this.first = first;
        this.second = second;
        this.third = third;
    }

    FooClass(final int id, final String... myStrings){
        if(myStrings.length == 1) {
            this.id     = id;
            this.first  = myStrings[0];
        } else if (myStrings.length == 2) {
            this.id     = id;
            this.first  = myStrings[0];
            this.second = myStrings[1];
        } else {
            this.id     = id;
            this.first  = myStrings[0];
            this.second …
Run Code Online (Sandbox Code Playgroud)

java constructor-overloading

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

复制文件的文件创建日期Java Nio

我想找出文件的创建日期,并在SO上找到了几个非常相似的答案。我的问题是,如果文件从一个文件夹移动到另一个文件夹,则无法使用。我根本没有修改文件-只是将其复制到另一个目录。

//file location before copy paste C:\\Users\\momo\\temp\\A.csv
File f = new File("C:\\Users\\momo\\temp\\xyz\\A.csv");
BasicFileAttributes attributes = Files.readAttributes(Paths.get(f.toURI()), BasicFileAttributes.class);
FileTime fileTime = attributes.creationTime();
Date date = new Date(fileTime.toMillis());
System.out.println(date);
Run Code Online (Sandbox Code Playgroud)

要重现此文件,您只需要复制一个较旧的文件并将其粘贴到另一个目录中。资源管理器显示了旧日期,但是上面代码的输出是复制日期。

java nio file

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

在每个第 i 个和第 j 个字符处拆分

我需要在每个第 i 个和第 j 个字符处拆分一个字符串,其中 i 和 j 可以根据输入参数进行更改。例如,如果我有一个输入

String s = "1234567890abcdef";
int i = 2;
int j = 3;
Run Code Online (Sandbox Code Playgroud)

我希望我的输出是一个数组:

[12, 345, 67, 890, ab, cde, f]
Run Code Online (Sandbox Code Playgroud)

我找到了一个紧凑的正则表达式,可以在每个第 n 个字符处进行拆分。n = 3 的示例使用"(?<=\\G...)""(?<=\\G.{3})"

String s = "1234567890abcdef";
int n = 3;
System.out.println(Arrays.toString(s.split("(?<=\\G.{"+n+"})")));

//output: [123, 456, 789, 0ab, cde, f]
Run Code Online (Sandbox Code Playgroud)

如何修改上面的正则表达式以交替拆分每个第 2 个第 3 个字符?

天真的链接像"(?<=\\G.{2})(?<=\\G.{3})"不起作用。

java regex split

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

Java IntStream 或 LongStream 按值而不是按元素数限制

我想迭代/生成一个无限的 IntStream 或 LongStream 并通过提供的最大值来限制它们,而不是通过操作可能的元素计数limit(long n),例如获得前 20 个正偶数:

List<Integer> evens = IntStream.iterate(0, i -> i + 2)
                               .limit(20)
                               .boxed()
                               .collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)

我需要的是通过最大值限制流。例如,如果我需要 1000 以下的所有 2 次幂

List<Integer> evens = IntStream.iterate(1, i -> i * 2)  //1, 2, 4, 8, 16, 32...
                               .limit(<here some how use the value 1000>)
                               .boxed()
                               .collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)

或斐波那契数列

List<Long> fibs = Stream.iterate(new long[]{1,1}, f -> new long[]{f[1], f[0] + f[1]})  //1,1,2,3,5,8,13,21...
                        .mapToLong(f -> f[1])
                        .limit(i -> i < 1000) //I know this doesn't work as limit …
Run Code Online (Sandbox Code Playgroud)

java java-stream

3
推荐指数
3
解决办法
89
查看次数

Java-Stream - 应用 Collector groupingBy 后将对象列表收集到一组字符串中

给定以下类OrderItem以及 s 的列表Order

@Getter
@AllArgsConstructor
@ToString
public class Order {
    String customerName;
    List<Item> items;
}

@Getter
@AllArgsConstructor
@ToString
@EqualsAndHashCode
public class Item {
    long id;
    String name;
}
Run Code Online (Sandbox Code Playgroud)

我需要创建一个映射Map<String,Set<String>> itemsByCustomerName,其中键是客户名称以及属于该客户名称Order的所有名称的一组名称。Item

输入示例:

List<Order> orders = List.of(
        new Order("John", List.of(new Item(1, "A"), new Item(2, "B"), new Item(3, "C"))),
        new Order("Alex", List.of(new Item(1, "A"), new Item(8, "H"), new Item(11, "K"))),
        new Order("John", List.of(new Item(1, "A"), new Item(6, "F"), new Item(7, "G"))),
        new …
Run Code Online (Sandbox Code Playgroud)

java java-stream collectors groupingby

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

Stream API 按名称区分,按值区分最大值

给出以下示例类:

class Foo{
    String name;
    int value;
    public Foo(String name, int value) {
        this.name = name;
        this.value = value;
    }
    // getters, setters, toString & equals
}
Run Code Online (Sandbox Code Playgroud)

和 foo 列表:

List<Foo> fooList = List.of(new Foo("A",1), new Foo("A",2),
                                new Foo("B",1),
                                new Foo("C",1),
                                new Foo("D",1), new Foo("D",2), new Foo("D",3)
                            );
Run Code Online (Sandbox Code Playgroud)

我想获得一份按名称区分的 foo 列表,如果有多个,Foos我想保留具有最高值的那个。

我发现这个java-8-distinct-by-property问题可以按名称获取不同列表的元素,它使用此方法来获取不同的元素:

public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
    Set<Object> seen = ConcurrentHashMap.newKeySet();
    return t -> seen.add(keyExtractor.apply(t));
}
Run Code Online (Sandbox Code Playgroud)

我这样使用它:

fooList.stream().filter(distinctByKey(Foo::getName)).collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)

它可以获取不同的元素,但如果有两个或多个同名元素,则保留列表中的第一个元素,并且我无法添加条件来保留具有最高值的元素。

另一种选择是使用分组依据:

Map<String,List<Foo>> …
Run Code Online (Sandbox Code Playgroud)

java java-stream

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

如何获取下一个n个星期五,即一个月中的第一个、第二个或第三个星期五?

我需要找到接下来的 n 个星期五,但想排除第 4 个和可能的第 5 个星期五,即我想得到接下来的 n 个星期五,即每月的第 1、第 2 或第 3 个星期五。我找到了一种在接下来的 n 个周五进行直播的方法(例如接下来的 10 个周五):

LocalDate now = LocalDate.now();
Stream.iterate(now , localDate -> localDate.with(TemporalAdjusters.next(DayOfWeek.FRIDAY)))
     .skip(1) // skip today 
     .limit(10)
     .forEach(System.out::println);
Run Code Online (Sandbox Code Playgroud)

输出:

2021-10-22
2021-10-29
2021-11-05
2021-11-12
2021-11-19
2021-11-26
2021-12-03
2021-12-10
2021-12-17
2021-12-24
Run Code Online (Sandbox Code Playgroud)

但我需要排除例如2021-10-22&2021-10-29因为它们是十月的第四个和第五个星期五。同样2021-11-262021-12-24因为它们不是第一个、第二个或第三个星期五。

我搜索了SO并找到了一些计算一个月第n个星期五的方法,例如这个

public static LocalDate nthFridayOfMonth(LocalDate localDate, int week) {
    return localDate.with(TemporalAdjusters.dayOfWeekInMonth(week, DayOfWeek.FRIDAY));
}
Run Code Online (Sandbox Code Playgroud)

返回给定日期第 n 个星期五。

如何修改此方法,以便在给定的 LocalDate 是一个月的第一个、第二个或第三个星期五时返回布尔值?或者使用这个方法来实现另一个满足我需要的方法?

理想情况下,我想使用上面的流并使用一个方法,该方法返回一个布尔值作为过滤器:

LocalDate now = LocalDate.now();
Stream.iterate(now , localDate …
Run Code Online (Sandbox Code Playgroud)

java date-manipulation localdate

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

pom中添加的依赖无法解析

我正在尝试向我的 pom.xml 添加依赖项并面临问题:IntelliJ 错误

无法解析 jfugue:jfugue:5.0.9

我想添加的依赖项是下面的https://mvnrepository.com/artifact/jfugue/jfugue/5.0.9

<!-- https://mvnrepository.com/artifact/jfugue/jfugue -->
<dependency>
    <groupId>jfugue</groupId>
    <artifactId>jfugue</artifactId>
    <version>5.0.9</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

只需将 Maven 中的 xml-snippet 添加到我的 pom 中并刷新或重新加载所有 Maven 项目,添加其他依赖项就没有问题。例如,我在同一个 pom 中具有此依赖项,该 pom 工作正常:

<!-- https://mvnrepository.com/artifact/org.jsoup/jsoup -->
<dependency>
    <groupId>org.jsoup</groupId>
    <artifactId>jsoup</artifactId>
    <version>1.14.3</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

但是,片段下方有一条注释,可以复制粘贴,https://mvnrepository.com/artifact/jfugue/jfugue/5.0.9

注意:此工件位于 SingGroup 存储库 ( https://maven.sing-group.org/repository/maven/ )

我需要在 pom 中添加什么,以便我可以在我的项目中使用该依赖项并消除错误?

无法解析 jfugue:jfugue:5.0.9

提前致谢。

java jfugue maven

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