2014-09-25 45 views
-3

Node Graph有關節點地圖

我正在尋找像列表中,設置,地圖中收集了一個框架,可以製作像PIC顯示的數據模型的Java框架。而從一個到另一個提供搜索算法像搜索距離。統計節點數量等等。 我在谷歌上搜索類似「Java節點地圖庫」或「節點圖框架」,我無法找到任何結果。有沒有什麼建議。非常感謝你。

回答

0

您需要在Java中實現的圖形。 檢查:http://jgrapht.org/

+0

尼斯之一。但我尋找的東西像我可以用我自己的POJO。像新的節點();然後將該對象添加到地圖中。就像Java Collections API – 2014-09-25 03:57:32

-3

我終於找到了解決方案只能實現自己這個樣子。

import java.util.HashMap; 

/** This class holds many to many associations between two classes. */ 
public class AssociationHolder<LeftClass, RightClass, AssociationClass> { 

    // ------------------------------------------------------- 
    // Attributes 
    // ------------------------------------------------------- 

    private HashMap<LeftClass, HashMap<RightClass, AssociationClass>> associationsLeft = 
     new HashMap<LeftClass, HashMap<RightClass,AssociationClass>>(); 
    private HashMap<RightClass, HashMap<LeftClass, AssociationClass>> associationsRight = 
     new HashMap<RightClass, HashMap<LeftClass,AssociationClass>>();  

    // ------------------------------------------------------- 
    // Methods 
    // ------------------------------------------------------- 

    /** 
    * Set an association between two instance. 
    * Any prior association is overwritten. 
    */ 
    public void setAssociation(LeftClass left, RightClass right, AssociationClass association) { 

     // Get the map for the left 
     HashMap<RightClass, AssociationClass> leftMap = this.associationsLeft.get(left); 

     // No association defined yet for this left key ? => Create new map 
     if (leftMap == null) { 
      leftMap = new HashMap<RightClass, AssociationClass>(); 
      this.associationsLeft.put(left, leftMap); 
     } 

     // Get the map for the right 
     HashMap<LeftClass, AssociationClass> rightMap = this.associationsRight.get(right); 

     // No association defined yet for this right key ? => Create new map 
     if (rightMap == null) { 
      rightMap = new HashMap<LeftClass, AssociationClass>(); 
      this.associationsRight.put(right, rightMap); 
     } 

     // Set the assoication on both maps 
     leftMap.put(right, association); 
     rightMap.put(left, association);   

    } 

    /** @return null if no association found. */ 
    public AssociationClass getAssociation(LeftClass left, RightClass right) { 

     // Use left maps (could have used the right one as well) 
     HashMap<RightClass, AssociationClass> leftMap = this.associationsLeft.get(left); 
     if (leftMap == null) return null; 
     return leftMap.get(right); 
    } 

    /** Get all associations defined for a given Left instance. */ 
    public HashMap<RightClass, AssociationClass> getAssociationsLeft(LeftClass left) { 

     HashMap<RightClass, AssociationClass> leftMap = this.associationsLeft.get(left); 

     // No map defined ? return empty one instead of null 
     if (leftMap == null) { 
      return new HashMap<RightClass, AssociationClass>(); 
     } else { 
      return leftMap; 
     } 
    } 

    /** Get all associations defined for a given Right instance. */ 
    public HashMap<LeftClass, AssociationClass> getAssociationsRight(RightClass right) { 

     HashMap<LeftClass, AssociationClass> rightMap = this.associationsRight.get(right); 

     // No map defined ? return empty one instead of null 
     if (rightMap == null) { 
      return new HashMap<LeftClass, AssociationClass>(); 
     } else { 
      return rightMap; 
     } 
    } 

    /** 
    * Remove an association between two instances. 
    */ 
    public void removeAssociation(LeftClass left, RightClass right) { 
     HashMap<RightClass, AssociationClass> leftMap = this.getAssociationsLeft(left); 
     HashMap<LeftClass, AssociationClass> rightMap = this.getAssociationsRight(right); 
     leftMap.remove(right);  
     rightMap.remove(left); 
    } 
} 
+0

雖然這個鏈接可能回答這個問題,但最好在這裏包含答案的重要部分,並提供供參考的鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 – Barranka 2014-09-25 05:15:43

+0

感謝的建議。我在搜索後更新我的答案。仍然無法找到一個庫。 – 2014-09-25 05:31:36