Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2014 Red Hat, Inc., and individual contributors
   * as indicated by the @author tags.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.jboss.marshalling;
 
A serializable pair of values. There is also a specified externalizer as well, to support more efficient I/O.

Parameters:
<A> the first value type
<B> the second value type
Apiviz.exclude:
 
 public final class Pair<A, B> implements Serializable {
 
     private static final long serialVersionUID = 7331975617882473974L;
 
     private final A a;
     private final B b;
     @SuppressWarnings({ "InstanceVariableMayNotBeInitializedByReadObject" })
     private final transient int hashCode;
 
     private static final FieldSetter setter = FieldSetter.get(Pair.class"hashCode");

    
Create a new instance.

Parameters:
a the first value
b the second value
 
     public Pair(final A afinal B b) {
         this. = a;
         this. = b;
          = hashCode(ab);
     }

    
Calculate the combined hash code of two objects.

Parameters:
a the first object
b the second object
Returns:
the combined hash code
 
     private static int hashCode(final Object afinal Object b) {
         return (a == null ? 0 : a.hashCode()) * 1319 + (b == null ? 0 : b.hashCode());
     }

    
Get the first value.

Returns:
the first value
 
     public A getA() {
         return ;
     }

    
Get the second value.

Returns:
the second value
 
     public B getB() {
         return ;
     }

    
Reinitialize the object and set the hash code.

Parameters:
ois the object input stream
Throws:
java.io.IOException if an I/O error occurs while reading the default fields
java.lang.ClassNotFoundException if a class isn't found while reading the default fields
 
     private void readObject(ObjectInputStream oisthrows IOExceptionClassNotFoundException {
         ois.defaultReadObject();
         .setInt(thishashCode());
     }

    
Return the combined hash code of the two argument objects.

Returns:
the combined hash code
    public int hashCode() {
        return ;
    }

    
Determine if this pair equals another. A pair is equal to another pair if both members are equal.

Parameters:
other the other pair
Returns:
true if they are equal, false otherwise
    public boolean equals(final Object other) {
        return (other instanceof Pair) ? equals((Pairother) : false;
    }

    
Determine if this pair equals another. A pair is equal to another pair if both members are equal.

Parameters:
other the other pair
Returns:
true if they are equal, false otherwise
    public boolean equals(final Pair<?, ?> other) {
        if (other == null) {
            return false;
        }
        final Object a = this.;
        final Object othera = other.a;
        final Object b = this.;
        final Object otherb = other.b;
        return (a == othera || a != null && a.equals(othera)) &&
                (b == otherb || b != null && b.equals(otherb));
    }

    
Get a string representation of this pair.

Returns:
the string representation
    public String toString() {
        final StringBuilder builder = new StringBuilder();
        builder.append("Pair (").append().append(", ").append().append(')');
        return builder.toString();
    }

    
Create a new instance.

Parameters:
a the first value
b the second value
<A> the first value type
<B> the second value type
Returns:
the new instance
    public static <A, B> Pair<A, B> create(A a, B b) {
        return new Pair<A, B>(ab);
    }

    
An externalizer for Pair instances.

Apiviz.exclude:
    public static final class Externalizer implements org.jboss.marshalling.ExternalizerExternalizable {
        private static final long serialVersionUID = 930391108343329811L;
        private static final Externalizer instance = new Externalizer();

        
Get the single instance. Though multiple instances can be created using the public constructor, only a single instance need be used in practice since this class maintains no internal state.

Returns:
the instance
        public static Externalizer getInstance() {
            return ;
        }

        
        public void writeExternal(final Object subjectfinal ObjectOutput outputthrows IOException {
            output.writeObject(((Pair<?, ?>)subject).);
            output.writeObject(((Pair<?, ?>)subject).);
        }

        
        public Object createExternal(final Class<?> subjectTypefinal ObjectInput inputfinal Creator defaultCreatorthrows IOExceptionClassNotFoundException {
            return create(input.readObject(), input.readObject());
        }

        
        public void readExternal(final Object subjectfinal ObjectInput input) {
        }

        
        public void writeExternal(final ObjectOutput out) {
        }

        
        public void readExternal(final ObjectInput in) {
        }

        
Resolve the object to the single externalizer instance.

Returns:
the instance
        protected Object readResolve() {
            return ;
        }
    }
New to GrepCode? Check out our FAQ X