2015-11-26 36 views
-3

我正在嘗試修改此類以包含下一個引用的額外字段。有任何想法嗎?爲下一個引用添加額外字段

package project2; 

public interface Entry<K,V> { 
K getKey(); 
V getValue(); 
} 

我想修改chainhashmap做與散列映射相同的行爲。

+2

目前還不清楚究竟是什麼問題。 [問] –

+0

你是指下一個條目的字段嗎?可能是這樣的: 'Entry getNextEntry()' – uzilan

+0

我正在開發一個字頻率計數器到最後,我有一個引用「下一步」我試圖在上面的類中修改,以包含一個額外的字段。 – nychancer

回答

0

不知道你到底在問什麼,但這可能會有幫助。

public final class Pair<L, R> { 

    private L left; 
    private R right; 

    public Pair() { 
     this(null, null); 
    } 

    public Pair(L initLeft, R initRight) { 
     left = initLeft; 
     right = initRight; 
    } 

    public synchronized L getLeft() { 
     return left; 
    } 

    public synchronized R getRight() { 
     return right; 
    } 

    public synchronized void setLeft(L newLeft) { 
     left = newLeft; 
    } 

    public synchronized void setRight(R newRight) { 
     right = newRight; 
    } 

    @Override 
    public synchronized boolean equals(Object other) { 
     if (other == null) 
      return false; 
     if (other instanceof Pair) { 
      Pair<?, ?> otherPair = (Pair<?, ?>) other; 
      return ((this.left == otherPair.left 
        || (this.left != null && otherPair.left != null && this.left.equals(otherPair.left))) 
        && (this.right == otherPair.right 
          || (this.right != null && otherPair.right != null && this.right.equals(otherPair.right)))); 
     } 
     return false; 
    } 

    @Override 
    public synchronized String toString() { 
     return "(" + left.toString() + "," + right.toString() + ")"; 
    } 

} 

您可以在映射條目使用Pair作爲值與left爲實際值和right作爲next值ü要

相關問題