001/*
002 * Copyright (C) 2009-2011 Mathias Doenitz
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.parboiled.common;
018
019public final class Tuple2<A, B> {
020    public final A a;
021    public final B b;
022
023    public Tuple2(A a, B b) {
024        this.a = a;
025        this.b = b;
026    }
027
028    @Override
029    public boolean equals(Object o) {
030        if (this == o) return true;
031        if (!(o instanceof Tuple2)) return false;
032        Tuple2 tuple2 = (Tuple2) o;
033        return
034                (a != null ? a.equals(tuple2.a) : tuple2.a == null) &&
035                (b != null ? b.equals(tuple2.b) : tuple2.b == null);
036    }
037
038    @Override
039    public int hashCode() {
040        int result = a != null ? a.hashCode() : 0;
041        result = 31 * result + (b != null ? b.hashCode() : 0);
042        return result;
043    }
044
045    @Override
046    public String toString() {
047        return "Tuple2{a=" + a + ", b=" + b + '}';
048    }
049}