iText 7 7.1.8 API
iText.IO.Util.HashCode Class Reference

This class is a convenience method to sequentially calculate hash code of the object based on the field values. More...

Public Member Functions

sealed override int  GetHashCode ()
  Returns accumulated hashCode More...
 
HashCode  Append (int value)
  Appends value's hashCode to the current hashCode. More...
 
HashCode  Append (long value)
  Appends value's hashCode to the current hashCode. More...
 
HashCode  Append (float value)
  Appends value's hashCode to the current hashCode. More...
 
HashCode  Append (double value)
  Appends value's hashCode to the current hashCode. More...
 
HashCode  Append (bool value)
  Appends value's hashCode to the current hashCode. More...
 
HashCode  Append (Object value)
  Appends value's hashCode to the current hashCode. More...
 

Static Public Member Functions

static int  Combine (int hashCode, bool value)
  Combines hashCode of previous elements sequence and value's hashCode. More...
 
static int  Combine (int hashCode, long value)
  Combines hashCode of previous elements sequence and value's hashCode. More...
 
static int  Combine (int hashCode, float value)
  Combines hashCode of previous elements sequence and value's hashCode. More...
 
static int  Combine (int hashCode, double value)
  Combines hashCode of previous elements sequence and value's hashCode. More...
 
static int  Combine (int hashCode, Object value)
  Combines hashCode of previous elements sequence and value's hashCode. More...
 
static int  Combine (int hashCode, int value)
  Combines hashCode of previous elements sequence and value's hashCode. More...
 

Static Public Attributes

const int  EMPTY_HASH_CODE = 1
  The hashCode value before any data is appended, equals to 1. More...
 

Detailed Description

This class is a convenience method to sequentially calculate hash code of the object based on the field values.

This class is a convenience method to sequentially calculate hash code of the object based on the field values. The result depends on the order of elements appended. The exact formula is the same as for System.Collections.IList.GetHashCode()If you need order independent hash code just summate, multiply or XOR all elements.

Suppose we have class:

      
      
      
      
      
class Thing {
long id;
String name;
float weight;
}

The hash code calculation can be expressed in 2 forms.

For maximum performance:

      
      
      
      
      
public int hashCode() {
int hashCode = HashCode.EMPTY_HASH_CODE;
hashCode = HashCode.combine(hashCode, id);
hashCode = HashCode.combine(hashCode, name);
hashCode = HashCode.combine(hashCode, weight);
return hashCode;
}

For convenience:

      
      
      
      
      
public int hashCode() {
return new HashCode().append(id).append(name).append(weight).hashCode();
}
See also
System.Collections.IList.GetHashCode()

Member Function Documentation

◆ Append() [1/6]

HashCode iText.IO.Util.HashCode.Append ( bool  value )
inline

Appends value's hashCode to the current hashCode.

Parameters
value new element
Returns
this

◆ Append() [2/6]

HashCode iText.IO.Util.HashCode.Append ( double  value )
inline

Appends value's hashCode to the current hashCode.

Parameters
value new element
Returns
this

◆ Append() [3/6]

HashCode iText.IO.Util.HashCode.Append ( float  value )
inline

Appends value's hashCode to the current hashCode.

Parameters
value new element
Returns
this

◆ Append() [4/6]

HashCode iText.IO.Util.HashCode.Append ( int  value )
inline

Appends value's hashCode to the current hashCode.

Parameters
value new element
Returns
this

◆ Append() [5/6]

HashCode iText.IO.Util.HashCode.Append ( long  value )
inline

Appends value's hashCode to the current hashCode.

Parameters
value new element
Returns
this

◆ Append() [6/6]

HashCode iText.IO.Util.HashCode.Append ( Object  value )
inline

Appends value's hashCode to the current hashCode.

Parameters
value new element
Returns
this

◆ Combine() [1/6]

static int iText.IO.Util.HashCode.Combine ( int  hashCode,
bool  value 
)
inlinestatic

Combines hashCode of previous elements sequence and value's hashCode.

Parameters
hashCode previous hashCode value
value new element
Returns
combined hashCode

◆ Combine() [2/6]

static int iText.IO.Util.HashCode.Combine ( int  hashCode,
double  value 
)
inlinestatic

Combines hashCode of previous elements sequence and value's hashCode.

Parameters
hashCode previous hashCode value
value new element
Returns
combined hashCode

◆ Combine() [3/6]

static int iText.IO.Util.HashCode.Combine ( int  hashCode,
float  value 
)
inlinestatic

Combines hashCode of previous elements sequence and value's hashCode.

Parameters
hashCode previous hashCode value
value new element
Returns
combined hashCode

◆ Combine() [4/6]

static int iText.IO.Util.HashCode.Combine ( int  hashCode,
int  value 
)
inlinestatic

Combines hashCode of previous elements sequence and value's hashCode.

Parameters
hashCode previous hashCode value
value new element
Returns
combined hashCode

◆ Combine() [5/6]

static int iText.IO.Util.HashCode.Combine ( int  hashCode,
long  value 
)
inlinestatic

Combines hashCode of previous elements sequence and value's hashCode.

Parameters
hashCode previous hashCode value
value new element
Returns
combined hashCode

◆ Combine() [6/6]

static int iText.IO.Util.HashCode.Combine ( int  hashCode,
Object  value 
)
inlinestatic

Combines hashCode of previous elements sequence and value's hashCode.

Parameters
hashCode previous hashCode value
value new element
Returns
combined hashCode

◆ GetHashCode()

sealed override int iText.IO.Util.HashCode.GetHashCode ( )
inline

Returns accumulated hashCode

Member Data Documentation

◆ EMPTY_HASH_CODE

const int iText.IO.Util.HashCode.EMPTY_HASH_CODE = 1
static

The hashCode value before any data is appended, equals to 1.

See also
System.Collections.IList.GetHashCode()