2014-01-22 94 views
0

我試圖使用Java Spatial Index Library,但無法加載examplesTIntProcedure無法解析

當我嘗試打開以下文件,從例子中,在Eclipse開普勒,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接口實際上在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定義。

回答

2

JSI正在使用Trove 2.0.2。直到3.x,他們纔將TIntProcedure移入該軟件包。降級包明確爲我工作。

+0

對不起,我錯過了你的答案。謝謝您的幫助! –

0

如果你不是用maven構建的,那麼你現在需要使用trove4j版本2.0.2。下一個版本的JSI(版本1.1)將取決於庫3.0.3(主分支剛剛更新)。

還要注意,用於運行JSI例子詳細說明,在我的答案都可以對這個問題:R tree library + how to run

ALED。