Generic Pair : Generic Collection « Generics « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JDK 6
25.JNDI LDAP
26.JPA
27.JSP
28.JSTL
29.Language Basics
30.Network Protocol
31.PDF RTF
32.Reflection
33.Regular Expressions
34.Scripting
35.Security
36.Servlets
37.Spring
38.Swing Components
39.Swing JFC
40.SWT JFace Eclipse
41.Threads
42.Tiny Application
43.Velocity
44.Web Services SOA
45.XML
Java » Generics » Generic CollectionScreenshots 
Generic Pair
      

/**
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
//package org.cspoker.common.util;

public class Pair<L,R> {

  private final L left;
  private final R right;
  
  public Pair(L left, R right) {
    if(left==null){
      throw new IllegalArgumentException("Left value is not effective.");
    }
    if(right==null){
      throw new IllegalArgumentException("Right value is not effective.");
    }
    this.left =left;
    this.right = right;
  }
  
  public L getLeft() {
    return this.left;
  }
  
  public R getRight() {
    return this.right;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((left == null: left.hashCode());
    result = prime * result + ((right == null: right.hashCode());
    return result;
  }

  @SuppressWarnings("unchecked")
  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (!(obj instanceof Pair))
      return false;
    Pair<Object, Object> other = (Pair<Object, Object>obj;
    if (left == null) {
      if (other.left != null)
        return false;
    else if (!left.equals(other.left))
      return false;
    if (right == null) {
      if (other.right != null)
        return false;
    else if (!right.equals(other.right))
      return false;
    return true;
  }
  
  @Override
  public String toString() {
    return "<"+left.toString()+","+right.toString()+">";
  }
  
}

   
    
    
    
    
    
  
Related examples in the same category
1.Creating a Type-Specific List
2.A list declared to hold objects of a type T can also hold objects that extend from T.
3.A value retrieved from a type-specific list does not need to be casted
4.Generic ArrayListGeneric ArrayList
5.Generic Data Structure
6.Unchecked Example
7.Generic StackGeneric Stack
8.Enum and GenericEnum and Generic
9.Generic HashMapGeneric HashMap
10.Foreach and generic data structureForeach and generic data structure
11.Pre generics example that uses a collection.Pre generics example that uses a collection.
12.Data structure and collections: Modern, generics version.Data structure and collections: Modern, generics version.
13.Java generic: Generics and arrays.
14.Collections and Data structure: the generic wayCollections and Data structure: the generic way
15.The GenStack Class
16.Create a typesafe copy of a raw set.
17.Create a typesafe copy of a raw list.
18.Create a typesafe copy of a raw map.
19.Create a typesafe filter of an unchecked iterator.
20.Create a typesafe view over an underlying raw set.
21.Create a typesafe view over an underlying raw map.
22.Create a typesafe filter of an unchecked enumeration.
23.Circular Object Buffer
24.A collection that do not hold stored elements in memory, but serialize it into a file
25.Generic Triple structure
26.A generic bag of properties used to store properties that apply to a specific target.
27.Pool container
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.