「getFirst()」と「getSecond()」という 2 つのメソッドを使用する IntPair クラスがあります。このメソッドで現在作業している間、「hashMap j」に特定の値が含まれているかどうかを確認してから、アクションを実行したいと考えています。私はこれらの行に問題があると思います:
Object obj = j.values();
t.moveCursor(((IntPair)obj).getFirst(), ((IntPair)obj).getSecond());
オブジェクトに問題なくキャストしているかどうか、または最初の行「Object obj = j.values()」を別のメソッド呼び出しに置き換える必要があるかどうかはわかりません。j.containsValue("0") の後に System.out.print ("Message") でテストしたところ、メッセージが返されました。
これは、私がそれを機能させようとしている方法の一部です。
public static HashMap<IntPair, String> j = new HashMap<>();
j.put(new IntPair(firstInt, secondInt), value);
if (j.containsValue("0"))
{
Object obj = j.values();
t.moveCursor(((IntPair)obj).getFirst(), ((IntPair)obj).getSecond());
t.putCharacter('x');
}
else if (j.containsValue("1"))
{
Object obj = j.values();
t.moveCursor(((IntPair)obj).getFirst(), ((IntPair)obj).getSecond());
t.putCharacter('v');
}
IntPair クラス:
public class IntPair {
private final int first;
private final int second;
public IntPair(int first, int second) {
this.first = first;
this.second = second;
}
@Override
public int hashCode() {
int hash = 3;
hash = 89 * hash + this.first;
hash = 89 * hash + this.second;
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final IntPair other = (IntPair) obj;
if (this.first != other.first) {
return false;
}
if (this.second != other.second) {
return false;
}
return true;
}
public int getFirst() {
return first;
}
public int getSecond() {
return second;
}
}
どんな助けでも本当に感謝しています。ありがとうございました!