小编Wic*_*cia的帖子

Java Reactor - 条件流执行

我想知道如何使用 Reactor 创建“逻辑流”。

让我们假设我想实现以下场景:

作为输入,我有对象要保存在数据库中。作为输出,我想获得 Mono 表示执行消息。

  • 选项 1: 如果要保存的对象已填充所有字段,则我执行附加操作,将其保存到数据库并最终返回“ Success”消息

  • 选项 2:如果要保存的对象至少有一个字段未填写,我返回“ Error

我已经创建了这样的代码:

Mono<String> message = Mono.just(new User("Bob the Reactor master")) // user with name = can be saved
    .flatMap(user -> {
        if(user.getName() != null && user.getName().length() > 1){
            // Perform additional operations e.g. user.setCreatedDate(new Date())
            // Save to repository e.g. repository.save(user)
            return Mono.just("Success!");
        }
        else{
            return Mono.just("Error!");
        }
    })
    .doOnNext(System.out::println); // print stream result

message.subscribe();
Run Code Online (Sandbox Code Playgroud)

这段代码是 100% 反应性的吗(有它的所有好处)?如果没有,那么它会是什么样子?

java reactive-programming project-reactor

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

JavaFX:如何绑定两个值?

我是这里的新人:)

我有一个小问题,涉及JavaFX中的绑定.我创建了一个作为时钟工作的Task,并返回必须在特殊标签(label_Time)中设置的值.此标签显示了测验中玩家回答的剩余时间.

问题是如何使用计时器任务自动更改标签中的值?我尝试以这种方式将来自计时器任务()的值链接到label_Time值...

label_Time.textProperty().bind(timer.getSeconds());
Run Code Online (Sandbox Code Playgroud)

......但它不起作用.做这件事有什么办法吗?

在此先感谢您的回答!:)


Controller类中的Initialize方法:

public void initialize(URL url, ResourceBundle rb) {

        Timer2 timer = new Timer2();
        label_Time.textProperty().bind(timer.getSeconds());
        new Thread(timer).start();  
}
Run Code Online (Sandbox Code Playgroud)

任务类"Timer2":

public class Timer2 extends Task{

    private static final int SLEEP_TIME = 1000;
    private static int sec;
    private StringProperty seconds;


    public Timer2(){
        Timer2.sec = 180;
        this.seconds = new SimpleStringProperty("180");
    }

    @Override protected StringProperty call() throws Exception {


        int iterations;

        for (iterations = 0; iterations < 1000; iterations++) {
            if (isCancelled()) {
                updateMessage("Cancelled"); …
Run Code Online (Sandbox Code Playgroud)

binding multithreading bind task javafx-2

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

jOOQ - 方法调用

我有关于在以下示例jOOQ语句中调用方法count()的问题:

create.select(AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME, count())
      .from(AUTHOR)
      .join(BOOK).on(AUTHOR.ID.equal(BOOK.AUTHOR_ID))
      .where(BOOK.LANGUAGE.eq("DE"))
      .and(BOOK.PUBLISHED.gt(date("2008-01-01")))
      .groupBy(AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME)
      .having(count().gt(5))
      .orderBy(AUTHOR.LAST_NAME.asc().nullsFirst())
      .limit(2)
      .offset(1)
      .forUpdate()
      .of(AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME)
Run Code Online (Sandbox Code Playgroud)

我试图创建这样的机制来调用方法而不使用对象/类引用,但我放弃了.它真的有可能实现吗?

感谢帮助.

Wicia

java sql methods invoke jooq

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

ProGuard-意外包含类

当我尝试在ProGuard中混淆简单的DataLoader.class文件时,出现此错误:

Reading program directory [C:\Users\uzytkownik\Documents\NetBeansProjects\ProTest\build\classes\Files\DataLoader.class]
Warning: class [DataLoader.class] unexpectedly contains class [Files.DataLoader]
Warning: there were 1 classes in incorrectly named files.
         You should make sure all file names correspond to their class names.
         The directory hierarchies must correspond to the package hierarchies.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unexpectedclass)
         If you don't mind the mentioned classes not being written out,
         you could try your luck using the '-ignorewarnings' option.
Please correct the above warnings first.
Run Code Online (Sandbox Code Playgroud)

这是项目:http : //www49.zippyshare.com/v/14668241/file.html

感谢您的帮助。

obfuscation warnings class proguard

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

如何获取.class文件的包名?

我有一个不寻常的问题,涉及在运行时动态加载java .class文件.我想要做的就是加载.class文件并在其基础上创建一个Class对象.

输入:.class文件的绝对路径.

基于它我想通过ClassLoader加载类,所以我需要一个文件所在的根目录路径和完整的类名,例如com.test.MyClass.基于提到的绝对路径,我只能得到一个类名,但我不能得到这个文件中"hiden"的包名.

这是我的"加载类方法"的代码:

    public static void loadClass(String directory){

        // Get file root directory
        String rootDirectory = new File(directory).getParent();

        // Get rid of file extension
        String className = getFileNameWithoutExtension(directory);

        URL[] urls = null;
        ClassLoader cl = null;

        try {
            // Convert File to a URL and save them
            urls = new URL[]{new File(rootDirectory).toURI().toURL()};

            // Create a new class loader with the directory
            cl = new URLClassLoader(urls);

            // Load in the class
            dynamicClass = cl.loadClass(className);
        } 
        catch (MalformedURLException e) 
        { …
Run Code Online (Sandbox Code Playgroud)

java reflection runtime class package

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