pair.java

来自「GJC编译器的源代码。是一个开放源代码的工业级编译器。」· Java 代码 · 共 41 行

JAVA
41
字号
/**
 * @(#)Pair.java	1.10 03/01/23
 *
 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.sun.tools.javac.v8.util;

/**
 * A generic class for pairs.
 */
public class Pair {
    public final Object fst;
    public final Object snd;

    public Pair(Object fst, Object snd) {
        super();
        this.fst = fst;
        this.snd = snd;
    }

    private static boolean equals(Object x, Object y) {
        return (x == null && y == null) || (x != null && x.equals(y));
    }

    public boolean equals(Object other) {
        return other instanceof Pair && equals(fst, ((Pair) other).fst) &&
                equals(snd, ((Pair) other).snd);
    }

    public int hashCode() {
        if (fst == null)
            return snd.hashCode() + 1;
        else if (snd == null)
            return fst.hashCode() + 2;
        else
            return fst.hashCode() * snd.hashCode();
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?