accessor name convention
[fedora-idea.git] / platform / util / src / com / intellij / openapi / util / Pair.java
blobd9e61c5b4e0f1f12b7eaa602fb0198c16edaca95
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.openapi.util;
18 import java.util.Arrays;
21 /**
24 public class Pair<A, B> {
25 public final A first;
26 public final B second;
28 public Pair(A first, B second) {
29 this.first = first;
30 this.second = second;
33 public final A getFirst() {
34 return first;
37 public final B getSecond() {
38 return second;
41 public static <A, B> Pair<A, B> create(A first, B second) {
42 return new Pair<A,B>(first, second);
45 public final boolean equals(Object o){
46 return o instanceof Pair && Comparing.equal(first, ((Pair)o).first) && Comparing.equal(second, ((Pair)o).second);
49 public final int hashCode(){
50 int hashCode = 0;
51 if (first != null){
52 hashCode += hashCode(first);
54 if (second != null){
55 hashCode += hashCode(second);
57 return hashCode;
60 private static int hashCode(final Object o) {
61 return (o instanceof Object[]) ? Arrays.hashCode((Object[])o) : o.hashCode();
64 public String toString() {
65 return "<" + first + "," + second + ">";