java - TIntProcedure 无法解析

标签 java jar

我正在尝试使用 Java Spatial Index Library ,但无法获取 examples加载。

当我尝试在 Eclipse Kepler 中打开示例中的以下文件时,Eclipse 提示 TIntProcedure 无法解析:

package net.sourceforge.jsi.examples;

import gnu.trove.*;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.infomatiq.jsi.Rectangle;
import com.infomatiq.jsi.SpatialIndex;
import com.infomatiq.jsi.rtree.RTree;

public class Contains {
  private static final Logger log = LoggerFactory.getLogger(Contains.class);

  public static void main(String[] args) {
    new Contains().run();
  }

  private void run() {
    // Create and initialize an rtree
    SpatialIndex si = new RTree();
    si.init(null);

    // We have some points or rectangles in some other data structure.
    // The rtree can handle millions of these.
    Rectangle[] rects = new Rectangle[] {
        new Rectangle(0, 0, 0, 0),
        new Rectangle(0, 1, 0, 1),
        new Rectangle(1, 0, 1, 0),
        new Rectangle(1, 1, 1, 1),
    };

    // Add our data to the rtree. Every time we add a rectangle we give it
    // an ID. This ID is what is returned by querying the rtree. In this 
    // example we use the array index as the ID.
    for (int i = 0; i < rects.length; i++) {
      si.add(rects[i], i);
    }

    // Now see which of these points is contained by some
    // other rectangle. The rtree returns the results of a query
    // by calling the execute() method on a TIntProcedure.
    // In this example we want to save the results of the query 
    // into a list, so that's what the execute() method does.
    class SaveToListProcedure implements TIntProcedure {
      private List<Integer> ids = new ArrayList<Integer>();

      @Override
      public boolean execute(int id) {
        ids.add(id);
        return true;
      }; 

      private List<Integer> getIds() {
        return ids;
      }
    };

    SaveToListProcedure myProc = new SaveToListProcedure();
    si.contains(new Rectangle(-0.5f, -0.5f, 1.5f, 0.5f), myProc);

    List<Integer> ids = myProc.getIds();

    for (Integer id : ids) {
      log.info(rects[id].toString() + " was contained");
    }

    // Actually that was a really long winded (and inefficient) way of 
    // printing out the rectangles. Would be better to use an anonymous
    // class to just do the printing inside the execute method. That is
    // what the NearestN class does.
  }
}

TIntProcedure 似乎来自 gnu trove包,但 TIntProcedure 接口(interface)实际上是在 gnu.trove.procedure 中定义的,而不是在 gnu.trove 中定义的。

我使用了错误的TIntProcedure吗? Eclipse 可以很好地处理 SaveToListProcedure 的声明,但在 si.contains(new Rectangle(-0.5f, -0.5f, 1.5f, 0.5f), myProc) 行显示警告。无论如何,我尝试运行该项目,只是为了看看 Eclipse 是否抛出了错误错误,但它出错了:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

    at net.sourceforge.jsi.examples.Contains.main(Contains.java:18)

第 18 行是定义 main 的地方。

最佳答案

JSI 使用的是 Trove 2.0.2。他们直到 3.x 才将 TIntProcedure 移入该包中。降级软件包对我来说确实有效。

关于java - TIntProcedure 无法解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21293856/

相关文章:

java - 使用 .java 文件的路径和外部 jar 的路径在 linux 中编译和运行 java 程序

jar - 如何在war文件中列出jar文件的内容

java - ResourcePool 无法从其主要工厂或来源获取资源

java - 对于给定的一大组数据的操作,有没有办法确定数据是否可以分解为mapreduce操作?

version - 我需要安装JRE8吗

gradle - Gradle插件输出名称

java - 运行 jwsc ant 任务所需的 WebLogic 12.2.1 jar 文件

android - 我可以使用任何 jar 文件从 Twitter 获取个人资料信息吗?

java - Collectors.groupingBy 基于嵌套静态类属性

java - 尝试访问 websocket 时出现错误 404